1 | #ifndef TYPEDEFTABLE_H |
---|
2 | #define TYPEDEFTABLE_H |
---|
3 | |
---|
4 | #include <map> |
---|
5 | #include <list> |
---|
6 | #include <string> |
---|
7 | #include <stack> |
---|
8 | |
---|
9 | class TypedefTable { |
---|
10 | public: |
---|
11 | enum kind_t { ID, TD, TG }; |
---|
12 | private: |
---|
13 | struct Entry { |
---|
14 | int scope; |
---|
15 | kind_t kind; |
---|
16 | }; |
---|
17 | |
---|
18 | struct DeferredEntry { |
---|
19 | std::string identifier; |
---|
20 | kind_t kind; |
---|
21 | }; |
---|
22 | |
---|
23 | typedef std::map<std::string, std::list<Entry> > tableType; |
---|
24 | tableType table; |
---|
25 | |
---|
26 | int currentScope; |
---|
27 | std::string currentContext; |
---|
28 | int contextScope; |
---|
29 | |
---|
30 | typedef std::list< DeferredEntry > deferListType; |
---|
31 | std::stack< deferListType > deferListStack; |
---|
32 | std::map< std::string, deferListType > contexts; |
---|
33 | |
---|
34 | std::stack< std::string > nextIdentifiers; |
---|
35 | |
---|
36 | bool isKind( std::string identifier, kind_t kind ) const; |
---|
37 | void addToScope( const std::string &identifier, kind_t kind, int scope ); |
---|
38 | public: |
---|
39 | TypedefTable(); |
---|
40 | |
---|
41 | bool isIdentifier( std::string identifier ) const; |
---|
42 | bool isTypedef( std::string identifier ) const; |
---|
43 | bool isTypegen( std::string identifier ) const; |
---|
44 | |
---|
45 | // "addToCurrentScope" adds the identifier/type pair to the current scope This does less than you think it does, |
---|
46 | // since each declaration is within its own scope. Mostly useful for type parameters. |
---|
47 | void addToCurrentScope( const std::string &identifier, kind_t kind ); |
---|
48 | void addToCurrentScope( kind_t kind ); // use nextIdentifiers.top() |
---|
49 | |
---|
50 | // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one. This is the |
---|
51 | // right way to handle type and typedef names |
---|
52 | void addToEnclosingScope( const std::string &identifier, kind_t kind ); |
---|
53 | void addToEnclosingScope( kind_t kind ); // use nextIdentifiers.top() |
---|
54 | |
---|
55 | // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the |
---|
56 | // current one. This is the right way to handle assertion names |
---|
57 | void addToEnclosingScope2( const std::string &identifier, kind_t kind ); |
---|
58 | void addToEnclosingScope2( kind_t kind ); // use nextIdentifiers.top() |
---|
59 | |
---|
60 | // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope |
---|
61 | void setNextIdentifier( const std::string &identifier ); |
---|
62 | |
---|
63 | // dump the definitions from a pre-defined context into the current scope |
---|
64 | void openContext( std::string contextName ); |
---|
65 | |
---|
66 | void enterScope( void ); |
---|
67 | void leaveScope( void ); |
---|
68 | void enterContext( std::string contextName ); |
---|
69 | void leaveContext( void ); |
---|
70 | |
---|
71 | void print( void ) const; |
---|
72 | }; |
---|
73 | |
---|
74 | #endif // TYPEDEFTABLE_H |
---|