Implements string evaluation and concat
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "../../ScriptType.hpp"
|
||||
#include "../EvaluationException.hpp"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
class EvalValue{
|
||||
public:
|
||||
@@ -57,6 +58,12 @@ public:
|
||||
return false;
|
||||
return this->EvaluateBool() == b->EvaluateBool();
|
||||
};
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_EVALVALUE_HPP
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
#define PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
|
||||
#include <sstream>
|
||||
#include "EvalValue.hpp"
|
||||
|
||||
class NumericEvalValue : public EvalValue{
|
||||
@@ -43,6 +44,12 @@ public:
|
||||
long EvaluateInteger() final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
};
|
||||
|
||||
class FloatEvalValue : public NumericEvalValue{
|
||||
@@ -61,6 +68,12 @@ public:
|
||||
double EvaluateFloat() final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
|
||||
2
src/Evaluator/EvalValues/StringEvalValue.cpp
Normal file
2
src/Evaluator/EvalValues/StringEvalValue.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
#include "StringEvalValue.hpp"
|
||||
38
src/Evaluator/EvalValues/StringEvalValue.hpp
Normal file
38
src/Evaluator/EvalValues/StringEvalValue.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
#ifndef PORYGONLANG_STRINGEVALVALUE_HPP
|
||||
#define PORYGONLANG_STRINGEVALVALUE_HPP
|
||||
|
||||
#include <string>
|
||||
#include "EvalValue.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class StringEvalValue : public EvalValue{
|
||||
string _value;
|
||||
ScriptType* _type;
|
||||
public:
|
||||
explicit StringEvalValue(string s){
|
||||
_value = move(s);
|
||||
_type = new ScriptType(TypeClass::String);
|
||||
}
|
||||
~StringEvalValue() final{
|
||||
delete _type;
|
||||
}
|
||||
|
||||
ScriptType* GetType() final{
|
||||
return _type;
|
||||
};
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::String)
|
||||
return false;
|
||||
return this->_value == b->EvaluateString();
|
||||
};
|
||||
|
||||
string EvaluateString() final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //PORYGONLANG_STRINGEVALVALUE_HPP
|
||||
Reference in New Issue
Block a user