Changeset c0d00b6 for src/SymTab
- Timestamp:
- Nov 25, 2017, 3:22:18 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c6e2c18
- Parents:
- 9d06142 (diff), 3de176d (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:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
r9d06142 rc0d00b6 62 62 void previsit( FunctionDecl * functionDecl ); 63 63 64 void previsit( FunctionType * ftype );65 void previsit( PointerType * ptype );66 67 64 void previsit( CompoundStmt * compoundStmt ); 68 65 … … 72 69 unsigned int functionNesting = 0; // current level of nested functions 73 70 74 InitTweak::ManagedTypes managedTypes;75 71 std::vector< FuncData > data; 76 72 }; … … 625 621 // generate ctor/dtors/assign for typedecls, e.g., otype T = int *; 626 622 void AutogenerateRoutines::previsit( TypeDecl * typeDecl ) { 627 visit_children = false;628 623 if ( ! typeDecl->base ) return; 629 624 … … 631 626 TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer ); 632 627 generateFunctions( gen, declsToAddAfter ); 633 } 634 635 void AutogenerateRoutines::previsit( FunctionType *) { 636 // ensure that we don't add assignment ops for types defined as part of the function 637 visit_children = false; 638 } 639 640 void AutogenerateRoutines::previsit( PointerType *) { 641 // ensure that we don't add assignment ops for types defined as part of the pointer 642 visit_children = false; 628 643 629 } 644 630 … … 648 634 } 649 635 650 void AutogenerateRoutines::previsit( FunctionDecl * functionDecl ) { 651 visit_children = false; 652 // record the existence of this function as appropriate 653 managedTypes.handleDWT( functionDecl ); 654 655 maybeAccept( functionDecl->type, *visitor ); 636 void AutogenerateRoutines::previsit( FunctionDecl * ) { 637 // Track whether we're currently in a function. 638 // Can ignore function type idiosyncrasies, because function type can never 639 // declare a new type. 656 640 functionNesting += 1; 657 maybeAccept( functionDecl->statements, *visitor ); 658 functionNesting -= 1; 641 GuardAction( [this]() { functionNesting -= 1; } ); 659 642 } 660 643 661 644 void AutogenerateRoutines::previsit( CompoundStmt * ) { 662 GuardScope( managedTypes );663 645 GuardScope( structsDone ); 664 646 } -
src/SymTab/Autogen.h
r9d06142 rc0d00b6 59 59 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 60 60 template< typename OutputIterator > 61 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );61 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast = nullptr, bool forward = true ); 62 62 63 63 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types. 64 64 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 65 65 template< typename OutputIterator > 66 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false) {66 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, Type * addCast = nullptr ) { 67 67 bool isReferenceCtorDtor = false; 68 68 if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) { … … 71 71 fname = "?=?"; 72 72 dstParam = new AddressExpr( dstParam ); 73 addCast = false;73 addCast = nullptr; 74 74 isReferenceCtorDtor = true; 75 75 } … … 86 86 // remove lvalue as a qualifier, this can change to 87 87 // type->get_qualifiers() = Type::Qualifiers(); 88 assert( type ); 89 Type * castType = type->clone(); 88 Type * castType = addCast->clone(); 90 89 castType->get_qualifiers() -= Type::Qualifiers( Type::Lvalue | Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 91 90 // castType->set_lvalue( true ); // xxx - might not need this … … 118 117 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 119 118 template< typename OutputIterator > 120 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {119 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, Type * addCast = nullptr, bool forward = true ) { 121 120 static UniqueName indexName( "_index" ); 122 121 123 122 // for a flexible array member nothing is done -- user must define own assignment 124 if ( ! array->get_dimension() ) return ; 123 if ( ! array->get_dimension() ) return; 124 125 if ( addCast ) { 126 // peel off array layer from cast 127 ArrayType * at = strict_dynamic_cast< ArrayType * >( addCast ); 128 addCast = at->base; 129 } 125 130 126 131 Expression * begin, * end, * update, * cmp; … … 174 179 175 180 template< typename OutputIterator > 176 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, booladdCast, bool forward ) {181 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast, bool forward ) { 177 182 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 178 183 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); … … 194 199 if ( isUnnamedBitfield( obj ) ) return; 195 200 196 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ); 201 Type * addCast = nullptr; 202 if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ) ) { 203 assert( dstParam->result ); 204 addCast = dstParam->result; 205 } 197 206 std::list< Statement * > stmts; 198 207 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward ); -
src/SymTab/Indexer.cc
r9d06142 rc0d00b6 567 567 } 568 568 569 void Indexer::addIds( const std::list< DeclarationWithType * > & decls ) { 570 for ( auto d : decls ) { 571 addId( d ); 572 } 573 } 574 575 void Indexer::addTypes( const std::list< TypeDecl * > & tds ) { 576 for ( auto td : tds ) { 577 addType( td ); 578 addIds( td->assertions ); 579 } 580 } 581 582 void Indexer::addFunctionType( FunctionType * ftype ) { 583 addTypes( ftype->forall ); 584 addIds( ftype->returnVals ); 585 addIds( ftype->parameters ); 586 } 587 569 588 void Indexer::enterScope() { 570 589 ++scope; -
src/SymTab/Indexer.h
r9d06142 rc0d00b6 76 76 void addTrait( TraitDecl *decl ); 77 77 78 /// convenience function for adding a list of Ids to the indexer 79 void addIds( const std::list< DeclarationWithType * > & decls ); 80 81 /// convenience function for adding a list of forall parameters to the indexer 82 void addTypes( const std::list< TypeDecl * > & tds ); 83 84 /// convenience function for adding all of the declarations in a function type to the indexer 85 void addFunctionType( FunctionType * ftype ); 86 78 87 bool doDebug = false; ///< Display debugging trace? 79 88 private: -
src/SymTab/Validate.cc
r9d06142 rc0d00b6 124 124 125 125 /// Associates forward declarations of aggregates with their definitions 126 struct LinkReferenceToTypes final : public WithIndexer {126 struct LinkReferenceToTypes final : public WithIndexer, public WithGuards { 127 127 LinkReferenceToTypes( const Indexer *indexer ); 128 128 void postvisit( TypeInstType *typeInst ); … … 137 137 void postvisit( UnionDecl *unionDecl ); 138 138 void postvisit( TraitDecl * traitDecl ); 139 140 void previsit( StructDecl *structDecl ); 141 void previsit( UnionDecl *unionDecl ); 142 143 void renameGenericParams( std::list< TypeDecl * > & params ); 139 144 140 145 private: … … 147 152 ForwardStructsType forwardStructs; 148 153 ForwardUnionsType forwardUnions; 154 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately 155 bool inGeneric = false; 149 156 }; 150 157 … … 423 430 } 424 431 432 void checkGenericParameters( ReferenceToType * inst ) { 433 for ( Expression * param : inst->parameters ) { 434 if ( ! dynamic_cast< TypeExpr * >( param ) ) { 435 throw SemanticError( "Expression parameters for generic types are currently unsupported: ", inst ); 436 } 437 } 438 } 439 425 440 void LinkReferenceToTypes::postvisit( StructInstType *structInst ) { 426 441 StructDecl *st = local_indexer->lookupStruct( structInst->get_name() ); … … 434 449 forwardStructs[ structInst->get_name() ].push_back( structInst ); 435 450 } // if 451 checkGenericParameters( structInst ); 436 452 } 437 453 … … 446 462 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 447 463 } // if 464 checkGenericParameters( unionInst ); 448 465 } 449 466 … … 525 542 // need to carry over the 'sized' status of each decl in the instance 526 543 for ( auto p : group_iterate( traitDecl->get_parameters(), traitInst->get_parameters() ) ) { 527 TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( std::get<1>(p) ); 544 TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) ); 545 if ( ! expr ) { 546 throw SemanticError( "Expression parameters for trait instances are currently unsupported: ", std::get<1>(p) ); 547 } 528 548 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) { 529 549 TypeDecl * formalDecl = std::get<0>(p); … … 546 566 } // if 547 567 } // if 568 } 569 570 void LinkReferenceToTypes::renameGenericParams( std::list< TypeDecl * > & params ) { 571 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g. 572 // forall(otype T) 573 // struct Box { 574 // T x; 575 // }; 576 // forall(otype T) 577 // void f(Box(T) b) { 578 // ... 579 // } 580 // The T in Box and the T in f are different, so internally the naming must reflect that. 581 GuardValue( inGeneric ); 582 inGeneric = ! params.empty(); 583 for ( TypeDecl * td : params ) { 584 td->name = "__" + td->name + "_generic_"; 585 } 586 } 587 588 void LinkReferenceToTypes::previsit( StructDecl * structDecl ) { 589 renameGenericParams( structDecl->parameters ); 590 } 591 592 void LinkReferenceToTypes::previsit( UnionDecl * unionDecl ) { 593 renameGenericParams( unionDecl->parameters ); 548 594 } 549 595 … … 575 621 576 622 void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) { 623 // ensure generic parameter instances are renamed like the base type 624 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name; 577 625 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) { 578 626 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
Note: See TracChangeset
for help on using the changeset viewer.