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