[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
|
---|
[6d49ea3] | 12 | // Last Modified On : Thu Aug 17 16:09:12 2017
|
---|
| 13 | // Update Count : 8
|
---|
[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 {
|
---|
[33a25f9] | 26 | class Indexer {
|
---|
[a08ba92] | 27 | public:
|
---|
[8b11840] | 28 | explicit Indexer();
|
---|
[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 |
|
---|
[a08ba92] | 36 | // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
|
---|
| 37 | // explicitly when scopes begin and end
|
---|
| 38 | void enterScope();
|
---|
| 39 | void leaveScope();
|
---|
[17cd4eb] | 40 |
|
---|
[bed4c63e] | 41 | /// Gets all declarations with the given ID
|
---|
[e8032b0] | 42 | void lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const;
|
---|
[bed4c63e] | 43 | /// Gets the top-most type declaration with the given ID
|
---|
[a08ba92] | 44 | NamedTypeDecl *lookupType( const std::string &id ) const;
|
---|
[bed4c63e] | 45 | /// Gets the top-most struct declaration with the given ID
|
---|
[a08ba92] | 46 | StructDecl *lookupStruct( const std::string &id ) const;
|
---|
[bed4c63e] | 47 | /// Gets the top-most enum declaration with the given ID
|
---|
[a08ba92] | 48 | EnumDecl *lookupEnum( const std::string &id ) const;
|
---|
[bed4c63e] | 49 | /// Gets the top-most union declaration with the given ID
|
---|
[a08ba92] | 50 | UnionDecl *lookupUnion( const std::string &id ) const;
|
---|
[bed4c63e] | 51 | /// Gets the top-most trait declaration with the given ID
|
---|
[4040425] | 52 | TraitDecl *lookupTrait( const std::string &id ) const;
|
---|
[1e1e15b] | 53 |
|
---|
[a08ba92] | 54 | void print( std::ostream &os, int indent = 0 ) const;
|
---|
[522363e] | 55 |
|
---|
[bed4c63e] | 56 | /// looks up a specific mangled ID at the given scope
|
---|
| 57 | DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
|
---|
[5447e09] | 58 | /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
|
---|
[09d1ad0] | 59 | bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
|
---|
[8884112] | 60 | /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
|
---|
| 61 | bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
|
---|
[52c2a72] | 62 | // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
|
---|
| 63 | NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
|
---|
| 64 | StructDecl *lookupStructAtScope( const std::string &id, unsigned long scope ) const;
|
---|
| 65 | EnumDecl *lookupEnumAtScope( const std::string &id, unsigned long scope ) const;
|
---|
| 66 | UnionDecl *lookupUnionAtScope( const std::string &id, unsigned long scope ) const;
|
---|
| 67 | TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const;
|
---|
[1e1e15b] | 68 |
|
---|
[e8032b0] | 69 | void addId( DeclarationWithType *decl );
|
---|
| 70 | void addType( NamedTypeDecl *decl );
|
---|
| 71 | void addStruct( const std::string &id );
|
---|
| 72 | void addStruct( StructDecl *decl );
|
---|
| 73 | void addEnum( EnumDecl *decl );
|
---|
| 74 | void addUnion( const std::string &id );
|
---|
| 75 | void addUnion( UnionDecl *decl );
|
---|
| 76 | void addTrait( TraitDecl *decl );
|
---|
[1e1e15b] | 77 |
|
---|
[8b11840] | 78 | bool doDebug = false; ///< Display debugging trace?
|
---|
[522363e] | 79 | private:
|
---|
[e8032b0] | 80 | struct Impl;
|
---|
[30f9072] | 81 |
|
---|
[52c2a72] | 82 | Impl *tables; ///< Copy-on-write instance of table data structure
|
---|
| 83 | unsigned long scope; ///< Scope index of this pointer
|
---|
[e8032b0] | 84 |
|
---|
| 85 | /// Takes a new ref to a table (returns null if null)
|
---|
| 86 | static Impl *newRef( Impl *toClone );
|
---|
| 87 | /// Clears a ref to a table (does nothing if null)
|
---|
| 88 | static void deleteRef( Impl *toFree );
|
---|
| 89 |
|
---|
[1ba88a0] | 90 | // Removes matching autogenerated constructors and destructors
|
---|
| 91 | // so that they will not be selected
|
---|
| 92 | // void removeSpecialOverrides( FunctionDecl *decl );
|
---|
| 93 | void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const;
|
---|
| 94 |
|
---|
[52c2a72] | 95 | /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
|
---|
[e8032b0] | 96 | void makeWritable();
|
---|
[a08ba92] | 97 | };
|
---|
[51b73452] | 98 | } // namespace SymTab
|
---|
| 99 |
|
---|
[0dd3a2f] | 100 | // Local Variables: //
|
---|
| 101 | // tab-width: 4 //
|
---|
| 102 | // mode: c++ //
|
---|
| 103 | // compile-command: "make install" //
|
---|
| 104 | // End: //
|
---|