Changeset fc4a0fa for src/Parser
- Timestamp:
- Sep 15, 2016, 3:45:32 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:
- 12bc63a, 24bc651, 89e6ffc
- Parents:
- 1eba452 (diff), 101e0bd (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/Parser
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/DeclarationNode.cc ¶
r1eba452 rfc4a0fa 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 ) { -
TabularUnified src/Parser/ParseNode.h ¶
r1eba452 rfc4a0fa 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Sep 10 17:14:37201613 // Update Count : 58912 // Last Modified On : Mon Sep 12 08:00:05 2016 13 // Update Count : 603 14 14 // 15 15 … … 196 196 class DeclarationNode : public ParseNode { 197 197 public: 198 enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoOfQualifier };198 // These must remain in the same order as the corresponding DeclarationNode names. 199 199 enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, }; 200 enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; 201 enum Modifier { Signed, Unsigned, Short, Long }; 200 enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoQualifier }; 201 enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType }; 202 enum ComplexType { Complex, Imaginary, NoComplexType }; 203 enum Signedness { Signed, Unsigned, NoSignedness }; 204 enum Length { Short, Long, LongLong, NoLength }; 202 205 enum Aggregate { Struct, Union, Trait }; 203 enum TypeClass { Type, Dtype, Ftype };206 enum TypeClass { Otype, Dtype, Ftype }; 204 207 enum BuiltinType { Valist }; 205 208 209 static const char * storageName[]; 206 210 static const char * qualifierName[]; 207 static const char * storageName[];208 211 static const char * basicTypeName[]; 209 static const char * modifierName[]; 212 static const char * complexTypeName[]; 213 static const char * signednessName[]; 214 static const char * lengthName[]; 210 215 static const char * aggregateName[]; 211 216 static const char * typeClassName[]; … … 217 222 static DeclarationNode * newStorageClass( StorageClass ); 218 223 static DeclarationNode * newBasicType( BasicType ); 219 static DeclarationNode * newModifier( Modifier ); 224 static DeclarationNode * newComplexType( ComplexType ); 225 static DeclarationNode * newSignedNess( Signedness sn ); 226 static DeclarationNode * newLength( Length lnth ); 220 227 static DeclarationNode * newBuiltinType( BuiltinType ); 221 228 static DeclarationNode * newFromTypedef( std::string *); … … 309 316 TypeData * type; 310 317 std::string name; 311 // std::list< StorageClass > storageClasses;312 318 StorageClass storageClass; 313 319 bool isInline, isNoreturn; -
TabularUnified src/Parser/TypeData.cc ¶
r1eba452 rfc4a0fa 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:31:53201613 // Update Count : 27712 // Last Modified On : Mon Sep 12 21:11:22 2016 13 // Update Count : 377 14 14 // 15 15 … … 178 178 break; 179 179 case Basic: 180 newtype->basic.typeSpec = basic.typeSpec; 181 newtype->basic.modifiers = basic.modifiers; 180 newtype->basictype = basictype; 181 newtype->complextype = complextype; 182 newtype->signedness = signedness; 183 newtype->length = length; 182 184 break; 183 185 case Array: … … 247 249 using std::string; 248 250 249 for ( int i = 0; i < DeclarationNode::No OfQualifier; i += 1 ) {251 for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) { 250 252 if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' '; 251 253 } // for … … 271 273 break; 272 274 case Basic: 273 printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os ); 274 printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os ); 275 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessName[ signedness ] << " "; 276 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthName[ length ] << " "; 277 assert( basictype != DeclarationNode::NoBasicType ); 278 os << DeclarationNode::basicTypeName[ basictype ] << " "; 279 if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeName[ complextype ] << " "; 275 280 break; 276 281 case Array: … … 418 423 break; 419 424 default: 420 os << "internal error: TypeData::print " << kind 425 os << "internal error: TypeData::print " << kind << endl; 421 426 assert( false ); 422 427 } // switch … … 531 536 532 537 Type * buildBasicType( const TypeData * td ) { 533 static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double,534 BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex,535 BasicType::DoubleImaginary };536 bool init = false;537 bool sawDouble = false;538 bool sawSigned = false;539 538 BasicType::Kind ret; 540 539 541 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) { 542 if ( ! init ) { 543 init = true; 544 if ( *i == DeclarationNode::Void ) { 545 if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) { 546 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 547 } else { 548 return new VoidType( buildQualifiers( td ) ); 549 } // if 550 } else { 551 ret = kindMap[ *i ]; 552 } // if 553 } else { 554 switch ( *i ) { 555 case DeclarationNode::Float: 556 if ( sawDouble ) { 557 throw SemanticError( "invalid type specifier \"float\" in type: ", td ); 558 } else { 559 switch ( ret ) { 560 case BasicType::DoubleComplex: 561 ret = BasicType::FloatComplex; 562 break; 563 case BasicType::DoubleImaginary: 564 ret = BasicType::FloatImaginary; 565 break; 566 default: 567 throw SemanticError( "invalid type specifier \"float\" in type: ", td ); 568 } // switch 569 } // if 570 break; 571 case DeclarationNode::Double: 572 if ( sawDouble ) { 573 throw SemanticError( "duplicate type specifier \"double\" in type: ", td ); 574 } else { 575 switch ( ret ) { 576 case BasicType::DoubleComplex: 577 case BasicType::DoubleImaginary: 578 break; 579 default: 580 throw SemanticError( "invalid type specifier \"double\" in type: ", td ); 581 } // switch 582 } // if 583 break; 584 case DeclarationNode::Complex: 585 switch ( ret ) { 586 case BasicType::Float: 587 ret = BasicType::FloatComplex; 588 break; 589 case BasicType::Double: 590 ret = BasicType::DoubleComplex; 591 break; 592 default: 593 throw SemanticError( "invalid type specifier \"_Complex\" in type: ", td ); 594 } // switch 595 break; 596 case DeclarationNode::Imaginary: 597 switch ( ret ) { 598 case BasicType::Float: 599 ret = BasicType::FloatImaginary; 600 break; 601 case BasicType::Double: 602 ret = BasicType::DoubleImaginary; 603 break; 604 default: 605 throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", td ); 606 } // switch 607 break; 608 default: 609 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", td ); 610 } // switch 611 } // if 612 if ( *i == DeclarationNode::Double ) { 613 sawDouble = true; 614 } // if 615 } // for 616 617 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) { 618 switch ( *i ) { 619 case DeclarationNode::Long: 620 if ( ! init ) { 621 init = true; 622 ret = BasicType::LongSignedInt; 623 } else { 624 switch ( ret ) { 625 case BasicType::SignedInt: 626 ret = BasicType::LongSignedInt; 627 break; 628 case BasicType::UnsignedInt: 629 ret = BasicType::LongUnsignedInt; 630 break; 631 case BasicType::LongSignedInt: 632 ret = BasicType::LongLongSignedInt; 633 break; 634 case BasicType::LongUnsignedInt: 635 ret = BasicType::LongLongUnsignedInt; 636 break; 637 case BasicType::Double: 638 ret = BasicType::LongDouble; 639 break; 640 case BasicType::DoubleComplex: 641 ret = BasicType::LongDoubleComplex; 642 break; 643 case BasicType::DoubleImaginary: 644 ret = BasicType::LongDoubleImaginary; 645 break; 646 default: 647 throw SemanticError( "invalid type modifier \"long\" in type: ", td ); 648 } // switch 649 } // if 650 break; 651 case DeclarationNode::Short: 652 if ( ! init ) { 653 init = true; 654 ret = BasicType::ShortSignedInt; 655 } else { 656 switch ( ret ) { 657 case BasicType::SignedInt: 658 ret = BasicType::ShortSignedInt; 659 break; 660 case BasicType::UnsignedInt: 661 ret = BasicType::ShortUnsignedInt; 662 break; 663 default: 664 throw SemanticError( "invalid type modifier \"short\" in type: ", td ); 665 } // switch 666 } // if 667 break; 668 case DeclarationNode::Signed: 669 if ( ! init ) { 670 init = true; 671 ret = BasicType::SignedInt; 672 } else if ( sawSigned ) { 673 throw SemanticError( "duplicate type modifer \"signed\" in type: ", td ); 674 } else { 675 switch ( ret ) { 676 case BasicType::LongLongSignedInt: 677 ret = BasicType::LongLongUnsignedInt; 678 break; 679 case BasicType::LongSignedInt: 680 ret = BasicType::LongUnsignedInt; 681 break; 682 case BasicType::SignedInt: 683 case BasicType::ShortSignedInt: 684 break; 685 case BasicType::Char: 686 ret = BasicType::SignedChar; 687 break; 688 default: 689 throw SemanticError( "invalid type modifer \"signed\" in type: ", td ); 690 } // switch 691 } // if 692 break; 693 case DeclarationNode::Unsigned: 694 if ( ! init ) { 695 init = true; 696 ret = BasicType::UnsignedInt; 697 } else if ( sawSigned ) { 698 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td ); 699 } else { 700 switch ( ret ) { 701 case BasicType::LongLongSignedInt: 702 ret = BasicType::LongLongUnsignedInt; 703 break; 704 case BasicType::LongSignedInt: 705 ret = BasicType::LongUnsignedInt; 706 break; 707 case BasicType::SignedInt: 708 ret = BasicType::UnsignedInt; 709 break; 710 case BasicType::ShortSignedInt: 711 ret = BasicType::ShortUnsignedInt; 712 break; 713 case BasicType::Char: 714 ret = BasicType::UnsignedChar; 715 break; 716 default: 717 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td ); 718 } // switch 719 } // if 720 break; 721 } // switch 722 723 if ( *i == DeclarationNode::Signed ) { 724 sawSigned = true; 725 } // if 726 } // for 727 728 BasicType * bt; 729 if ( ! init ) { 730 bt = new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 731 } else { 732 bt = new BasicType( buildQualifiers( td ), ret ); 733 } // if 540 switch ( td->basictype ) { 541 case DeclarationNode::Void: 542 if ( td->signedness != DeclarationNode::NoSignedness && td->length != DeclarationNode::NoLength ) { 543 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 544 } // if 545 546 return new VoidType( buildQualifiers( td ) ); 547 break; 548 549 case DeclarationNode::Bool: 550 if ( td->signedness != DeclarationNode::NoSignedness ) { 551 throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 552 } // if 553 if ( td->length != DeclarationNode::NoLength ) { 554 throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 555 } // if 556 557 ret = BasicType::Bool; 558 break; 559 560 case DeclarationNode::Char: 561 // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the 562 // character types. The implementation shall define char to have the same range, representation, and behavior as 563 // either signed char or unsigned char. 564 static BasicType::Kind chartype[] = { BasicType::SignedChar, BasicType::UnsignedChar, BasicType::Char }; 565 566 if ( td->length != DeclarationNode::NoLength ) { 567 throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 568 } // if 569 570 ret = chartype[ td->signedness ]; 571 break; 572 573 case DeclarationNode::Int: 574 static BasicType::Kind inttype[2][4] = { 575 { BasicType::ShortSignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt }, 576 { BasicType::ShortUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt }, 577 }; 578 579 Integral: ; 580 if ( td->signedness == DeclarationNode::NoSignedness ) { 581 const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed; 582 } // if 583 ret = inttype[ td->signedness ][ td->length ]; 584 break; 585 586 case DeclarationNode::Float: 587 case DeclarationNode::Double: 588 case DeclarationNode::LongDouble: // not set until below 589 static BasicType::Kind floattype[3][3] = { 590 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 591 { BasicType::FloatImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary }, 592 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 593 }; 594 595 FloatingPoint: ; 596 if ( td->signedness != DeclarationNode::NoSignedness ) { 597 throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 598 } // if 599 if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) { 600 throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 601 } // if 602 if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) { 603 throw SemanticError( "invalid type specifier \"long\" in type: ", td ); 604 } // if 605 if ( td->length == DeclarationNode::Long ) { 606 const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble; 607 } // if 608 609 ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ]; 610 break; 611 612 case DeclarationNode::NoBasicType: 613 // No basic type in declaration => default double for Complex/Imaginary and int type for integral types 614 if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) { 615 const_cast<TypeData *>(td)->basictype = DeclarationNode::Double; 616 goto FloatingPoint; 617 } // if 618 619 const_cast<TypeData *>(td)->basictype = DeclarationNode::Int; 620 goto Integral; 621 } // switch 622 623 BasicType * bt = new BasicType( buildQualifiers( td ), ret ); 734 624 buildForall( td->forall, bt->get_forall() ); 735 625 return bt; -
TabularUnified src/Parser/TypeData.h ¶
r1eba452 rfc4a0fa 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Sep 10 09:42:54201613 // Update Count : 1 1812 // Last Modified On : Mon Sep 12 17:15:49 2016 13 // Update Count : 129 14 14 // 15 15 … … 25 25 enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, 26 26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr }; 27 28 struct Basic_t {29 std::list< DeclarationNode::BasicType > typeSpec;30 std::list< DeclarationNode::Modifier > modifiers;31 };32 27 33 28 struct Aggregate_t { … … 73 68 }; 74 69 75 // struct Tuple_t {76 // DeclarationNode * members;77 // };78 79 // struct Typeof_t {80 // ExpressionNode * expr;81 // };82 83 // struct Builtin_t {84 // DeclarationNode::BuiltinType type;85 // };86 87 70 Kind kind; 88 71 TypeData * base; 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; 72 DeclarationNode::BasicType basictype = DeclarationNode::NoBasicType; 73 DeclarationNode::ComplexType complextype = DeclarationNode::NoComplexType; 74 DeclarationNode::Signedness signedness = DeclarationNode::NoSignedness; 75 DeclarationNode::Length length = DeclarationNode::NoLength; 76 typedef std::bitset< DeclarationNode::NoQualifier > Qualifiers; 90 77 Qualifiers qualifiers; 91 typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;92 StorageClasses storageclasses;93 78 DeclarationNode * forall; 94 79 95 Basic_t basic;80 // Basic_t basic; 96 81 Aggregate_t aggregate; 97 82 AggInst_t aggInst; -
TabularUnified src/Parser/parser.cc ¶
r1eba452 rfc4a0fa 5929 5929 /* Line 1806 of yacc.c */ 5930 5930 #line 829 "parser.yy" 5931 { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn) ) ); }5931 { (yyval.sn) = new StatementNode( build_while( (yyvsp[(5) - (7)].en), (yyvsp[(2) - (7)].sn), true ) ); } 5932 5932 break; 5933 5933 … … 6744 6744 /* Line 1806 of yacc.c */ 6745 6745 #line 1365 "parser.yy" 6746 { (yyval.decl) = DeclarationNode::new Modifier( DeclarationNode::Long ); }6746 { (yyval.decl) = DeclarationNode::newLength( DeclarationNode::Long ); } 6747 6747 break; 6748 6748 … … 6751 6751 /* Line 1806 of yacc.c */ 6752 6752 #line 1367 "parser.yy" 6753 { (yyval.decl) = DeclarationNode::new Modifier( DeclarationNode::Short ); }6753 { (yyval.decl) = DeclarationNode::newLength( DeclarationNode::Short ); } 6754 6754 break; 6755 6755 … … 6758 6758 /* Line 1806 of yacc.c */ 6759 6759 #line 1369 "parser.yy" 6760 { (yyval.decl) = DeclarationNode::new Modifier( DeclarationNode::Signed ); }6760 { (yyval.decl) = DeclarationNode::newSignedNess( DeclarationNode::Signed ); } 6761 6761 break; 6762 6762 … … 6765 6765 /* Line 1806 of yacc.c */ 6766 6766 #line 1371 "parser.yy" 6767 { (yyval.decl) = DeclarationNode::new Modifier( DeclarationNode::Unsigned ); }6767 { (yyval.decl) = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); } 6768 6768 break; 6769 6769 … … 6786 6786 /* Line 1806 of yacc.c */ 6787 6787 #line 1377 "parser.yy" 6788 { (yyval.decl) = DeclarationNode::new BasicType( DeclarationNode::Complex ); }6788 { (yyval.decl) = DeclarationNode::newComplexType( DeclarationNode::Complex ); } 6789 6789 break; 6790 6790 … … 6793 6793 /* Line 1806 of yacc.c */ 6794 6794 #line 1379 "parser.yy" 6795 { (yyval.decl) = DeclarationNode::new BasicType( DeclarationNode::Imaginary ); }6795 { (yyval.decl) = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); } 6796 6796 break; 6797 6797 … … 7544 7544 /* Line 1806 of yacc.c */ 7545 7545 #line 1851 "parser.yy" 7546 { (yyval.tclass) = DeclarationNode:: Type; }7546 { (yyval.tclass) = DeclarationNode::Otype; } 7547 7547 break; 7548 7548 -
TabularUnified src/Parser/parser.h ¶
r1eba452 rfc4a0fa 1 /* A Bison parser, made by GNU Bison 3.0.2. */1 /* A Bison parser, made by GNU Bison 2.5. */ 2 2 3 3 /* Bison interface for Yacc-like parsers in C 4 5 Copyright (C) 1984, 1989-1990, 2000-2013Free Software Foundation, Inc.6 4 5 Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. 6 7 7 This program is free software: you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation, either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ … … 27 27 Bison output files to be licensed under the GNU General Public 28 28 License without this special exception. 29 29 30 30 This special exception was added by the Free Software Foundation in 31 31 version 2.2 of Bison. */ 32 32 33 #ifndef YY_YY_PARSER_PARSER_H_INCLUDED 34 # define YY_YY_PARSER_PARSER_H_INCLUDED 35 /* Debug traces. */ 36 #ifndef YYDEBUG 37 # define YYDEBUG 1 38 #endif 39 #if YYDEBUG 40 extern int yydebug; 41 #endif 42 43 /* Token type. */ 33 34 /* Tokens. */ 44 35 #ifndef YYTOKENTYPE 45 36 # define YYTOKENTYPE 46 enum yytokentype 47 { 48 TYPEDEF = 258, 49 AUTO = 259, 50 EXTERN = 260, 51 REGISTER = 261, 52 STATIC = 262, 53 INLINE = 263, 54 FORTRAN = 264, 55 CONST = 265, 56 VOLATILE = 266, 57 RESTRICT = 267, 58 FORALL = 268, 59 LVALUE = 269, 60 VOID = 270, 61 CHAR = 271, 62 SHORT = 272, 63 INT = 273, 64 LONG = 274, 65 FLOAT = 275, 66 DOUBLE = 276, 67 SIGNED = 277, 68 UNSIGNED = 278, 69 VALIST = 279, 70 BOOL = 280, 71 COMPLEX = 281, 72 IMAGINARY = 282, 73 TYPEOF = 283, 74 LABEL = 284, 75 ENUM = 285, 76 STRUCT = 286, 77 UNION = 287, 78 OTYPE = 288, 79 FTYPE = 289, 80 DTYPE = 290, 81 TRAIT = 291, 82 SIZEOF = 292, 83 OFFSETOF = 293, 84 ATTRIBUTE = 294, 85 EXTENSION = 295, 86 IF = 296, 87 ELSE = 297, 88 SWITCH = 298, 89 CASE = 299, 90 DEFAULT = 300, 91 DO = 301, 92 WHILE = 302, 93 FOR = 303, 94 BREAK = 304, 95 CONTINUE = 305, 96 GOTO = 306, 97 RETURN = 307, 98 CHOOSE = 308, 99 DISABLE = 309, 100 ENABLE = 310, 101 FALLTHRU = 311, 102 TRY = 312, 103 CATCH = 313, 104 CATCHRESUME = 314, 105 FINALLY = 315, 106 THROW = 316, 107 THROWRESUME = 317, 108 AT = 318, 109 ASM = 319, 110 ALIGNAS = 320, 111 ALIGNOF = 321, 112 ATOMIC = 322, 113 GENERIC = 323, 114 NORETURN = 324, 115 STATICASSERT = 325, 116 THREADLOCAL = 326, 117 IDENTIFIER = 327, 118 QUOTED_IDENTIFIER = 328, 119 TYPEDEFname = 329, 120 TYPEGENname = 330, 121 ATTR_IDENTIFIER = 331, 122 ATTR_TYPEDEFname = 332, 123 ATTR_TYPEGENname = 333, 124 INTEGERconstant = 334, 125 FLOATINGconstant = 335, 126 CHARACTERconstant = 336, 127 STRINGliteral = 337, 128 ZERO = 338, 129 ONE = 339, 130 ARROW = 340, 131 ICR = 341, 132 DECR = 342, 133 LS = 343, 134 RS = 344, 135 LE = 345, 136 GE = 346, 137 EQ = 347, 138 NE = 348, 139 ANDAND = 349, 140 OROR = 350, 141 ELLIPSIS = 351, 142 MULTassign = 352, 143 DIVassign = 353, 144 MODassign = 354, 145 PLUSassign = 355, 146 MINUSassign = 356, 147 LSassign = 357, 148 RSassign = 358, 149 ANDassign = 359, 150 ERassign = 360, 151 ORassign = 361, 152 ATassign = 362, 153 THEN = 363 154 }; 37 /* Put the tokens into the symbol table, so that GDB and other debuggers 38 know about them. */ 39 enum yytokentype { 40 TYPEDEF = 258, 41 AUTO = 259, 42 EXTERN = 260, 43 REGISTER = 261, 44 STATIC = 262, 45 INLINE = 263, 46 FORTRAN = 264, 47 CONST = 265, 48 VOLATILE = 266, 49 RESTRICT = 267, 50 FORALL = 268, 51 LVALUE = 269, 52 VOID = 270, 53 CHAR = 271, 54 SHORT = 272, 55 INT = 273, 56 LONG = 274, 57 FLOAT = 275, 58 DOUBLE = 276, 59 SIGNED = 277, 60 UNSIGNED = 278, 61 VALIST = 279, 62 BOOL = 280, 63 COMPLEX = 281, 64 IMAGINARY = 282, 65 TYPEOF = 283, 66 LABEL = 284, 67 ENUM = 285, 68 STRUCT = 286, 69 UNION = 287, 70 OTYPE = 288, 71 FTYPE = 289, 72 DTYPE = 290, 73 TRAIT = 291, 74 SIZEOF = 292, 75 OFFSETOF = 293, 76 ATTRIBUTE = 294, 77 EXTENSION = 295, 78 IF = 296, 79 ELSE = 297, 80 SWITCH = 298, 81 CASE = 299, 82 DEFAULT = 300, 83 DO = 301, 84 WHILE = 302, 85 FOR = 303, 86 BREAK = 304, 87 CONTINUE = 305, 88 GOTO = 306, 89 RETURN = 307, 90 CHOOSE = 308, 91 DISABLE = 309, 92 ENABLE = 310, 93 FALLTHRU = 311, 94 TRY = 312, 95 CATCH = 313, 96 CATCHRESUME = 314, 97 FINALLY = 315, 98 THROW = 316, 99 THROWRESUME = 317, 100 AT = 318, 101 ASM = 319, 102 ALIGNAS = 320, 103 ALIGNOF = 321, 104 ATOMIC = 322, 105 GENERIC = 323, 106 NORETURN = 324, 107 STATICASSERT = 325, 108 THREADLOCAL = 326, 109 IDENTIFIER = 327, 110 QUOTED_IDENTIFIER = 328, 111 TYPEDEFname = 329, 112 TYPEGENname = 330, 113 ATTR_IDENTIFIER = 331, 114 ATTR_TYPEDEFname = 332, 115 ATTR_TYPEGENname = 333, 116 INTEGERconstant = 334, 117 FLOATINGconstant = 335, 118 CHARACTERconstant = 336, 119 STRINGliteral = 337, 120 ZERO = 338, 121 ONE = 339, 122 ARROW = 340, 123 ICR = 341, 124 DECR = 342, 125 LS = 343, 126 RS = 344, 127 LE = 345, 128 GE = 346, 129 EQ = 347, 130 NE = 348, 131 ANDAND = 349, 132 OROR = 350, 133 ELLIPSIS = 351, 134 MULTassign = 352, 135 DIVassign = 353, 136 MODassign = 354, 137 PLUSassign = 355, 138 MINUSassign = 356, 139 LSassign = 357, 140 RSassign = 358, 141 ANDassign = 359, 142 ERassign = 360, 143 ORassign = 361, 144 ATassign = 362, 145 THEN = 363 146 }; 155 147 #endif 156 148 /* Tokens. */ … … 262 254 #define THEN 363 263 255 264 /* Value type. */ 256 257 258 265 259 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 266 typedef union YYSTYPE YYSTYPE; 267 union YYSTYPE 260 typedef union YYSTYPE 268 261 { 269 #line 115 "parser.yy" /* yacc.c:1909 */ 262 263 /* Line 2068 of yacc.c */ 264 #line 115 "parser.yy" 270 265 271 266 Token tok; … … 284 279 bool flag; 285 280 286 #line 287 "Parser/parser.h" /* yacc.c:1909 */ 287 }; 281 282 283 /* Line 2068 of yacc.c */ 284 #line 285 "Parser/parser.h" 285 } YYSTYPE; 288 286 # define YYSTYPE_IS_TRIVIAL 1 287 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ 289 288 # define YYSTYPE_IS_DECLARED 1 290 289 #endif 291 290 292 293 291 extern YYSTYPE yylval; 294 292 295 int yyparse (void); 296 297 #endif /* !YY_YY_PARSER_PARSER_H_INCLUDED */ 293 -
TabularUnified src/Parser/parser.yy ¶
r1eba452 rfc4a0fa 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 26 16:45:44201613 // Update Count : 196 412 // Last Modified On : Mon Sep 12 17:29:45 2016 13 // Update Count : 1969 14 14 // 15 15 … … 1363 1363 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); } 1364 1364 | LONG 1365 { $$ = DeclarationNode::new Modifier( DeclarationNode::Long ); }1365 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); } 1366 1366 | SHORT 1367 { $$ = DeclarationNode::new Modifier( DeclarationNode::Short ); }1367 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); } 1368 1368 | SIGNED 1369 { $$ = DeclarationNode::new Modifier( DeclarationNode::Signed ); }1369 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); } 1370 1370 | UNSIGNED 1371 { $$ = DeclarationNode::new Modifier( DeclarationNode::Unsigned ); }1371 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); } 1372 1372 | VOID 1373 1373 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } … … 1375 1375 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); } 1376 1376 | COMPLEX // C99 1377 { $$ = DeclarationNode::new BasicType( DeclarationNode::Complex ); }1377 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } 1378 1378 | IMAGINARY // C99 1379 { $$ = DeclarationNode::new BasicType( DeclarationNode::Imaginary ); }1379 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); } 1380 1380 | VALIST // GCC, __builtin_va_list 1381 1381 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } … … 1849 1849 type_class: // CFA 1850 1850 OTYPE 1851 { $$ = DeclarationNode:: Type; }1851 { $$ = DeclarationNode::Otype; } 1852 1852 | DTYPE 1853 1853 { $$ = DeclarationNode::Ftype; }
Note: See TracChangeset
for help on using the changeset viewer.