source: src/SymTab/Indexer.h @ 0ac366b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 0ac366b was 0ac366b, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add Indexer support for deleting identifiers

  • Property mode set to 100644
File size: 5.6 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 : Thu Aug 17 16:09:12 2017
13// Update Count     : 8
14//
15
16#pragma once
17
18#include <iosfwd>             // for ostream
19#include <list>               // for list
20#include <string>             // for string
21#include <functional>         // for function
22
23#include "SynTree/Visitor.h"  // for Visitor
24#include "SynTree/SynTree.h"  // for AST nodes
25
26namespace SymTab {
27        class Indexer {
28          public:
29                explicit Indexer();
30
31                Indexer( const Indexer &that );
32                Indexer( Indexer &&that );
33                virtual ~Indexer();
34                Indexer& operator= ( const Indexer &that );
35                Indexer& operator= ( Indexer &&that );
36
37                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
38                // explicitly when scopes begin and end
39                void enterScope();
40                void leaveScope();
41
42                struct IdData {
43                        DeclarationWithType * id = nullptr;
44                        Expression * baseExpr = nullptr; // WithExpr
45
46                        /// non-null if this declaration is deleted
47                        BaseSyntaxNode * deleteStmt = nullptr;
48
49                        Expression * combine() const;
50                };
51
52                /// Gets all declarations with the given ID
53                void lookupId( const std::string &id, std::list< IdData > &out ) const;
54                /// Gets the top-most type declaration with the given ID
55                NamedTypeDecl *lookupType( const std::string &id ) const;
56                /// Gets the top-most struct declaration with the given ID
57                StructDecl *lookupStruct( const std::string &id ) const;
58                /// Gets the top-most enum declaration with the given ID
59                EnumDecl *lookupEnum( const std::string &id ) const;
60                /// Gets the top-most union declaration with the given ID
61                UnionDecl *lookupUnion( const std::string &id ) const;
62                /// Gets the top-most trait declaration with the given ID
63                TraitDecl *lookupTrait( const std::string &id ) const;
64
65                void print( std::ostream &os, int indent = 0 ) const;
66
67                /// looks up a specific mangled ID at the given scope
68                IdData * lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope );
69                const IdData * lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
70                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
71                bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
72                /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
73                bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
74                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
75                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
76                StructDecl *lookupStructAtScope( const std::string &id, unsigned long scope ) const;
77                EnumDecl *lookupEnumAtScope( const std::string &id, unsigned long scope ) const;
78                UnionDecl *lookupUnionAtScope( const std::string &id, unsigned long scope ) const;
79                TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const;
80
81                typedef std::function<bool(IdData &, const std::string &)> ConflictFunction;
82
83                void addId( DeclarationWithType * decl, Expression * baseExpr = nullptr );
84                void addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt );
85
86                void addType( NamedTypeDecl *decl );
87                void addStruct( const std::string &id );
88                void addStruct( StructDecl *decl );
89                void addEnum( EnumDecl *decl );
90                void addUnion( const std::string &id );
91                void addUnion( UnionDecl *decl );
92                void addTrait( TraitDecl *decl );
93
94                /// adds all of the IDs from WithStmt exprs
95                void addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt );
96
97                /// adds all of the members of the Aggregate (addWith helper)
98                void addMembers( AggregateDecl * aggr, Expression * expr, ConflictFunction );
99
100                /// convenience function for adding a list of Ids to the indexer
101                void addIds( const std::list< DeclarationWithType * > & decls );
102
103                /// convenience function for adding a list of forall parameters to the indexer
104                void addTypes( const std::list< TypeDecl * > & tds );
105
106                /// convenience function for adding all of the declarations in a function type to the indexer
107                void addFunctionType( FunctionType * ftype );
108
109                bool doDebug = false; ///< Display debugging trace?
110          private:
111                struct Impl;
112
113                Impl *tables;         ///< Copy-on-write instance of table data structure
114                unsigned long scope;  ///< Scope index of this pointer
115
116                /// Takes a new ref to a table (returns null if null)
117                static Impl *newRef( Impl *toClone );
118                /// Clears a ref to a table (does nothing if null)
119                static void deleteRef( Impl *toFree );
120
121                // Removes matching autogenerated constructors and destructors
122                // so that they will not be selected
123                // void removeSpecialOverrides( FunctionDecl *decl );
124                void removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const;
125
126                /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
127                void makeWritable();
128
129                /// common code for addId, addDeletedId, etc.
130                void addId( DeclarationWithType * decl, ConflictFunction, Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr );
131        };
132} // namespace SymTab
133
134// Local Variables: //
135// tab-width: 4 //
136// mode: c++ //
137// compile-command: "make install" //
138// End: //
Note: See TracBrowser for help on using the repository browser.