Add support for const declarations (#264)

Adds:
- analyzer/Constants: holds constant name -> value for lookup
- ast/ConstDeclaration: AST node for a const declaration
- optimizer/ConstValidator: validates that an optimized expression is valid to use as a constant.

the Optimizer converts Identifiers that refer to a constant to the optimized constant value.
This commit is contained in:
Eric Swanson 2020-09-01 00:54:24 -07:00 committed by GitHub
parent 6d163918c5
commit 6ce9c38de3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 354 additions and 13 deletions

View file

@ -1,6 +1,7 @@
#include "ModuleProcessor.h"
#include "compiler/Profile.h"
#include "compiler/ast/ConstDeclaration.h"
#include "compiler/ast/ModuleFunctionDeclaration.h"
#include "compiler/astbuilder/BuilderWorkspace.h"
#include "compiler/file/SourceFile.h"
@ -31,6 +32,11 @@ antlrcpp::Any ModuleProcessor::visitModuleDeclarationStatement(
workspace.compiler_workspace.module_function_declarations.push_back( std::move( ast ) );
}
else if ( auto constStatement = ctx->constStatement() )
{
workspace.compiler_workspace.const_declarations.push_back(
tree_builder.const_declaration( constStatement ) );
}
return antlrcpp::Any();
}