This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Porygon {
|
||||
class GenericFunctionOption{
|
||||
shared_ptr<ScriptType> _returnType;
|
||||
shared_ptr<const ScriptType> _returnType;
|
||||
vector<shared_ptr<ScriptType>> _parameterTypes;
|
||||
size_t _option = 0;
|
||||
public:
|
||||
@@ -17,7 +17,7 @@ namespace Porygon {
|
||||
|
||||
virtual ~GenericFunctionOption() = default;
|
||||
|
||||
inline const shared_ptr<ScriptType> GetReturnType() const {
|
||||
[[nodiscard]] inline shared_ptr<const ScriptType> GetReturnType() const {
|
||||
return _returnType;
|
||||
}
|
||||
|
||||
@@ -25,19 +25,19 @@ namespace Porygon {
|
||||
_option = v;
|
||||
}
|
||||
|
||||
inline void SetReturnType(shared_ptr<ScriptType> t) {
|
||||
_returnType = move(t);
|
||||
inline void SetReturnType(const shared_ptr<const ScriptType>& t) {
|
||||
_returnType = t;
|
||||
}
|
||||
|
||||
inline const vector<shared_ptr<ScriptType>> GetParameterTypes() const {
|
||||
[[nodiscard]] inline vector<shared_ptr<ScriptType>> GetParameterTypes() const {
|
||||
return _parameterTypes;
|
||||
}
|
||||
|
||||
const bool IsValid(const vector<shared_ptr<ScriptType>>& parameters){
|
||||
bool IsValid(const vector<shared_ptr<const ScriptType>>& parameters){
|
||||
if (parameters.size() != _parameterTypes.size()){
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < parameters.size(); i++){
|
||||
for (size_t i = 0; i < parameters.size(); i++){
|
||||
if (parameters[i]->operator!=(_parameterTypes[i].get())){
|
||||
return false;
|
||||
}
|
||||
@@ -45,15 +45,15 @@ namespace Porygon {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const size_t GetOptionId() const{
|
||||
[[nodiscard]] inline size_t GetOptionId() const{
|
||||
return _option;
|
||||
}
|
||||
|
||||
virtual const bool IsScriptFunction() const = 0;
|
||||
[[nodiscard]] virtual bool IsScriptFunction() const = 0;
|
||||
};
|
||||
|
||||
class GenericFunctionScriptType : public Porygon::ScriptType {
|
||||
vector<GenericFunctionOption *> _options;
|
||||
vector<GenericFunctionOption *>* _options = new vector<GenericFunctionOption *>;
|
||||
public:
|
||||
GenericFunctionScriptType()
|
||||
: ScriptType(Porygon::TypeClass::Function){};
|
||||
@@ -64,18 +64,18 @@ namespace Porygon {
|
||||
};
|
||||
|
||||
~GenericFunctionScriptType() final{
|
||||
for (auto o: _options){
|
||||
for (auto o: *_options){
|
||||
delete o;
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterFunctionOption (GenericFunctionOption * opt){
|
||||
opt->SetOption(_options.size());
|
||||
_options.push_back(opt);
|
||||
void RegisterFunctionOption (GenericFunctionOption * opt) const{
|
||||
opt->SetOption(_options->size());
|
||||
_options->push_back(opt);
|
||||
}
|
||||
|
||||
GenericFunctionOption* GetFunctionOption(const vector<shared_ptr<ScriptType>>& parameters){
|
||||
for (auto o: _options){
|
||||
GenericFunctionOption* GetFunctionOption(const vector<shared_ptr<const ScriptType>>& parameters) const{
|
||||
for (auto o: *_options){
|
||||
if (o->IsValid(parameters)){
|
||||
return o;
|
||||
}
|
||||
@@ -83,24 +83,24 @@ namespace Porygon {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline GenericFunctionOption* GetFirstOption(){
|
||||
return _options[0];
|
||||
[[nodiscard]] inline GenericFunctionOption* GetFirstOption() const{
|
||||
return _options->at(0);
|
||||
}
|
||||
};
|
||||
|
||||
class ScriptFunctionOption : public GenericFunctionOption {
|
||||
vector<shared_ptr<Porygon::Binder::BoundVariableKey>> _parameterKeys;
|
||||
vector<shared_ptr<const Porygon::Binder::BoundVariableKey>> _parameterKeys;
|
||||
public:
|
||||
ScriptFunctionOption(shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes,
|
||||
vector<shared_ptr<Porygon::Binder::BoundVariableKey>> parameterKeys)
|
||||
vector<shared_ptr<const Porygon::Binder::BoundVariableKey>> parameterKeys)
|
||||
: GenericFunctionOption(move(returnType), std::move(parameterTypes)), _parameterKeys(move(parameterKeys)) {
|
||||
}
|
||||
|
||||
inline const vector<shared_ptr<Porygon::Binder::BoundVariableKey>> GetParameterKeys() const {
|
||||
[[nodiscard]] inline vector<shared_ptr<const Porygon::Binder::BoundVariableKey>> GetParameterKeys() const {
|
||||
return _parameterKeys;
|
||||
}
|
||||
|
||||
inline const bool IsScriptFunction() const final {
|
||||
[[nodiscard]] inline bool IsScriptFunction() const final {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user