Fixes and changes for function declarations, using shared_ptr instead of raw pointers

This commit is contained in:
2019-06-01 13:43:25 +02:00
parent 6936b26cae
commit 1231a77761
8 changed files with 91 additions and 68 deletions

View File

@@ -1,8 +1,12 @@
#include <utility>
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
#define PORYGONLANG_SCRIPTTYPE_HPP
#include <utility>
#include <vector>
#include <memory>
#include "Binder/BoundVariables/BoundVariableKey.hpp"
enum class TypeClass{
Error,
@@ -58,40 +62,28 @@ public:
};
class FunctionScriptType : public ScriptType{
ScriptType* _returnType;
std::vector<ScriptType*> _parameterTypes;
std::vector<int> _parameterKeys;
int _scopeId;
std::shared_ptr<ScriptType> _returnType;
std::vector<std::shared_ptr<ScriptType>> _parameterTypes;
std::vector<std::shared_ptr<BoundVariableKey>> _parameterKeys;
public:
FunctionScriptType(ScriptType* returnType, std::vector<ScriptType*> parameterTypes, std::vector<int> parameterKeys, int scopeId)
FunctionScriptType(std::shared_ptr<ScriptType> returnType, std::vector<std::shared_ptr<ScriptType>> parameterTypes,
std::vector<std::shared_ptr<BoundVariableKey>> parameterKeys)
: ScriptType(TypeClass::Function){
_returnType = returnType;
_returnType = std::move(returnType);
_parameterTypes = std::move(parameterTypes);
_parameterKeys = std::move(parameterKeys);
_scopeId = scopeId;
}
~FunctionScriptType() final{
delete _returnType;
for (auto t: _parameterTypes){
delete t;
}
}
ScriptType* GetReturnType(){
return _returnType;
return _returnType.get();
}
std::vector<ScriptType*> GetParameterTypes(){
std::vector<std::shared_ptr<ScriptType>> GetParameterTypes(){
return _parameterTypes;
}
std::vector<int> GetParameterKeys(){
std::vector<std::shared_ptr<BoundVariableKey>> GetParameterKeys(){
return _parameterKeys;
}
int GetScopeId(){
return _scopeId;
}
};
#endif //PORYGONLANG_SCRIPTTYPE_HPP