Changeset 12bc63a for src/Parser/DeclarationNode.cc
- Timestamp:
- Sep 15, 2016, 3:49:22 PM (9 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:
- 3c13c03
- Parents:
- 4ab9536 (diff), fc4a0fa (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r4ab9536 r12bc63a 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 11 09:24:11201613 // Update Count : 43812 // Last Modified On : Wed Sep 14 23:13:28 2016 13 // Update Count : 502 14 14 // 15 15 … … 32 32 // These must remain in the same order as the corresponding DeclarationNode enumerations. 33 33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" }; 34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", }; 36 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; 34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" }; 35 const char *DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" }; 36 const char *DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" }; 37 const char *DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" }; 38 const char *DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" }; 37 39 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 38 const char *DeclarationNode::typeClassName[] = { " type", "dtype", "ftype" };40 const char *DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" }; 39 41 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" }; 40 42 … … 53 55 linkage( ::linkage ), 54 56 extension( false ) { 55 variable.tyClass = DeclarationNode:: Type;57 variable.tyClass = DeclarationNode::Otype; 56 58 variable.assertions = nullptr; 57 59 … … 188 190 DeclarationNode *newnode = new DeclarationNode; 189 191 newnode->type = new TypeData( TypeData::Basic ); 190 newnode->type->basic .typeSpec.push_back( bt );192 newnode->type->basictype = bt; 191 193 return newnode; 192 194 } // DeclarationNode::newBasicType 193 195 194 DeclarationNode * DeclarationNode::new Modifier( Modifier mod) {196 DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) { 195 197 DeclarationNode *newnode = new DeclarationNode; 196 198 newnode->type = new TypeData( TypeData::Basic ); 197 newnode->type->basic.modifiers.push_back( mod ); 198 return newnode; 199 } // DeclarationNode::newModifier 199 newnode->type->complextype = ct; 200 return newnode; 201 } // DeclarationNode::newComplexType 202 203 DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) { 204 DeclarationNode *newnode = new DeclarationNode; 205 newnode->type = new TypeData( TypeData::Basic ); 206 newnode->type->signedness = sn; 207 return newnode; 208 } // DeclarationNode::newSignedNess 209 210 DeclarationNode * DeclarationNode::newLength( Length lnth ) { 211 DeclarationNode *newnode = new DeclarationNode; 212 newnode->type = new TypeData( TypeData::Basic ); 213 newnode->type->length = lnth; 214 return newnode; 215 } // DeclarationNode::newLength 200 216 201 217 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { … … 367 383 } 368 384 369 static void addQualifiersToType( TypeData *&src, TypeData *dst ) { 370 if ( src && dst ) { 371 if ( src->forall && dst->kind == TypeData::Function ) { 372 if ( dst->forall ) { 373 dst->forall->appendList( src->forall ); 374 } else { 375 dst->forall = src->forall; 376 } // if 377 src->forall = 0; 378 } // if 379 if ( dst->base ) { 380 addQualifiersToType( src, dst->base ); 381 } else if ( dst->kind == TypeData::Function ) { 382 dst->base = src; 383 src = 0; 384 } else { 385 dst->qualifiers |= src->qualifiers; 386 } // if 387 } // if 388 } 385 void appendError( string & dst, const string & src ) { 386 if ( src.empty() ) return; 387 if ( dst.empty() ) { dst = src; return; } 388 dst += ", " + src; 389 } // appendError 389 390 390 391 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { … … 392 393 393 394 if ( (qsrc & qdst).any() ) { // common qualifier ? 394 for ( int i = 0; i < NoOfQualifier; i += 1 ) { // find common qualifiers 395 if ( qsrc[i] & qdst[i] ) { 396 if ( ! error.empty() ) error += ", "; // separator 397 error += string( "duplicate " ) + DeclarationNode::qualifierName[i]; 395 for ( int i = 0; i < NoQualifier; i += 1 ) { // find common qualifiers 396 if ( qsrc[i] && qdst[i] ) { 397 appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] ); 398 398 } // if 399 399 } // for … … 403 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) { 404 404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 if ( ! error.empty() ) error += ", "; // separator406 405 if ( storageClass == q->storageClass ) { // duplicate qualifier 407 error += string( "duplicate " ) + storageName[ storageClass ];406 appendError( error, string( "duplicate " ) + storageName[ storageClass ] ); 408 407 } else { // only one storage class 409 error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ]; 410 q->storageClass = storageClass; // FIX ERROR 411 } // if 412 if ( ! q->error.empty() ) error += ", " + q->error; // separator 413 } else { 414 if ( ! error.empty() ) { 415 if ( ! q->error.empty() ) error += ", " + q->error; // separator 416 } else if ( ! q->error.empty() ) error += q->error; 417 } // if 408 appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] ); 409 q->storageClass = storageClass; // FIX ERROR, prevent assertions from triggering 410 } // if 411 } // if 412 appendError( error, q->error ); 418 413 } // DeclarationNode::copyStorageClasses 419 414 420 415 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 421 isInline = isInline | q->isInline;422 isNoreturn = isNoreturn | q->isNoreturn;416 isInline = isInline || q->isInline; 417 isNoreturn = isNoreturn || q->isNoreturn; 423 418 // do not overwrite an existing value with NoStorageClass 424 419 if ( q->storageClass != NoStorageClass ) { … … 429 424 } // DeclarationNode::copyStorageClasses 430 425 426 static void addQualifiersToType( TypeData *&src, TypeData *dst ) { 427 if ( src->forall && dst->kind == TypeData::Function ) { 428 if ( dst->forall ) { 429 dst->forall->appendList( src->forall ); 430 } else { 431 dst->forall = src->forall; 432 } // if 433 src->forall = 0; 434 } // if 435 if ( dst->base ) { 436 addQualifiersToType( src, dst->base ); 437 } else if ( dst->kind == TypeData::Function ) { 438 dst->base = src; 439 src = 0; 440 } else { 441 dst->qualifiers |= src->qualifiers; 442 } // if 443 } // addQualifiersToType 444 431 445 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 432 if ( q ) { 433 checkStorageClasses( q ); 434 copyStorageClasses( q ); 435 if ( q->type ) { 436 if ( ! type ) { 437 type = new TypeData; 446 if ( ! q ) return this; 447 448 checkStorageClasses( q ); 449 copyStorageClasses( q ); 450 451 if ( ! q->type ) { delete q; return this; } 452 453 if ( ! type ) { 454 // type = new TypeData; 455 type = q->type; 456 return this; 457 } // if 458 459 checkQualifiers( q->type, type ); 460 addQualifiersToType( q->type, type ); 461 462 if ( q->type->forall ) { 463 if ( type->forall ) { 464 type->forall->appendList( q->type->forall ); 465 } else { 466 if ( type->kind == TypeData::Aggregate ) { 467 type->aggregate.params = q->type->forall; 468 // change implicit typedef from TYPEDEFname to TYPEGENname 469 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG ); 438 470 } else { 439 checkQualifiers( q->type, type );471 type->forall = q->type->forall; 440 472 } // if 441 addQualifiersToType( q->type, type ); 442 if ( q->type && q->type->forall ) { 443 if ( type->forall ) { 444 type->forall->appendList( q->type->forall ); 445 } else { 446 if ( type->kind == TypeData::Aggregate ) { 447 type->aggregate.params = q->type->forall; 448 // change implicit typedef from TYPEDEFname to TYPEGENname 449 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG ); 450 } else { 451 type->forall = q->type->forall; 452 } // if 473 } // if 474 q->type->forall = 0; 475 } // if 476 delete q; 477 return this; 478 } // addQualifiers 479 480 static void addTypeToType( TypeData *&src, TypeData *&dst ) { 481 if ( src->forall && dst->kind == TypeData::Function ) { 482 if ( dst->forall ) { 483 dst->forall->appendList( src->forall ); 484 } else { 485 dst->forall = src->forall; 486 } // if 487 src->forall = 0; 488 } // if 489 if ( dst->base ) { 490 addTypeToType( src, dst->base ); 491 } else { 492 switch ( dst->kind ) { 493 case TypeData::Unknown: 494 src->qualifiers |= dst->qualifiers; 495 dst = src; 496 src = 0; 497 break; 498 case TypeData::Basic: 499 dst->qualifiers |= src->qualifiers; 500 if ( src->kind != TypeData::Unknown ) { 501 assert( src->kind == TypeData::Basic ); 502 503 if ( dst->basictype == DeclarationNode::NoBasicType ) { 504 dst->basictype = src->basictype; 505 } else if ( src->basictype != DeclarationNode::NoBasicType ) 506 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src ); 507 508 if ( dst->complextype == DeclarationNode::NoComplexType ) { 509 dst->complextype = src->complextype; 510 } else if ( src->complextype != DeclarationNode::NoComplexType ) 511 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src ); 512 513 if ( dst->signedness == DeclarationNode::NoSignedness ) { 514 dst->signedness = src->signedness; 515 } else if ( src->signedness != DeclarationNode::NoSignedness ) 516 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src ); 517 518 if ( dst->length == DeclarationNode::NoLength ) { 519 dst->length = src->length; 520 } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) { 521 dst->length = DeclarationNode::LongLong; 522 } else if ( src->length != DeclarationNode::NoLength ) 523 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src ); 524 } // if 525 break; 526 default: 527 switch ( src->kind ) { 528 case TypeData::Aggregate: 529 case TypeData::Enum: 530 dst->base = new TypeData( TypeData::AggregateInst ); 531 dst->base->aggInst.aggregate = src; 532 if ( src->kind == TypeData::Aggregate ) { 533 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 453 534 } // if 454 q->type->forall = 0; 455 } // if 456 } // if 457 } // if 458 delete q; 459 return this; 460 } 461 462 static void addTypeToType( TypeData *&src, TypeData *&dst ) { 463 if ( src && dst ) { 464 if ( src->forall && dst->kind == TypeData::Function ) { 465 if ( dst->forall ) { 466 dst->forall->appendList( src->forall ); 467 } else { 468 dst->forall = src->forall; 469 } // if 470 src->forall = 0; 471 } // if 472 if ( dst->base ) { 473 addTypeToType( src, dst->base ); 474 } else { 475 switch ( dst->kind ) { 476 case TypeData::Unknown: 477 src->qualifiers |= dst->qualifiers; 478 dst = src; 535 dst->base->qualifiers |= src->qualifiers; 479 536 src = 0; 480 537 break; 481 case TypeData::Basic: 482 dst->qualifiers |= src->qualifiers; 483 if ( src->kind != TypeData::Unknown ) { 484 assert( src->kind == TypeData::Basic ); 485 dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers ); 486 dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec ); 538 default: 539 if ( dst->forall ) { 540 dst->forall->appendList( src->forall ); 541 } else { 542 dst->forall = src->forall; 487 543 } // if 488 break; 489 default: 490 switch ( src->kind ) { 491 case TypeData::Aggregate: 492 case TypeData::Enum: 493 dst->base = new TypeData( TypeData::AggregateInst ); 494 dst->base->aggInst.aggregate = src; 495 if ( src->kind == TypeData::Aggregate ) { 496 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 497 } // if 498 dst->base->qualifiers |= src->qualifiers; 499 src = 0; 500 break; 501 default: 502 if ( dst->forall ) { 503 dst->forall->appendList( src->forall ); 504 } else { 505 dst->forall = src->forall; 506 } // if 507 src->forall = 0; 508 dst->base = src; 509 src = 0; 510 } // switch 544 src->forall = 0; 545 dst->base = src; 546 src = 0; 511 547 } // switch 512 } // if548 } // switch 513 549 } // if 514 550 } … … 875 911 while ( cur ) { 876 912 try { 877 /// if ( DeclarationNode *extr = cur->extractAggregate() ) {878 /// // handle the case where a structure declaration is contained within an object or type879 /// // declaration880 /// Declaration *decl = extr->build();881 /// if ( decl ) {882 /// *out++ = decl;883 /// }884 /// }885 913 Declaration *decl = cur->build(); 886 914 if ( decl ) {
Note: See TracChangeset
for help on using the changeset viewer.