Implements support for functions with the same name, but different parameters
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,24 +4,63 @@
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
#include "../../ScriptType.hpp"
|
||||
#include "EvalValue.hpp"
|
||||
#include "../../Binder/BoundStatements/BoundStatement.hpp"
|
||||
#include "../EvaluationScope/EvaluationScope.hpp"
|
||||
#include "../../FunctionScriptType.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
class GenericFunctionOption{
|
||||
public:
|
||||
virtual ~GenericFunctionOption() = default;
|
||||
};
|
||||
|
||||
class EvaluationScriptFunctionOption : public GenericFunctionOption{
|
||||
const std::shared_ptr<BoundBlockStatement> _innerBlock;
|
||||
const std::shared_ptr<EvaluationScope> _scope;
|
||||
|
||||
public:
|
||||
EvaluationScriptFunctionOption(const shared_ptr<BoundBlockStatement> innerBlock, const shared_ptr<EvaluationScope> scope)
|
||||
: _innerBlock(innerBlock), _scope(scope) {
|
||||
|
||||
}
|
||||
|
||||
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
|
||||
return _innerBlock;
|
||||
}
|
||||
|
||||
const std::shared_ptr<EvaluationScope> &GetScope() const {
|
||||
return _scope;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class GenericFunctionEvalValue : public EvalValue{
|
||||
protected:
|
||||
const std::shared_ptr<GenericFunctionScriptType> _type;
|
||||
const std::size_t _hash;
|
||||
|
||||
std::vector<shared_ptr<GenericFunctionOption>> _options;
|
||||
public:
|
||||
GenericFunctionEvalValue(shared_ptr<GenericFunctionScriptType> type, size_t hash)
|
||||
: _type(move(type)),
|
||||
_hash(hash){
|
||||
}
|
||||
|
||||
const shared_ptr<EvalValue> Clone() const final {
|
||||
auto t = make_shared<GenericFunctionEvalValue>(_type, _hash);
|
||||
for (const auto& o: _options){
|
||||
t->_options.push_back(o);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void RegisterOption(GenericFunctionOption* option){
|
||||
_options.push_back(shared_ptr<GenericFunctionOption>(option));
|
||||
}
|
||||
|
||||
const std::shared_ptr<ScriptType> GetType() const {
|
||||
@@ -41,42 +80,9 @@ namespace Porygon::Evaluation {
|
||||
const std::size_t GetHashCode() const final {
|
||||
return _hash;
|
||||
}
|
||||
};
|
||||
|
||||
class ScriptFunctionEvalValue : public GenericFunctionEvalValue {
|
||||
const std::shared_ptr<BoundBlockStatement> _innerBlock;
|
||||
const std::shared_ptr<EvaluationScope> _scope;
|
||||
|
||||
explicit ScriptFunctionEvalValue(shared_ptr<BoundBlockStatement> innerBlock,
|
||||
shared_ptr<EvaluationScope> scope,
|
||||
shared_ptr<FunctionScriptType> type, size_t hash)
|
||||
: GenericFunctionEvalValue(move(type), hash),
|
||||
_innerBlock(std::move(innerBlock)),
|
||||
_scope(std::move(scope)){
|
||||
}
|
||||
|
||||
public:
|
||||
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock,
|
||||
std::shared_ptr<EvaluationScope> scope,
|
||||
std::shared_ptr<FunctionScriptType> type)
|
||||
: GenericFunctionEvalValue(move(type), rand()),
|
||||
_innerBlock(std::move(innerBlock)),
|
||||
_scope(std::move(scope)){
|
||||
}
|
||||
|
||||
|
||||
const shared_ptr<EvalValue> Clone() const final {
|
||||
// We don't run make_shared here as it can't call private constructors
|
||||
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope,
|
||||
dynamic_pointer_cast<FunctionScriptType>(_type), _hash));
|
||||
}
|
||||
|
||||
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
|
||||
return _innerBlock;
|
||||
}
|
||||
|
||||
const std::shared_ptr<EvaluationScope> &GetScope() const {
|
||||
return _scope;
|
||||
const shared_ptr<GenericFunctionOption> GetOption(const size_t id) const{
|
||||
return this->_options.at(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user