source: src/SymTab/Indexer.h @ e8032b0

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since e8032b0 was e8032b0, checked in by Aaron Moss <a3moss@…>, 8 years ago

Switch Indexer over to copy-on-write semantics for dramatic speedup

  • Property mode set to 100644
File size: 4.2 KB
Line 
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
24namespace SymTab {
25        class Indexer : public Visitor {
26          public:
27                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( AttrExpr *attrExpr );
62                virtual void visit( LogicalExpr *logicalExpr );
63                virtual void visit( ConditionalExpr *conditionalExpr );
64                virtual void visit( CommaExpr *commaExpr );
65                virtual void visit( TupleExpr *tupleExpr );
66                virtual void visit( SolvedTupleExpr *tupleExpr );
67                virtual void visit( TypeExpr *typeExpr );
68                virtual void visit( AsmExpr *asmExpr );
69                virtual void visit( UntypedValofExpr *valofExpr );
70
71                virtual void visit( TraitInstType *contextInst );
72                virtual void visit( StructInstType *contextInst );
73                virtual void visit( UnionInstType *contextInst );
74
75                virtual void visit( ForStmt *forStmt );
76
77                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
78                // explicitly when scopes begin and end
79                void enterScope();
80                void leaveScope();
81
82                void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
83                DeclarationWithType* lookupId( const std::string &id ) const;
84                NamedTypeDecl *lookupType( const std::string &id ) const;
85                StructDecl *lookupStruct( const std::string &id ) const;
86                EnumDecl *lookupEnum( const std::string &id ) const;
87                UnionDecl *lookupUnion( const std::string &id ) const;
88                TraitDecl *lookupTrait( const std::string &id ) const;
89 
90                void print( std::ostream &os, int indent = 0 ) const;
91          private:
92                void addId( DeclarationWithType *decl );
93                void addType( NamedTypeDecl *decl );
94                void addStruct( const std::string &id );
95                void addStruct( StructDecl *decl );
96                void addEnum( EnumDecl *decl );
97                void addUnion( const std::string &id );
98                void addUnion( UnionDecl *decl );
99                void addTrait( TraitDecl *decl );
100               
101                struct Impl;
102                Impl *tables;  ///< Copy-on-write instance of table data structure
103                bool doDebug;  ///< Display debugging trace?
104
105                Indexer( Impl *_tables, bool _doDebug ) : tables( _tables ), doDebug( _doDebug ) {}
106
107                /// Takes a new ref to a table (returns null if null)
108                static Impl *newRef( Impl *toClone );
109                /// Clears a ref to a table (does nothing if null)
110                static void deleteRef( Impl *toFree );
111
112                /// Ensures that tables variable is writable (i.e. allocated and uniquely owned by this Indexer)
113                void makeWritable();
114        };
115} // namespace SymTab
116
117#endif // INDEXER_H
118
119// Local Variables: //
120// tab-width: 4 //
121// mode: c++ //
122// compile-command: "make install" //
123// End: //
Note: See TracBrowser for help on using the repository browser.