tan  0.0.1
context.h
1 #ifndef __TAN_CONTEXT_H__
2 #define __TAN_CONTEXT_H__
3 #include "base.h"
4 
5 namespace tanlang {
6 
7 class ASTBase;
8 class Decl;
9 class FunctionDecl;
10 
11 class Context {
12 public:
13  Context &operator=(const Context &) = delete;
14  Context(const Context &) = delete;
15  Context() = delete;
16  explicit Context(ASTBase *owner);
17 
18 public:
19  /**
20  * \brief Register a type declaration
21  */
22  void set_decl(const str &name, Decl *decl);
23 
24  /**
25  * \brief Search for a declaration by name
26  */
27  Decl *get_decl(const str &name) const;
28 
29  /**
30  * \brief Get all type declarations in the context
31  */
32  vector<Decl *> get_decls() const;
33 
34  /**
35  * \brief Register a function declaration
36  */
37  void set_function_decl(FunctionDecl *func);
38 
39  /**
40  * \brief Search for a function declaration by name
41  */
42  FunctionDecl *get_func_decl(const str &name) const;
43 
44  /**
45  * \brief Get all functions registered in the context
46  */
47  vector<FunctionDecl *> get_func_decls() const;
48 
49  ASTBase *owner() const;
50 
51 private:
52  umap<str, Decl *> _type_decls{};
53  umap<str, FunctionDecl *> _func_decls{};
54  ASTBase *_owner = nullptr;
55 };
56 
57 } // namespace tanlang
58 
59 #endif //__TAN_CONTEXT_H__
void set_decl(const str &name, Decl *decl)
Register a type declaration.
Definition: context.cpp:10
vector< Decl * > get_decls() const
Get all type declarations in the context.
Definition: context.cpp:24
Decl * get_decl(const str &name) const
Search for a declaration by name.
Definition: context.cpp:15
void set_function_decl(FunctionDecl *func)
Register a function declaration.
Definition: context.cpp:41
vector< FunctionDecl * > get_func_decls() const
Get all functions registered in the context.
Definition: context.cpp:47
FunctionDecl * get_func_decl(const str &name) const
Search for a function declaration by name.
Definition: context.cpp:32