Changeset b8524ca for src/InitTweak
- Timestamp:
- Jun 20, 2019, 6:50:42 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:
- 9af00d23
- Parents:
- 234b1cb
- Location:
- src/InitTweak
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/InitTweak/FixInit.cc ¶
r234b1cb rb8524ca 1111 1111 arg2 = new MemberExpr( field, new VariableExpr( params.back() ) ); 1112 1112 } 1113 InitExpander srcParam( arg2 );1113 InitExpander_old srcParam( arg2 ); 1114 1114 // cast away reference type and construct field. 1115 1115 Expression * thisExpr = new CastExpr( new VariableExpr( thisParam ), thisParam->get_type()->stripReferences()->clone() ); -
TabularUnified src/InitTweak/GenInit.cc ¶
r234b1cb rb8524ca 18 18 #include <algorithm> // for any_of 19 19 #include <cassert> // for assert, strict_dynamic_cast, assertf 20 #include <deque> 20 21 #include <iterator> // for back_inserter, inserter, back_inse... 21 22 #include <list> // for _List_iterator, list 22 23 24 #include "AST/Decl.hpp" 25 #include "AST/Init.hpp" 26 #include "AST/Node.hpp" 27 #include "AST/Stmt.hpp" 23 28 #include "CodeGen/OperatorTable.h" 24 29 #include "Common/PassVisitor.h" // for PassVisitor, WithGuards, WithShort... … … 274 279 assertf( objDecl, "genCtorDtor passed null objDecl" ); 275 280 std::list< Statement * > stmts; 276 InitExpander srcParam( maybeClone( arg ) );281 InitExpander_old srcParam( maybeClone( arg ) ); 277 282 SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), fname, back_inserter( stmts ), objDecl ); 278 283 assert( stmts.size() <= 1 ); … … 286 291 std::list< Statement * > dtor; 287 292 288 InitExpander srcParam( objDecl->get_init() );289 InitExpander nullParam( (Initializer *)NULL );293 InitExpander_old srcParam( objDecl->get_init() ); 294 InitExpander_old nullParam( (Initializer *)NULL ); 290 295 SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl ); 291 296 SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false ); … … 354 359 } 355 360 356 ast::ConstructorInit * genCtorInit( const ast::ObjectDecl * objDecl ) { 357 #warning unimplemented 358 (void)objDecl; 359 assert( false ); 361 ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl ) { 362 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor for each 363 // constructable object 364 InitExpander_new srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr }; 365 366 ast::ptr< ast::Stmt > ctor = SymTab::genImplicitCall( 367 srcParam, new ast::VariableExpr{ loc, objDecl }, loc, "?{}", objDecl ); 368 ast::ptr< ast::Stmt > dtor = SymTab::genImplicitCall( 369 nullParam, new ast::VariableExpr{ loc, objDecl }, loc, "^?{}", objDecl, 370 SymTab::LoopBackward ); 371 372 // check that either both ctor and dtor are present, or neither 373 assert( (bool)ctor == (bool)dtor ); 374 375 if ( ctor ) { 376 // need to remember init expression, in case no ctors exist. If ctor does exist, want to 377 // use ctor expression instead of init. 378 ctor.strict_as< ast::ImplicitCtorDtorStmt >(); 379 dtor.strict_as< ast::ImplicitCtorDtorStmt >(); 380 381 return new ast::ConstructorInit{ loc, ctor, dtor, objDecl->init }; 382 } 383 360 384 return nullptr; 361 385 } -
TabularUnified src/InitTweak/GenInit.h ¶
r234b1cb rb8524ca 20 20 21 21 #include "AST/Fwd.hpp" 22 #include "Common/CodeLocation.h" 22 23 #include "GenPoly/ScopedSet.h" // for ScopedSet 23 24 #include "SynTree/SynTree.h" // for Visitor Nodes … … 35 36 /// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer 36 37 ConstructorInit * genCtorInit( ObjectDecl * objDecl ); 37 ast::ConstructorInit * genCtorInit( const ast::ObjectDecl * objDecl );38 ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl ); 38 39 39 40 class ManagedTypes { -
TabularUnified src/InitTweak/InitTweak.cc ¶
r234b1cb rb8524ca 22 22 23 23 #include "AST/Expr.hpp" 24 #include "AST/Node.hpp" 24 25 #include "AST/Stmt.hpp" 25 26 #include "AST/Type.hpp" … … 112 113 } 113 114 114 class InitExpander::ExpanderImpl { 115 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ) { 116 #warning unimplmented 117 (void)init; 118 assert(false); 119 return {}; 120 } 121 122 class InitExpander_old::ExpanderImpl { 115 123 public: 116 124 virtual ~ExpanderImpl() = default; … … 119 127 }; 120 128 121 class InitImpl : public InitExpander::ExpanderImpl {129 class InitImpl_old : public InitExpander_old::ExpanderImpl { 122 130 public: 123 InitImpl ( Initializer * init ) : init( init ) {}124 virtual ~InitImpl () = default;131 InitImpl_old( Initializer * init ) : init( init ) {} 132 virtual ~InitImpl_old() = default; 125 133 126 134 virtual std::list< Expression * > next( __attribute((unused)) std::list< Expression * > & indices ) { … … 136 144 }; 137 145 138 class ExprImpl : public InitExpander::ExpanderImpl {146 class ExprImpl_old : public InitExpander_old::ExpanderImpl { 139 147 public: 140 ExprImpl ( Expression * expr ) : arg( expr ) {}141 virtual ~ExprImpl () { delete arg; }148 ExprImpl_old( Expression * expr ) : arg( expr ) {} 149 virtual ~ExprImpl_old() { delete arg; } 142 150 143 151 virtual std::list< Expression * > next( std::list< Expression * > & indices ) { … … 163 171 }; 164 172 165 InitExpander ::InitExpander( Initializer * init ) : expander( new InitImpl( init ) ) {}166 167 InitExpander ::InitExpander( Expression * expr ) : expander( new ExprImpl( expr ) ) {}168 169 std::list< Expression * > InitExpander ::operator*() {173 InitExpander_old::InitExpander_old( Initializer * init ) : expander( new InitImpl_old( init ) ) {} 174 175 InitExpander_old::InitExpander_old( Expression * expr ) : expander( new ExprImpl_old( expr ) ) {} 176 177 std::list< Expression * > InitExpander_old::operator*() { 170 178 return cur; 171 179 } 172 180 173 InitExpander & InitExpander::operator++() {181 InitExpander_old & InitExpander_old::operator++() { 174 182 cur = expander->next( indices ); 175 183 return *this; … … 177 185 178 186 // use array indices list to build switch statement 179 void InitExpander ::addArrayIndex( Expression * index, Expression * dimension ) {187 void InitExpander_old::addArrayIndex( Expression * index, Expression * dimension ) { 180 188 indices.push_back( index ); 181 189 indices.push_back( dimension ); 182 190 } 183 191 184 void InitExpander ::clearArrayIndices() {192 void InitExpander_old::clearArrayIndices() { 185 193 deleteAll( indices ); 186 194 indices.clear(); 187 195 } 188 196 189 bool InitExpander ::addReference() {197 bool InitExpander_old::addReference() { 190 198 bool added = false; 191 199 for ( Expression *& expr : cur ) { … … 218 226 219 227 template< typename OutIterator > 220 void build( UntypedExpr * callExpr, InitExpander ::IndexList::iterator idx, InitExpander::IndexList::iterator idxEnd, Initializer * init, OutIterator out ) {228 void build( UntypedExpr * callExpr, InitExpander_old::IndexList::iterator idx, InitExpander_old::IndexList::iterator idxEnd, Initializer * init, OutIterator out ) { 221 229 if ( idx == idxEnd ) return; 222 230 Expression * index = *idx++; … … 275 283 // remaining elements. 276 284 // To accomplish this, generate switch statement, consuming all of expander's elements 277 Statement * InitImpl ::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) {285 Statement * InitImpl_old::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) { 278 286 if ( ! init ) return nullptr; 279 287 CompoundStmt * block = new CompoundStmt(); … … 288 296 } 289 297 290 Statement * ExprImpl ::buildListInit( UntypedExpr *, std::list< Expression * > & ) {298 Statement * ExprImpl_old::buildListInit( UntypedExpr *, std::list< Expression * > & ) { 291 299 return nullptr; 292 300 } 293 301 294 Statement * InitExpander ::buildListInit( UntypedExpr * dst ) {302 Statement * InitExpander_old::buildListInit( UntypedExpr * dst ) { 295 303 return expander->buildListInit( dst, indices ); 296 304 } 305 306 class InitExpander_new::ExpanderImpl { 307 public: 308 virtual ~ExpanderImpl() = default; 309 virtual std::vector< ast::ptr< ast::Expr > > next( IndexList & indices ) = 0; 310 virtual ast::ptr< ast::Stmt > buildListInit( 311 const ast::UntypedExpr * callExpr, IndexList & indices ) = 0; 312 }; 313 314 namespace { 315 class InitImpl_new final : public InitExpander_new::ExpanderImpl { 316 ast::ptr< ast::Init > init; 317 public: 318 InitImpl_new( const ast::Init * i ) : init( i ) {} 319 320 std::vector< ast::ptr< ast::Expr > > next( InitExpander_new::IndexList & ) override { 321 return makeInitList( init ); 322 } 323 324 ast::ptr< ast::Stmt > buildListInit( 325 const ast::UntypedExpr * callExpr, InitExpander_new::IndexList & indices 326 ) override { 327 #warning unimplemented 328 (void)callExpr; (void)indices; 329 assert(false); 330 return {}; 331 } 332 }; 333 334 class ExprImpl_new final : public InitExpander_new::ExpanderImpl { 335 ast::ptr< ast::Expr > arg; 336 public: 337 ExprImpl_new( const ast::Expr * a ) : arg( a ) {} 338 339 std::vector< ast::ptr< ast::Expr > > next( 340 InitExpander_new::IndexList & indices 341 ) override { 342 #warning unimplemented 343 (void)indices; 344 assert(false); 345 return {}; 346 } 347 348 ast::ptr< ast::Stmt > buildListInit( 349 const ast::UntypedExpr *, InitExpander_new::IndexList & 350 ) override { 351 return {}; 352 } 353 }; 354 } // anonymous namespace 355 356 InitExpander_new::InitExpander_new( const ast::Init * init ) 357 : expander( new InitImpl_new{ init } ), crnt(), indices() {} 358 359 InitExpander_new::InitExpander_new( const ast::Expr * expr ) 360 : expander( new ExprImpl_new{ expr } ), crnt(), indices() {} 361 362 std::vector< ast::ptr< ast::Expr > > InitExpander_new::operator* () { return crnt; } 363 364 InitExpander_new & InitExpander_new::operator++ () { 365 crnt = expander->next( indices ); 366 return *this; 367 } 368 369 /// builds statement which has the same semantics as a C-style list initializer (for array 370 /// initializers) using callExpr as the base expression to perform initialization 371 ast::ptr< ast::Stmt > InitExpander_new::buildListInit( const ast::UntypedExpr * callExpr ) { 372 return expander->buildListInit( callExpr, indices ); 373 } 374 375 void InitExpander_new::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) { 376 indices.emplace_back( index ); 377 indices.emplace_back( dimension ); 378 } 379 380 void InitExpander_new::clearArrayIndices() { indices.clear(); } 381 382 bool InitExpander_new::addReference() { 383 for ( ast::ptr< ast::Expr > & expr : crnt ) { 384 expr = new ast::AddressExpr{ expr }; 385 } 386 return ! crnt.empty(); 387 } 297 388 298 389 Type * getTypeofThis( FunctionType * ftype ) { -
TabularUnified src/InitTweak/InitTweak.h ¶
r234b1cb rb8524ca 44 44 /// transform Initializer into an argument list that can be passed to a call expression 45 45 std::list< Expression * > makeInitList( Initializer * init ); 46 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ); 46 47 47 48 /// True if the resolver should try to construct dwt … … 101 102 bool isConstExpr( Initializer * init ); 102 103 103 class InitExpander {104 class InitExpander_old { 104 105 public: 105 106 // expand by stepping through init to get each list of arguments 106 InitExpander ( Initializer * init );107 InitExpander_old( Initializer * init ); 107 108 108 109 // always expand to expr 109 InitExpander ( Expression * expr );110 InitExpander_old( Expression * expr ); 110 111 111 112 // iterator-like interface 112 113 std::list< Expression * > operator*(); 113 InitExpander & operator++();114 InitExpander_old & operator++(); 114 115 115 116 // builds statement which has the same semantics as a C-style list initializer … … 130 131 IndexList indices; 131 132 }; 133 134 class InitExpander_new { 135 public: 136 using IndexList = std::vector< ast::ptr< ast::Expr > >; 137 class ExpanderImpl; 138 139 private: 140 std::shared_ptr< ExpanderImpl > expander; 141 std::vector< ast::ptr< ast::Expr > > crnt; 142 // invariant: list of size 2N (elements come in pairs [index, dimension]) 143 IndexList indices; 144 145 public: 146 /// Expand by stepping through init to get each list of arguments 147 InitExpander_new( const ast::Init * init ); 148 149 /// Always expand to expression 150 InitExpander_new( const ast::Expr * expr ); 151 152 std::vector< ast::ptr< ast::Expr > > operator* (); 153 InitExpander_new & operator++ (); 154 155 /// builds statement which has the same semantics as a C-style list initializer (for array 156 /// initializers) using callExpr as the base expression to perform initialization 157 ast::ptr< ast::Stmt > buildListInit( const ast::UntypedExpr * callExpr ); 158 159 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ); 160 161 void clearArrayIndices(); 162 163 bool addReference(); 164 }; 132 165 } // namespace 133 166
Note: See TracChangeset
for help on using the changeset viewer.