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 | // Indexer.h -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 21:38:55 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Wed Mar 2 17:34:14 2016 |
---|
13 | // Update Count : 6 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef INDEXER_H |
---|
17 | #define INDEXER_H |
---|
18 | |
---|
19 | #include <list> |
---|
20 | #include <string> |
---|
21 | |
---|
22 | #include "SynTree/Visitor.h" |
---|
23 | |
---|
24 | namespace SymTab { |
---|
25 | class Indexer : public Visitor { |
---|
26 | public: |
---|
27 | explicit Indexer( bool useDebug = false ); |
---|
28 | |
---|
29 | Indexer( const Indexer &that ); |
---|
30 | Indexer( Indexer &&that ); |
---|
31 | virtual ~Indexer(); |
---|
32 | Indexer& operator= ( const Indexer &that ); |
---|
33 | Indexer& operator= ( Indexer &&that ); |
---|
34 | |
---|
35 | using Visitor::visit; |
---|
36 | virtual void visit( ObjectDecl *objectDecl ); |
---|
37 | virtual void visit( FunctionDecl *functionDecl ); |
---|
38 | virtual void visit( TypeDecl *typeDecl ); |
---|
39 | virtual void visit( TypedefDecl *typeDecl ); |
---|
40 | virtual void visit( StructDecl *aggregateDecl ); |
---|
41 | virtual void visit( UnionDecl *aggregateDecl ); |
---|
42 | virtual void visit( EnumDecl *aggregateDecl ); |
---|
43 | virtual void visit( TraitDecl *aggregateDecl ); |
---|
44 | |
---|
45 | virtual void visit( CompoundStmt *compoundStmt ); |
---|
46 | |
---|
47 | virtual void visit( ApplicationExpr *applicationExpr ); |
---|
48 | virtual void visit( UntypedExpr *untypedExpr ); |
---|
49 | virtual void visit( NameExpr *nameExpr ); |
---|
50 | virtual void visit( CastExpr *castExpr ); |
---|
51 | virtual void visit( AddressExpr *addressExpr ); |
---|
52 | virtual void visit( LabelAddressExpr *labAddressExpr ); |
---|
53 | virtual void visit( UntypedMemberExpr *memberExpr ); |
---|
54 | virtual void visit( MemberExpr *memberExpr ); |
---|
55 | virtual void visit( VariableExpr *variableExpr ); |
---|
56 | virtual void visit( ConstantExpr *constantExpr ); |
---|
57 | virtual void visit( SizeofExpr *sizeofExpr ); |
---|
58 | virtual void visit( AlignofExpr *alignofExpr ); |
---|
59 | virtual void visit( UntypedOffsetofExpr *offsetofExpr ); |
---|
60 | virtual void visit( OffsetofExpr *offsetofExpr ); |
---|
61 | virtual void visit( OffsetPackExpr *offsetPackExpr ); |
---|
62 | virtual void visit( AttrExpr *attrExpr ); |
---|
63 | virtual void visit( LogicalExpr *logicalExpr ); |
---|
64 | virtual void visit( ConditionalExpr *conditionalExpr ); |
---|
65 | virtual void visit( CommaExpr *commaExpr ); |
---|
66 | virtual void visit( TypeExpr *typeExpr ); |
---|
67 | virtual void visit( AsmExpr *asmExpr ); |
---|
68 | virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr ); |
---|
69 | virtual void visit( ConstructorExpr * ctorExpr ); |
---|
70 | virtual void visit( CompoundLiteralExpr *compLitExpr ); |
---|
71 | virtual void visit( UntypedValofExpr *valofExpr ); |
---|
72 | virtual void visit( RangeExpr *rangeExpr ); |
---|
73 | virtual void visit( UntypedTupleExpr *tupleExpr ); |
---|
74 | virtual void visit( TupleExpr *tupleExpr ); |
---|
75 | virtual void visit( TupleIndexExpr *tupleExpr ); |
---|
76 | virtual void visit( TupleAssignExpr *tupleExpr ); |
---|
77 | virtual void visit( StmtExpr * stmtExpr ); |
---|
78 | virtual void visit( UniqueExpr * uniqueExpr ); |
---|
79 | |
---|
80 | virtual void visit( TraitInstType *contextInst ); |
---|
81 | virtual void visit( StructInstType *contextInst ); |
---|
82 | virtual void visit( UnionInstType *contextInst ); |
---|
83 | |
---|
84 | virtual void visit( ForStmt *forStmt ); |
---|
85 | |
---|
86 | // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer |
---|
87 | // explicitly when scopes begin and end |
---|
88 | void enterScope(); |
---|
89 | void leaveScope(); |
---|
90 | |
---|
91 | /// Gets all declarations with the given ID |
---|
92 | void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const; |
---|
93 | /// Gets the top-most type declaration with the given ID |
---|
94 | NamedTypeDecl *lookupType( const std::string &id ) const; |
---|
95 | /// Gets the top-most struct declaration with the given ID |
---|
96 | StructDecl *lookupStruct( const std::string &id ) const; |
---|
97 | /// Gets the top-most enum declaration with the given ID |
---|
98 | EnumDecl *lookupEnum( const std::string &id ) const; |
---|
99 | /// Gets the top-most union declaration with the given ID |
---|
100 | UnionDecl *lookupUnion( const std::string &id ) const; |
---|
101 | /// Gets the top-most trait declaration with the given ID |
---|
102 | TraitDecl *lookupTrait( const std::string &id ) const; |
---|
103 | |
---|
104 | void print( std::ostream &os, int indent = 0 ) const; |
---|
105 | private: |
---|
106 | /// looks up a specific mangled ID at the given scope |
---|
107 | DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const; |
---|
108 | /// returns true if there exists a declaration with C linkage and the given name with a different mangled name |
---|
109 | bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const; |
---|
110 | /// returns true if there exists a declaration with C linkage and the given name with the same mangled name |
---|
111 | bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const; |
---|
112 | // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope) |
---|
113 | NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const; |
---|
114 | StructDecl *lookupStructAtScope( const std::string &id, unsigned long scope ) const; |
---|
115 | EnumDecl *lookupEnumAtScope( const std::string &id, unsigned long scope ) const; |
---|
116 | UnionDecl *lookupUnionAtScope( const std::string &id, unsigned long scope ) const; |
---|
117 | TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const; |
---|
118 | |
---|
119 | void addId( DeclarationWithType *decl ); |
---|
120 | void addType( NamedTypeDecl *decl ); |
---|
121 | void addStruct( const std::string &id ); |
---|
122 | void addStruct( StructDecl *decl ); |
---|
123 | void addEnum( EnumDecl *decl ); |
---|
124 | void addUnion( const std::string &id ); |
---|
125 | void addUnion( UnionDecl *decl ); |
---|
126 | void addTrait( TraitDecl *decl ); |
---|
127 | |
---|
128 | struct Impl; |
---|
129 | Impl *tables; ///< Copy-on-write instance of table data structure |
---|
130 | unsigned long scope; ///< Scope index of this pointer |
---|
131 | bool doDebug; ///< Display debugging trace? |
---|
132 | |
---|
133 | /// Takes a new ref to a table (returns null if null) |
---|
134 | static Impl *newRef( Impl *toClone ); |
---|
135 | /// Clears a ref to a table (does nothing if null) |
---|
136 | static void deleteRef( Impl *toFree ); |
---|
137 | |
---|
138 | // Removes matching autogenerated constructors and destructors |
---|
139 | // so that they will not be selected |
---|
140 | // void removeSpecialOverrides( FunctionDecl *decl ); |
---|
141 | void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const; |
---|
142 | |
---|
143 | /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope) |
---|
144 | void makeWritable(); |
---|
145 | }; |
---|
146 | } // namespace SymTab |
---|
147 | |
---|
148 | #endif // INDEXER_H |
---|
149 | |
---|
150 | // Local Variables: // |
---|
151 | // tab-width: 4 // |
---|
152 | // mode: c++ // |
---|
153 | // compile-command: "make install" // |
---|
154 | // End: // |
---|