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

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

View File

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

View File

@@ -10,48 +10,48 @@
namespace Porygon::Evaluation{
class EvalValueHelper{
public:
static EvalValue* Create(unsigned char i){
inline static EvalValue* Create(unsigned char i){
return new IntegerEvalValue((long)i);
}
static EvalValue* Create(signed char i){
inline static EvalValue* Create(signed char i){
return new IntegerEvalValue((long)i);
}
static EvalValue* Create(short int i){
inline static EvalValue* Create(short int i){
return new IntegerEvalValue(i);
}
static EvalValue* Create(unsigned short int i){
inline static EvalValue* Create(unsigned short int i){
return new IntegerEvalValue(i);
}
static EvalValue* Create(signed int i){
inline static EvalValue* Create(signed int i){
return new IntegerEvalValue(i);
}
static EvalValue* Create(unsigned int i){
inline static EvalValue* Create(unsigned int i){
return new IntegerEvalValue(i);
}
static EvalValue* Create(signed long l){
inline static EvalValue* Create(signed long l){
return new IntegerEvalValue(l);
}
static EvalValue* Create(unsigned long l){
inline static EvalValue* Create(unsigned long l){
return new IntegerEvalValue(l);
}
static EvalValue* Create(float f){
inline static EvalValue* Create(float f){
return new FloatEvalValue(f);
}
static EvalValue* Create(double f){
inline static EvalValue* Create(double f){
return new FloatEvalValue(f);
}
static EvalValue* Create(long double f){
inline static EvalValue* Create(long double f){
return new FloatEvalValue(f);
}
static EvalValue* Create(bool b){
inline static EvalValue* Create(bool 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));
}
static EvalValue* Create(u16string s){
inline static EvalValue* Create(u16string s){
return new StringEvalValue(std::move(s));
}
};

View File

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

View File

@@ -16,7 +16,7 @@ namespace Porygon::Evaluation {
public:
virtual const bool IsFloat() const = 0;
const TypeClass GetTypeClass() const final {
inline const TypeClass GetTypeClass() const final {
return TypeClass::Number;
}
@@ -52,23 +52,23 @@ namespace Porygon::Evaluation {
explicit IntegerEvalValue(long value) : _value(value) {
}
const bool IsFloat() const final {
inline const bool IsFloat() const final {
return false;
}
const long EvaluateInteger() const final {
inline const long EvaluateInteger() const final {
return _value;
}
const std::u16string EvaluateString() const final{
inline const std::u16string EvaluateString() const final{
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);
}
const std::size_t GetHashCode() const final {
inline const std::size_t GetHashCode() const final {
return std::hash<long>{}(_value);
}
};
@@ -76,29 +76,31 @@ namespace Porygon::Evaluation {
class FloatEvalValue : public NumericEvalValue {
const double _value;
const long GetIntegerValue() const final {
inline const long GetIntegerValue() const final {
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:
explicit FloatEvalValue(double value) : _value(value) {
}
const bool IsFloat() const final {
inline const bool IsFloat() const final {
return true;
}
const double EvaluateFloat() const final {
inline const double EvaluateFloat() const final {
return _value;
}
const shared_ptr<EvalValue> Clone() const final {
inline const shared_ptr<EvalValue> Clone() const final {
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);
}
};

View File

@@ -1,6 +1,6 @@
#include "NumericalTableEvalValue.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);
}

View File

@@ -26,39 +26,39 @@ namespace Porygon::Evaluation {
{
}
const TypeClass GetTypeClass() const final {
inline const TypeClass GetTypeClass() const final {
return TypeClass::Table;
}
const size_t GetHashCode() const final {
inline const size_t GetHashCode() const final {
return _hash;
}
const bool operator==(EvalValue *b) const final {
inline const bool operator==(EvalValue *b) const final {
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));
}
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;
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);
}
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();
this->_table->at(index - 1) = value;
}
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;
};
};

View File

@@ -29,11 +29,11 @@ namespace Porygon::Evaluation {
}
~EvaluationScriptFunctionOption() final = default;
const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
inline const std::shared_ptr<BoundBlockStatement> &GetInnerBlock() const {
return _innerBlock;
}
const std::shared_ptr<EvaluationScope> &GetScope() const {
inline const std::shared_ptr<EvaluationScope> &GetScope() const {
return _scope;
}
};
@@ -57,15 +57,15 @@ namespace Porygon::Evaluation {
return t;
}
void RegisterOption(GenericFunctionOption* option){
inline void RegisterOption(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;
}
const TypeClass GetTypeClass() const final {
inline const TypeClass GetTypeClass() const final {
return TypeClass::Function;
}
@@ -75,11 +75,11 @@ namespace Porygon::Evaluation {
return this->_hash == ((GenericFunctionEvalValue *) b)->_hash;
};
const std::size_t GetHashCode() const final {
inline const std::size_t GetHashCode() const final {
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);
}
};

View File

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

View File

@@ -1,6 +1,6 @@
#include "TableEvalValue.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);
}

View File

@@ -25,47 +25,47 @@ namespace Porygon::Evaluation {
{
}
const TypeClass GetTypeClass() const final {
inline const TypeClass GetTypeClass() const final {
return TypeClass::Table;
}
const size_t GetHashCode() const final {
inline const size_t GetHashCode() const final {
return _hash;
}
const bool operator==(EvalValue *b) const final {
inline const bool operator==(EvalValue *b) const final {
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));
}
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
inline const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
const auto stringKey = val->EvaluateString();
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));
}
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);
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();
this->_table->at(Utilities::HashedString::CreateLookup(hash)) = value;
}
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();
};
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();
};
};

View File

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

View File

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

View File

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