Changeset b067d9b for src/InitTweak/InitTweak.h
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.h
r7951100 rb067d9b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.h --7 // InitTweak.h -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:30:33 201713 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 19 14:18:00 2019 13 // Update Count : 6 14 14 // 15 15 … … 19 19 #include <memory> // for shared_ptr 20 20 #include <string> // for string, allocator 21 #include <vector> 21 22 23 #include "AST/Fwd.hpp" // for AST nodes 22 24 #include "SynTree/SynTree.h" // for Visitor Nodes 23 25 24 26 // helper functions for initialization 25 27 namespace InitTweak { 26 FunctionDecl * isAssignment( Declaration * decl ); 27 FunctionDecl * isDestructor( Declaration * decl ); 28 FunctionDecl * isDefaultConstructor( Declaration * decl ); 29 FunctionDecl * isCopyConstructor( Declaration * decl ); 30 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ); 28 const FunctionDecl * isAssignment( const Declaration * decl ); 29 const FunctionDecl * isDestructor( const Declaration * decl ); 30 const FunctionDecl * isDefaultConstructor( const Declaration * decl ); 31 const FunctionDecl * isCopyConstructor( const Declaration * decl ); 32 const FunctionDecl * isCopyFunction( const Declaration * decl, const std::string & fname ); 33 bool isCopyFunction( const ast::FunctionDecl * decl ); 31 34 32 35 /// returns the base type of the first parameter to a constructor/destructor/assignment function … … 41 44 /// transform Initializer into an argument list that can be passed to a call expression 42 45 std::list< Expression * > makeInitList( Initializer * init ); 46 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ); 43 47 44 48 /// True if the resolver should try to construct dwt … … 57 61 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr) 58 62 DeclarationWithType * getFunction( Expression * expr ); 63 const DeclarationWithType * getFunction( const Expression * expr ); 64 const ast::DeclWithType * getFunction( const ast::Expr * expr ); 59 65 60 66 /// Non-Null if expr is a call expression whose target function is intrinsic 61 67 ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); 68 const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr); 62 69 63 70 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. … … 65 72 /// Currently has assertions that make it less than fully general. 66 73 bool isIntrinsicSingleArgCallStmt( Statement * stmt ); 74 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ); 67 75 68 76 /// True if stmt is a call statement where the function called is intrinsic. … … 71 79 /// get all Ctor/Dtor call expressions from a Statement 72 80 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ); 81 std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ); 73 82 74 83 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call … … 77 86 /// returns the name of the function being called 78 87 std::string getFunctionName( Expression * expr ); 88 std::string getFunctionName( const ast::Expr * expr ); 79 89 80 90 /// returns the argument to a call expression in position N indexed from 0 81 91 Expression *& getCallArg( Expression * callExpr, unsigned int pos ); 92 const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ); 82 93 83 94 /// returns the base type of a PointerType or ArrayType, else returns NULL 84 95 Type * getPointerBase( Type * ); 96 const ast::Type* getPointerBase( const ast::Type* ); 85 97 86 98 /// returns the argument if it is a PointerType or ArrayType, else returns NULL … … 91 103 bool isConstExpr( Initializer * init ); 92 104 93 class InitExpander {105 class InitExpander_old { 94 106 public: 95 107 // expand by stepping through init to get each list of arguments 96 InitExpander ( Initializer * init );108 InitExpander_old( Initializer * init ); 97 109 98 110 // always expand to expr 99 InitExpander ( Expression * expr );111 InitExpander_old( Expression * expr ); 100 112 101 113 // iterator-like interface 102 114 std::list< Expression * > operator*(); 103 InitExpander & operator++();115 InitExpander_old & operator++(); 104 116 105 117 // builds statement which has the same semantics as a C-style list initializer … … 120 132 IndexList indices; 121 133 }; 134 135 class InitExpander_new { 136 public: 137 using IndexList = std::vector< ast::ptr< ast::Expr > >; 138 class ExpanderImpl; 139 140 private: 141 std::shared_ptr< ExpanderImpl > expander; 142 std::vector< ast::ptr< ast::Expr > > crnt; 143 // invariant: list of size 2N (elements come in pairs [index, dimension]) 144 IndexList indices; 145 146 public: 147 /// Expand by stepping through init to get each list of arguments 148 InitExpander_new( const ast::Init * init ); 149 150 /// Always expand to expression 151 InitExpander_new( const ast::Expr * expr ); 152 153 std::vector< ast::ptr< ast::Expr > > operator* (); 154 InitExpander_new & operator++ (); 155 156 /// builds statement which has the same semantics as a C-style list initializer (for array 157 /// initializers) using callExpr as the base expression to perform initialization. 158 /// Mutates callExpr 159 ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr ); 160 161 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ); 162 163 void clearArrayIndices(); 164 165 bool addReference(); 166 }; 122 167 } // namespace 123 168
Note:
See TracChangeset
for help on using the changeset viewer.