Changeset 3c70d38 for translator
- Timestamp:
- Nov 20, 2014, 9:50:35 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- ea3eb06
- Parents:
- 1db2c5be
- Location:
- translator
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/TypeTable.h
r1db2c5be r3c70d38 1 /*2 * This file is part of the Cforall project3 *4 * $Id: TypeTable.h,v 1.2 2005/08/29 20:14:18 rcbilson Exp $5 *6 */7 8 1 #ifndef SYMTAB_TYPETABLE_H 9 2 #define SYMTAB_TYPETABLE_H … … 19 12 20 13 namespace SymTab { 14 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > { 15 public: 16 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) { 17 if ( existing->get_base() == 0 ) { 18 return added; 19 } else if( added->get_base() == 0 ) { 20 return existing; 21 } else { 22 throw SemanticError( "redeclaration of ", added ); 23 } 24 assert( false ); 25 return 0; 26 } 27 }; 21 28 22 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl*, NamedTypeDecl*, NamedTypeDecl* > 23 { 24 public: 25 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) 26 { 27 if( existing->get_base() == 0 ) { 28 return added; 29 } else if( added->get_base() == 0 ) { 30 return existing; 31 } else { 32 throw SemanticError( "redeclaration of ", added ); 33 } 34 assert( false ); 35 return 0; 36 } 37 38 }; 29 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable; 30 } // SymTab 39 31 40 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable; 41 42 } // namespace SymTab 43 44 #endif /* #ifndef SYMTAB_TYPETABLE_H */ 32 #endif // SYMTAB_TYPETABLE_H -
translator/SymTab/Validate.cc
r1db2c5be r3c70d38 117 117 virtual void visit( TypeDecl *typeDecl ); 118 118 virtual void visit( ContextDecl *ctxDecl ); 119 virtual void visit( FunctionDecl *functionDecl ); 119 120 120 121 virtual void visit( FunctionType *ftype ); … … 129 130 virtual void visit( CaseStmt *caseStmt ); 130 131 virtual void visit( CatchStmt *catchStmt ); 132 133 AddStructAssignment() : functionNesting( 0 ) {} 131 134 private: 132 135 template< typename StmtClass > void visitStatement( StmtClass *stmt ); … … 134 137 std::list< Declaration * > declsToAdd; 135 138 std::set< std::string > structsDone; 139 unsigned int functionNesting; // current level of nested functions 136 140 }; 137 141 … … 194 198 } 195 199 196 void filter( std::list< Declaration * > &declList, bool (*pred 200 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) { 197 201 std::list< Declaration * >::iterator i = declList.begin(); 198 202 while ( i != declList.end() ) { … … 216 220 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { 217 221 if ( inStruct ) { 218 declsToAdd.push_back( aggregateDecl ); 222 // Add elements in stack order corresponding to nesting structure. 223 declsToAdd.push_front( aggregateDecl ); 219 224 Visitor::visit( aggregateDecl ); 220 225 } else { … … 222 227 Visitor::visit( aggregateDecl ); 223 228 inStruct = false; 224 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 225 } 229 } 230 // Always remove the hoisted aggregate from the inner structure. 231 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 226 232 } 227 233 … … 523 529 } 524 530 525 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType ) {531 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 526 532 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 527 533 … … 534 540 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 535 541 assignType->get_parameters().push_back( srcParam ); 536 537 FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 542 543 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 544 // because each unit generates copies of the default routines for each aggregate. 545 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 538 546 assignDecl->fixUniqueId(); 539 547 … … 552 560 } 553 561 554 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType ) {562 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 555 563 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 556 564 … … 564 572 assignType->get_parameters().push_back( srcParam ); 565 573 566 FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 574 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 575 // because each unit generates copies of the default routines for each aggregate. 576 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 567 577 assignDecl->fixUniqueId(); 568 578 … … 582 592 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); 583 593 structInst->set_baseStruct( structDecl ); 584 declsToAdd.push_back( makeStructAssignment( structDecl, structInst ) );594 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 585 595 structsDone.insert( structDecl->get_name() ); 586 596 } … … 591 601 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); 592 602 unionInst->set_baseUnion( unionDecl ); 593 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst ) );603 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 594 604 } 595 605 } … … 647 657 } 648 658 659 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 660 maybeAccept( functionDecl->get_functionType(), *this ); 661 acceptAll( functionDecl->get_oldDecls(), *this ); 662 functionNesting += 1; 663 maybeAccept( functionDecl->get_statements(), *this ); 664 functionNesting -= 1; 665 } 666 649 667 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 650 668 visitStatement( compoundStmt ); -
translator/SymTab/Validate.h
r1db2c5be r3c70d38 1 /* 2 * This file is part of the Cforall project 3 * 4 * This class is intended to perform pre-processing of declarations, validating their 5 * correctness and computing some auxilliary data that is necessary for the indexer. 6 * 7 * $Id: Validate.h,v 1.7 2005/08/29 20:14:18 rcbilson Exp $ 8 * 9 */ 1 // This class is intended to perform pre-processing of declarations, validating their 2 // correctness and computing some auxilliary data that is necessary for the indexer. 10 3 11 4 #ifndef SYMTAB_VALIDATE_H … … 15 8 16 9 namespace SymTab { 10 class Indexer; 17 11 18 class Indexer; 12 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false, const Indexer *indexer = 0 ); 13 void validateType( Type *type, const Indexer *indexer ); 14 } // SymTab 19 15 20 void validate( std::list< Declaration* > &translationUnit, bool doDebug = false, 21 const Indexer *indexer = 0 ); 22 23 void validateType( Type *type, const Indexer *indexer ); 24 25 } // namespace SymTab 26 27 #endif /* #ifndef SYMTAB_VALIDATE_H */ 16 #endif // SYMTAB_VALIDATE_H
Note: See TracChangeset
for help on using the changeset viewer.