[b87a5ed] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // TypedefTable.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Rodolfo G. Esteves |
---|
| 10 | // Created On : Sat May 16 15:24:36 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[7880579] | 12 | // Last Modified On : Mon Aug 15 18:25:04 2016 |
---|
| 13 | // Update Count : 28 |
---|
[b87a5ed] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #ifndef TYPEDEFTABLE_H |
---|
| 17 | #define TYPEDEFTABLE_H |
---|
| 18 | |
---|
| 19 | #include <map> |
---|
| 20 | #include <list> |
---|
| 21 | #include <string> |
---|
| 22 | #include <stack> |
---|
| 23 | |
---|
[984dce6] | 24 | #include "lex.h" |
---|
| 25 | #include "parser.h" |
---|
| 26 | |
---|
[c8ffe20b] | 27 | class TypedefTable { |
---|
[51b7345] | 28 | public: |
---|
[984dce6] | 29 | enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname }; |
---|
[51b7345] | 30 | private: |
---|
[b87a5ed] | 31 | struct Entry { |
---|
| 32 | int scope; |
---|
| 33 | kind_t kind; |
---|
| 34 | }; |
---|
| 35 | |
---|
| 36 | struct DeferredEntry { |
---|
| 37 | std::string identifier; |
---|
| 38 | kind_t kind; |
---|
| 39 | }; |
---|
[51b7345] | 40 | |
---|
[7880579] | 41 | typedef std::map< std::string, std::list< Entry > > tableType; |
---|
[b87a5ed] | 42 | tableType table; |
---|
[51b7345] | 43 | |
---|
[b87a5ed] | 44 | int currentScope; |
---|
[4040425] | 45 | std::string currentTrait; |
---|
[b87a5ed] | 46 | int contextScope; |
---|
| 47 | |
---|
| 48 | typedef std::list< DeferredEntry > deferListType; |
---|
| 49 | std::stack< deferListType > deferListStack; |
---|
| 50 | std::map< std::string, deferListType > contexts; |
---|
| 51 | |
---|
| 52 | std::stack< std::string > nextIdentifiers; |
---|
[51b7345] | 53 | |
---|
[b87a5ed] | 54 | void addToScope( const std::string &identifier, kind_t kind, int scope ); |
---|
[51b7345] | 55 | public: |
---|
[b87a5ed] | 56 | TypedefTable(); |
---|
[51b7345] | 57 | |
---|
[984dce6] | 58 | bool exists( const std::string &identifier ); |
---|
| 59 | int isKind( const std::string &identifier ) const; |
---|
[721f17a] | 60 | void changeKind( const std::string &identifier, kind_t kind ); |
---|
[45161b4d] | 61 | |
---|
| 62 | void makeTypedef( const std::string &name ); |
---|
| 63 | |
---|
[de62360d] | 64 | // "addToCurrentScope" adds the identifier/type pair to the current scope. This does less than you think it does, |
---|
[b87a5ed] | 65 | // since each declaration is within its own scope. Mostly useful for type parameters. |
---|
| 66 | void addToCurrentScope( const std::string &identifier, kind_t kind ); |
---|
[721f17a] | 67 | void addToCurrentScope( kind_t kind ); // use nextIdentifiers.top() |
---|
[51b7345] | 68 | |
---|
[b87a5ed] | 69 | // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one. This is the |
---|
| 70 | // right way to handle type and typedef names |
---|
| 71 | void addToEnclosingScope( const std::string &identifier, kind_t kind ); |
---|
| 72 | void addToEnclosingScope( kind_t kind ); // use nextIdentifiers.top() |
---|
| 73 | |
---|
| 74 | // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the |
---|
| 75 | // current one. This is the right way to handle assertion names |
---|
| 76 | void addToEnclosingScope2( const std::string &identifier, kind_t kind ); |
---|
| 77 | void addToEnclosingScope2( kind_t kind ); // use nextIdentifiers.top() |
---|
| 78 | |
---|
| 79 | // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope |
---|
| 80 | void setNextIdentifier( const std::string &identifier ); |
---|
| 81 | |
---|
| 82 | // dump the definitions from a pre-defined context into the current scope |
---|
[4040425] | 83 | void openTrait( const std::string &contextName ); |
---|
[b87a5ed] | 84 | |
---|
| 85 | void enterScope(); |
---|
| 86 | void leaveScope(); |
---|
[4040425] | 87 | void enterTrait( const std::string &contextName ); |
---|
| 88 | void leaveTrait(); |
---|
[51b7345] | 89 | |
---|
[b87a5ed] | 90 | void print() const; |
---|
[51b7345] | 91 | }; |
---|
| 92 | |
---|
[c8ffe20b] | 93 | #endif // TYPEDEFTABLE_H |
---|
[b87a5ed] | 94 | |
---|
| 95 | // Local Variables: // |
---|
| 96 | // tab-width: 4 // |
---|
| 97 | // mode: c++ // |
---|
| 98 | // compile-command: "make install" // |
---|
| 99 | // End: // |
---|