|
topazc
|
#include <semantic.hpp>
Classes | |
| struct | Value |
| Structure of value. More... | |
| struct | FunctionInfo |
| Structure of information about function. More... | |
| struct | ModuleInfo |
| Structure of information about module. More... | |
| struct | PathPart |
| Structure of part of path to object. More... | |
Public Member Functions | |
| SemanticAnalyzer (std::vector< AST::StmtPtr > &s, std::string lp, std::string fn, bool id) | |
| void | analyze () |
| Method for analyze all statements. | |
| std::map< std::string, ModuleInfo * > | get_modules () const |
| Method for getting modules from semantic. | |
| std::map< std::string, std::vector< std::shared_ptr< FunctionInfo > > > | get_functions () const |
| Method for getting functions from semantic. | |
Private Types | |
| enum | Space { SPACE_GLOBAL , SPACE_MODULE , SPACE_FUNCTION } |
| Current space (in global, in module or in function). More... | |
Private Member Functions | |
| void | analyze_stmt (AST::Stmt &stmt) |
| Method for analyze one statement. | |
| void | analyze_var_decl_stmt (AST::VarDeclStmt &vds, bool is_func_arg=false) |
| Method for analyze variable declaration. | |
| void | analyze_var_asgn_stmt (AST::VarAsgnStmt &vas) |
| Method for analyze variable assignment. | |
| void | analyze_func_decl_stmt (AST::FuncDeclStmt &fds) |
| Method for analyze function declaration. | |
| void | analyze_func_call_stmt (AST::FuncCallStmt &fcs) |
| Method for analyze function calling. | |
| void | analyze_return_stmt (AST::ReturnStmt &rs) |
| Method for analyze 'return' statement. | |
| void | analyze_if_else_stmt (AST::IfElseStmt &ies) |
| Method for analyze control flow operators. | |
| void | analyze_while_cycle_stmt (AST::WhileCycleStmt &wcs) |
| Method for analyze while cycle. | |
| void | analyze_do_while_cycle_stmt (AST::DoWhileCycleStmt &dwcs) |
| Method for analyze do-while cycle. | |
| void | analyze_for_cycle_stmt (AST::ForCycleStmt &fcs) |
| Method for analyze for cycle. | |
| void | analyze_break_stmt (AST::BreakStmt &bs) |
| Method for analyze break statement. | |
| void | analyze_continue_stmt (AST::ContinueStmt &cs) |
| Method for analyze continue statement. | |
| void | analyze_module_stmt (AST::ModuleStmt &ms) |
| Method for analyze module definition. | |
| void | analyze_use_module_stmt (AST::UseModuleStmt &ums) |
| Method for analyze import the module. | |
| void | analyze_extern_stmt (AST::ExternStmt &es) |
| Method for analyze extern calls. | |
| Value | analyze_expr (AST::Expr &expr) |
| Method for analyze expression. | |
| Value | analyze_literal_expr (AST::Literal &lit) |
| Method for analyze literal. | |
| Value | analyze_binary_expr (AST::BinaryExpr &be) |
| Method for analyze binary expression. | |
| Value | analyze_unary_expr (AST::UnaryExpr &ue) |
| Method for analyze unary expression. | |
| Value | analyze_var_expr (AST::VarExpr &ve) |
| Method for analyze variable expression. | |
| Value | analyze_func_call_expr (AST::FuncCallExpr &fce) |
| Method for analyze function calling expression. | |
| Value | analyze_obj_chain_expr (AST::ChainObjects &co) |
| Method for analyze chain of objects expression. | |
| Value | analyze_obj_from_chain (Value target, AST::Expr &obj) |
| Method for analyze object from chain of objects expression. | |
| Value | get_function_return_value (std::shared_ptr< FunctionInfo > func, AST::FuncCallExpr &fce) |
| Method for evaluating and returning function returned value. | |
| Value * | get_function_return_value_from_if_else (AST::IfElseStmt &ies) |
| Method for evaluating and returning function returned value from control flow operators. | |
| Value * | get_function_return_value_from_while_cycle (AST::WhileCycleStmt &wcs) |
| Method for evaluating and returning function returned value from while cycle. | |
| Value * | get_function_return_value_from_do_while_cycle (AST::DoWhileCycleStmt &dwcs) |
| Method for evaluating and returning function returned value from do-while cycle. | |
| Value * | get_function_return_value_from_for_cycle (AST::ForCycleStmt &fcs) |
| Method for evaluating and returning function returned value from for cycle. | |
| AST::Value | get_default_val_by_type (AST::Type type, uint32_t line) |
| Method for getting default value by type. | |
| std::unique_ptr< Value > | get_variable_value (std::string name) |
| Method for getting value of variable from view scope of variables table. | |
| std::vector< std::shared_ptr< FunctionInfo > > | get_function_candidates (std::string name) |
| Method for getting function candidates from functions table. | |
| bool | has_common_type (AST::Type left, AST::Type right) |
| Method for determining whether two types have a common type. | |
| AST::Type | get_common_type (AST::Type left, AST::Type right, uint32_t line) |
| Method for getting common type between two types. | |
| Value | implicitly_cast (Value val, AST::Type type, uint32_t line) |
| Method for getting implicitly casted value between two values. | |
| double | binary_two_variants (Value left, Value right, TokenType op, uint32_t line) |
| Method for evaluating binary operations on two values from std::variant. | |
| double | unary_two_variants (Value value, TokenType op, uint32_t line) |
| Method for evaluating unary operations on two values from std::variant. | |
| std::string | get_mangled_name (std::string base_name) |
| Method for getting mangled name. | |
| std::vector< PathPart > | get_resolved_name (std::string mangled_name) |
| Method for getting resolved name by mangled name. | |
Private Attributes | |
| std::string | libs_path |
| std::string | file_name |
| std::string | path_to_current_dir |
| std::vector< AST::StmtPtr > & | stmts |
| bool | is_debug |
| enum SemanticAnalyzer::Space | current_space |
| std::map< AST::TypeValue, std::vector< AST::TypeValue > > | implicitly_cast_allowed_types |
| std::stack< std::map< std::string, Value > > | variables |
| std::map< std::string, std::vector< std::shared_ptr< FunctionInfo > > > | functions |
| std::stack< AST::Type > | functions_ret_types |
| unsigned | depth_of_loops |
| std::vector< std::string > | allowed_langs_for_extern |
| std::map< std::string, ModuleInfo * > | modules |
| std::vector< std::string > | names_of_imported_modules |
| std::stack< PathPart > | current_path |
Definition at line 14 of file semantic.hpp.
|
private |
Current space (in global, in module or in function).
| Enumerator | |
|---|---|
| SPACE_GLOBAL | |
| SPACE_MODULE | |
| SPACE_FUNCTION | |
Definition at line 25 of file semantic.hpp.
|
inline |
| void SemanticAnalyzer::analyze | ( | ) |
Method for analyze all statements.
This method analyze all statements to semantic errors. If have error, then throwing exception
Definition at line 15 of file semantic.cpp.


|
private |
Method for analyze binary expression.
This method analyze passed binary expression and returns value of it
| be | Binary expression for analyzing |
Definition at line 709 of file semantic.cpp.


|
private |
Method for analyze break statement.
This method analyze break statement. If break statement isn't in cycle, then throwing exception
| bs | Break statement |
Definition at line 505 of file semantic.cpp.


|
private |
Method for analyze continue statement.
This method analyze continue statement. If continue statement isn't in cycle, then throwing exception
| cs | Continue statement |
Definition at line 511 of file semantic.cpp.


|
private |
Method for analyze do-while cycle.
This method analyze do-while cycle. If condition for do-while cycle is not a bool type, then throwing exception
| dwcs | Do-while cycle |
Definition at line 467 of file semantic.cpp.


|
private |
Method for analyze expression.
This method analyze passed expression and returns value of it
| expr | Expression for analyzing |
Definition at line 681 of file semantic.cpp.


|
private |
Method for analyze extern calls.
This method analyze extern calls (only in unsafe context)
| es | Extern functions block |
Definition at line 670 of file semantic.cpp.


|
private |
Method for analyze for cycle.
This method analyze for cycle. If condition for for cycle is not a bool type, then throwing exception. If indexator statement is not a variable declaration/assignment, then throwing exception.
| fcs | For cycle |
Definition at line 483 of file semantic.cpp.


|
private |
Method for analyze function calling expression.
This method searching passed function in functions table and returns value of call this function
| fce | Function calling expression for analyzing |
Definition at line 866 of file semantic.cpp.


|
private |
Method for analyze function calling.
This method analyze function calling
| fds | Function calling statement for analyzing |
Definition at line 353 of file semantic.cpp.


|
private |
Method for analyze function declaration.
This method analyze function declaration
| fds | Function declaration statement for analyzing |
Definition at line 241 of file semantic.cpp.


|
private |
Method for analyze control flow operators.
This method analyze control flow operators. If condition for control flow operator 'if' is not a bool type, then throwing exception
| ies | Control flow operator |
Definition at line 430 of file semantic.cpp.


|
private |
Method for analyze literal.
This method analyze passed literal and returns value of it
| lit | Literal for analyzing |
Definition at line 705 of file semantic.cpp.

|
private |
Method for analyze module definition.
This method analyze module definition
| ms | Module definition statement |
Definition at line 517 of file semantic.cpp.


|
private |
Method for analyze chain of objects expression.
This method checking all expressions in path from chain
| co | Chain of objects expression for evaluating |
Definition at line 970 of file semantic.cpp.


|
private |
Method for analyze object from chain of objects expression.
This method analyzing passed object expression by passed target value
| target | Value of target object |
| obj | Expression of object for analyzing |
Definition at line 981 of file semantic.cpp.


|
private |
Method for analyze 'return' statement.
This method analyze 'return' statement
| rs | 'return' statement for analyzing |
Definition at line 411 of file semantic.cpp.


|
private |
Method for analyze one statement.
This method analyze one statement to semantic errors. If have error, then throwing exception
| stmt | Statement for analyzing |
Definition at line 21 of file semantic.cpp.


|
private |
Method for analyze unary expression.
This method analyze passed unary expression and returns value of it
| ue | Unary expression for analyzing |
Definition at line 793 of file semantic.cpp.


|
private |
Method for analyze import the module.
This method analyze import the module. If module already imported, then throwing exception
| ums | Importing module |
Definition at line 555 of file semantic.cpp.


|
private |
Method for analyze variable assignment.
This method analyze variable assignment
| vas | Variable assignment statement for analyzing |
Definition at line 170 of file semantic.cpp.


|
private |
Method for analyze variable declaration.
This method analyze variable declaration
| vds | Variable declaration statement for analyzing |
| is_func_arg | Flag that indicates that a variable is an argument to a function |
Definition at line 87 of file semantic.cpp.


|
private |
Method for analyze variable expression.
This method searching passed variable in view scope of variables table and returns value of it
| ve | Variable expression for analyzing |
Definition at line 853 of file semantic.cpp.


|
private |
Method for analyze while cycle.
This method analyze while cycle. If condition for while cycle is not a bool type, then throwing exception
| wcs | While cycle |
Definition at line 451 of file semantic.cpp.


|
private |
Method for evaluating binary operations on two values from std::variant.
This method evaluating binary operations on two values from std::variant and returns result
| left | Value of left operand |
| right | Value of right operand |
| op | Type of binary operator |
| line | Line coordinate in Topaz source code (for exception) |
Definition at line 1400 of file semantic.cpp.

|
private |
Method for getting common type between two types.
This method getting common type between two passed types and returns it. If common type does not exist, then throwing exception
| left | Type to be implicitly cast |
| right | Type to be implicitly cast to |
| line | Line coordinate in Topaz source code (for exception) |
Definition at line 1322 of file semantic.cpp.


|
private |
Method for getting default value by type.
This method getting default value by passed type and returns it. If cannot generating value, then throwing exception
| type | Type by which the default value is generated |
| line | Line coordinate in Topaz source code (for exception) |
Definition at line 1263 of file semantic.cpp.


|
private |
Method for getting function candidates from functions table.
This method getting function candidates from functions table and returns it. If function not found, then returning empty vector
| name | Name of function |
Definition at line 1298 of file semantic.cpp.

|
private |
Method for evaluating and returning function returned value.
This method evaluating function returned value and returns it. If function dont have return statement, then throwing exception
| func | Pointer to information about function |
| fce | Function calling expression |
Definition at line 1047 of file semantic.cpp.


|
private |
Method for evaluating and returning function returned value from do-while cycle.
This method evaluating function returned value from do-while cycle and returns it. If in block of statements of do-while cycle does not have a 'return' statement, then returns nullptr
| dwcs | Do-while cycle |
Definition at line 1190 of file semantic.cpp.


|
private |
Method for evaluating and returning function returned value from for cycle.
This method evaluating function returned value from for cycle and returns it. If in block of statements of for cycle does not have a 'return' statement, then returns nullptr
| fcs | For cycle |
Definition at line 1221 of file semantic.cpp.


|
private |
Method for evaluating and returning function returned value from control flow operators.
This method evaluating function returned value from control flow operators and returns it. If in block of statements of control flow operators does not have a 'return' statement, then returns nullptr
| ies | Control flow operators |
Definition at line 1107 of file semantic.cpp.


|
private |
Method for evaluating and returning function returned value from while cycle.
This method evaluating function returned value from while cycle and returns it. If in block of statements of while cycle does not have a 'return' statement, then returns nullptr
| wcs | While cycle |
Definition at line 1156 of file semantic.cpp.


|
inline |
Method for getting functions from semantic.
Definition at line 129 of file semantic.hpp.

|
private |
Method for getting mangled name.
This method returns mangled name based passed object name and SemanticAnalyzer::current_path. Names of parts of path separated '-' (if current part of path is module) or '#' (if current part of path is class)
| base_name | Based name for mangling |
Definition at line 1537 of file semantic.cpp.

|
inline |
Method for getting modules from semantic.
Definition at line 120 of file semantic.hpp.

|
private |
Method for getting resolved name by mangled name.
This method returns resolved name by passed mangled name
| mangled_name | Mangled name for resolving |
Definition at line 1553 of file semantic.cpp.

|
private |
Method for getting value of variable from view scope of variables table.
This method getting value of variable from view scope of variables table and returns it. If variable not found, then returning null
| name | Name of variable |
Definition at line 1286 of file semantic.cpp.

Method for determining whether two types have a common type.
This method searches the table of types that can be implicitly cast to the type that needs to be converted to the type that is required. If a match is found, then true is returned, otherwise false.
| left | Type to be implicitly cast |
| right | Type to be implicitly cast to |
Definition at line 1306 of file semantic.cpp.

|
private |
Method for getting implicitly casted value between two values.
This method getting implicitly casted value between two passed values and returns it. If common type does not exist, then throwing exception
| val | Value to be implicitly cast |
| type | Type to be implicitly cast to |
| line | Line coordinate in Topaz source code (for exception) |
Definition at line 1343 of file semantic.cpp.


Method for evaluating unary operations on two values from std::variant.
This method evaluating unary operations on two values from std::variant and returns result
| left | Value of left operand |
| right | Value of right operand |
| op | Type of unary operator |
| line | Line coordinate in Topaz source code (for exception) |
Definition at line 1490 of file semantic.cpp.

|
private |
Allowed names of languages for extern calling
Definition at line 67 of file semantic.hpp.
|
private |
Stack to current path to some object
Definition at line 99 of file semantic.hpp.
|
private |
|
private |
Depth of loops
Definition at line 66 of file semantic.hpp.
|
private |
Absolute path to the Topaz source code
Definition at line 17 of file semantic.hpp.
|
private |
Functions table (name, candidates)
Definition at line 64 of file semantic.hpp.
|
private |
Stack of functions return types
Definition at line 65 of file semantic.hpp.
|
private |
Type table for implicit casting
Definition at line 31 of file semantic.hpp.
|
private |
Flag for debug exception
Definition at line 20 of file semantic.hpp.
|
private |
Absolute path to the Topaz libraries
Definition at line 16 of file semantic.hpp.
|
private |
Modules table
Definition at line 82 of file semantic.hpp.
|
private |
Names of already imported modules
Definition at line 83 of file semantic.hpp.
|
private |
Absolute path to the directory which contains current Topaz source code file
Definition at line 18 of file semantic.hpp.
|
private |
AST Tree (statements from Parser)
Definition at line 19 of file semantic.hpp.
|
private |
View scope of the variables table
Definition at line 52 of file semantic.hpp.