#ifndef MINI_C_SEMANTIC_H #define MINI_C_SEMANTIC_H #include #include #include #include "ast.h" #include "symbol.h" struct Diagnostic { SourceLoc loc; std::string message; }; class SemanticAnalyzer { public: SemanticAnalyzer(); void analyze(ASTNode* root); void visitForDeclStmt(ASTNode* n); const std::vector& diagnostics() const { return diags_; } std::shared_ptr getGlobalScope() const { return rootScope_; } private: std::shared_ptr rootScope_; std::shared_ptr currentScope_; std::vector diags_; void visit(ASTNode* n); void visitFunctionDef(ASTNode* n); void visitCompoundStmt(ASTNode* n); void visitDeclaration(ASTNode* n); void visitInitDecl(ASTNode* n); void visitIdentifier(ASTNode* n); ASTNode* lastSpecList_{nullptr}; void error(SourceLoc loc, const std::string& msg) { diags_.push_back({loc, msg}); } }; #endif // MINI_C_SEMANTIC_H