[51b7345] | 1 | #ifndef TYPEDEFTABLE_H |
---|
| 2 | #define TYPEDEFTABLE_H |
---|
| 3 | |
---|
| 4 | #include <map> |
---|
| 5 | #include <list> |
---|
| 6 | #include <string> |
---|
| 7 | #include <stack> |
---|
| 8 | |
---|
[c8ffe20b] | 9 | class TypedefTable { |
---|
[51b7345] | 10 | public: |
---|
| 11 | enum kind_t { ID, TD, TG }; |
---|
| 12 | private: |
---|
[c8ffe20b] | 13 | struct Entry { |
---|
[51b7345] | 14 | int scope; |
---|
| 15 | kind_t kind; |
---|
| 16 | }; |
---|
| 17 | |
---|
[c8ffe20b] | 18 | struct DeferredEntry { |
---|
| 19 | std::string identifier; |
---|
| 20 | kind_t kind; |
---|
[51b7345] | 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 | |
---|
[c8ffe20b] | 36 | bool isKind( std::string identifier, kind_t kind ) const; |
---|
| 37 | void addToScope( const std::string &identifier, kind_t kind, int scope ); |
---|
[51b7345] | 38 | public: |
---|
| 39 | TypedefTable(); |
---|
| 40 | |
---|
[c8ffe20b] | 41 | bool isIdentifier( std::string identifier ) const; |
---|
| 42 | bool isTypedef( std::string identifier ) const; |
---|
| 43 | bool isTypegen( std::string identifier ) const; |
---|
[51b7345] | 44 | |
---|
[c8ffe20b] | 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() |
---|
[51b7345] | 49 | |
---|
[c8ffe20b] | 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() |
---|
[51b7345] | 54 | |
---|
[c8ffe20b] | 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() |
---|
[51b7345] | 59 | |
---|
[c8ffe20b] | 60 | // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope |
---|
[51b7345] | 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 | |
---|
[c8ffe20b] | 66 | void enterScope( void ); |
---|
| 67 | void leaveScope( void ); |
---|
[51b7345] | 68 | void enterContext( std::string contextName ); |
---|
[c8ffe20b] | 69 | void leaveContext( void ); |
---|
[51b7345] | 70 | |
---|
[c8ffe20b] | 71 | void print( void ) const; |
---|
[51b7345] | 72 | }; |
---|
| 73 | |
---|
[c8ffe20b] | 74 | #endif // TYPEDEFTABLE_H |
---|