Make a lot of one-liner functions inline
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2019-07-04 19:08:13 +02:00
parent bb0a6aba19
commit 32836c6c58
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
53 changed files with 428 additions and 424 deletions

View File

@ -49,15 +49,15 @@ namespace Porygon::Binder {
return _type; return _type;
}; };
const unsigned int GetStartPosition() const { inline const unsigned int GetStartPosition() const {
return _start; return _start;
} }
const unsigned int GetLength() const { inline const unsigned int GetLength() const {
return _length; return _length;
} }
const unsigned int GetEndPosition() const { inline const unsigned int GetEndPosition() const {
return _start + _length - 1; return _start + _length - 1;
} }
}; };
@ -68,7 +68,7 @@ namespace Porygon::Binder {
make_shared<ScriptType>( make_shared<ScriptType>(
TypeClass::Error)) {} TypeClass::Error)) {}
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Bad; return BoundExpressionKind::Bad;
} }
}; };
@ -81,11 +81,11 @@ namespace Porygon::Binder {
_value(value) { _value(value) {
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::LiteralInteger; return BoundExpressionKind::LiteralInteger;
} }
const long GetValue() const { inline const long GetValue() const {
return _value; return _value;
} }
}; };
@ -98,11 +98,11 @@ namespace Porygon::Binder {
_value(value) { _value(value) {
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::LiteralFloat; return BoundExpressionKind::LiteralFloat;
} }
const double GetValue() const { inline const double GetValue() const {
return _value; return _value;
} }
}; };
@ -116,11 +116,11 @@ namespace Porygon::Binder {
_value(value) { _value(value) {
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::LiteralString; return BoundExpressionKind::LiteralString;
} }
const u16string GetValue() const { inline const u16string GetValue() const {
return _value; return _value;
} }
}; };
@ -133,11 +133,11 @@ namespace Porygon::Binder {
_value(value) { _value(value) {
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::LiteralBool; return BoundExpressionKind::LiteralBool;
} }
const bool GetValue() const { inline const bool GetValue() const {
return _value; return _value;
} }
}; };
@ -155,11 +155,11 @@ namespace Porygon::Binder {
delete _key; delete _key;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Variable; return BoundExpressionKind::Variable;
} }
const BoundVariableKey *GetKey() const { inline const BoundVariableKey *GetKey() const {
return _key; return _key;
} }
}; };
@ -183,19 +183,19 @@ namespace Porygon::Binder {
delete _right; delete _right;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Binary; return BoundExpressionKind::Binary;
} }
const BoundExpression *GetLeft() const { inline const BoundExpression *GetLeft() const {
return _left; return _left;
} }
const BoundExpression *GetRight() const { inline const BoundExpression *GetRight() const {
return _right; return _right;
} }
const BoundBinaryOperation GetOperation() const { inline const BoundBinaryOperation GetOperation() const {
return _operation; return _operation;
} }
}; };
@ -215,15 +215,15 @@ namespace Porygon::Binder {
delete _operand; delete _operand;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Unary; return BoundExpressionKind::Unary;
} }
const BoundExpression *GetOperand() const { inline const BoundExpression *GetOperand() const {
return _operand; return _operand;
} }
const BoundUnaryOperation GetOperation() const { inline const BoundUnaryOperation GetOperation() const {
return _operation; return _operation;
} }
}; };
@ -243,15 +243,15 @@ namespace Porygon::Binder {
delete _indexExpression; delete _indexExpression;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Index; return BoundExpressionKind::Index;
} }
const BoundExpression *GetIndexableExpression() const { inline const BoundExpression *GetIndexableExpression() const {
return _indexableExpression; return _indexableExpression;
} }
const BoundExpression *GetIndexExpression() const { inline const BoundExpression *GetIndexExpression() const {
return _indexExpression; return _indexExpression;
} }
}; };
@ -270,15 +270,15 @@ namespace Porygon::Binder {
delete _indexableExpression; delete _indexableExpression;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::PeriodIndex; return BoundExpressionKind::PeriodIndex;
} }
const BoundExpression *GetIndexableExpression() const { inline const BoundExpression *GetIndexableExpression() const {
return _indexableExpression; return _indexableExpression;
} }
const Utilities::HashedString GetIndex() const { inline const Utilities::HashedString GetIndex() const {
return _index; return _index;
} }
}; };
@ -297,11 +297,11 @@ namespace Porygon::Binder {
} }
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::NumericalTable; return BoundExpressionKind::NumericalTable;
} }
const vector<const BoundExpression *> *GetExpressions() const { inline const vector<const BoundExpression *> *GetExpressions() const {
return &_expressions; return &_expressions;
} }
}; };

View File

@ -22,19 +22,19 @@ namespace Porygon::Binder {
} }
} }
const Porygon::Binder::BoundExpressionKind GetKind() const final { inline const Porygon::Binder::BoundExpressionKind GetKind() const final {
return Porygon::Binder::BoundExpressionKind::FunctionCall; return Porygon::Binder::BoundExpressionKind::FunctionCall;
} }
const BoundExpression *GetFunctionExpression() const { inline const BoundExpression *GetFunctionExpression() const {
return _functionExpression; return _functionExpression;
} }
const vector<BoundExpression *> *GetParameters() const { inline const vector<BoundExpression *> *GetParameters() const {
return &_parameters; return &_parameters;
} }
const Porygon::GenericFunctionOption *GetFunctionOption() const { inline const Porygon::GenericFunctionOption *GetFunctionOption() const {
return _option; return _option;
} }
}; };

View File

@ -20,11 +20,11 @@ namespace Porygon::Binder {
delete _block; delete _block;
} }
const BoundExpressionKind GetKind() const final { inline const BoundExpressionKind GetKind() const final {
return BoundExpressionKind::Table; return BoundExpressionKind::Table;
} }
const BoundBlockStatement *GetBlock() const { inline const BoundBlockStatement *GetBlock() const {
return _block; return _block;
} }
}; };

View File

@ -21,19 +21,19 @@ namespace Porygon::Binder {
delete _key; delete _key;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::FunctionDeclaration; return BoundStatementKind::FunctionDeclaration;
} }
const BoundVariableKey *GetKey() const { inline const BoundVariableKey *GetKey() const {
return _key; return _key;
} }
const std::shared_ptr<BoundBlockStatement> GetBlock() const { inline const std::shared_ptr<BoundBlockStatement> GetBlock() const {
return _block; return _block;
} }
const std::shared_ptr<GenericFunctionScriptType> GetType() const { inline const std::shared_ptr<GenericFunctionScriptType> GetType() const {
return _type; return _type;
} }
}; };

View File

@ -35,14 +35,14 @@ namespace Porygon::Binder {
class BoundBadStatement : public BoundStatement { class BoundBadStatement : public BoundStatement {
public: public:
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Bad; return BoundStatementKind::Bad;
} }
}; };
class BoundBreakStatement : public BoundStatement { class BoundBreakStatement : public BoundStatement {
public: public:
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Break; return BoundStatementKind::Break;
} }
}; };
@ -60,11 +60,11 @@ namespace Porygon::Binder {
} }
} }
const BoundStatementKind GetKind() const override { inline const BoundStatementKind GetKind() const override {
return BoundStatementKind::Block; return BoundStatementKind::Block;
} }
const vector<BoundStatement *> *GetStatements() const { inline const vector<BoundStatement *> *GetStatements() const {
return &_statements; return &_statements;
} }
}; };
@ -77,11 +77,11 @@ namespace Porygon::Binder {
_localVariableCount(localVariableCount) { _localVariableCount(localVariableCount) {
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Script; return BoundStatementKind::Script;
} }
const int GetLocalVariableCount() const { inline const int GetLocalVariableCount() const {
return _localVariableCount; return _localVariableCount;
} }
}; };
@ -98,11 +98,11 @@ namespace Porygon::Binder {
delete _expression; delete _expression;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Expression; return BoundStatementKind::Expression;
} }
const BoundExpression *GetExpression() const { inline const BoundExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -120,15 +120,15 @@ namespace Porygon::Binder {
delete _expression; delete _expression;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Assignment; return BoundStatementKind::Assignment;
} }
const BoundVariableKey *GetKey() const { inline const BoundVariableKey *GetKey() const {
return _key; return _key;
} }
const BoundExpression *GetExpression() const { inline const BoundExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -146,15 +146,15 @@ namespace Porygon::Binder {
delete _valueExpression; delete _valueExpression;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::IndexAssignment; return BoundStatementKind::IndexAssignment;
} }
const BoundExpression *GetIndexExpression() const { inline const BoundExpression *GetIndexExpression() const {
return _indexExpression; return _indexExpression;
} }
const BoundExpression *GetValueExpression() const { inline const BoundExpression *GetValueExpression() const {
return _valueExpression; return _valueExpression;
} }
}; };
@ -170,11 +170,11 @@ namespace Porygon::Binder {
delete _expression; delete _expression;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Return; return BoundStatementKind::Return;
} }
const BoundExpression *GetExpression() const { inline const BoundExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -194,19 +194,19 @@ namespace Porygon::Binder {
delete _elseStatement; delete _elseStatement;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::Conditional; return BoundStatementKind::Conditional;
} }
const BoundExpression *GetCondition() const { inline const BoundExpression *GetCondition() const {
return _condition; return _condition;
} }
const BoundStatement *GetBlock() const { inline const BoundStatement *GetBlock() const {
return _block; return _block;
} }
const BoundStatement *GetElseStatement() const { inline const BoundStatement *GetElseStatement() const {
return _elseStatement; return _elseStatement;
} }
}; };
@ -233,27 +233,27 @@ namespace Porygon::Binder {
delete _block; delete _block;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::NumericalFor; return BoundStatementKind::NumericalFor;
} }
const BoundVariableKey* GetIdentifier() const{ inline const BoundVariableKey* GetIdentifier() const{
return _identifier; return _identifier;
} }
const BoundExpression* GetStart() const{ inline const BoundExpression* GetStart() const{
return _start; return _start;
} }
const BoundExpression* GetEnd() const{ inline const BoundExpression* GetEnd() const{
return _end; return _end;
} }
const BoundExpression* GetStep() const{ inline const BoundExpression* GetStep() const{
return _step; return _step;
} }
const BoundStatement* GetBlock() const{ inline const BoundStatement* GetBlock() const{
return _block; return _block;
} }
}; };
@ -278,23 +278,23 @@ namespace Porygon::Binder {
delete _block; delete _block;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::GenericFor; return BoundStatementKind::GenericFor;
} }
const BoundVariableKey* GetKeyIdentifier() const{ inline const BoundVariableKey* GetKeyIdentifier() const{
return _keyIdentifier; return _keyIdentifier;
} }
const BoundVariableKey* GetValueIdentifier() const{ inline const BoundVariableKey* GetValueIdentifier() const{
return _valueIdentifier; return _valueIdentifier;
} }
const BoundExpression* GetIterator() const{ inline const BoundExpression* GetIterator() const{
return _iterator; return _iterator;
} }
const BoundStatement* GetBlock() const{ inline const BoundStatement* GetBlock() const{
return _block; return _block;
} }
}; };
@ -312,15 +312,15 @@ namespace Porygon::Binder {
delete _block; delete _block;
} }
const BoundStatementKind GetKind() const final { inline const BoundStatementKind GetKind() const final {
return BoundStatementKind::While; return BoundStatementKind::While;
} }
const BoundExpression* GetCondition() const{ inline const BoundExpression* GetCondition() const{
return _condition; return _condition;
} }
const BoundStatement* GetBlock() const{ inline const BoundStatement* GetBlock() const{
return _block; return _block;
} }
}; };

View File

@ -36,11 +36,11 @@ namespace Porygon::Binder {
VariableAssignment AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<ScriptType> &type); VariableAssignment AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<ScriptType> &type);
size_t GetLocalVariableCount() { inline size_t GetLocalVariableCount() {
return _localScope.size(); return _localScope.size();
} }
int GetCurrentScope() { inline int GetCurrentScope() {
return _currentScope; return _currentScope;
} }
}; };

View File

@ -13,10 +13,10 @@ namespace Porygon::Binder {
class BoundVariable { class BoundVariable {
std::shared_ptr<ScriptType> _type; std::shared_ptr<ScriptType> _type;
public: public:
explicit BoundVariable(std::shared_ptr<ScriptType> type) : _type(std::move(type)) { inline explicit BoundVariable(std::shared_ptr<ScriptType> type) : _type(std::move(type)) {
} }
std::shared_ptr<ScriptType> GetType() { inline std::shared_ptr<ScriptType> GetType() {
return _type; return _type;
} }
}; };

View File

@ -26,19 +26,19 @@ namespace Porygon::Binder {
_hash(KnuthsHash(id.GetHash(), scope)) {} _hash(KnuthsHash(id.GetHash(), scope)) {}
const Utilities::HashedString GetIdentifier() const { inline const Utilities::HashedString GetIdentifier() const {
return _identifier; return _identifier;
} }
const unsigned int GetScopeId() const { inline const unsigned int GetScopeId() const {
return _scopeId; return _scopeId;
} }
const bool IsCreation() const { inline const bool IsCreation() const {
return _isCreation; return _isCreation;
} }
const uint64_t GetHash() const { inline const uint64_t GetHash() const {
return _hash; return _hash;
} }
}; };

View File

@ -20,11 +20,11 @@ namespace Porygon::Binder {
_key = key; _key = key;
} }
VariableAssignmentResult GetResult() { inline VariableAssignmentResult GetResult() {
return _result; return _result;
} }
BoundVariableKey *GetKey() { inline BoundVariableKey *GetKey() {
return _key; return _key;
} }
}; };

View File

@ -28,31 +28,31 @@ namespace Porygon::Diagnostics {
delete _message; delete _message;
} }
DiagnosticSeverity GetSeverity() { inline DiagnosticSeverity GetSeverity() {
return _severity; return _severity;
} }
DiagnosticCode GetCode() { inline DiagnosticCode GetCode() {
return _code; return _code;
} }
unsigned int GetStartPosition() { inline unsigned int GetStartPosition() {
return _start; return _start;
} }
unsigned int GetLength() { inline unsigned int GetLength() {
return _length; return _length;
} }
std::vector<std::string> GetArguments(){ inline std::vector<std::string> GetArguments(){
return _arguments; return _arguments;
} }
void SetMessage(std::string* s){ inline void SetMessage(std::string* s){
this -> _message = s; this -> _message = s;
} }
std::string* GetMessage(){ inline std::string* GetMessage(){
return _message; return _message;
} }
}; };

View File

@ -17,27 +17,27 @@ void DiagnosticsHolder::Log(DiagnosticSeverity severity, DiagnosticCode code, un
} }
} }
void DiagnosticsHolder::LogError(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) { inline void DiagnosticsHolder::LogError(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
Log(DiagnosticSeverity::Error, code, start, length, std::move(arguments)); Log(DiagnosticSeverity::Error, code, start, length, std::move(arguments));
} }
void DiagnosticsHolder::LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) { inline void DiagnosticsHolder::LogWarning(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
Log(DiagnosticSeverity::Warning, code, start, length, std::move(arguments)); Log(DiagnosticSeverity::Warning, code, start, length, std::move(arguments));
} }
void DiagnosticsHolder::LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) { inline void DiagnosticsHolder::LogInfo(DiagnosticCode code, unsigned int start, unsigned int length, std::vector<string> arguments) {
Log(DiagnosticSeverity::Info, code, start, length, std::move(arguments)); Log(DiagnosticSeverity::Info, code, start, length, std::move(arguments));
} }
bool DiagnosticsHolder::HasErrors() { inline bool DiagnosticsHolder::HasErrors() {
return _hasErrors; return _hasErrors;
} }
int DiagnosticsHolder::DiagnosticsCount() { inline int DiagnosticsHolder::DiagnosticsCount() {
return _diagnostics.size(); return _diagnostics.size();
} }
Diagnostic *DiagnosticsHolder::GetDiagnosticAt(int position) { inline Diagnostic *DiagnosticsHolder::GetDiagnosticAt(int position) {
return &_diagnostics[position]; return &_diagnostics[position];
} }

View File

@ -52,7 +52,7 @@ namespace Porygon::Diagnostics {
Diagnostic *GetDiagnosticAt(int position); Diagnostic *GetDiagnosticAt(int position);
size_t GetLineFromPosition(size_t i); size_t GetLineFromPosition(size_t i);
size_t GetStartPositionForLine(size_t i){ inline size_t GetStartPositionForLine(size_t i){
return _lineStarts[i]; return _lineStarts[i];
} }

View File

@ -73,15 +73,15 @@ namespace Porygon::Evaluation {
: _value(val) { : _value(val) {
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return make_shared<BooleanEvalValue>(_value); return make_shared<BooleanEvalValue>(_value);
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::Bool; return TypeClass::Bool;
} }
const bool EvaluateBool() const final { inline const bool EvaluateBool() const final {
return _value; return _value;
} }
@ -91,7 +91,7 @@ namespace Porygon::Evaluation {
return this->EvaluateBool() == b->EvaluateBool(); return this->EvaluateBool() == b->EvaluateBool();
}; };
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return _value; return _value;
} }
}; };

View File

@ -10,48 +10,48 @@
namespace Porygon::Evaluation{ namespace Porygon::Evaluation{
class EvalValueHelper{ class EvalValueHelper{
public: public:
static EvalValue* Create(unsigned char i){ inline static EvalValue* Create(unsigned char i){
return new IntegerEvalValue((long)i); return new IntegerEvalValue((long)i);
} }
static EvalValue* Create(signed char i){ inline static EvalValue* Create(signed char i){
return new IntegerEvalValue((long)i); return new IntegerEvalValue((long)i);
} }
static EvalValue* Create(short int i){ inline static EvalValue* Create(short int i){
return new IntegerEvalValue(i); return new IntegerEvalValue(i);
} }
static EvalValue* Create(unsigned short int i){ inline static EvalValue* Create(unsigned short int i){
return new IntegerEvalValue(i); return new IntegerEvalValue(i);
} }
static EvalValue* Create(signed int i){ inline static EvalValue* Create(signed int i){
return new IntegerEvalValue(i); return new IntegerEvalValue(i);
} }
static EvalValue* Create(unsigned int i){ inline static EvalValue* Create(unsigned int i){
return new IntegerEvalValue(i); return new IntegerEvalValue(i);
} }
static EvalValue* Create(signed long l){ inline static EvalValue* Create(signed long l){
return new IntegerEvalValue(l); return new IntegerEvalValue(l);
} }
static EvalValue* Create(unsigned long l){ inline static EvalValue* Create(unsigned long l){
return new IntegerEvalValue(l); return new IntegerEvalValue(l);
} }
static EvalValue* Create(float f){ inline static EvalValue* Create(float f){
return new FloatEvalValue(f); return new FloatEvalValue(f);
} }
static EvalValue* Create(double f){ inline static EvalValue* Create(double f){
return new FloatEvalValue(f); return new FloatEvalValue(f);
} }
static EvalValue* Create(long double f){ inline static EvalValue* Create(long double f){
return new FloatEvalValue(f); return new FloatEvalValue(f);
} }
static EvalValue* Create(bool b){ inline static EvalValue* Create(bool b){
return new BooleanEvalValue(b); return new BooleanEvalValue(b);
} }
static EvalValue* Create(const string& s){ inline static EvalValue* Create(const string& s){
return new StringEvalValue(Utilities::StringUtils::ToUTF8(s)); return new StringEvalValue(Utilities::StringUtils::ToUTF8(s));
} }
static EvalValue* Create(u16string s){ inline static EvalValue* Create(u16string s){
return new StringEvalValue(std::move(s)); return new StringEvalValue(std::move(s));
} }
}; };

View File

@ -5,18 +5,18 @@
namespace Porygon::Evaluation{ namespace Porygon::Evaluation{
class NilEvalValue : public EvalValue{ class NilEvalValue : public EvalValue{
const TypeClass GetTypeClass() const final{ inline const TypeClass GetTypeClass() const final{
return TypeClass ::Nil; return TypeClass ::Nil;
} }
const bool operator==(EvalValue *b) const final{ inline const bool operator==(EvalValue *b) const final{
return b->GetTypeClass() == TypeClass ::Nil; return b->GetTypeClass() == TypeClass ::Nil;
} }
const shared_ptr<EvalValue> Clone() const final{ inline const shared_ptr<EvalValue> Clone() const final{
return make_shared<NilEvalValue>(); return make_shared<NilEvalValue>();
} }
const std::size_t GetHashCode() const final{ inline const std::size_t GetHashCode() const final{
return 0; return 0;
} }
}; };

View File

@ -16,7 +16,7 @@ namespace Porygon::Evaluation {
public: public:
virtual const bool IsFloat() const = 0; virtual const bool IsFloat() const = 0;
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::Number; return TypeClass::Number;
} }
@ -52,23 +52,23 @@ namespace Porygon::Evaluation {
explicit IntegerEvalValue(long value) : _value(value) { explicit IntegerEvalValue(long value) : _value(value) {
} }
const bool IsFloat() const final { inline const bool IsFloat() const final {
return false; return false;
} }
const long EvaluateInteger() const final { inline const long EvaluateInteger() const final {
return _value; return _value;
} }
const std::u16string EvaluateString() const final{ inline const std::u16string EvaluateString() const final{
return Utilities::StringUtils::IntToString(_value); return Utilities::StringUtils::IntToString(_value);
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return make_shared<IntegerEvalValue>(_value); return make_shared<IntegerEvalValue>(_value);
} }
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return std::hash<long>{}(_value); return std::hash<long>{}(_value);
} }
}; };
@ -76,29 +76,31 @@ namespace Porygon::Evaluation {
class FloatEvalValue : public NumericEvalValue { class FloatEvalValue : public NumericEvalValue {
const double _value; const double _value;
const long GetIntegerValue() const final { inline const long GetIntegerValue() const final {
throw EvaluationException("Attempting to retrieve float from int eval value."); throw EvaluationException("Attempting to retrieve float from int eval value.");
} }
const double GetFloatValue() const final { return _value; } inline const double GetFloatValue() const final {
return _value;
}
public: public:
explicit FloatEvalValue(double value) : _value(value) { explicit FloatEvalValue(double value) : _value(value) {
} }
const bool IsFloat() const final { inline const bool IsFloat() const final {
return true; return true;
} }
const double EvaluateFloat() const final { inline const double EvaluateFloat() const final {
return _value; return _value;
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return make_shared<FloatEvalValue>(_value); return make_shared<FloatEvalValue>(_value);
} }
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return std::hash<double>{}(_value); return std::hash<double>{}(_value);
} }
}; };

View File

@ -1,6 +1,6 @@
#include "NumericalTableEvalValue.hpp" #include "NumericalTableEvalValue.hpp"
#include "../Iterator/NumericalKeyIterator.hpp" #include "../Iterator/NumericalKeyIterator.hpp"
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericalTableEvalValue::GetKeyIterator() const { inline Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericalTableEvalValue::GetKeyIterator() const {
return new NumericalKeyIterator(this); return new NumericalKeyIterator(this);
} }

View File

@ -26,39 +26,39 @@ namespace Porygon::Evaluation {
{ {
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::Table; return TypeClass::Table;
} }
const size_t GetHashCode() const final { inline const size_t GetHashCode() const final {
return _hash; return _hash;
} }
const bool operator==(EvalValue *b) const final { inline const bool operator==(EvalValue *b) const final {
return this->_hash == b->GetHashCode(); return this->_hash == b->GetHashCode();
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return shared_ptr<EvalValue>(new NumericalTableEvalValue(_table, _hash)); return shared_ptr<EvalValue>(new NumericalTableEvalValue(_table, _hash));
} }
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final { inline const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
const auto index = val->EvaluateInteger() - 1; const auto index = val->EvaluateInteger() - 1;
return this->_table->at(index); return this->_table->at(index);
} }
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final { inline const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
return this->_table->at(hash - 1); return this->_table->at(hash - 1);
} }
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final { inline void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final {
auto index = key->EvaluateInteger(); auto index = key->EvaluateInteger();
this->_table->at(index - 1) = value; this->_table->at(index - 1) = value;
} }
Iterator * GetKeyIterator() const final; Iterator * GetKeyIterator() const final;
const shared_ptr<vector<shared_ptr<EvalValue>>> GetTable() const{ inline const shared_ptr<vector<shared_ptr<EvalValue>>> GetTable() const{
return _table; return _table;
}; };
}; };

View File

@ -29,11 +29,11 @@ namespace Porygon::Evaluation {
} }
~EvaluationScriptFunctionOption() final = default; ~EvaluationScriptFunctionOption() final = default;
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const { inline const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
return _innerBlock; return _innerBlock;
} }
const std::shared_ptr<EvaluationScope> &GetScope() const { inline const std::shared_ptr<EvaluationScope> &GetScope() const {
return _scope; return _scope;
} }
}; };
@ -57,15 +57,15 @@ namespace Porygon::Evaluation {
return t; return t;
} }
void RegisterOption(GenericFunctionOption* option){ inline void RegisterOption(GenericFunctionOption* option){
_options.push_back(shared_ptr<GenericFunctionOption>(option)); _options.push_back(shared_ptr<GenericFunctionOption>(option));
} }
const std::shared_ptr<ScriptType> GetType() const { inline const std::shared_ptr<ScriptType> GetType() const {
return _type; return _type;
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::Function; return TypeClass::Function;
} }
@ -75,11 +75,11 @@ namespace Porygon::Evaluation {
return this->_hash == ((GenericFunctionEvalValue *) b)->_hash; return this->_hash == ((GenericFunctionEvalValue *) b)->_hash;
}; };
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return _hash; return _hash;
} }
const shared_ptr<GenericFunctionOption> GetOption(const size_t id) const{ inline const shared_ptr<GenericFunctionOption> GetOption(const size_t id) const{
return this->_options.at(id); return this->_options.at(id);
} }
}; };

View File

@ -17,7 +17,7 @@ namespace Porygon::Evaluation {
_hash = Utilities::HashedString::ConstHash(_value.c_str()); _hash = Utilities::HashedString::ConstHash(_value.c_str());
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::String; return TypeClass::String;
} }
@ -27,11 +27,11 @@ namespace Porygon::Evaluation {
return this->_hash == b->GetHashCode(); return this->_hash == b->GetHashCode();
}; };
const u16string EvaluateString() const final { inline const u16string EvaluateString() const final {
return _value; return _value;
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return make_shared<StringEvalValue>(_value); return make_shared<StringEvalValue>(_value);
} }
@ -41,7 +41,7 @@ namespace Porygon::Evaluation {
return make_shared<StringEvalValue>(u16string(1, _value[l])); return make_shared<StringEvalValue>(u16string(1, _value[l]));
} }
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return _hash; return _hash;
} }
}; };

View File

@ -1,6 +1,6 @@
#include "TableEvalValue.hpp" #include "TableEvalValue.hpp"
#include "../Iterator/SimpleKeyIterator.hpp" #include "../Iterator/SimpleKeyIterator.hpp"
Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const { inline Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
return new TableKeyIterator(this); return new TableKeyIterator(this);
} }

View File

@ -25,47 +25,47 @@ namespace Porygon::Evaluation {
{ {
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::Table; return TypeClass::Table;
} }
const size_t GetHashCode() const final { inline const size_t GetHashCode() const final {
return _hash; return _hash;
} }
const bool operator==(EvalValue *b) const final { inline const bool operator==(EvalValue *b) const final {
return this->_hash == b->GetHashCode(); return this->_hash == b->GetHashCode();
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash)); return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash));
} }
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final { inline const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
const auto stringKey = val->EvaluateString(); const auto stringKey = val->EvaluateString();
return this->_table->at(Utilities::HashedString::CreateLookup(stringKey)); return this->_table->at(Utilities::HashedString::CreateLookup(stringKey));
} }
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final { inline const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
return this->_table->at(Utilities::HashedString::CreateLookup(hash)); return this->_table->at(Utilities::HashedString::CreateLookup(hash));
} }
const shared_ptr<EvalValue> IndexValue(const char *val) const { inline const shared_ptr<EvalValue> IndexValue(const char *val) const {
auto hash = Utilities::HashedString::ConstHash(val); auto hash = Utilities::HashedString::ConstHash(val);
return this->_table->at(Utilities::HashedString::CreateLookup(hash)); return this->_table->at(Utilities::HashedString::CreateLookup(hash));
} }
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final { inline void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final {
auto hash = key->GetHashCode(); auto hash = key->GetHashCode();
this->_table->at(Utilities::HashedString::CreateLookup(hash)) = value; this->_table->at(Utilities::HashedString::CreateLookup(hash)) = value;
} }
Iterator * GetKeyIterator() const final; Iterator * GetKeyIterator() const final;
const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIterator() const{ inline const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIterator() const{
return _table->cbegin(); return _table->cbegin();
}; };
const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIteratorEnd() const{ inline const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIteratorEnd() const{
return _table->cend(); return _table->cend();
}; };
}; };

View File

@ -17,7 +17,7 @@ namespace Porygon::Evaluation {
const string defaultErrorText = "An evaluation exception occurred: "; const string defaultErrorText = "An evaluation exception occurred: ";
const char *what() const noexcept final { inline const char *what() const noexcept final {
return _message.c_str(); return _message.c_str();
} }
}; };

View File

@ -16,16 +16,16 @@ namespace Porygon::Evaluation{
explicit NumericalKeyIterator(const NumericalTableEvalValue* table) explicit NumericalKeyIterator(const NumericalTableEvalValue* table)
: _vec(table->GetTable()), _size(_vec->size() + 1){} : _vec(table->GetTable()), _size(_vec->size() + 1){}
shared_ptr<EvalValue> GetCurrent() final{ inline shared_ptr<EvalValue> GetCurrent() final{
return make_shared<IntegerEvalValue>(_position); return make_shared<IntegerEvalValue>(_position);
} }
bool MoveNext() final{ inline bool MoveNext() final{
_position++; _position++;
return _position != _size; return _position != _size;
} }
void Reset() final{ inline void Reset() final{
_position = 0; _position = 0;
} }
}; };

View File

@ -15,7 +15,7 @@ namespace Porygon::Evaluation{
explicit TableKeyIterator(const TableEvalValue* table) explicit TableKeyIterator(const TableEvalValue* table)
: _iterator(table->GetTableIterator()), _end(table->GetTableIteratorEnd()){} : _iterator(table->GetTableIterator()), _end(table->GetTableIteratorEnd()){}
shared_ptr<EvalValue> GetCurrent() final{ inline shared_ptr<EvalValue> GetCurrent() final{
return make_shared<StringEvalValue>(*_iterator->first.GetString()); return make_shared<StringEvalValue>(*_iterator->first.GetString());
} }
@ -28,7 +28,7 @@ namespace Porygon::Evaluation{
return _iterator != _end; return _iterator != _end;
} }
void Reset() final{ inline void Reset() final{
throw EvaluationException("Can't reset table key iterator"); throw EvaluationException("Can't reset table key iterator");
} }
}; };

View File

@ -17,19 +17,19 @@ namespace Porygon {
virtual ~GenericFunctionOption() = default; virtual ~GenericFunctionOption() = default;
const shared_ptr<ScriptType> GetReturnType() const { inline const shared_ptr<ScriptType> GetReturnType() const {
return _returnType; return _returnType;
} }
void SetOption(size_t v){ inline void SetOption(size_t v){
_option = v; _option = v;
} }
void SetReturnType(shared_ptr<ScriptType> t) { inline void SetReturnType(shared_ptr<ScriptType> t) {
_returnType = move(t); _returnType = move(t);
} }
const vector<shared_ptr<ScriptType>> GetParameterTypes() const { inline const vector<shared_ptr<ScriptType>> GetParameterTypes() const {
return _parameterTypes; return _parameterTypes;
} }
@ -45,7 +45,7 @@ namespace Porygon {
return true; return true;
} }
const size_t GetOptionId() const{ inline const size_t GetOptionId() const{
return _option; return _option;
} }
@ -83,7 +83,7 @@ namespace Porygon {
return nullptr; return nullptr;
} }
GenericFunctionOption* GetFirstOption(){ inline GenericFunctionOption* GetFirstOption(){
return _options[0]; return _options[0];
} }
}; };
@ -96,11 +96,11 @@ namespace Porygon {
: GenericFunctionOption(move(returnType), std::move(parameterTypes)), _parameterKeys(move(parameterKeys)) { : GenericFunctionOption(move(returnType), std::move(parameterTypes)), _parameterKeys(move(parameterKeys)) {
} }
const vector<shared_ptr<Porygon::Binder::BoundVariableKey>> GetParameterKeys() const { inline const vector<shared_ptr<Porygon::Binder::BoundVariableKey>> GetParameterKeys() const {
return _parameterKeys; return _parameterKeys;
} }
const bool IsScriptFunction() const final { inline const bool IsScriptFunction() const final {
return true; return true;
} }
}; };

View File

@ -9,7 +9,7 @@ namespace Porygon{
static std::streambuf* _printBuffer; static std::streambuf* _printBuffer;
static std::ostream* _printStream; static std::ostream* _printStream;
public: public:
static void Print(const std::u16string& s){ inline static void Print(const std::u16string& s){
GlobalScriptOptions::_print(s); GlobalScriptOptions::_print(s);
} }

View File

@ -14,10 +14,10 @@ namespace Porygon::Parser {
} }
vector<const IToken *> Lexer::Lex() { vector<const Token *> Lexer::Lex() {
vector<const IToken *> tokens; vector<const Token *> tokens;
while (true) { while (true) {
IToken *next = this->LexNext(this->Next()); Token *next = this->LexNext(this->Next());
auto nextKind = next->GetKind(); auto nextKind = next->GetKind();
if (nextKind != TokenKind::WhiteSpace) if (nextKind != TokenKind::WhiteSpace)
tokens.push_back(next); tokens.push_back(next);
@ -41,7 +41,7 @@ namespace Porygon::Parser {
return next; return next;
} }
IToken *Lexer::LexNext(char16_t c) { Token *Lexer::LexNext(char16_t c) {
switch (c) { switch (c) {
case '\0': case '\0':
return new SimpleToken(TokenKind::EndOfFile, this->_position - 1, 1); return new SimpleToken(TokenKind::EndOfFile, this->_position - 1, 1);
@ -154,7 +154,7 @@ namespace Porygon::Parser {
} }
} }
IToken *Lexer::LexNumber(char16_t c) { Token *Lexer::LexNumber(char16_t c) {
long int_value = CharToInt(c); long int_value = CharToInt(c);
double float_value = 0; double float_value = 0;
short decimal_index = 0; short decimal_index = 0;
@ -201,7 +201,7 @@ namespace Porygon::Parser {
} }
} }
IToken *Lexer::LexIdentifierOrKeyword() { Token *Lexer::LexIdentifierOrKeyword() {
auto start = this->_position - 1; auto start = this->_position - 1;
auto end = start; auto end = start;
while (true) { while (true) {
@ -275,7 +275,7 @@ namespace Porygon::Parser {
{'\\', '\\'}, {'\\', '\\'},
}; };
IToken *Lexer::LexString(char16_t c) { Token *Lexer::LexString(char16_t c) {
auto start = this->_position - 1; auto start = this->_position - 1;
auto end = start; auto end = start;
char16_t last = c; char16_t last = c;

View File

@ -17,14 +17,14 @@ namespace Porygon::Parser{
unsigned int _scriptSize; unsigned int _scriptSize;
char16_t Peek(); char16_t Peek();
char16_t Next(); char16_t Next();
IToken* LexNext(char16_t c); Token* LexNext(char16_t c);
IToken* LexNumber(char16_t c); Token* LexNumber(char16_t c);
IToken* LexIdentifierOrKeyword(); Token* LexIdentifierOrKeyword();
IToken* LexString(char16_t c); Token* LexString(char16_t c);
public: public:
Porygon::Script* ScriptData; Porygon::Script* ScriptData;
vector<const IToken*> Lex(); vector<const Token*> Lex();
explicit Lexer(const u16string& scriptString, Porygon::Script* script); explicit Lexer(const u16string& scriptString, Porygon::Script* script);
}; };

View File

@ -43,15 +43,15 @@ namespace Porygon::Parser {
virtual const ParsedExpressionKind GetKind() const = 0; virtual const ParsedExpressionKind GetKind() const = 0;
const unsigned int GetStartPosition() const { inline const unsigned int GetStartPosition() const {
return _position; return _position;
} }
const unsigned int GetEndPosition() const { inline const unsigned int GetEndPosition() const {
return _position + _length - 1; return _position + _length - 1;
} }
const unsigned int GetLength() const { inline const unsigned int GetLength() const {
return _length; return _length;
} }
}; };
@ -60,7 +60,7 @@ namespace Porygon::Parser {
public: public:
BadExpression(unsigned int position, unsigned int length) : ParsedExpression(position, length) {} BadExpression(unsigned int position, unsigned int length) : ParsedExpression(position, length) {}
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Bad; return ParsedExpressionKind::Bad;
} }
}; };
@ -68,7 +68,7 @@ namespace Porygon::Parser {
class LiteralIntegerExpression : public ParsedExpression { class LiteralIntegerExpression : public ParsedExpression {
const long _value; const long _value;
public: public:
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::LiteralInteger; return ParsedExpressionKind::LiteralInteger;
} }
@ -77,7 +77,7 @@ namespace Porygon::Parser {
_value(token->GetValue()) { _value(token->GetValue()) {
} }
const long GetValue() const { inline const long GetValue() const {
return _value; return _value;
} }
}; };
@ -85,7 +85,7 @@ namespace Porygon::Parser {
class LiteralFloatExpression : public ParsedExpression { class LiteralFloatExpression : public ParsedExpression {
const double _value; const double _value;
public: public:
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::LiteralFloat; return ParsedExpressionKind::LiteralFloat;
} }
@ -94,7 +94,7 @@ namespace Porygon::Parser {
_value(token->GetValue()) { _value(token->GetValue()) {
} }
const double GetValue() const { inline const double GetValue() const {
return _value; return _value;
} }
}; };
@ -102,16 +102,16 @@ namespace Porygon::Parser {
class LiteralStringExpression : public ParsedExpression { class LiteralStringExpression : public ParsedExpression {
const u16string _value; const u16string _value;
public: public:
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::LiteralString; return ParsedExpressionKind::LiteralString;
} }
explicit LiteralStringExpression(const StringToken *token) explicit LiteralStringExpression(const StringToken *token)
: ParsedExpression(token->GetStartPosition(), token->GetLength()), : ParsedExpression(token->GetStartPosition(), token->GetLength()),
_value(std::move(token->GetValue())) { _value(token->GetValue()) {
} }
const u16string &GetValue() const { inline const u16string &GetValue() const {
return _value; return _value;
} }
}; };
@ -119,16 +119,16 @@ namespace Porygon::Parser {
class LiteralBoolExpression : public ParsedExpression { class LiteralBoolExpression : public ParsedExpression {
const bool _value; const bool _value;
public: public:
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::LiteralBool; return ParsedExpressionKind::LiteralBool;
} }
explicit LiteralBoolExpression(const IToken *token) explicit LiteralBoolExpression(const Token *token)
: ParsedExpression(token->GetStartPosition(), token->GetLength()), : ParsedExpression(token->GetStartPosition(), token->GetLength()),
_value(token->GetKind() == TokenKind::TrueKeyword) { _value(token->GetKind() == TokenKind::TrueKeyword) {
} }
const bool GetValue() const { inline const bool GetValue() const {
return _value; return _value;
} }
}; };
@ -136,7 +136,7 @@ namespace Porygon::Parser {
class VariableExpression : public ParsedExpression { class VariableExpression : public ParsedExpression {
const HashedString _value; const HashedString _value;
public: public:
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Variable; return ParsedExpressionKind::Variable;
} }
@ -145,7 +145,7 @@ namespace Porygon::Parser {
_value(HashedString(token->GetValue())) { _value(HashedString(token->GetValue())) {
} }
const HashedString GetValue() const { inline const HashedString GetValue() const {
return _value; return _value;
} }
}; };
@ -158,7 +158,7 @@ namespace Porygon::Parser {
delete _expression; delete _expression;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Parenthesized; return ParsedExpressionKind::Parenthesized;
} }
@ -166,7 +166,7 @@ namespace Porygon::Parser {
: ParsedExpression(start, length), _expression(innerExpression) { : ParsedExpression(start, length), _expression(innerExpression) {
} }
const ParsedExpression *GetInnerExpression() const { inline const ParsedExpression *GetInnerExpression() const {
return _expression; return _expression;
} }
}; };
@ -179,7 +179,7 @@ namespace Porygon::Parser {
delete _operand; delete _operand;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Unary; return ParsedExpressionKind::Unary;
} }
@ -188,11 +188,11 @@ namespace Porygon::Parser {
_kind(kind), _operand(operand) { _kind(kind), _operand(operand) {
} }
const UnaryOperatorKind GetOperatorKind() const { inline const UnaryOperatorKind GetOperatorKind() const {
return _kind; return _kind;
} }
const ParsedExpression *GetOperand() const { inline const ParsedExpression *GetOperand() const {
return _operand; return _operand;
} }
}; };
@ -207,7 +207,7 @@ namespace Porygon::Parser {
delete _right; delete _right;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Binary; return ParsedExpressionKind::Binary;
} }
@ -217,15 +217,15 @@ namespace Porygon::Parser {
_kind(kind), _left(left), _right(right) { _kind(kind), _left(left), _right(right) {
} }
const BinaryOperatorKind GetOperatorKind() const { inline const BinaryOperatorKind GetOperatorKind() const {
return _kind; return _kind;
} }
const ParsedExpression *GetLeft() const { inline const ParsedExpression *GetLeft() const {
return _left; return _left;
} }
const ParsedExpression *GetRight() const { inline const ParsedExpression *GetRight() const {
return _right; return _right;
} }
}; };
@ -246,15 +246,15 @@ namespace Porygon::Parser {
} }
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::FunctionCall; return ParsedExpressionKind::FunctionCall;
} }
const ParsedExpression *GetFunction() const { inline const ParsedExpression *GetFunction() const {
return _function.get(); return _function.get();
} }
const vector<const ParsedExpression *> *GetParameters() const { inline const vector<const ParsedExpression *> *GetParameters() const {
return &_parameters; return &_parameters;
} }
}; };
@ -273,15 +273,15 @@ namespace Porygon::Parser {
delete _indexExpression; delete _indexExpression;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::Indexer; return ParsedExpressionKind::Indexer;
} }
const ParsedExpression *GetIndexer() const { inline const ParsedExpression *GetIndexer() const {
return _indexerExpression; return _indexerExpression;
} }
const ParsedExpression *GetIndex() const { inline const ParsedExpression *GetIndex() const {
return _indexExpression; return _indexExpression;
} }
}; };
@ -299,15 +299,15 @@ namespace Porygon::Parser {
delete _indexerExpression; delete _indexerExpression;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::PeriodIndexer; return ParsedExpressionKind::PeriodIndexer;
} }
const ParsedExpression *GetIndexer() const { inline const ParsedExpression *GetIndexer() const {
return _indexerExpression; return _indexerExpression;
} }
const HashedString &GetIndex() const { inline const HashedString &GetIndex() const {
return _index; return _index;
} }
}; };
@ -327,11 +327,11 @@ namespace Porygon::Parser {
} }
} }
const vector<const ParsedExpression *> *GetExpressions() const { inline const vector<const ParsedExpression *> *GetExpressions() const {
return &_expressions; return &_expressions;
} }
const ParsedExpressionKind GetKind() const final { inline const ParsedExpressionKind GetKind() const final {
return ParsedExpressionKind::NumericalTable; return ParsedExpressionKind::NumericalTable;
} }
}; };

View File

@ -56,7 +56,7 @@ namespace Porygon::Parser {
public: public:
ParsedBadStatement(unsigned int start, unsigned int length) : ParsedStatement(start, length) {}; ParsedBadStatement(unsigned int start, unsigned int length) : ParsedStatement(start, length) {};
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Bad; return ParsedStatementKind::Bad;
} }
}; };
@ -65,7 +65,7 @@ namespace Porygon::Parser {
public: public:
ParsedBreakStatement(unsigned int start, unsigned int length) : ParsedStatement(start, length) {}; ParsedBreakStatement(unsigned int start, unsigned int length) : ParsedStatement(start, length) {};
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Break; return ParsedStatementKind::Break;
} }
}; };
@ -89,11 +89,11 @@ namespace Porygon::Parser {
} }
} }
const ParsedStatementKind GetKind() const override { inline const ParsedStatementKind GetKind() const override {
return ParsedStatementKind::Block; return ParsedStatementKind::Block;
} }
const std::vector<const ParsedStatement *> *GetStatements() const { inline const std::vector<const ParsedStatement *> *GetStatements() const {
return &_statements; return &_statements;
} }
}; };
@ -103,7 +103,7 @@ namespace Porygon::Parser {
explicit ParsedScriptStatement(vector<const ParsedStatement *> statements) : ParsedBlockStatement( explicit ParsedScriptStatement(vector<const ParsedStatement *> statements) : ParsedBlockStatement(
move(statements)) {} move(statements)) {}
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Script; return ParsedStatementKind::Script;
} }
}; };
@ -120,15 +120,15 @@ namespace Porygon::Parser {
delete _expression; delete _expression;
} }
void NullifyExpression(){ inline void NullifyExpression(){
_expression = nullptr; _expression = nullptr;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Expression; return ParsedStatementKind::Expression;
} }
const ParsedExpression *GetExpression() const { inline const ParsedExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -151,19 +151,19 @@ namespace Porygon::Parser {
delete _block; delete _block;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::FunctionDeclaration; return ParsedStatementKind::FunctionDeclaration;
} }
const HashedString GetIdentifier() const { inline const HashedString GetIdentifier() const {
return _identifier; return _identifier;
} }
const vector<TypedVariableIdentifier *> *GetParameters() const { inline const vector<TypedVariableIdentifier *> *GetParameters() const {
return &_parameters; return &_parameters;
} }
const ParsedBlockStatement *GetBlock() const { inline const ParsedBlockStatement *GetBlock() const {
return _block; return _block;
} }
}; };
@ -182,19 +182,19 @@ namespace Porygon::Parser {
delete _expression; delete _expression;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Assignment; return ParsedStatementKind::Assignment;
} }
const bool IsLocal() const { inline const bool IsLocal() const {
return _local; return _local;
} }
const HashedString GetIdentifier() const { inline const HashedString GetIdentifier() const {
return _identifier; return _identifier;
} }
const ParsedExpression *GetExpression() const { inline const ParsedExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -214,15 +214,15 @@ namespace Porygon::Parser {
delete _valueExpression; delete _valueExpression;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::IndexAssignment; return ParsedStatementKind::IndexAssignment;
} }
const ParsedExpression *GetIndexExpression() const { inline const ParsedExpression *GetIndexExpression() const {
return _indexExpression; return _indexExpression;
} }
const ParsedExpression *GetValueExpression() const { inline const ParsedExpression *GetValueExpression() const {
return _valueExpression; return _valueExpression;
} }
}; };
@ -239,11 +239,11 @@ namespace Porygon::Parser {
delete _expression; delete _expression;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Return; return ParsedStatementKind::Return;
} }
const ParsedExpression *GetExpression() const { inline const ParsedExpression *GetExpression() const {
return _expression; return _expression;
} }
}; };
@ -273,19 +273,19 @@ namespace Porygon::Parser {
delete _elseStatement; delete _elseStatement;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::Conditional; return ParsedStatementKind::Conditional;
} }
const ParsedExpression *GetCondition() const { inline const ParsedExpression *GetCondition() const {
return _condition; return _condition;
} }
const ParsedStatement *GetBlock() const { inline const ParsedStatement *GetBlock() const {
return _block; return _block;
} }
const ParsedStatement *GetElseStatement() const { inline const ParsedStatement *GetElseStatement() const {
return _elseStatement; return _elseStatement;
} }
}; };
@ -310,27 +310,27 @@ namespace Porygon::Parser {
delete _block; delete _block;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::NumericalFor; return ParsedStatementKind::NumericalFor;
} }
const HashedString GetIdentifier() const{ inline const HashedString GetIdentifier() const{
return _identifier; return _identifier;
} }
const ParsedExpression *GetStart() const{ inline const ParsedExpression *GetStart() const{
return _start; return _start;
} }
const ParsedExpression *GetEnd() const{ inline const ParsedExpression *GetEnd() const{
return _end; return _end;
} }
const ParsedExpression *GetStep() const{ inline const ParsedExpression *GetStep() const{
return _step; return _step;
} }
const ParsedStatement *GetBlock() const{ inline const ParsedStatement *GetBlock() const{
return _block; return _block;
} }
}; };
@ -352,23 +352,23 @@ namespace Porygon::Parser {
delete _block; delete _block;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::GenericFor; return ParsedStatementKind::GenericFor;
} }
const HashedString GetKeyIdentifier() const{ inline const HashedString GetKeyIdentifier() const{
return _keyIdentifier; return _keyIdentifier;
} }
const HashedString GetValueIdentifier() const{ inline const HashedString GetValueIdentifier() const{
return _valueIdentifier; return _valueIdentifier;
} }
const ParsedExpression* GetIteratorExpression() const{ inline const ParsedExpression* GetIteratorExpression() const{
return _iteratorExpression; return _iteratorExpression;
} }
const ParsedStatement* GetBlock() const{ inline const ParsedStatement* GetBlock() const{
return _block; return _block;
} }
}; };
@ -386,15 +386,15 @@ namespace Porygon::Parser {
delete _block; delete _block;
} }
const ParsedStatementKind GetKind() const final { inline const ParsedStatementKind GetKind() const final {
return ParsedStatementKind::While; return ParsedStatementKind::While;
} }
const ParsedExpression* GetCondition(){ inline const ParsedExpression* GetCondition(){
return _condition; return _condition;
} }
const ParsedStatement* GetBlock(){ inline const ParsedStatement* GetBlock(){
return _block; return _block;
} }
}; };

View File

@ -20,20 +20,20 @@ namespace Porygon::Parser {
return new ParsedScriptStatement(statements); return new ParsedScriptStatement(statements);
} }
const IToken *Parser::Peek() { inline const Token *Parser::Peek() {
return this->_tokens[_position]; return this->_tokens[_position];
} }
const IToken *Parser::PeekAt(int offset) { inline const Token *Parser::PeekAt(int offset) {
return this->_tokens[_position + offset]; return this->_tokens[_position + offset];
} }
const IToken *Parser::Next() { inline const Token *Parser::Next() {
this->_position++; this->_position++;
return this->_tokens[_position - 1]; return this->_tokens[_position - 1];
} }
ParsedStatement *Parser::ParseStatement(const IToken *current) { ParsedStatement *Parser::ParseStatement(const Token *current) {
auto currentKind = current->GetKind(); auto currentKind = current->GetKind();
switch (currentKind) { switch (currentKind) {
case TokenKind::LocalKeyword: case TokenKind::LocalKeyword:
@ -65,9 +65,9 @@ namespace Porygon::Parser {
return new ParsedExpressionStatement(expression); return new ParsedExpressionStatement(expression);
} }
ParsedStatement *Parser::ParseVariableAssignment(const IToken *current) { ParsedStatement *Parser::ParseVariableAssignment(const Token *current) {
bool isLocal = false; bool isLocal = false;
const IToken *identifier; const Token *identifier;
if (current->GetKind() == TokenKind::LocalKeyword) { if (current->GetKind() == TokenKind::LocalKeyword) {
isLocal = true; isLocal = true;
identifier = this->Next(); identifier = this->Next();
@ -125,7 +125,7 @@ namespace Porygon::Parser {
return new ParsedBlockStatement(statements); return new ParsedBlockStatement(statements);
} }
ParsedStatement *Parser::ParseFunctionDeclaration(const IToken *current) { ParsedStatement *Parser::ParseFunctionDeclaration(const Token *current) {
auto functionIdentifierToken = this->Next(); auto functionIdentifierToken = this->Next();
auto openParenthesis = this->Next(); auto openParenthesis = this->Next();
vector<TypedVariableIdentifier *> parameters; vector<TypedVariableIdentifier *> parameters;
@ -196,7 +196,7 @@ namespace Porygon::Parser {
block->GetEndPosition() - start); block->GetEndPosition() - start);
} }
ParsedStatement *Parser::ParseReturnStatement(const IToken *current) { ParsedStatement *Parser::ParseReturnStatement(const Token *current) {
auto start = current->GetStartPosition(); auto start = current->GetStartPosition();
auto startLine = this -> ScriptData -> Diagnostics ->GetLineFromPosition(start); auto startLine = this -> ScriptData -> Diagnostics ->GetLineFromPosition(start);
if (startLine != this -> ScriptData -> Diagnostics -> GetLineFromPosition(this -> Peek() -> GetStartPosition())){ if (startLine != this -> ScriptData -> Diagnostics -> GetLineFromPosition(this -> Peek() -> GetStartPosition())){
@ -206,7 +206,7 @@ namespace Porygon::Parser {
return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start); return new ParsedReturnStatement(expression, start, expression->GetEndPosition() - start);
} }
ParsedStatement *Parser::ParseIfStatement(const IToken *current) { ParsedStatement *Parser::ParseIfStatement(const Token *current) {
auto condition = this->ParseExpression(this->Next()); auto condition = this->ParseExpression(this->Next());
auto next = this->Next(); auto next = this->Next();
if (next->GetKind() != TokenKind::ThenKeyword) { if (next->GetKind() != TokenKind::ThenKeyword) {
@ -238,7 +238,7 @@ namespace Porygon::Parser {
} }
} }
ParsedStatement *Parser::ParseNumericForStatement(const IToken *current) { ParsedStatement *Parser::ParseNumericForStatement(const Token *current) {
auto identifier = dynamic_cast<const IdentifierToken*>(current); auto identifier = dynamic_cast<const IdentifierToken*>(current);
this->Next(); // consume assignment token this->Next(); // consume assignment token
bool hasErrors = false; bool hasErrors = false;
@ -270,7 +270,7 @@ namespace Porygon::Parser {
} }
ParsedStatement *Parser::ParseGenericForStatement(const IToken *current) { ParsedStatement *Parser::ParseGenericForStatement(const Token *current) {
auto keyIdentifier = dynamic_cast<const IdentifierToken*>(current)->GetValue(); auto keyIdentifier = dynamic_cast<const IdentifierToken*>(current)->GetValue();
const IdentifierToken* valueIdentifierToken = nullptr; const IdentifierToken* valueIdentifierToken = nullptr;
bool hasErrors = false; bool hasErrors = false;
@ -314,7 +314,7 @@ namespace Porygon::Parser {
} }
} }
ParsedStatement *Parser::ParseWhileStatement(const IToken *current) { ParsedStatement *Parser::ParseWhileStatement(const Token *current) {
auto condition = this -> ParseExpression(this -> Next()); auto condition = this -> ParseExpression(this -> Next());
auto doKeyword = this -> Next(); auto doKeyword = this -> Next();
if (doKeyword -> GetKind() != TokenKind::DoKeyword){ if (doKeyword -> GetKind() != TokenKind::DoKeyword){
@ -331,7 +331,7 @@ namespace Porygon::Parser {
// Expressions // // Expressions //
///////////////// /////////////////
ParsedExpression *Parser::ParseExpression(const IToken *current) { ParsedExpression *Parser::ParseExpression(const Token *current) {
auto expression = this->ParseBinaryExpression(current, OperatorPrecedence::No); auto expression = this->ParseBinaryExpression(current, OperatorPrecedence::No);
auto peekKind = this->Peek()->GetKind(); auto peekKind = this->Peek()->GetKind();
while (peekKind == TokenKind::OpenParenthesis || while (peekKind == TokenKind::OpenParenthesis ||
@ -447,7 +447,7 @@ namespace Porygon::Parser {
} }
} }
ParsedExpression *Parser::ParseBinaryExpression(const IToken *current, OperatorPrecedence parentPrecedence) { ParsedExpression *Parser::ParseBinaryExpression(const Token *current, OperatorPrecedence parentPrecedence) {
OperatorPrecedence unaryPrecedence = GetUnaryPrecedence(current->GetKind()); OperatorPrecedence unaryPrecedence = GetUnaryPrecedence(current->GetKind());
ParsedExpression *left; ParsedExpression *left;
if (unaryPrecedence != OperatorPrecedence::No && unaryPrecedence >= parentPrecedence) { if (unaryPrecedence != OperatorPrecedence::No && unaryPrecedence >= parentPrecedence) {
@ -474,7 +474,7 @@ namespace Porygon::Parser {
return left; return left;
} }
ParsedExpression *Parser::ParsePrimaryExpression(const IToken *current) { ParsedExpression *Parser::ParsePrimaryExpression(const Token *current) {
switch (current->GetKind()) { switch (current->GetKind()) {
case TokenKind::Integer: case TokenKind::Integer:
return new LiteralIntegerExpression(dynamic_cast<const IntegerToken*>(current)); return new LiteralIntegerExpression(dynamic_cast<const IntegerToken*>(current));
@ -502,7 +502,7 @@ namespace Porygon::Parser {
} }
} }
ParsedExpression *Parser::ParseParenthesizedExpression(const IToken *current) { ParsedExpression *Parser::ParseParenthesizedExpression(const Token *current) {
auto next = this->Next(); auto next = this->Next();
auto expression = this->ParseExpression(next); auto expression = this->ParseExpression(next);
auto closeToken = this->Next(); auto closeToken = this->Next();
@ -571,7 +571,7 @@ namespace Porygon::Parser {
} }
ParsedExpression *Parser::ParseTableExpression(const IToken *current) { ParsedExpression *Parser::ParseTableExpression(const Token *current) {
if (this->Peek()->GetKind() == TokenKind::CloseCurlyBracket) { if (this->Peek()->GetKind() == TokenKind::CloseCurlyBracket) {
this->Next(); this->Next();
auto start = current->GetStartPosition(); auto start = current->GetStartPosition();

View File

@ -1,3 +1,5 @@
#include <utility>
#ifndef PORYGONLANG_PARSER_HPP #ifndef PORYGONLANG_PARSER_HPP
#define PORYGONLANG_PARSER_HPP #define PORYGONLANG_PARSER_HPP
@ -19,45 +21,45 @@ namespace Porygon::Parser {
}; };
class Parser { class Parser {
vector<const IToken *> _tokens; vector<const Token *> _tokens;
unsigned int _position; unsigned int _position;
Porygon::Script *ScriptData; Porygon::Script *ScriptData;
const IToken *Peek(); const Token *Peek();
const IToken *PeekAt(int offset); const Token *PeekAt(int offset);
const IToken *Next(); const Token *Next();
// Statements // Statements
ParsedStatement *ParseStatement(const IToken *current); ParsedStatement *ParseStatement(const Token *current);
ParsedStatement *ParseVariableAssignment(const IToken *current); ParsedStatement *ParseVariableAssignment(const Token *current);
ParsedStatement *ParseIndexAssignment(ParsedExpression *indexer); ParsedStatement *ParseIndexAssignment(ParsedExpression *indexer);
ParsedBlockStatement *ParseBlock(const vector<TokenKind> &endTokens, const vector<const ParsedStatement *> &openStatements = {}); ParsedBlockStatement *ParseBlock(const vector<TokenKind> &endTokens, const vector<const ParsedStatement *> &openStatements = {});
ParsedStatement *ParseFunctionDeclaration(const IToken *current); ParsedStatement *ParseFunctionDeclaration(const Token *current);
ParsedStatement *ParseReturnStatement(const IToken *current); ParsedStatement *ParseReturnStatement(const Token *current);
ParsedStatement *ParseIfStatement(const IToken *current); ParsedStatement *ParseIfStatement(const Token *current);
ParsedStatement *ParseForStatement(); ParsedStatement *ParseForStatement();
ParsedStatement *ParseNumericForStatement(const IToken *current); ParsedStatement *ParseNumericForStatement(const Token *current);
ParsedStatement *ParseGenericForStatement(const IToken *current); ParsedStatement *ParseGenericForStatement(const Token *current);
ParsedStatement *ParseWhileStatement(const IToken *current); ParsedStatement *ParseWhileStatement(const Token *current);
// Expressions // Expressions
ParsedExpression *ParseExpression(const IToken *current); ParsedExpression *ParseExpression(const Token *current);
ParsedExpression *ParseBinaryExpression(const IToken *current, OperatorPrecedence parentPrecedence); ParsedExpression *ParseBinaryExpression(const Token *current, OperatorPrecedence parentPrecedence);
ParsedExpression *ParsePrimaryExpression(const IToken *current); ParsedExpression *ParsePrimaryExpression(const Token *current);
ParsedExpression *ParseParenthesizedExpression(const IToken *current); ParsedExpression *ParseParenthesizedExpression(const Token *current);
ParsedExpression *ParseFunctionCallExpression(ParsedExpression *functionExpression); ParsedExpression *ParseFunctionCallExpression(ParsedExpression *functionExpression);
ParsedExpression *ParseIndexExpression(ParsedExpression *indexingExpression); ParsedExpression *ParseIndexExpression(ParsedExpression *indexingExpression);
ParsedExpression *ParsePeriodIndexExpression(ParsedExpression *indexingExpression); ParsedExpression *ParsePeriodIndexExpression(ParsedExpression *indexingExpression);
ParsedExpression *ParseTableExpression(const IToken *current); ParsedExpression *ParseTableExpression(const Token *current);
public: public:
ParsedScriptStatement *Parse(); ParsedScriptStatement *Parse();
explicit Parser(const vector<const IToken *> &tokens, Porygon::Script *scriptData) : _tokens(tokens), _position(0), explicit Parser(vector<const Token *> tokens, Porygon::Script *scriptData) : _tokens(std::move(tokens)), _position(0),
ScriptData(scriptData){ ScriptData(scriptData){
} }

View File

@ -13,113 +13,113 @@ using namespace std;
using namespace Porygon::Utilities; using namespace Porygon::Utilities;
namespace Porygon::Parser { namespace Porygon::Parser {
class IToken { class Token {
const unsigned int _position; const unsigned int _position;
const unsigned int _length; const unsigned int _length;
public: public:
virtual const TokenKind GetKind() const = 0; virtual const TokenKind GetKind() const = 0;
IToken(unsigned int position, unsigned int length) Token(unsigned int position, unsigned int length)
: _position(position), _length(length) { : _position(position), _length(length) {
} }
const unsigned int GetStartPosition() const { inline const unsigned int GetStartPosition() const {
return _position; return _position;
} }
const unsigned int GetEndPosition() const { inline const unsigned int GetEndPosition() const {
return _position + _length - 1; return _position + _length - 1;
} }
const unsigned int GetLength() const { inline const unsigned int GetLength() const {
return _length; return _length;
} }
virtual ~IToken() = default; virtual ~Token() = default;
}; };
class SimpleToken : public IToken { class SimpleToken : public Token {
const TokenKind _kind; const TokenKind _kind;
public: public:
explicit SimpleToken(TokenKind kind, unsigned int position, unsigned int length) explicit SimpleToken(TokenKind kind, unsigned int position, unsigned int length)
: IToken(position, length), : Token(position, length),
_kind(kind) { _kind(kind) {
} }
const TokenKind GetKind() const final { inline const TokenKind GetKind() const final {
return _kind; return _kind;
} }
}; };
class IntegerToken : public IToken { class IntegerToken : public Token {
const long _value; const long _value;
public: public:
explicit IntegerToken(long value, unsigned int position, unsigned int length) explicit IntegerToken(long value, unsigned int position, unsigned int length)
: IToken(position, length), : Token(position, length),
_value(value) { _value(value) {
} }
const TokenKind GetKind() const final { inline const TokenKind GetKind() const final {
return TokenKind::Integer; return TokenKind::Integer;
} }
const long GetValue() const { inline const long GetValue() const {
return _value; return _value;
} }
}; };
class FloatToken : public IToken { class FloatToken : public Token {
const double _value; const double _value;
public: public:
explicit FloatToken(double value, unsigned int position, unsigned int length) explicit FloatToken(double value, unsigned int position, unsigned int length)
: IToken(position, length), : Token(position, length),
_value(value) { _value(value) {
} }
const TokenKind GetKind() const final { inline const TokenKind GetKind() const final {
return TokenKind::Float; return TokenKind::Float;
} }
const double GetValue() const { inline const double GetValue() const {
return _value; return _value;
} }
}; };
class StringToken : public IToken { class StringToken : public Token {
const u16string _value; const u16string _value;
public: public:
explicit StringToken(u16string value, unsigned int position, unsigned int length) explicit StringToken(u16string value, unsigned int position, unsigned int length)
: IToken(position, length), : Token(position, length),
_value(std::move(value)) { _value(std::move(value)) {
} }
const TokenKind GetKind() const final { inline const TokenKind GetKind() const final {
return TokenKind::String; return TokenKind::String;
} }
const u16string &GetValue() const { inline const u16string &GetValue() const {
return _value; return _value;
} }
}; };
class IdentifierToken : public IToken { class IdentifierToken : public Token {
const Utilities::HashedString _value; const Utilities::HashedString _value;
public: public:
explicit IdentifierToken(const HashedString value, unsigned int position, unsigned int length) explicit IdentifierToken(const HashedString value, unsigned int position, unsigned int length)
: IToken(position, length), : Token(position, length),
_value(value) { _value(value) {
} }
const TokenKind GetKind() const final { inline const TokenKind GetKind() const final {
return TokenKind::Identifier; return TokenKind::Identifier;
} }
const HashedString GetValue() const { inline const HashedString GetValue() const {
return _value; return _value;
} }
}; };

View File

@ -9,15 +9,15 @@ namespace Porygon::Parser {
HashedString _type; HashedString _type;
HashedString _identifier; HashedString _identifier;
public: public:
TypedVariableIdentifier(HashedString type, HashedString identifier) TypedVariableIdentifier(const HashedString& type, const HashedString& identifier)
: _type(type), _identifier(identifier) { : _type(type), _identifier(identifier) {
} }
HashedString GetType() { inline HashedString GetType() {
return _type; return _type;
} }
HashedString GetIdentifier() { inline HashedString GetIdentifier() {
return _identifier; return _identifier;
} }
}; };

View File

@ -11,7 +11,7 @@
#include "Parser/Parser.hpp" #include "Parser/Parser.hpp"
#include "Binder/Binder.hpp" #include "Binder/Binder.hpp"
Porygon::Script* Porygon::Script::Create(const u16string& script) { inline Porygon::Script* Porygon::Script::Create(const u16string& script) {
return new Script(script); return new Script(script);
} }
@ -20,7 +20,7 @@ std::u16string To_UTF16(const string &s)
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return conv.from_bytes(s); return conv.from_bytes(s);
} }
Porygon::Script *Porygon::Script::Create(const string &script) { inline Porygon::Script *Porygon::Script::Create(const string &script) {
return Script::Create(To_UTF16(script)); return Script::Create(To_UTF16(script));
} }
@ -65,7 +65,7 @@ void Porygon::Script::Parse(const u16string& script) {
delete parseResult; delete parseResult;
} }
EvalValue *Porygon::Script::GetVariable(const u16string &key) { inline EvalValue *Porygon::Script::GetVariable(const u16string &key) {
return _scriptVariables -> at(HashedString::CreateLookup(key)).get(); return _scriptVariables -> at(HashedString::CreateLookup(key)).get();
} }
@ -74,7 +74,7 @@ bool Porygon::Script::HasVariable(const u16string &key) {
return f != _scriptVariables->end(); return f != _scriptVariables->end();
} }
EvalValue *Porygon::Script::GetLastValue() { inline EvalValue *Porygon::Script::GetLastValue() {
return _evaluator->GetLastValue(); return _evaluator->GetLastValue();
} }
@ -83,7 +83,7 @@ bool Porygon::Script::HasFunction(const u16string &key) {
return f != _scriptVariables->end() && f.operator->()->second->GetTypeClass() == TypeClass ::Function; return f != _scriptVariables->end() && f.operator->()->second->GetTypeClass() == TypeClass ::Function;
} }
shared_ptr<EvalValue> Porygon::Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) { inline shared_ptr<EvalValue> Porygon::Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) {
auto var = (GenericFunctionEvalValue*)GetVariable(key); auto var = (GenericFunctionEvalValue*)GetVariable(key);
return this->_evaluator->EvaluateFunction(var, variables); return this->_evaluator->EvaluateFunction(var, variables);
} }

View File

@ -33,11 +33,11 @@ namespace Porygon{
~Script(); ~Script();
shared_ptr<ScriptType> GetReturnType(){ inline shared_ptr<ScriptType> GetReturnType(){
return _returnType; return _returnType;
} }
void SetReturnType(shared_ptr<ScriptType> t){ inline void SetReturnType(shared_ptr<ScriptType> t){
_returnType = std::move(t); _returnType = std::move(t);
} }

View File

@ -2,7 +2,7 @@
#include "UserData/UserDataFunctionType.hpp" #include "UserData/UserDataFunctionType.hpp"
namespace Porygon{ namespace Porygon{
const bool ScriptType::CanBeIndexedWith(ScriptType *indexer) const{ inline const bool ScriptType::CanBeIndexedWith(ScriptType *indexer) const{
return false; return false;
} }

View File

@ -81,11 +81,11 @@ namespace Porygon{
_isFloat = isFloat; _isFloat = isFloat;
} }
const bool IsAwareOfFloat() const{ inline const bool IsAwareOfFloat() const{
return _awareOfFloat; return _awareOfFloat;
} }
const bool IsFloat() const{ inline const bool IsFloat() const{
return _isFloat; return _isFloat;
} }
}; };
@ -106,15 +106,15 @@ namespace Porygon{
return !(num->IsAwareOfFloat() && num->IsFloat()); return !(num->IsAwareOfFloat() && num->IsFloat());
} }
const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{ inline const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{
return make_shared<StringScriptType>(false, 0); return make_shared<StringScriptType>(false, 0);
} }
const bool IsKnownAtBind() const{ inline const bool IsKnownAtBind() const{
return _isKnownAtBind; return _isKnownAtBind;
} }
const uint32_t GetHashValue() const{ inline const uint32_t GetHashValue() const{
return _hashValue; return _hashValue;
} }
}; };
@ -134,14 +134,14 @@ namespace Porygon{
return !(num->IsAwareOfFloat() && num->IsFloat()); return !(num->IsAwareOfFloat() && num->IsFloat());
} }
const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{ inline const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{
return _valueType; return _valueType;
} }
const bool CanBeIterated() const final{ inline const bool CanBeIterated() const final{
return true; return true;
} }
shared_ptr<ScriptType> GetIteratorKeyType() const final{ inline shared_ptr<ScriptType> GetIteratorKeyType() const final{
return make_shared<NumericScriptType>(true, false); return make_shared<NumericScriptType>(true, false);
} }
}; };

View File

@ -47,7 +47,7 @@ namespace Porygon::StandardLibraries{
return nullptr; return nullptr;
} }
static shared_ptr<Evaluation::EvalValue> GetVariable(const Utilities::HashedString &identifier){ inline static shared_ptr<Evaluation::EvalValue> GetVariable(const Utilities::HashedString &identifier){
return _internal._variables[identifier]; return _internal._variables[identifier];
} }
}; };

View File

@ -22,7 +22,7 @@ namespace Porygon{
delete _values; delete _values;
} }
const bool CanBeIndexedWith(ScriptType* indexer) const final{ inline const bool CanBeIndexedWith(ScriptType* indexer) const final{
return indexer->GetClass() == TypeClass ::String; return indexer->GetClass() == TypeClass ::String;
} }
@ -38,15 +38,15 @@ namespace Porygon{
throw "TODO: indexing with dynamic keys"; throw "TODO: indexing with dynamic keys";
} }
const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const final{ inline const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const final{
return _values-> at(Utilities::HashedString::CreateLookup(hash))->GetType(); return _values-> at(Utilities::HashedString::CreateLookup(hash))->GetType();
} }
const map<Utilities::HashedString, BoundVariable*>* GetValues() const{ inline const map<Utilities::HashedString, BoundVariable*>* GetValues() const{
return _values; return _values;
} }
const int GetLocalVariableCount() const{ inline const int GetLocalVariableCount() const{
return _localVariableCount; return _localVariableCount;
} }
}; };

View File

@ -52,19 +52,19 @@ namespace Porygon::UserData {
delete _concatenation; delete _concatenation;
} }
bool ContainsField(uint32_t fieldId) const{ inline bool ContainsField(uint32_t fieldId) const{
return _fields.find(fieldId) != _fields.end(); return _fields.find(fieldId) != _fields.end();
} }
UserDataField *GetField(uint32_t fieldId) const { inline UserDataField *GetField(uint32_t fieldId) const {
return _fields.at(fieldId); return _fields.at(fieldId);
} }
void CreateField(uint32_t fieldId, UserDataField *field) { inline void CreateField(uint32_t fieldId, UserDataField *field) {
_fields.insert({fieldId, field}); _fields.insert({fieldId, field});
} }
int32_t GetFieldCount() const{ inline int32_t GetFieldCount() const{
return _fields.size(); return _fields.size();
} }

View File

@ -16,23 +16,23 @@ namespace Porygon::UserData{
: _type(shared_ptr<ScriptType>(type)), _get(getter), _set(setter){ : _type(shared_ptr<ScriptType>(type)), _get(getter), _set(setter){
} }
shared_ptr<ScriptType> GetType(){ inline shared_ptr<ScriptType> GetType(){
return _type; return _type;
} }
bool HasGetter(){ inline bool HasGetter(){
return _get != nullptr; return _get != nullptr;
} }
Evaluation::EvalValue* Get(void* obj){ inline Evaluation::EvalValue* Get(void* obj){
return this ->_get(obj); return this ->_get(obj);
} }
bool HasSetter(){ inline bool HasSetter(){
return _set != nullptr; return _set != nullptr;
} }
void Set(void* obj, Evaluation::EvalValue* val){ inline void Set(void* obj, Evaluation::EvalValue* val){
this->_set(obj, val); this->_set(obj, val);
} }
}; };

View File

@ -27,7 +27,7 @@ namespace Porygon::UserData{
} }
Evaluation::EvalValue* Call(Evaluation::EvalValue* parameters[], int parameterCount){ inline Evaluation::EvalValue* Call(Evaluation::EvalValue* parameters[], int parameterCount){
return _call(_obj, parameters, parameterCount); return _call(_obj, parameters, parameterCount);
} }
}; };

View File

@ -21,7 +21,7 @@ namespace Porygon::UserData{
return new UserDataFunctionOption(rt, p); return new UserDataFunctionOption(rt, p);
} }
static UserDataFunctionOption* FromRawPointers(ScriptType* returnType){ inline static UserDataFunctionOption* FromRawPointers(ScriptType* returnType){
auto rt = shared_ptr<ScriptType>(returnType); auto rt = shared_ptr<ScriptType>(returnType);
return new UserDataFunctionOption(rt, {}); return new UserDataFunctionOption(rt, {});
} }
@ -29,7 +29,7 @@ namespace Porygon::UserData{
const bool IsScriptFunction() const final{ inline const bool IsScriptFunction() const final{
return false; return false;
} }
}; };

View File

@ -23,11 +23,11 @@ namespace Porygon::UserData {
return _func(_parent, b); return _func(_parent, b);
} }
const shared_ptr<ScriptType> GetSecondParameterType() const{ inline const shared_ptr<ScriptType> GetSecondParameterType() const{
return _secondParameter; return _secondParameter;
} }
const shared_ptr<ScriptType> GetReturnType() const{ inline const shared_ptr<ScriptType> GetReturnType() const{
return _returnType; return _returnType;
} }
}; };

View File

@ -30,11 +30,11 @@ namespace Porygon::UserData {
return _userData->ContainsField(str->GetHashValue()); return _userData->ContainsField(str->GetHashValue());
} }
const bool CanBeIndexedWithIdentifier(uint32_t hash) const final { inline const bool CanBeIndexedWithIdentifier(uint32_t hash) const final {
return _userData -> ContainsField(hash); return _userData -> ContainsField(hash);
} }
UserDataField *GetField(uint32_t id) { inline UserDataField *GetField(uint32_t id) {
return _userData->GetField(id); return _userData->GetField(id);
} }
@ -46,7 +46,7 @@ namespace Porygon::UserData {
throw "TODO: indexing with dynamic keys"; throw "TODO: indexing with dynamic keys";
} }
const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const final { inline const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const final {
return _userData->GetField(hash)->GetType(); return _userData->GetField(hash)->GetType();
} }
}; };

View File

@ -43,11 +43,11 @@ namespace Porygon::UserData {
_internal._userData.clear(); _internal._userData.clear();
} }
static bool HasUserDataType(uint32_t i) { inline static bool HasUserDataType(uint32_t i) {
return UserDataStorage::_internal._userData.find(i) != UserDataStorage::_internal._userData.end(); return UserDataStorage::_internal._userData.find(i) != UserDataStorage::_internal._userData.end();
} }
static UserData* GetUserDataType(uint32_t i) { inline static UserData* GetUserDataType(uint32_t i) {
return UserDataStorage::_internal._userData[i]; return UserDataStorage::_internal._userData[i];
} }
}; };

View File

@ -22,7 +22,7 @@ namespace Porygon::UserData {
_obj = obj; _obj = obj;
} }
const TypeClass GetTypeClass() const final { inline const TypeClass GetTypeClass() const final {
return TypeClass::UserData; return TypeClass::UserData;
} }
@ -32,11 +32,11 @@ namespace Porygon::UserData {
return _obj == ((UserDataValue *) b)->_obj; return _obj == ((UserDataValue *) b)->_obj;
} }
const shared_ptr<EvalValue> Clone() const final { inline const shared_ptr<EvalValue> Clone() const final {
return make_shared<UserDataValue>(_userData, _obj); return make_shared<UserDataValue>(_userData, _obj);
} }
const std::size_t GetHashCode() const final { inline const std::size_t GetHashCode() const final {
return reinterpret_cast<intptr_t>(_obj); return reinterpret_cast<intptr_t>(_obj);
} }
@ -46,7 +46,7 @@ namespace Porygon::UserData {
return shared_ptr<EvalValue>(field->Get(_obj)); return shared_ptr<EvalValue>(field->Get(_obj));
} }
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final { inline const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
auto field = _userData->GetField(hash); auto field = _userData->GetField(hash);
return shared_ptr<EvalValue>(field->Get(_obj)); return shared_ptr<EvalValue>(field->Get(_obj));
} }
@ -57,7 +57,7 @@ namespace Porygon::UserData {
field->Set(_obj, value.get()); field->Set(_obj, value.get());
} }
void* GetObjectPointer(){ inline void* GetObjectPointer(){
return _obj; return _obj;
} }
}; };

View File

@ -22,45 +22,45 @@ namespace Porygon::Utilities{
_string(std::shared_ptr<const std::u16string>(s)) _string(std::shared_ptr<const std::u16string>(s))
{ {
} }
static HashedString CreateLookup(const std::u16string& s){ inline static HashedString CreateLookup(const std::u16string& s){
return HashedString(s); return HashedString(s);
} }
static HashedString CreateLookup(uint32_t hash){ inline static HashedString CreateLookup(uint32_t hash){
return HashedString(hash); return HashedString(hash);
} }
HashedString(const HashedString& b) = default; HashedString(const HashedString& b) = default;
static uint32_t constexpr ConstHash(char16_t const *input) { inline static uint32_t constexpr ConstHash(char16_t const *input) {
return *input ? return *input ?
static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) : static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) :
5381; 5381;
} }
static uint32_t constexpr ConstHash(char const *input) { inline static uint32_t constexpr ConstHash(char const *input) {
return *input ? return *input ?
static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) : static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) :
5381; 5381;
} }
const uint32_t GetHash() const{ inline const uint32_t GetHash() const{
return _hash; return _hash;
} }
const std::shared_ptr<const std::u16string> GetString() const{ inline const std::shared_ptr<const std::u16string> GetString() const{
return _string; return _string;
} }
bool operator==(const HashedString& b) const{ inline bool operator==(const HashedString& b) const{
return _hash == b._hash; return _hash == b._hash;
} }
bool operator!=(const HashedString& b) const{ inline bool operator!=(const HashedString& b) const{
return _hash != b._hash; return _hash != b._hash;
} }
bool operator<(const HashedString& b) const{ inline bool operator<(const HashedString& b) const{
return _hash < b._hash; return _hash < b._hash;
} }
bool operator>(const HashedString& b) const{ inline bool operator>(const HashedString& b) const{
return _hash > b._hash; return _hash > b._hash;
} }

View File

@ -13,17 +13,17 @@ namespace Porygon::Utilities{
private: private:
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>, char16_t> to_16; static std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>, char16_t> to_16;
public: public:
static std::u16string IntToString(long const &i) { inline static std::u16string IntToString(long const &i) {
return to_16.from_bytes(std::to_string(i)); return to_16.from_bytes(std::to_string(i));
} }
static std::u16string ToUTF8(const std::string &s) { inline static std::u16string ToUTF8(const std::string &s) {
return to_16.from_bytes(s); return to_16.from_bytes(s);
} }
static std::string FromUTF8(const std::u16string &s) { inline static std::string FromUTF8(const std::u16string &s) {
return to_16.to_bytes(s); return to_16.to_bytes(s);
} }
static int64_t ParseInteger(const std::u16string &s){ inline static int64_t ParseInteger(const std::u16string &s){
auto parsed = std::stol(FromUTF8(s)); auto parsed = std::stol(FromUTF8(s));
return parsed; return parsed;
} }

View File

@ -77,7 +77,7 @@ TEST_CASE( "Lex Equality Token", "[lexer]" ) {
Lexer lexer = Lexer(u"==", nullptr); Lexer lexer = Lexer(u"==", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::EqualityToken); REQUIRE(firstToken -> GetKind() == TokenKind::EqualityToken);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -117,7 +117,7 @@ TEST_CASE( "Lex Longer Integers", "[lexer]" ) {
Lexer lexer = Lexer(s, nullptr); Lexer lexer = Lexer(s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::Integer); REQUIRE(firstToken -> GetKind() == TokenKind::Integer);
auto* integerToken = (IntegerToken *)firstToken; auto* integerToken = (IntegerToken *)firstToken;
CHECK(integerToken -> GetValue() == integer); CHECK(integerToken -> GetValue() == integer);
@ -139,7 +139,7 @@ TEST_CASE( "Lex Floats", "[lexer]" ) {
Lexer lexer = Lexer(s, nullptr); Lexer lexer = Lexer(s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::Float); REQUIRE(firstToken -> GetKind() == TokenKind::Float);
auto* floatToken = (FloatToken *)firstToken; auto* floatToken = (FloatToken *)firstToken;
CHECK(floatToken -> GetValue() == Approx(f)); CHECK(floatToken -> GetValue() == Approx(f));
@ -154,7 +154,7 @@ TEST_CASE( "Lex And Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"and", nullptr); Lexer lexer = Lexer(u"and", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::AndKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::AndKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -164,7 +164,7 @@ TEST_CASE( "Lex Break Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"break", nullptr); Lexer lexer = Lexer(u"break", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::BreakKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::BreakKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -174,7 +174,7 @@ TEST_CASE( "Lex Do Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"do", nullptr); Lexer lexer = Lexer(u"do", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::DoKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::DoKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -184,7 +184,7 @@ TEST_CASE( "Lex else Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"else", nullptr); Lexer lexer = Lexer(u"else", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::ElseKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::ElseKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -194,7 +194,7 @@ TEST_CASE( "Lex else if Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"elseif", nullptr); Lexer lexer = Lexer(u"elseif", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::ElseIfKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::ElseIfKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -204,7 +204,7 @@ TEST_CASE( "Lex end Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"end", nullptr); Lexer lexer = Lexer(u"end", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::EndKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::EndKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -214,7 +214,7 @@ TEST_CASE( "Lex false Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"false", nullptr); Lexer lexer = Lexer(u"false", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::FalseKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::FalseKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -224,7 +224,7 @@ TEST_CASE( "Lex for Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"for", nullptr); Lexer lexer = Lexer(u"for", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::ForKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::ForKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -235,7 +235,7 @@ TEST_CASE( "Lex function Keyword", "[lexer]" ) {
Lexer lexer = Lexer(*s, nullptr); Lexer lexer = Lexer(*s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::FunctionKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::FunctionKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -246,7 +246,7 @@ TEST_CASE( "Lex if Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"if", nullptr); Lexer lexer = Lexer(u"if", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::IfKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::IfKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -256,7 +256,7 @@ TEST_CASE( "Lex in Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"in", nullptr); Lexer lexer = Lexer(u"in", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::InKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::InKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -266,7 +266,7 @@ TEST_CASE( "Lex local Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"local", nullptr); Lexer lexer = Lexer(u"local", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::LocalKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::LocalKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -276,7 +276,7 @@ TEST_CASE( "Lex nil Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"nil", nullptr); Lexer lexer = Lexer(u"nil", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::NilKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::NilKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -286,7 +286,7 @@ TEST_CASE( "Lex not Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"not", nullptr); Lexer lexer = Lexer(u"not", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::NotKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::NotKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -296,7 +296,7 @@ TEST_CASE( "Lex or Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"or", nullptr); Lexer lexer = Lexer(u"or", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::OrKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::OrKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -306,7 +306,7 @@ TEST_CASE( "Lex return Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"return", nullptr); Lexer lexer = Lexer(u"return", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::ReturnKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::ReturnKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -316,7 +316,7 @@ TEST_CASE( "Lex then Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"then", nullptr); Lexer lexer = Lexer(u"then", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::ThenKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::ThenKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -326,7 +326,7 @@ TEST_CASE( "Lex true Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"true", nullptr); Lexer lexer = Lexer(u"true", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::TrueKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::TrueKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -336,7 +336,7 @@ TEST_CASE( "Lex while Keyword", "[lexer]" ) {
Lexer lexer = Lexer(u"while", nullptr); Lexer lexer = Lexer(u"while", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::WhileKeyword); REQUIRE(firstToken -> GetKind() == TokenKind::WhileKeyword);
for (auto t: tokens){ for (auto t: tokens){
delete t; delete t;
@ -347,7 +347,7 @@ TEST_CASE( "Lex identifier", "[lexer]" ) {
Lexer lexer = Lexer(u"foo", nullptr); Lexer lexer = Lexer(u"foo", nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::Identifier); REQUIRE(firstToken -> GetKind() == TokenKind::Identifier);
REQUIRE(((IdentifierToken*)firstToken) -> GetValue() == HashedString::CreateLookup(u"foo")); REQUIRE(((IdentifierToken*)firstToken) -> GetValue() == HashedString::CreateLookup(u"foo"));
for (auto t: tokens){ for (auto t: tokens){
@ -392,7 +392,7 @@ TEST_CASE("Lex Double Quote String", "[lexer]") {
Lexer lexer = Lexer(*s, nullptr); Lexer lexer = Lexer(*s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::String); REQUIRE(firstToken -> GetKind() == TokenKind::String);
REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo bar"); REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo bar");
for (auto t: tokens){ for (auto t: tokens){
@ -406,7 +406,7 @@ TEST_CASE("Lex Single Quote String", "[lexer]") {
Lexer lexer = Lexer(*s, nullptr); Lexer lexer = Lexer(*s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::String); REQUIRE(firstToken -> GetKind() == TokenKind::String);
REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo bar"); REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo bar");
for (auto t: tokens){ for (auto t: tokens){
@ -420,7 +420,7 @@ TEST_CASE("Lex Double Quote String, Escape Quote", "[lexer]") {
Lexer lexer = Lexer(*s, nullptr); Lexer lexer = Lexer(*s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::String); REQUIRE(firstToken -> GetKind() == TokenKind::String);
REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo\"bar"); REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo\"bar");
for (auto t: tokens){ for (auto t: tokens){
@ -434,7 +434,7 @@ TEST_CASE("Lex String with newline", "[lexer]") {
Lexer lexer = Lexer(*s, nullptr); Lexer lexer = Lexer(*s, nullptr);
auto tokens = lexer.Lex(); auto tokens = lexer.Lex();
REQUIRE(tokens.size() == 2); REQUIRE(tokens.size() == 2);
const IToken* firstToken = tokens[0]; const Token* firstToken = tokens[0];
REQUIRE(firstToken -> GetKind() == TokenKind::String); REQUIRE(firstToken -> GetKind() == TokenKind::String);
REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo\nbar"); REQUIRE(((StringToken*)firstToken) -> GetValue() == u"foo\nbar");
for (auto t: tokens){ for (auto t: tokens){

View File

@ -6,7 +6,7 @@
using namespace Porygon::Parser; using namespace Porygon::Parser;
TEST_CASE( "Parse single true keyword", "[parser]" ) { TEST_CASE( "Parse single true keyword", "[parser]" ) {
vector<const IToken*> v {new SimpleToken(TokenKind::TrueKeyword,0,0), new SimpleToken(TokenKind::EndOfFile,0,0)}; vector<const Token*> v {new SimpleToken(TokenKind::TrueKeyword,0,0), new SimpleToken(TokenKind::EndOfFile,0,0)};
Parser parser = Parser(v, nullptr); Parser parser = Parser(v, nullptr);
auto parsedScript = parser.Parse(); auto parsedScript = parser.Parse();
auto parsedStatements = parsedScript -> GetStatements(); auto parsedStatements = parsedScript -> GetStatements();
@ -25,7 +25,7 @@ TEST_CASE( "Parse single true keyword", "[parser]" ) {
} }
TEST_CASE( "Parse single false keyword", "[parser]" ) { TEST_CASE( "Parse single false keyword", "[parser]" ) {
vector<const IToken*> v {new SimpleToken(TokenKind::FalseKeyword,0,0), new SimpleToken(TokenKind::EndOfFile,0,0)}; vector<const Token*> v {new SimpleToken(TokenKind::FalseKeyword,0,0), new SimpleToken(TokenKind::EndOfFile,0,0)};
Parser parser = Parser(v, nullptr); Parser parser = Parser(v, nullptr);
auto parsedScript = parser.Parse(); auto parsedScript = parser.Parse();
auto parsedStatements = parsedScript -> GetStatements(); auto parsedStatements = parsedScript -> GetStatements();
@ -44,7 +44,7 @@ TEST_CASE( "Parse single false keyword", "[parser]" ) {
} }
TEST_CASE( "Parse simple addition", "[parser]" ) { TEST_CASE( "Parse simple addition", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new IntegerToken(5, 0, 0), new IntegerToken(5, 0, 0),
new SimpleToken(TokenKind::PlusToken,0,0), new SimpleToken(TokenKind::PlusToken,0,0),
new IntegerToken(10, 0, 0), new IntegerToken(10, 0, 0),
@ -74,7 +74,7 @@ TEST_CASE( "Parse simple addition", "[parser]" ) {
} }
TEST_CASE( "Parse simple negation", "[parser]" ) { TEST_CASE( "Parse simple negation", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new SimpleToken(TokenKind::MinusToken,0,0), new SimpleToken(TokenKind::MinusToken,0,0),
new IntegerToken(10, 0, 0), new IntegerToken(10, 0, 0),
new SimpleToken(TokenKind::EndOfFile,0,0) new SimpleToken(TokenKind::EndOfFile,0,0)
@ -99,7 +99,7 @@ TEST_CASE( "Parse simple negation", "[parser]" ) {
} }
TEST_CASE( "Parse logical negation", "[parser]" ) { TEST_CASE( "Parse logical negation", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new SimpleToken(TokenKind::NotKeyword,0,0), new SimpleToken(TokenKind::NotKeyword,0,0),
new SimpleToken(TokenKind::FalseKeyword,0,0), new SimpleToken(TokenKind::FalseKeyword,0,0),
new SimpleToken(TokenKind::EndOfFile,0,0) new SimpleToken(TokenKind::EndOfFile,0,0)
@ -124,7 +124,7 @@ TEST_CASE( "Parse logical negation", "[parser]" ) {
} }
TEST_CASE( "Are parenthesized expressions valid", "[parser]" ) { TEST_CASE( "Are parenthesized expressions valid", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new IntegerToken(5, 0, 0), new IntegerToken(5, 0, 0),
new SimpleToken(TokenKind::PlusToken,0,0), new SimpleToken(TokenKind::PlusToken,0,0),
new IntegerToken(10, 0, 0), new IntegerToken(10, 0, 0),
@ -159,7 +159,7 @@ TEST_CASE( "Are parenthesized expressions valid", "[parser]" ) {
} }
TEST_CASE( "Assert binary precedence", "[parser]" ) { TEST_CASE( "Assert binary precedence", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new SimpleToken(TokenKind::OpenParenthesis,0,0), new SimpleToken(TokenKind::OpenParenthesis,0,0),
new IntegerToken(10, 0, 0), new IntegerToken(10, 0, 0),
new SimpleToken(TokenKind::CloseParenthesis,0,0), new SimpleToken(TokenKind::CloseParenthesis,0,0),
@ -183,7 +183,7 @@ TEST_CASE( "Assert binary precedence", "[parser]" ) {
} }
TEST_CASE( "Parse String Tokens", "[parser]" ) { TEST_CASE( "Parse String Tokens", "[parser]" ) {
vector<const IToken*> v {new StringToken(u"foo bar", 0,0), new SimpleToken(TokenKind::EndOfFile,0,0)}; vector<const Token*> v {new StringToken(u"foo bar", 0,0), new SimpleToken(TokenKind::EndOfFile,0,0)};
Parser parser = Parser(v, nullptr); Parser parser = Parser(v, nullptr);
auto parsedScript = parser.Parse(); auto parsedScript = parser.Parse();
auto parsedStatements = parsedScript -> GetStatements(); auto parsedStatements = parsedScript -> GetStatements();
@ -202,7 +202,7 @@ TEST_CASE( "Parse String Tokens", "[parser]" ) {
} }
TEST_CASE( "Parse Global Assignment", "[parser]" ) { TEST_CASE( "Parse Global Assignment", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new IdentifierToken(HashedString::CreateLookup(u"foo"),0,0), new IdentifierToken(HashedString::CreateLookup(u"foo"),0,0),
new SimpleToken(TokenKind::AssignmentToken,0,0), new SimpleToken(TokenKind::AssignmentToken,0,0),
new SimpleToken(TokenKind::TrueKeyword,0,0), new SimpleToken(TokenKind::TrueKeyword,0,0),
@ -226,7 +226,7 @@ TEST_CASE( "Parse Global Assignment", "[parser]" ) {
} }
TEST_CASE( "Parse local Assignment", "[parser]" ) { TEST_CASE( "Parse local Assignment", "[parser]" ) {
vector<const IToken*> v { vector<const Token*> v {
new SimpleToken(TokenKind::LocalKeyword,0,0), new SimpleToken(TokenKind::LocalKeyword,0,0),
new IdentifierToken(HashedString(new u16string(u"foo")),0,0), new IdentifierToken(HashedString(new u16string(u"foo")),0,0),
new SimpleToken(TokenKind::AssignmentToken,0,0), new SimpleToken(TokenKind::AssignmentToken,0,0),
@ -252,7 +252,7 @@ TEST_CASE( "Parse local Assignment", "[parser]" ) {
} }
TEST_CASE( "Parse function declaration", "[parser]" ){ TEST_CASE( "Parse function declaration", "[parser]" ){
vector<const IToken*> v { vector<const Token*> v {
new SimpleToken(TokenKind::FunctionKeyword,0,0), new SimpleToken(TokenKind::FunctionKeyword,0,0),
new IdentifierToken(HashedString(new u16string(u"foo")),0,0), new IdentifierToken(HashedString(new u16string(u"foo")),0,0),
new SimpleToken(TokenKind::OpenParenthesis,0,0), new SimpleToken(TokenKind::OpenParenthesis,0,0),