tan  0.0.1
type_precheck.h
1 #ifndef __TAN_ANALYSIS_TYPE_PRE_CHECK_H__
2 #define __TAN_ANALYSIS_TYPE_PRE_CHECK_H__
3 #include "base.h"
4 #include "analysis/analysis_action.h"
5 #include "common/dependency_graph.h"
6 #include "ast/package.h"
7 
8 namespace tanlang {
9 
10 class Decl;
11 class Expr;
12 class Type;
13 class Program;
14 class TokenizedSourceFile;
15 class ASTBase;
16 
17 /**
18  * \brief Perform preliminary type checking. We try our best to resolve types,
19  * and remember those that cannot be fully resolved plus their symbol dependencies.
20  * \details This class only operates on top-level declarations, such as functions, structs, ...
21  * And it expects all input AST nodes to contain a non-empty type.
22  */
23 class TypePrecheck : public SemanticAnalysisAction<TypePrecheck, Package *, void> {
24 public:
25  void run_impl(Package *cu);
26 
27  void default_visit(ASTBase *p) override;
28 
29 private:
30  /**
31  * \brief Try to resolve a type by its name.
32  * By resolve we mean figuring out all required information related to bit size, alignment, etc.
33  * If this is currently not possible, it will be stored in a dependency graph and analyzed again in later
34  * stages.
35  *
36  * \param p The type
37  * \param node The AST node requires \p p to be resolved.
38  * \return The resolved type. Returns \p p as is if failed.
39  */
40  Type *check_type_ref(Type *p, ASTBase *node);
41 
42  /**
43  * \brief Try to resolve a type. Trivial if it's plain old data.
44  * Most of the work is done for functions, structs, typedefs, etc.
45  *
46  * \param p The type
47  * \param node The AST node requires p to be resolved.
48  * \return A resolved type, could be a different Type instance than \p p.
49  * \sa check_type_ref
50  */
51  Type *check_type(Type *p, ASTBase *node);
52 
53 public:
54  DECLARE_AST_VISITOR_IMPL(VarDecl);
55  DECLARE_AST_VISITOR_IMPL(ArgDecl);
56  DECLARE_AST_VISITOR_IMPL(Assignment);
57  DECLARE_AST_VISITOR_IMPL(FunctionDecl);
58  DECLARE_AST_VISITOR_IMPL(Import);
59  DECLARE_AST_VISITOR_IMPL(Intrinsic);
60  DECLARE_AST_VISITOR_IMPL(StructDecl);
61 
62 private:
63  Package *_package = nullptr;
64 };
65 
66 } // namespace tanlang
67 
68 #endif // __TAN_ANALYSIS_TYPE_PRE_CHECK_H__
A generic representation of Intrinsic variables/functions.
Definition: intrinsic.h:55
Perform preliminary type checking. We try our best to resolve types, and remember those that cannot b...
Definition: type_precheck.h:23
Type is immutable once created. The exception is StructType. Its information is updated in multiple s...
Definition: type.h:22