#pragma once #include #include #include #include namespace ir { class Function; class Value; } enum class SemanticType { Void, Int, Float, }; enum class SymbolKind { Variable, Constant, Function, }; struct ConstantValue { SemanticType type = SemanticType::Int; int int_value = 0; float float_value = 0.0f; }; struct FunctionTypeInfo { SemanticType return_type = SemanticType::Void; std::vector param_types; std::vector param_is_array; std::vector> param_dims; }; struct SymbolEntry { SymbolKind kind = SymbolKind::Variable; SemanticType type = SemanticType::Int; bool is_const = false; bool is_array = false; bool is_param_array = false; std::vector dims; ir::Value* ir_value = nullptr; ir::Function* function = nullptr; std::optional const_scalar; std::vector const_array; FunctionTypeInfo function_type; }; class SymbolTable { public: void Clear(); void EnterScope(); void ExitScope(); bool Insert(const std::string& name, const SymbolEntry& entry); bool ContainsInCurrentScope(const std::string& name) const; SymbolEntry* Lookup(const std::string& name); const SymbolEntry* Lookup(const std::string& name) const; private: std::vector> scopes_; };