mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] Compilation pipeline, register global symbols in advance
Since I've implemented AST, now I can drop forward declarations. Instead, I traverse AST of all files and register global symbols (functions, constants, global vars) as a separate step, in advance. That's why, while converting AST to Expr/Op, all available symbols are already registered. This greatly simplifies "intermediate state" of yet unknown functions and checking them afterward. Redeclaration of local variables (inside the same scope) is now also prohibited.
This commit is contained in:
parent
80001d1756
commit
5a3e3595d6
28 changed files with 1266 additions and 1134 deletions
|
@ -148,52 +148,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class ASTVisitorToplevelDeclarations : public ASTVisitor {
|
||||
protected:
|
||||
using parent = ASTVisitorToplevelDeclarations;
|
||||
|
||||
virtual void on_pragma_no_arg(V<ast_pragma_no_arg> v) = 0;
|
||||
virtual void on_pragma_version(V<ast_pragma_version> v) = 0;
|
||||
virtual void on_include_statement(V<ast_include_statement> v) = 0;
|
||||
virtual void on_constant_declaration(V<ast_constant_declaration> v) = 0;
|
||||
virtual void on_global_var_declaration(V<ast_global_var_declaration> v) = 0;
|
||||
virtual void on_function_declaration(V<ast_function_declaration> v) = 0;
|
||||
|
||||
void visit(AnyV v) final {
|
||||
switch (v->type) {
|
||||
case ast_pragma_no_arg:
|
||||
on_pragma_no_arg(v->as<ast_pragma_no_arg>());
|
||||
break;
|
||||
case ast_pragma_version:
|
||||
on_pragma_version(v->as<ast_pragma_version>());
|
||||
break;
|
||||
case ast_include_statement:
|
||||
on_include_statement(v->as<ast_include_statement>());
|
||||
break;
|
||||
case ast_constant_declaration_list:
|
||||
for (const auto& v_decl : v->as<ast_constant_declaration_list>()->get_declarations()) {
|
||||
on_constant_declaration(v_decl->as<ast_constant_declaration>());
|
||||
}
|
||||
break;
|
||||
case ast_global_var_declaration_list:
|
||||
for (const auto& v_decl : v->as<ast_global_var_declaration_list>()->get_declarations()) {
|
||||
on_global_var_declaration(v_decl->as<ast_global_var_declaration>());
|
||||
}
|
||||
break;
|
||||
case ast_function_declaration:
|
||||
on_function_declaration(v->as<ast_function_declaration>());
|
||||
break;
|
||||
default:
|
||||
throw UnexpectedASTNodeType(v, "ASTVisitorToplevelDeclarations::visit");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void start_visiting_file(V<ast_tolk_file> v_file) {
|
||||
for (AnyV v : v_file->get_toplevel_declarations()) {
|
||||
visit(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace tolk
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue