Mark evalValues as const
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-17 17:43:54 +02:00
parent d91caa7f32
commit 21d3329c55
14 changed files with 204 additions and 215 deletions

View File

@@ -1,7 +1,5 @@
#include <utility>
#include <utility>
#ifndef PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
#define PORYGONLANG_SCRIPTFUNCTIONEVALVALUE_HPP
@@ -15,57 +13,58 @@
class ScriptFunctionEvalValue : public EvalValue{
std::shared_ptr<BoundBlockStatement> _innerBlock;
std::shared_ptr<FunctionScriptType> _type;
std::shared_ptr<EvaluationScope> _scope;
std::size_t _hash;
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
const std::shared_ptr<BoundBlockStatement> _innerBlock;
const std::shared_ptr<FunctionScriptType> _type;
const std::shared_ptr<EvaluationScope> _scope;
const std::size_t _hash;
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type, size_t hash)
: _type(std::move(type))
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(hash)
{
_innerBlock = std::move(innerBlock);
_scope = std::move(scope);
_hash = hash;
}
public:
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
explicit ScriptFunctionEvalValue(std::shared_ptr<BoundBlockStatement> innerBlock, std::shared_ptr<EvaluationScope> scope,
std::shared_ptr<FunctionScriptType> type)
: _type(std::move(type))
: _type(std::move(type)),
_innerBlock(std::move(innerBlock)),
_scope(std::move(scope)),
_hash(rand())
{
_innerBlock = std::move(innerBlock);
_scope = std::move(scope);
_hash = rand();
}
std::shared_ptr<ScriptType> GetType() const{
const std::shared_ptr<ScriptType> GetType() const{
return _type;
}
const TypeClass GetTypeClass() final{
const TypeClass GetTypeClass() const final{
return TypeClass ::Function;
}
shared_ptr<EvalValue> Clone() final{
const shared_ptr<EvalValue> Clone() const final{
// We don't run make_shared here as it can't call private constructors
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope, _type, _hash));
}
bool operator ==(EvalValue* b) final{
const bool operator ==(EvalValue* b) const final{
if (b->GetTypeClass() != TypeClass::Function)
return false;
return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash;
};
std::shared_ptr<BoundBlockStatement> GetInnerBlock() const{
const std::shared_ptr<BoundBlockStatement>& GetInnerBlock() const{
return _innerBlock;
}
std::size_t GetHashCode() final{
const std::size_t GetHashCode() const final{
return _hash;
}
std::shared_ptr<EvaluationScope> GetScope() const{
const std::shared_ptr<EvaluationScope>& GetScope() const{
return _scope;
}
};