source: src/SymTab/Indexer.h @ 4fd45bc

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 4fd45bc was ed34540, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Update Indexer handling for typedefs

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[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
[51b7345]17
[30f9072]18#include <iosfwd>             // for ostream
19#include <list>               // for list
20#include <string>             // for string
[0ac366b]21#include <functional>         // for function
[51b7345]22
[30f9072]23#include "SynTree/Visitor.h"  // for Visitor
24#include "SynTree/SynTree.h"  // for AST nodes
[51b7345]25
[a181494]26namespace ResolvExpr {
27class Cost;
28}
29
[51b7345]30namespace SymTab {
[33a25f9]31        class Indexer {
[a08ba92]32          public:
[8b11840]33                explicit Indexer();
[e8032b0]34
35                Indexer( const Indexer &that );
36                Indexer( Indexer &&that );
[a08ba92]37                virtual ~Indexer();
[e8032b0]38                Indexer& operator= ( const Indexer &that );
39                Indexer& operator= ( Indexer &&that );
[17cd4eb]40
[a08ba92]41                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer
42                // explicitly when scopes begin and end
43                void enterScope();
44                void leaveScope();
[17cd4eb]45
[a40d503]46                struct IdData {
[490ff5c3]47                        DeclarationWithType * id = nullptr;
48                        Expression * baseExpr = nullptr; // WithExpr
49
50                        /// non-null if this declaration is deleted
51                        BaseSyntaxNode * deleteStmt = nullptr;
[a40d503]52
[78d69da7]53                        // NOTE: shouldn't need either of these constructors, but gcc-4 does not properly support initializer lists with default members.
54                        IdData() = default;
55                        IdData( DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt ) : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ) {}
56
[a181494]57                        Expression * combine( ResolvExpr::Cost & cost ) const;
[a40d503]58                };
59
[bed4c63e]60                /// Gets all declarations with the given ID
[a40d503]61                void lookupId( const std::string &id, std::list< IdData > &out ) const;
[bed4c63e]62                /// Gets the top-most type declaration with the given ID
[a08ba92]63                NamedTypeDecl *lookupType( const std::string &id ) const;
[bed4c63e]64                /// Gets the top-most struct declaration with the given ID
[a08ba92]65                StructDecl *lookupStruct( const std::string &id ) const;
[bed4c63e]66                /// Gets the top-most enum declaration with the given ID
[a08ba92]67                EnumDecl *lookupEnum( const std::string &id ) const;
[bed4c63e]68                /// Gets the top-most union declaration with the given ID
[a08ba92]69                UnionDecl *lookupUnion( const std::string &id ) const;
[bed4c63e]70                /// Gets the top-most trait declaration with the given ID
[4040425]71                TraitDecl *lookupTrait( const std::string &id ) const;
[1e1e15b]72
[ed34540]73                /// Gets the type declaration with the given ID at global scope
74                NamedTypeDecl *globalLookupType( const std::string &id ) const;
[9a7a3b6]75                /// Gets the struct declaration with the given ID at global scope
76                StructDecl *globalLookupStruct( const std::string &id ) const;
77                /// Gets the union declaration with the given ID at global scope
78                UnionDecl *globalLookupUnion( const std::string &id ) const;
79                /// Gets the enum declaration with the given ID at global scope
80                EnumDecl *globalLookupEnum( const std::string &id ) const;
81
[a08ba92]82                void print( std::ostream &os, int indent = 0 ) const;
[522363e]83
[bed4c63e]84                /// looks up a specific mangled ID at the given scope
[0ac366b]85                IdData * lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope );
86                const IdData * lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
[5447e09]87                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
[09d1ad0]88                bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
[8884112]89                /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
90                bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
[52c2a72]91                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
92                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
93                StructDecl *lookupStructAtScope( const std::string &id, unsigned long scope ) const;
94                EnumDecl *lookupEnumAtScope( const std::string &id, unsigned long scope ) const;
95                UnionDecl *lookupUnionAtScope( const std::string &id, unsigned long scope ) const;
96                TraitDecl *lookupTraitAtScope( const std::string &id, unsigned long scope ) const;
[1e1e15b]97
[0ac366b]98                typedef std::function<bool(IdData &, const std::string &)> ConflictFunction;
99
100                void addId( DeclarationWithType * decl, Expression * baseExpr = nullptr );
101                void addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt );
102
[e8032b0]103                void addType( NamedTypeDecl *decl );
104                void addStruct( const std::string &id );
105                void addStruct( StructDecl *decl );
106                void addEnum( EnumDecl *decl );
107                void addUnion( const std::string &id );
108                void addUnion( UnionDecl *decl );
109                void addTrait( TraitDecl *decl );
[1e1e15b]110
[81644e0]111                /// adds all of the IDs from WithStmt exprs
[0ac366b]112                void addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt );
[81644e0]113
[1485c1a]114                /// adds all of the members of the Aggregate (addWith helper)
[0ac366b]115                void addMembers( AggregateDecl * aggr, Expression * expr, ConflictFunction );
[1485c1a]116
[5fe35d6]117                /// convenience function for adding a list of Ids to the indexer
118                void addIds( const std::list< DeclarationWithType * > & decls );
119
120                /// convenience function for adding a list of forall parameters to the indexer
121                void addTypes( const std::list< TypeDecl * > & tds );
122
123                /// convenience function for adding all of the declarations in a function type to the indexer
124                void addFunctionType( FunctionType * ftype );
125
[8b11840]126                bool doDebug = false; ///< Display debugging trace?
[522363e]127          private:
[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
[e8032b0]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
[1ba88a0]138                // Removes matching autogenerated constructors and destructors
139                // so that they will not be selected
140                // void removeSpecialOverrides( FunctionDecl *decl );
[a40d503]141                void removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const;
[1ba88a0]142
[52c2a72]143                /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
[e8032b0]144                void makeWritable();
[0ac366b]145
146                /// common code for addId, addDeletedId, etc.
147                void addId( DeclarationWithType * decl, ConflictFunction, Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr );
[a08ba92]148        };
[51b7345]149} // namespace SymTab
150
[0dd3a2f]151// Local Variables: //
152// tab-width: 4 //
153// mode: c++ //
154// compile-command: "make install" //
155// End: //
Note: See TracBrowser for help on using the repository browser.