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 |
---|
12 | // Last Modified On : Sat Jul 22 09:33:14 2017 |
---|
13 | // Update Count : 34 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <list> // for list |
---|
19 | #include <map> // for map, map<>::value_compare |
---|
20 | #include <stack> // for stack |
---|
21 | #include <string> // for string |
---|
22 | |
---|
23 | #include "ParserTypes.h" |
---|
24 | #include "parser.hh" // for IDENTIFIER, TYPEDEFname, TYPEGENname |
---|
25 | |
---|
26 | class TypedefTable { |
---|
27 | public: |
---|
28 | enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname }; |
---|
29 | private: |
---|
30 | struct Entry { |
---|
31 | int scope; |
---|
32 | kind_t kind; |
---|
33 | }; |
---|
34 | |
---|
35 | struct DeferredEntry { |
---|
36 | std::string identifier; |
---|
37 | kind_t kind; |
---|
38 | }; |
---|
39 | |
---|
40 | typedef std::map< std::string, std::list< Entry > > tableType; |
---|
41 | tableType table; |
---|
42 | |
---|
43 | int currentScope; |
---|
44 | std::string currentTrait; |
---|
45 | int contextScope; |
---|
46 | |
---|
47 | typedef std::list< DeferredEntry > deferListType; |
---|
48 | std::stack< deferListType > deferListStack; |
---|
49 | std::map< std::string, deferListType > contexts; |
---|
50 | |
---|
51 | std::stack< std::string > nextIdentifiers; |
---|
52 | |
---|
53 | void addToScope( const std::string &identifier, kind_t kind, int scope ); |
---|
54 | public: |
---|
55 | TypedefTable(); |
---|
56 | |
---|
57 | bool exists( const std::string &identifier ); |
---|
58 | int isKind( const std::string &identifier ) const; |
---|
59 | void changeKind( const std::string &identifier, kind_t kind ); |
---|
60 | |
---|
61 | void makeTypedef( const std::string &name ); |
---|
62 | |
---|
63 | // "addToCurrentScope" adds the identifier/type pair to the current scope. This does less than you think it does, |
---|
64 | // since each declaration is within its own scope. Mostly useful for type parameters. |
---|
65 | void addToCurrentScope( const std::string &identifier, kind_t kind ); |
---|
66 | void addToCurrentScope( kind_t kind ); // use nextIdentifiers.top() |
---|
67 | |
---|
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() |
---|
72 | |
---|
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() |
---|
77 | |
---|
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 ); |
---|
80 | |
---|
81 | // dump the definitions from a pre-defined context into the current scope |
---|
82 | void openTrait( const std::string &contextName ); |
---|
83 | |
---|
84 | void enterScope(); |
---|
85 | void leaveScope(); |
---|
86 | void enterTrait( const std::string &contextName ); |
---|
87 | void leaveTrait(); |
---|
88 | |
---|
89 | void print() const; |
---|
90 | }; |
---|
91 | |
---|
92 | // Local Variables: // |
---|
93 | // tab-width: 4 // |
---|
94 | // mode: c++ // |
---|
95 | // compile-command: "make install" // |
---|
96 | // End: // |
---|