Changeset 3ca540f for src/SymTab
- Timestamp:
- Dec 1, 2017, 2:55:41 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a40d503
- Parents:
- 882ad37 (diff), 5da9d6a (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. - Location:
- src/SymTab
- Files:
-
- 4 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/AddVisit.h
r882ad37 r3ca540f 24 24 // add any new declarations after the previous statement 25 25 for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) { 26 DeclStmt *declStmt = new DeclStmt( noLabels,*decl );26 DeclStmt *declStmt = new DeclStmt( *decl ); 27 27 stmts.insert( stmt, declStmt ); 28 28 } … … 36 36 // add any new declarations before the statement 37 37 for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) { 38 DeclStmt *declStmt = new DeclStmt( noLabels,*decl );38 DeclStmt *declStmt = new DeclStmt( *decl ); 39 39 stmts.insert( stmt, declStmt ); 40 40 } -
src/SymTab/Autogen.cc
r882ad37 r3ca540f 264 264 Type::StorageClasses scs = functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ); 265 265 LinkageSpec::Spec spec = isIntrinsic ? LinkageSpec::Intrinsic : LinkageSpec::AutoGen; 266 FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt( noLabels),266 FunctionDecl * decl = new FunctionDecl( fname, scs, spec, ftype, new CompoundStmt(), 267 267 std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ); 268 268 decl->fixUniqueId(); … … 299 299 assert( assignType->returnVals.size() == 1 ); 300 300 ObjectDecl * dstParam = strict_dynamic_cast< ObjectDecl * >( assignType->parameters.front() ); 301 dcl->statements->push_back( new ReturnStmt( n oLabels, new VariableExpr( dstParam ) ) );301 dcl->statements->push_back( new ReturnStmt( new VariableExpr( dstParam ) ) ); 302 302 } 303 303 resolve( dcl ); … … 468 468 copy->args.push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 469 469 copy->args.push_back( new SizeofExpr( srcParam->get_type()->clone() ) ); 470 *out++ = new ExprStmt( noLabels,copy );470 *out++ = new ExprStmt( copy ); 471 471 } 472 472 … … 544 544 callExpr->get_args().push_back( new VariableExpr( dstParam ) ); 545 545 callExpr->get_args().push_back( new VariableExpr( srcParam ) ); 546 funcDecl->statements->push_back( new ExprStmt( noLabels,callExpr ) );546 funcDecl->statements->push_back( new ExprStmt( callExpr ) ); 547 547 } else { 548 548 // default ctor/dtor body is empty - add unused attribute to parameter to silence warnings … … 569 569 expr->args.push_back( new CastExpr( new VariableExpr( dst ), new ReferenceType( Type::Qualifiers(), typeDecl->base->clone() ) ) ); 570 570 if ( src ) expr->args.push_back( new CastExpr( new VariableExpr( src ), typeDecl->base->clone() ) ); 571 dcl->statements->kids.push_back( new ExprStmt( noLabels,expr ) );571 dcl->statements->kids.push_back( new ExprStmt( expr ) ); 572 572 }; 573 573 … … 664 664 untyped->get_args().push_back( new VariableExpr( ftype->get_parameters().back() ) ); 665 665 } 666 function->get_statements()->get_kids().push_back( new ExprStmt( noLabels,untyped ) );667 function->get_statements()->get_kids().push_back( new ReturnStmt( noLabels,UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );666 function->get_statements()->get_kids().push_back( new ExprStmt( untyped ) ); 667 function->get_statements()->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) ); 668 668 } 669 669 -
src/SymTab/Autogen.h
r882ad37 r3ca540f 104 104 fExpr->args.splice( fExpr->args.end(), args ); 105 105 106 *out++ = new ExprStmt( noLabels,fExpr );106 *out++ = new ExprStmt( fExpr ); 107 107 108 108 srcParam.clearArrayIndices(); … … 162 162 163 163 // for stmt's body, eventually containing call 164 CompoundStmt * body = new CompoundStmt( noLabels);164 CompoundStmt * body = new CompoundStmt(); 165 165 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward ); 166 166 167 167 // block containing for stmt and index variable 168 168 std::list<Statement *> initList; 169 CompoundStmt * block = new CompoundStmt( noLabels);170 block->push_back( new DeclStmt( noLabels,index ) );169 CompoundStmt * block = new CompoundStmt(); 170 block->push_back( new DeclStmt( index ) ); 171 171 if ( listInit ) block->get_kids().push_back( listInit ); 172 block->push_back( new ForStmt( noLabels,initList, cond, inc, body ) );172 block->push_back( new ForStmt( initList, cond, inc, body ) ); 173 173 174 174 *out++ = block; -
src/SymTab/Validate.cc
r882ad37 r3ca540f 81 81 82 82 namespace SymTab { 83 class HoistStruct final : public Visitor { 84 template< typename Visitor > 85 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 86 template< typename Visitor > 87 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 88 public: 83 struct HoistStruct final : public WithDeclsToAdd, public WithGuards { 89 84 /// Flattens nested struct types 90 85 static void hoistStruct( std::list< Declaration * > &translationUnit ); 91 86 92 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 93 94 virtual void visit( EnumInstType *enumInstType ); 95 virtual void visit( StructInstType *structInstType ); 96 virtual void visit( UnionInstType *unionInstType ); 97 virtual void visit( StructDecl *aggregateDecl ); 98 virtual void visit( UnionDecl *aggregateDecl ); 99 100 virtual void visit( CompoundStmt *compoundStmt ); 101 virtual void visit( SwitchStmt *switchStmt ); 87 void previsit( EnumInstType * enumInstType ); 88 void previsit( StructInstType * structInstType ); 89 void previsit( UnionInstType * unionInstType ); 90 void previsit( StructDecl * aggregateDecl ); 91 void previsit( UnionDecl * aggregateDecl ); 92 102 93 private: 103 HoistStruct();104 105 94 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 106 95 107 std::list< Declaration * > declsToAdd, declsToAddAfter; 108 bool inStruct; 96 bool inStruct = false; 109 97 }; 110 98 … … 305 293 306 294 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 307 HoistStruct hoister; 308 acceptAndAdd( translationUnit, hoister ); 309 } 310 311 HoistStruct::HoistStruct() : inStruct( false ) { 295 PassVisitor<HoistStruct> hoister; 296 acceptAll( translationUnit, hoister ); 312 297 } 313 298 … … 320 305 if ( inStruct ) { 321 306 // Add elements in stack order corresponding to nesting structure. 322 declsToAdd.push_front( aggregateDecl ); 323 Visitor::visit( aggregateDecl ); 307 declsToAddBefore.push_front( aggregateDecl ); 324 308 } else { 309 GuardValue( inStruct ); 325 310 inStruct = true; 326 Visitor::visit( aggregateDecl );327 inStruct = false;328 311 } // if 329 312 // Always remove the hoisted aggregate from the inner structure. 330 filter( aggregateDecl->get_members(), isStructOrUnion, false);331 } 332 333 void HoistStruct:: visit( EnumInstType *structInstType) {334 if ( structInstType->get_baseEnum()) {335 declsToAdd .push_front( structInstType->get_baseEnum());336 } 337 } 338 339 void HoistStruct:: visit( StructInstType *structInstType) {340 if ( structInstType->get_baseStruct()) {341 declsToAdd .push_front( structInstType->get_baseStruct());342 } 343 } 344 345 void HoistStruct:: visit( UnionInstType *structInstType) {346 if ( structInstType->get_baseUnion()) {347 declsToAdd .push_front( structInstType->get_baseUnion());348 } 349 } 350 351 void HoistStruct:: visit( StructDecl *aggregateDecl ) {313 GuardAction( [this, aggregateDecl]() { filter( aggregateDecl->members, isStructOrUnion, false ); } ); 314 } 315 316 void HoistStruct::previsit( EnumInstType * inst ) { 317 if ( inst->baseEnum ) { 318 declsToAddBefore.push_front( inst->baseEnum ); 319 } 320 } 321 322 void HoistStruct::previsit( StructInstType * inst ) { 323 if ( inst->baseStruct ) { 324 declsToAddBefore.push_front( inst->baseStruct ); 325 } 326 } 327 328 void HoistStruct::previsit( UnionInstType * inst ) { 329 if ( inst->baseUnion ) { 330 declsToAddBefore.push_front( inst->baseUnion ); 331 } 332 } 333 334 void HoistStruct::previsit( StructDecl * aggregateDecl ) { 352 335 handleAggregate( aggregateDecl ); 353 336 } 354 337 355 void HoistStruct:: visit( UnionDecl *aggregateDecl ) {338 void HoistStruct::previsit( UnionDecl * aggregateDecl ) { 356 339 handleAggregate( aggregateDecl ); 357 }358 359 void HoistStruct::visit( CompoundStmt *compoundStmt ) {360 addVisit( compoundStmt, *this );361 }362 363 void HoistStruct::visit( SwitchStmt *switchStmt ) {364 addVisit( switchStmt, *this );365 340 } 366 341 -
src/SymTab/module.mk
r882ad37 r3ca540f 19 19 SymTab/Validate.cc \ 20 20 SymTab/FixFunction.cc \ 21 SymTab/ImplementationType.cc \22 SymTab/TypeEquality.cc \23 21 SymTab/Autogen.cc
Note: See TracChangeset
for help on using the changeset viewer.