21 #ifndef SEMANTIC_ANALYSIS_H
22 #define SEMANTIC_ANALYSIS_H
33 #include "ast_visitor.h"
37 typedef std::vector<SymbolTable *> SymbolTableList;
45 SymbolTableList m_all_symtabs;
49 typedef std::pair<std::string, std::shared_ptr<Type>> Declarator;
56 SymbolTable *get_global_symtab() {
return m_global_symtab; }
59 SymbolTableList::const_iterator symtab_cbegin()
const {
return m_all_symtabs.cbegin(); }
60 SymbolTableList::const_iterator symtab_cend()
const {
return m_all_symtabs.cend(); }
86 std::shared_ptr<Type> create_basic_type(
Node *n);
87 std::shared_ptr<Type> determine_function_type(
Node *n);
88 void check_function(
Node *n,
const std::shared_ptr<Type> &fn_type,
Symbol *prev);
89 Declarator process_declarator(
Node *n,
const std::shared_ptr<Type> &type);
92 bool is_assignable_from(
const std::shared_ptr<Type> &lhs_type,
const std::shared_ptr<Type> &rhs_type);
93 void handle_assignment(
Node *n);
94 void determine_binop_result_type(
Node *n);
95 bool is_conversion_needed(
const std::shared_ptr<Type> &to_type,
const std::shared_ptr<Type> &from_type);
97 Node *implicit_conversion(
Node *n,
const std::shared_ptr<Type> &type);
Base class for AST visitors.
Definition: ast_visitor.h:7
Definition: semantic_analysis.h:35
virtual void visit_literal_value(Node *n)
Visit a Node with the AST_LITERAL_VALUE tag value.
Definition: semantic_analysis.cpp:616
virtual void visit_union_type(Node *n)
Visit a Node with the AST_UNION_TYPE tag value.
Definition: semantic_analysis.cpp:60
virtual void visit_field_ref_expression(Node *n)
Visit a Node with the AST_FIELD_REF_EXPRESSION tag value.
Definition: semantic_analysis.cpp:529
virtual void visit_statement_list(Node *n)
Visit a Node with the AST_STATEMENT_LIST tag value.
Definition: semantic_analysis.cpp:225
virtual void visit_cast_expression(Node *n)
Visit a Node with the AST_CAST_EXPRESSION tag value.
Definition: semantic_analysis.cpp:442
virtual void visit_variable_ref(Node *n)
Visit a Node with the AST_VARIABLE_REF tag value.
Definition: semantic_analysis.cpp:601
virtual void visit_basic_type(Node *n)
Visit a Node with the AST_BASIC_TYPE tag value.
Definition: semantic_analysis.cpp:102
virtual void visit_function_parameter(Node *n)
Visit a Node with the AST_FUNCTION_PARAMETER tag value.
Definition: semantic_analysis.cpp:188
virtual void visit_unary_expression(Node *n)
Visit a Node with the AST_UNARY_EXPRESSION tag value.
Definition: semantic_analysis.cpp:352
virtual void visit_struct_type_definition(Node *n)
Visit a Node with the AST_STRUCT_TYPE_DEFINITION tag value.
Definition: semantic_analysis.cpp:257
virtual void visit_indirect_field_ref_expression(Node *n)
Visit a Node with the AST_INDIRECT_FIELD_REF_EXPRESSION tag value.
Definition: semantic_analysis.cpp:552
virtual void visit_function_call_expression(Node *n)
Visit a Node with the AST_FUNCTION_CALL_EXPRESSION tag value.
Definition: semantic_analysis.cpp:457
virtual void visit_conditional_expression(Node *n)
Visit a Node with the AST_CONDITIONAL_EXPRESSION tag value.
Definition: semantic_analysis.cpp:434
virtual void visit_function_definition(Node *n)
Visit a Node with the AST_FUNCTION_DEFINITION tag value.
Definition: semantic_analysis.cpp:111
virtual void visit_postfix_expression(Node *n)
Visit a Node with the AST_POSTFIX_EXPRESSION tag value.
Definition: semantic_analysis.cpp:426
virtual void visit_array_element_ref_expression(Node *n)
Visit a Node with the AST_ARRAY_ELEMENT_REF_EXPRESSION tag value.
Definition: semantic_analysis.cpp:580
virtual void visit_binary_expression(Node *n)
Visit a Node with the AST_BINARY_EXPRESSION tag value.
Definition: semantic_analysis.cpp:298
virtual void visit_struct_type(Node *n)
Visit a Node with the AST_STRUCT_TYPE tag value.
Definition: semantic_analysis.cpp:48
virtual void visit_function_declaration(Node *n)
Visit a Node with the AST_FUNCTION_DECLARATION tag value.
Definition: semantic_analysis.cpp:167
virtual void visit_variable_declaration(Node *n)
Visit a Node with the AST_VARIABLE_DECLARATION tag value.
Definition: semantic_analysis.cpp:64
virtual void visit_return_expression_statement(Node *n)
Visit a Node with the AST_RETURN_EXPRESSION_STATEMENT tag value.
Definition: semantic_analysis.cpp:236