mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Update grammar * Update expression handling for uninit * update existing tests * Add new tests * Remove fullpath from escriptgrammar generation comment * fix tests * Update eScript guide * Declare escript version 0x11 * Add core-changes * Add `true` and `false` to grammar * true/false implementation * Fix existing tests * Add new tests * Update core changes * add docs * Fix BooleanValue::describe_to * bool optimizations * optimize uninit * remove unused var assignments * Update grammar for case labels for uninit, booleans * Fix case label handling for uninit, true, false * Tests * Fix compiler version display v1.1700000017881393 -> v1.17 * optimize boolean binary operations * fix unary boolean optimizer * add boolean, uninit optimizer test * Use new fmt lib apis * Fix compiler warning * really fix warning lol * Add Executor[Module]::getParam for bools, FindSubstance test
82 lines
2 KiB
C++
82 lines
2 KiB
C++
#include "ConstantValidator.h"
|
|
|
|
#include "bscript/compiler/ast/ArrayInitializer.h"
|
|
#include "bscript/compiler/ast/BooleanValue.h"
|
|
#include "bscript/compiler/ast/ConstDeclaration.h"
|
|
#include "bscript/compiler/ast/DictionaryInitializer.h"
|
|
#include "bscript/compiler/ast/ErrorInitializer.h"
|
|
#include "bscript/compiler/ast/FloatValue.h"
|
|
#include "bscript/compiler/ast/FunctionCall.h"
|
|
#include "bscript/compiler/ast/Identifier.h"
|
|
#include "bscript/compiler/ast/IntegerValue.h"
|
|
#include "bscript/compiler/ast/StringValue.h"
|
|
#include "bscript/compiler/ast/StructInitializer.h"
|
|
#include "bscript/compiler/model/FunctionLink.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
ConstantValidator::ConstantValidator() : valid( false ) {}
|
|
|
|
bool ConstantValidator::validate( Node& node )
|
|
{
|
|
valid = false;
|
|
node.accept( *this );
|
|
return valid;
|
|
}
|
|
|
|
void ConstantValidator::visit_array_initializer( ArrayInitializer& initializer )
|
|
{
|
|
valid = initializer.children.empty();
|
|
}
|
|
|
|
void ConstantValidator::visit_boolean_value( BooleanValue& )
|
|
{
|
|
valid = true;
|
|
}
|
|
|
|
void ConstantValidator::visit_dictionary_initializer( DictionaryInitializer& initializer )
|
|
{
|
|
valid = initializer.children.empty();
|
|
}
|
|
|
|
void ConstantValidator::visit_error_initializer( ErrorInitializer& initializer )
|
|
{
|
|
valid = initializer.children.empty();
|
|
}
|
|
|
|
void ConstantValidator::visit_float_value( FloatValue& )
|
|
{
|
|
valid = true;
|
|
}
|
|
|
|
void ConstantValidator::visit_function_call( FunctionCall& fc )
|
|
{
|
|
// this was only allowed by accident.
|
|
valid = ( fc.function_link->module_function_declaration() && fc.children.empty() );
|
|
}
|
|
|
|
void ConstantValidator::visit_integer_value( IntegerValue& )
|
|
{
|
|
valid = true;
|
|
}
|
|
|
|
void ConstantValidator::visit_string_value( StringValue& )
|
|
{
|
|
valid = true;
|
|
}
|
|
|
|
void ConstantValidator::visit_struct_initializer( StructInitializer& initializer )
|
|
{
|
|
valid = initializer.children.empty();
|
|
}
|
|
|
|
void ConstantValidator::visit_uninitialized_value( UninitializedValue& )
|
|
{
|
|
valid = true;
|
|
}
|
|
|
|
void ConstantValidator::visit_children( Node& )
|
|
{
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|