[0dd3a2f] | 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 | //
|
---|
[1e1e15b] | 7 | // Indexer.h --
|
---|
[0dd3a2f] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Sun May 17 21:38:55 2015
|
---|
[4040425] | 11 | // Last Modified By : Peter A. Buhr
|
---|
[6b0b624] | 12 | // Last Modified On : Sat Jul 22 09:46:34 2017
|
---|
| 13 | // Update Count : 7
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
[30f9072] | 18 | #include <iosfwd> // for ostream
|
---|
| 19 | #include <list> // for list
|
---|
| 20 | #include <string> // for string
|
---|
[51b73452] | 21 |
|
---|
[30f9072] | 22 | #include "SynTree/Visitor.h" // for Visitor
|
---|
| 23 | #include "SynTree/SynTree.h" // for AST nodes
|
---|
[51b73452] | 24 |
|
---|
| 25 | namespace SymTab {
|
---|
[a08ba92] | 26 | class Indexer : public Visitor {
|
---|
| 27 | public:
|
---|
[fc638d2] | 28 | explicit Indexer( bool useDebug = false );
|
---|
[e8032b0] | 29 |
|
---|
| 30 | Indexer( const Indexer &that );
|
---|
| 31 | Indexer( Indexer &&that );
|
---|
[a08ba92] | 32 | virtual ~Indexer();
|
---|
[e8032b0] | 33 | Indexer& operator= ( const Indexer &that );
|
---|
| 34 | Indexer& operator= ( Indexer &&that );
|
---|
[17cd4eb] | 35 |
|
---|
[1e1e15b] | 36 | using Visitor::visit;
|
---|
[a08ba92] | 37 | virtual void visit( ObjectDecl *objectDecl );
|
---|
| 38 | virtual void visit( FunctionDecl *functionDecl );
|
---|
| 39 | virtual void visit( TypeDecl *typeDecl );
|
---|
| 40 | virtual void visit( TypedefDecl *typeDecl );
|
---|
| 41 | virtual void visit( StructDecl *aggregateDecl );
|
---|
| 42 | virtual void visit( UnionDecl *aggregateDecl );
|
---|
| 43 | virtual void visit( EnumDecl *aggregateDecl );
|
---|
[4040425] | 44 | virtual void visit( TraitDecl *aggregateDecl );
|
---|
[17cd4eb] | 45 |
|
---|
[a08ba92] | 46 | virtual void visit( CompoundStmt *compoundStmt );
|
---|
[17cd4eb] | 47 |
|
---|
[ae4c85a] | 48 | virtual void visit( ApplicationExpr *applicationExpr );
|
---|
| 49 | virtual void visit( UntypedExpr *untypedExpr );
|
---|
| 50 | virtual void visit( NameExpr *nameExpr );
|
---|
| 51 | virtual void visit( CastExpr *castExpr );
|
---|
| 52 | virtual void visit( AddressExpr *addressExpr );
|
---|
| 53 | virtual void visit( LabelAddressExpr *labAddressExpr );
|
---|
| 54 | virtual void visit( UntypedMemberExpr *memberExpr );
|
---|
| 55 | virtual void visit( MemberExpr *memberExpr );
|
---|
| 56 | virtual void visit( VariableExpr *variableExpr );
|
---|
[1e1e15b] | 57 | virtual void visit( ConstantExpr *constantExpr );
|
---|
[ae4c85a] | 58 | virtual void visit( SizeofExpr *sizeofExpr );
|
---|
[47534159] | 59 | virtual void visit( AlignofExpr *alignofExpr );
|
---|
[2a4b088] | 60 | virtual void visit( UntypedOffsetofExpr *offsetofExpr );
|
---|
[25a054f] | 61 | virtual void visit( OffsetofExpr *offsetofExpr );
|
---|
[afc1045] | 62 | virtual void visit( OffsetPackExpr *offsetPackExpr );
|
---|
[ae4c85a] | 63 | virtual void visit( AttrExpr *attrExpr );
|
---|
| 64 | virtual void visit( LogicalExpr *logicalExpr );
|
---|
| 65 | virtual void visit( ConditionalExpr *conditionalExpr );
|
---|
| 66 | virtual void visit( CommaExpr *commaExpr );
|
---|
| 67 | virtual void visit( TypeExpr *typeExpr );
|
---|
| 68 | virtual void visit( AsmExpr *asmExpr );
|
---|
[907eccb] | 69 | virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr );
|
---|
| 70 | virtual void visit( ConstructorExpr * ctorExpr );
|
---|
| 71 | virtual void visit( CompoundLiteralExpr *compLitExpr );
|
---|
| 72 | virtual void visit( RangeExpr *rangeExpr );
|
---|
| 73 | virtual void visit( UntypedTupleExpr *tupleExpr );
|
---|
[6eb8948] | 74 | virtual void visit( TupleExpr *tupleExpr );
|
---|
[907eccb] | 75 | virtual void visit( TupleIndexExpr *tupleExpr );
|
---|
[6eb8948] | 76 | virtual void visit( TupleAssignExpr *tupleExpr );
|
---|
[907eccb] | 77 | virtual void visit( StmtExpr * stmtExpr );
|
---|
| 78 | virtual void visit( UniqueExpr * uniqueExpr );
|
---|
[ae4c85a] | 79 |
|
---|
[4040425] | 80 | virtual void visit( TraitInstType *contextInst );
|
---|
[a08ba92] | 81 | virtual void visit( StructInstType *contextInst );
|
---|
| 82 | virtual void visit( UnionInstType *contextInst );
|
---|
[d4778a6] | 83 |
|
---|
[a08ba92] | 84 | virtual void visit( ForStmt *forStmt );
|
---|
[d4778a6] | 85 |
|
---|
[a08ba92] | 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();
|
---|
[17cd4eb] | 90 |
|
---|
[bed4c63e] | 91 | /// Gets all declarations with the given ID
|
---|
[e8032b0] | 92 | void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
|
---|
[bed4c63e] | 93 | /// Gets the top-most type declaration with the given ID
|
---|
[a08ba92] | 94 | NamedTypeDecl *lookupType( const std::string &id ) const;
|
---|
[bed4c63e] | 95 | /// Gets the top-most struct declaration with the given ID
|
---|
[a08ba92] | 96 | StructDecl *lookupStruct( const std::string &id ) const;
|
---|
[bed4c63e] | 97 | /// Gets the top-most enum declaration with the given ID
|
---|
[a08ba92] | 98 | EnumDecl *lookupEnum( const std::string &id ) const;
|
---|
[bed4c63e] | 99 | /// Gets the top-most union declaration with the given ID
|
---|
[a08ba92] | 100 | UnionDecl *lookupUnion( const std::string &id ) const;
|
---|
[bed4c63e] | 101 | /// Gets the top-most trait declaration with the given ID
|
---|
[4040425] | 102 | TraitDecl *lookupTrait( const std::string &id ) const;
|
---|
[1e1e15b] | 103 |
|
---|
[a08ba92] | 104 | void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 105 | private:
|
---|
[bed4c63e] | 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;
|
---|
[5447e09] | 108 | /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
|
---|
[09d1ad0] | 109 | bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
|
---|
[8884112] | 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;
|
---|
[52c2a72] | 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;
|
---|
[1e1e15b] | 118 |
|
---|
[e8032b0] | 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 );
|
---|
[1e1e15b] | 127 |
|
---|
[e8032b0] | 128 | struct Impl;
|
---|
[30f9072] | 129 |
|
---|
[52c2a72] | 130 | Impl *tables; ///< Copy-on-write instance of table data structure
|
---|
| 131 | unsigned long scope; ///< Scope index of this pointer
|
---|
| 132 | bool doDebug; ///< Display debugging trace?
|
---|
[e8032b0] | 133 |
|
---|
| 134 | /// Takes a new ref to a table (returns null if null)
|
---|
| 135 | static Impl *newRef( Impl *toClone );
|
---|
| 136 | /// Clears a ref to a table (does nothing if null)
|
---|
| 137 | static void deleteRef( Impl *toFree );
|
---|
| 138 |
|
---|
[1ba88a0] | 139 | // Removes matching autogenerated constructors and destructors
|
---|
| 140 | // so that they will not be selected
|
---|
| 141 | // void removeSpecialOverrides( FunctionDecl *decl );
|
---|
| 142 | void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const;
|
---|
| 143 |
|
---|
[52c2a72] | 144 | /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
|
---|
[e8032b0] | 145 | void makeWritable();
|
---|
[a08ba92] | 146 | };
|
---|
[51b73452] | 147 | } // namespace SymTab
|
---|
| 148 |
|
---|
[0dd3a2f] | 149 | // Local Variables: //
|
---|
| 150 | // tab-width: 4 //
|
---|
| 151 | // mode: c++ //
|
---|
| 152 | // compile-command: "make install" //
|
---|
| 153 | // End: //
|
---|