Joos1W Compiler Framework
All Classes Functions Typedefs Pages
AstValidator.h
1 #pragma once
2 
3 #include "ast/AST.h"
4 #include "ast/AstNode.h"
5 #include "ast/DeclContext.h"
6 #include "diagnostics/Diagnostics.h"
7 #include "semantic/ExprTypeResolver.h"
8 #include "utils/BumpAllocator.h"
9 
10 namespace semantic {
11 
12 class AstChecker {
13 public:
14  AstChecker(BumpAllocator& alloc, diagnostics::DiagnosticEngine& diag,
15  ExprTypeResolver& exprTypeResolver)
16  : alloc{alloc}, diag{diag}, exprTypeResolver{exprTypeResolver} {}
17 
18  void ValidateLU(const ast::LinkingUnit& LU);
19 
20 private:
21  void validateCU(const ast::CompilationUnit& CU);
22  void validateMethod(const ast::MethodDecl& method);
23  void validateStmt(const ast::Stmt& stmt);
24  void validateReturnStmt(const ast::ReturnStmt& stmt);
25  void valdiateTypedDecl(const ast::TypedDecl& decl);
26 
27 private:
28  ast::Type const* getTypeFromExpr(ast::Expr const* expr) const;
29 
30 private:
31  ast::MethodDecl const* currentMethod;
32  ast::CompilationUnit const* cu_;
33  BumpAllocator& alloc;
34  diagnostics::DiagnosticEngine& diag;
35  ExprTypeResolver& exprTypeResolver;
36 };
37 
38 } // namespace semantic