Changeset 579263a for src/SymTab
- Timestamp:
- Jun 26, 2017, 4:48:35 PM (8 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:
- bb1cd95
- Parents:
- e4d829b (diff), 2a7b3ca (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:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
re4d829b r579263a 262 262 // E ?=?(E volatile*, int), 263 263 // ?=?(E _Atomic volatile*, int); 264 void makeEnumFunctions( Enum Decl *enumDecl, EnumInstType *refType, unsigned int functionNesting, std::list< Declaration * > &declsToAdd ) {264 void makeEnumFunctions( EnumInstType *refType, unsigned int functionNesting, std::list< Declaration * > &declsToAdd ) { 265 265 266 266 // T ?=?(E *, E); … … 486 486 487 487 /// generates the body of a union assignment/copy constructor/field constructor 488 void makeUnionAssignBody( FunctionDecl * funcDecl , bool isDynamicLayout) {488 void makeUnionAssignBody( FunctionDecl * funcDecl ) { 489 489 FunctionType * ftype = funcDecl->get_functionType(); 490 490 assert( ftype->get_parameters().size() == 2 ); … … 506 506 // Make function polymorphic in same parameters as generic union, if applicable 507 507 const std::list< TypeDecl* > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions 508 bool isDynamicLayout = hasDynamicLayout( aggregateDecl ); // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct) 509 508 510 509 // default ctor/dtor need only first parameter 511 510 // void ?{}(T *); void ^?{}(T *); … … 533 532 FunctionDecl *dtorDecl = genFunc( "^?{}", dtorType, functionNesting ); 534 533 535 makeUnionAssignBody( assignDecl , isDynamicLayout);534 makeUnionAssignBody( assignDecl ); 536 535 537 536 // body of assignment and copy ctor is the same 538 makeUnionAssignBody( copyCtorDecl , isDynamicLayout);537 makeUnionAssignBody( copyCtorDecl ); 539 538 540 539 // create a constructor which takes the first member type as a parameter. … … 551 550 FunctionDecl * ctor = genFunc( "?{}", memCtorType, functionNesting ); 552 551 553 makeUnionAssignBody( ctor , isDynamicLayout);552 makeUnionAssignBody( ctor ); 554 553 memCtors.push_back( ctor ); 555 554 // only generate a ctor for the first field … … 578 577 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); 579 578 // enumInst->set_baseEnum( enumDecl ); 580 makeEnumFunctions( enum Decl, enumInst, functionNesting, declsToAddAfter );579 makeEnumFunctions( enumInst, functionNesting, declsToAddAfter ); 581 580 } 582 581 } -
src/SymTab/Autogen.h
re4d829b r579263a 10 10 // Created On : Sun May 17 21:53:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 17 09:10:41201713 // Update Count : 912 // Last Modified On : Wed Jun 21 17:25:26 2017 13 // Update Count : 14 14 14 // 15 15 … … 43 43 template< typename OutputIterator > 44 44 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) { 45 46 47 45 // want to be able to generate assignment, ctor, and dtor generically, 46 // so fname is either ?=?, ?{}, or ^?{} 47 UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) ); 48 48 49 // do something special for unnamed members 50 dstParam = new AddressExpr( dstParam ); 51 if ( addCast ) { 52 // cast to T* with qualifiers removed, so that qualified objects can be constructed 53 // and destructed with the same functions as non-qualified objects. 54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 56 // remove lvalue as a qualifier, this can change to 57 // type->get_qualifiers() = Type::Qualifiers(); 58 assert( type ); 59 Type * castType = type->clone(); 60 // castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false); 61 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 62 castType->set_lvalue( true ); // xxx - might not need this 63 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 64 } 65 fExpr->get_args().push_back( dstParam ); 49 // do something special for unnamed members 50 dstParam = new AddressExpr( dstParam ); 51 if ( addCast ) { 52 // cast to T* with qualifiers removed, so that qualified objects can be constructed 53 // and destructed with the same functions as non-qualified objects. 54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 56 // remove lvalue as a qualifier, this can change to 57 // type->get_qualifiers() = Type::Qualifiers(); 58 assert( type ); 59 Type * castType = type->clone(); 60 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 61 castType->set_lvalue( true ); // xxx - might not need this 62 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 63 } 64 fExpr->get_args().push_back( dstParam ); 66 65 67 66 Statement * listInit = srcParam.buildListInit( fExpr ); 68 67 69 70 68 std::list< Expression * > args = *++srcParam; 69 fExpr->get_args().splice( fExpr->get_args().end(), args ); 71 70 72 71 *out++ = new ExprStmt( noLabels, fExpr ); 73 72 74 73 srcParam.clearArrayIndices(); 75 74 76 75 return listInit; 77 76 } 78 77 … … 88 87 Expression * begin, * end, * update, * cmp; 89 88 if ( forward ) { 90 // generate: for ( int i = 0; i < 0; ++i )91 begin = new ConstantExpr( Constant ( new ZeroType( emptyQualifiers ), "0") );89 // generate: for ( int i = 0; i < N; ++i ) 90 begin = new ConstantExpr( Constant::from_int( 0 ) ); 92 91 end = array->get_dimension()->clone(); 93 92 cmp = new NameExpr( "?<?" ); … … 97 96 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 98 97 ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() ); 99 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant ( new OneType( emptyQualifiers ), "1") ) );100 end = new ConstantExpr( Constant ( new ZeroType( emptyQualifiers ), "0") );98 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) ); 99 end = new ConstantExpr( Constant::from_int( 0 ) ); 101 100 cmp = new NameExpr( "?>=?" ); 102 101 update = new NameExpr( "--?" ); -
src/SymTab/ImplementationType.cc
re4d829b r579263a 76 76 } 77 77 78 void ImplementationType::visit(FunctionType *functionType) { 79 /// FunctionType *newType = functionType->clone(); 80 /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { 81 /// i->set_type( implementationType( i->get_type(), indexer ) ); 82 /// } 83 /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { 84 /// i->set_type( implementationType( i->get_type(), indexer ) ); 85 /// } 86 } 87 78 void ImplementationType::visit( __attribute__((unused)) FunctionType *functionType ) {} 88 79 void ImplementationType::visit( __attribute__((unused)) StructInstType * aggregateUseType ) {} 89 80 void ImplementationType::visit( __attribute__((unused)) UnionInstType * aggregateUseType ) {} -
src/SymTab/Indexer.cc
re4d829b r579263a 495 495 } 496 496 497 void Indexer::visit( UntypedValofExpr *valofExpr ) {498 acceptNewScope( valofExpr->get_result(), *this );499 maybeAccept( valofExpr->get_body(), *this );500 }501 502 497 void Indexer::visit( RangeExpr *rangeExpr ) { 503 498 maybeAccept( rangeExpr->get_low(), *this ); … … 518 513 acceptNewScope( tupleExpr->get_result(), *this ); 519 514 maybeAccept( tupleExpr->get_tuple(), *this ); 520 }521 522 void Indexer::visit( MemberTupleExpr *tupleExpr ) {523 acceptNewScope( tupleExpr->get_result(), *this );524 maybeAccept( tupleExpr->get_member(), *this );525 maybeAccept( tupleExpr->get_aggregate(), *this );526 515 } 527 516 -
src/SymTab/Indexer.h
re4d829b r579263a 69 69 virtual void visit( ConstructorExpr * ctorExpr ); 70 70 virtual void visit( CompoundLiteralExpr *compLitExpr ); 71 virtual void visit( UntypedValofExpr *valofExpr );72 71 virtual void visit( RangeExpr *rangeExpr ); 73 72 virtual void visit( UntypedTupleExpr *tupleExpr ); 74 73 virtual void visit( TupleExpr *tupleExpr ); 75 74 virtual void visit( TupleIndexExpr *tupleExpr ); 76 virtual void visit( MemberTupleExpr *tupleExpr );77 75 virtual void visit( TupleAssignExpr *tupleExpr ); 78 76 virtual void visit( StmtExpr * stmtExpr ); -
src/SymTab/Mangler.cc
re4d829b r579263a 236 236 } 237 237 238 void Mangler::visit( ZeroType *zeroType ) {238 void Mangler::visit( __attribute__((unused)) ZeroType *zeroType ) { 239 239 mangleName << "Z"; 240 240 } 241 241 242 void Mangler::visit( OneType *oneType ) {242 void Mangler::visit( __attribute__((unused)) OneType *oneType ) { 243 243 mangleName << "O"; 244 244 } -
src/SymTab/Validate.cc
re4d829b r579263a 106 106 107 107 /// Fix return types so that every function returns exactly one value 108 class ReturnTypeFixer { 109 public: 108 struct ReturnTypeFixer { 110 109 static void fix( std::list< Declaration * > &translationUnit ); 111 110 … … 115 114 116 115 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 117 class EnumAndPointerDecayPass final : public Visitor { 118 typedef Visitor Parent; 119 virtual void visit( EnumDecl *aggregateDecl ); 120 virtual void visit( FunctionType *func ); 116 struct EnumAndPointerDecay { 117 void previsit( EnumDecl *aggregateDecl ); 118 void previsit( FunctionType *func ); 121 119 }; 122 120 … … 126 124 public: 127 125 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 128 private:129 126 using Parent::visit; 130 127 void visit( EnumInstType *enumInst ) final; … … 136 133 void visit( UnionDecl *unionDecl ) final; 137 134 void visit( TypeInstType *typeInst ) final; 138 135 private: 139 136 const Indexer *indexer; 140 137 … … 147 144 }; 148 145 149 /// Replaces array and function types in forall lists by appropriate pointer type 150 class Pass3final : public Indexer {146 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 147 class ForallPointerDecay final : public Indexer { 151 148 typedef Indexer Parent; 152 149 public: 153 150 using Parent::visit; 154 Pass3( const Indexer *indexer );155 private: 151 ForallPointerDecay( const Indexer *indexer ); 152 156 153 virtual void visit( ObjectDecl *object ) override; 157 154 virtual void visit( FunctionDecl *func ) override; … … 160 157 }; 161 158 162 class ReturnChecker { 163 public: 159 struct ReturnChecker : public WithGuards { 164 160 /// Checks that return statements return nothing if their return type is void 165 161 /// and return something if the return type is non-void. 166 162 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 167 private: 163 168 164 void previsit( FunctionDecl * functionDecl ); 169 void postvisit( FunctionDecl * functionDecl );170 165 void previsit( ReturnStmt * returnStmt ); 171 166 172 167 typedef std::list< DeclarationWithType * > ReturnVals; 173 168 ReturnVals returnVals; 174 std::stack< ReturnVals > returnValsStack;175 169 }; 176 170 … … 208 202 }; 209 203 210 class VerifyCtorDtorAssign { 211 public: 204 struct VerifyCtorDtorAssign { 212 205 /// ensure that constructors, destructors, and assignment have at least one 213 206 /// parameter, the first of which must be a pointer, and that ctor/dtors have no … … 219 212 220 213 /// ensure that generic types have the correct number of type arguments 221 class ValidateGenericParameters { 222 public: 214 struct ValidateGenericParameters { 223 215 void previsit( StructInstType * inst ); 224 216 void previsit( UnionInstType * inst ); 225 217 }; 226 218 227 class ArrayLength { 228 public: 219 struct ArrayLength { 229 220 /// for array types without an explicit length, compute the length and store it so that it 230 221 /// is known to the rest of the phases. For example, … … 239 230 }; 240 231 241 class CompoundLiteral final : public GenPoly::DeclMutator{232 struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral> { 242 233 Type::StorageClasses storageClasses; 243 234 244 using GenPoly::DeclMutator::mutate; 245 DeclarationWithType * mutate( ObjectDecl *objectDecl ) final; 246 Expression *mutate( CompoundLiteralExpr *compLitExpr ) final; 235 void premutate( ObjectDecl *objectDecl ); 236 Expression * postmutate( CompoundLiteralExpr *compLitExpr ); 247 237 }; 248 238 249 239 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 250 EnumAndPointerDecayPassepc;240 PassVisitor<EnumAndPointerDecay> epc; 251 241 LinkReferenceToTypes lrt( doDebug, 0 ); 252 Pass3 pass3( 0 );253 CompoundLiteralcompoundliteral;242 ForallPointerDecay fpd( 0 ); 243 PassVisitor<CompoundLiteral> compoundliteral; 254 244 PassVisitor<ValidateGenericParameters> genericParams; 255 245 … … 262 252 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 263 253 Concurrency::applyKeywords( translationUnit ); 264 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay Pass254 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 265 255 Concurrency::implementMutexFuncs( translationUnit ); 266 256 Concurrency::implementThreadStarter( translationUnit ); 267 257 ReturnChecker::checkFunctionReturns( translationUnit ); 268 compoundliteral.mutateDeclarationList( translationUnit);269 acceptAll( translationUnit, pass3);258 mutateAll( translationUnit, compoundliteral ); 259 acceptAll( translationUnit, fpd ); 270 260 ArrayLength::computeLength( translationUnit ); 271 261 } 272 262 273 263 void validateType( Type *type, const Indexer *indexer ) { 274 EnumAndPointerDecayPassepc;264 PassVisitor<EnumAndPointerDecay> epc; 275 265 LinkReferenceToTypes lrt( false, indexer ); 276 Pass3 pass3( indexer );266 ForallPointerDecay fpd( indexer ); 277 267 type->accept( epc ); 278 268 type->accept( lrt ); 279 type->accept( pass3);269 type->accept( fpd ); 280 270 } 281 271 … … 356 346 } 357 347 358 void EnumAndPointerDecay Pass::visit( EnumDecl *enumDecl ) {348 void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) { 359 349 // Set the type of each member of the enumeration to be EnumConstant 360 350 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 363 353 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 364 354 } // for 365 Parent::visit( enumDecl );366 355 } 367 356 … … 370 359 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 371 360 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 372 // entirely other fix ups are handled by the FixFunction class361 // entirely. other fix ups are handled by the FixFunction class 373 362 typedef typename DWTList::iterator DWTIterator; 374 363 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 389 378 for ( ; i != end; ++i ) { 390 379 FixFunction fixer; 391 *i = (*i 380 *i = (*i)->acceptMutator( fixer ); 392 381 if ( fixer.get_isVoid() ) { 393 382 throw SemanticError( "invalid type void in function type ", func ); … … 398 387 } 399 388 400 void EnumAndPointerDecay Pass::visit( FunctionType *func ) {389 void EnumAndPointerDecay::previsit( FunctionType *func ) { 401 390 // Fix up parameters and return types 402 391 fixFunctionList( func->get_parameters(), func ); 403 392 fixFunctionList( func->get_returnVals(), func ); 404 Visitor::visit( func );405 393 } 406 394 … … 549 537 } 550 538 551 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {539 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) { 552 540 if ( other_indexer ) { 553 541 indexer = other_indexer; … … 587 575 } 588 576 589 void Pass3::visit( ObjectDecl *object ) {577 void ForallPointerDecay::visit( ObjectDecl *object ) { 590 578 forallFixer( object->get_type() ); 591 579 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 596 584 } 597 585 598 void Pass3::visit( FunctionDecl *func ) {586 void ForallPointerDecay::visit( FunctionDecl *func ) { 599 587 forallFixer( func->get_type() ); 600 588 Parent::visit( func ); … … 608 596 609 597 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 610 returnValsStack.push( returnVals );598 GuardValue( returnVals ); 611 599 returnVals = functionDecl->get_functionType()->get_returnVals(); 612 }613 void ReturnChecker::postvisit( FunctionDecl * functionDecl ) {614 returnVals = returnValsStack.top();615 returnValsStack.pop();616 600 } 617 601 … … 892 876 } 893 877 894 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {878 void CompoundLiteral::premutate( ObjectDecl *objectDecl ) { 895 879 storageClasses = objectDecl->get_storageClasses(); 896 DeclarationWithType * temp = Mutator::mutate( objectDecl ); 897 return temp; 898 } 899 900 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) { 880 } 881 882 Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) { 901 883 // transform [storage_class] ... (struct S){ 3, ... }; 902 884 // into [storage_class] struct S temp = { 3, ... }; 903 885 static UniqueName indexName( "_compLit" ); 904 886 905 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() );906 compLitExpr->set_result( 0);907 compLitExpr->set_initializer( 0);887 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() ); 888 compLitExpr->set_result( nullptr ); 889 compLitExpr->set_initializer( nullptr ); 908 890 delete compLitExpr; 909 DeclarationWithType * newtempvar = mutate( tempvar ); 910 addDeclaration( newtempvar ); // add modified temporary to current block 911 return new VariableExpr( newtempvar ); 891 declsToAddBefore.push_back( tempvar ); // add modified temporary to current block 892 return new VariableExpr( tempvar ); 912 893 } 913 894
Note: See TracChangeset
for help on using the changeset viewer.