source: src/SymTab/Indexer.h @ 490ff5c3

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 490ff5c3 was 490ff5c3, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Minor code cleanup

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