Changeset 90152a4 for src/Parser/TypeData.cc
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 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:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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/TypeData.cc
rf9feab8 r90152a4 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 25 18:33:41 201713 // Update Count : 58712 // Last Modified On : Fri Jul 20 14:39:31 2018 13 // Update Count : 622 14 14 // 15 15 … … 31 31 using namespace std; 32 32 33 TypeData::TypeData( Kind k ) : kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ {33 TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ { 34 34 switch ( kind ) { 35 35 case Unknown: … … 37 37 case Reference: 38 38 case EnumConstant: 39 case GlobalScope: 39 40 // nothing else to initialize 40 41 break; … … 54 55 function.oldDeclList = nullptr; 55 56 function.body = nullptr; 56 function. newStyle = false;57 function.withExprs = nullptr; 57 58 break; 58 59 // Enum is an Aggregate, so both structures are initialized together. … … 62 63 enumeration.constants = nullptr; 63 64 enumeration.body = false; 65 enumeration.anon = false; 66 break; 64 67 case Aggregate: 65 68 // aggregate = new Aggregate_t; 69 aggregate.kind = DeclarationNode::NoAggregate; 66 70 aggregate.name = nullptr; 67 71 aggregate.params = nullptr; … … 69 73 aggregate.fields = nullptr; 70 74 aggregate.body = false; 75 aggregate.tagged = false; 76 aggregate.parent = nullptr; 77 aggregate.anon = false; 71 78 break; 72 79 case AggregateInst: … … 74 81 aggInst.aggregate = nullptr; 75 82 aggInst.params = nullptr; 76 aggInst.hoistType = false; ;83 aggInst.hoistType = false; 77 84 break; 78 85 case Symbolic: … … 94 101 case Builtin: 95 102 // builtin = new Builtin_t; 103 case Qualified: 104 qualified.parent = nullptr; 105 qualified.child = nullptr; 96 106 break; 97 107 } // switch … … 108 118 case Reference: 109 119 case EnumConstant: 120 case GlobalScope: 110 121 // nothing to destroy 111 122 break; … … 122 133 delete function.oldDeclList; 123 134 delete function.body; 135 delete function.withExprs; 124 136 // delete function; 125 137 break; … … 160 172 // delete builtin; 161 173 break; 174 case Qualified: 175 delete qualified.parent; 176 delete qualified.child; 162 177 } // switch 163 178 } // TypeData::~TypeData … … 175 190 case Pointer: 176 191 case Reference: 192 case GlobalScope: 177 193 // nothing else to copy 178 194 break; … … 193 209 newtype->function.oldDeclList = maybeClone( function.oldDeclList ); 194 210 newtype->function.body = maybeClone( function.body ); 195 newtype->function. newStyle = function.newStyle;211 newtype->function.withExprs = maybeClone( function.withExprs ); 196 212 break; 197 213 case Aggregate: 214 newtype->aggregate.kind = aggregate.kind; 198 215 newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr; 199 216 newtype->aggregate.params = maybeClone( aggregate.params ); 200 217 newtype->aggregate.actuals = maybeClone( aggregate.actuals ); 201 218 newtype->aggregate.fields = maybeClone( aggregate.fields ); 202 newtype->aggregate.kind = aggregate.kind;203 219 newtype->aggregate.body = aggregate.body; 220 newtype->aggregate.anon = aggregate.anon; 204 221 newtype->aggregate.tagged = aggregate.tagged; 205 222 newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr; … … 214 231 newtype->enumeration.constants = maybeClone( enumeration.constants ); 215 232 newtype->enumeration.body = enumeration.body; 233 newtype->enumeration.anon = enumeration.anon; 216 234 break; 217 235 case Symbolic: … … 233 251 newtype->builtintype = builtintype; 234 252 break; 253 case Qualified: 254 newtype->qualified.parent = maybeClone( qualified.parent ); 255 newtype->qualified.child = maybeClone( qualified.child ); 256 break; 235 257 } // switch 236 258 return newtype; … … 249 271 250 272 switch ( kind ) { 251 case Unknown: 252 os << "entity of unknown type "; 273 case Basic: 274 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " "; 275 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " "; 276 if ( complextype == DeclarationNode::NoComplexType ) { // basic type 277 assert( basictype != DeclarationNode::NoBasicType ); 278 os << DeclarationNode::basicTypeNames[ basictype ] << " "; 279 } else { // complex type 280 // handle double _Complex 281 if ( basictype != DeclarationNode::NoBasicType ) os << DeclarationNode::basicTypeNames[ basictype ] << " "; 282 os << DeclarationNode::complexTypeNames[ complextype ] << " "; 283 } // if 253 284 break; 254 285 case Pointer: … … 259 290 } // if 260 291 break; 261 case EnumConstant: 262 os << "enumeration constant "; 263 break; 264 case Basic: 265 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " "; 266 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " "; 267 assert( basictype != DeclarationNode::NoBasicType ); 268 os << DeclarationNode::basicTypeNames[ basictype ] << " "; 269 if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeNames[ complextype ] << " "; 292 case Reference: 293 os << "reference "; 294 if ( base ) { 295 os << "to "; 296 base->print( os, indent ); 297 } // if 270 298 break; 271 299 case Array: … … 353 381 } // if 354 382 break; 355 case SymbolicInst: 356 os << "instance of type " << *symbolic.name; 357 if ( symbolic.actuals ) { 358 os << " with parameters" << endl; 359 symbolic.actuals->printList( os, indent + 2 ); 360 } // if 383 case EnumConstant: 384 os << "enumeration constant "; 361 385 break; 362 386 case Symbolic: … … 380 404 } // if 381 405 break; 406 case SymbolicInst: 407 os << *symbolic.name; 408 if ( symbolic.actuals ) { 409 os << "("; 410 symbolic.actuals->printList( os, indent + 2 ); 411 os << ")"; 412 } // if 413 break; 382 414 case Tuple: 383 415 os << "tuple "; … … 394 426 break; 395 427 case Builtin: 396 os << "gcc builtin type"; 428 os << DeclarationNode::builtinTypeNames[builtintype]; 429 break; 430 case GlobalScope: 431 break; 432 case Qualified: 433 qualified.parent->print( os ); 434 os << "."; 435 qualified.child->print( os ); 436 break; 437 case Unknown: 438 os << "entity of unknown type "; 397 439 break; 398 440 default: … … 401 443 } // switch 402 444 } // TypeData::print 445 446 const std::string * TypeData::leafName() const { 447 switch ( kind ) { 448 case Unknown: 449 case Pointer: 450 case Reference: 451 case EnumConstant: 452 case GlobalScope: 453 case Array: 454 case Basic: 455 case Function: 456 case AggregateInst: 457 case Tuple: 458 case Typeof: 459 case Builtin: 460 assertf(false, "Tried to get leaf name from kind without a name: %d", kind); 461 break; 462 case Aggregate: 463 return aggregate.name; 464 case Enum: 465 return enumeration.name; 466 case Symbolic: 467 case SymbolicInst: 468 return symbolic.name; 469 case Qualified: 470 return qualified.child->leafName(); 471 } // switch 472 assert(false); 473 } 403 474 404 475 … … 460 531 return new EnumInstType( buildQualifiers( td ), "" ); 461 532 case TypeData::SymbolicInst: 462 return buildSymbolicInst( td ); ;533 return buildSymbolicInst( td ); 463 534 case TypeData::Tuple: 464 535 return buildTuple( td ); … … 475 546 return new VarArgsType( buildQualifiers( td ) ); 476 547 } 548 case TypeData::GlobalScope: 549 return new GlobalScopeType(); 550 case TypeData::Qualified: 551 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) ); 477 552 case TypeData::Symbolic: 478 553 case TypeData::Enum: … … 480 555 assert( false ); 481 556 } // switch 557 482 558 return nullptr; 483 559 } // typebuild … … 489 565 switch ( td->kind ) { 490 566 case TypeData::Aggregate: 491 if ( ! toplevel && td->aggregate. fields) {567 if ( ! toplevel && td->aggregate.body ) { 492 568 ret = td->clone(); 493 569 } // if 494 570 break; 495 571 case TypeData::Enum: 496 if ( ! toplevel && td->enumeration. constants) {572 if ( ! toplevel && td->enumeration.body ) { 497 573 ret = td->clone(); 498 574 } // if … … 518 594 519 595 static string genTSError( string msg, DeclarationNode::BasicType basictype ) { 520 throw SemanticError(string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );596 SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." ); 521 597 } // genTSError 522 598 … … 573 649 574 650 case DeclarationNode::Int128: 575 ret = td->signedness == 1? BasicType::UnsignedInt128 : BasicType::SignedInt128;651 ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128; 576 652 if ( td->length != DeclarationNode::NoLength ) { 577 653 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype ); … … 597 673 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype ); 598 674 } // if 599 if ( td->basictype == DeclarationNode::Float&& td->length == DeclarationNode::Long ) {675 if ( td->basictype != DeclarationNode::Double && td->length == DeclarationNode::Long ) { 600 676 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype ); 601 677 } // if … … 603 679 const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble; 604 680 } // if 681 682 if ( td->basictype == DeclarationNode::Float80 || td->basictype == DeclarationNode::Float128 ) { 683 // if ( td->complextype != DeclarationNode::NoComplexType ) { 684 // genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype ); 685 // } 686 if ( td->basictype == DeclarationNode::Float80 ) ret = BasicType::Float80; 687 else ret = BasicType::Float128; 688 break; 689 } 605 690 606 691 ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ]; … … 797 882 assert( td->base ); 798 883 if ( td->symbolic.isTypedef ) { 799 ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage );884 ret = new TypedefDecl( name, td->location, scs, typebuild( td->base ), linkage ); 800 885 } else { 801 886 ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Dtype, true ); … … 861 946 CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt ); 862 947 decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec ); 948 buildList( td->function.withExprs, decl->withExprs ); 863 949 return decl->set_asmName( asmName ); 864 950 } else if ( td->kind == TypeData::Aggregate ) { … … 877 963 FunctionType * buildFunction( const TypeData * td ) { 878 964 assert( td->kind == TypeData::Function ); 879 bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true; 880 if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle; 881 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 882 buildList( td->function.params, ft->get_parameters() ); 883 buildForall( td->forall, ft->get_forall() ); 965 FunctionType * ft = new FunctionType( buildQualifiers( td ), ! td->function.params || td->function.params->hasEllipsis ); 966 buildList( td->function.params, ft->parameters ); 967 buildForall( td->forall, ft->forall ); 884 968 if ( td->base ) { 885 969 switch ( td->base->kind ) { 886 970 case TypeData::Tuple: 887 buildList( td->base->tuple, ft-> get_returnVals());971 buildList( td->base->tuple, ft->returnVals ); 888 972 break; 889 973 default: … … 919 1003 // type set => parameter name already transformed by a declaration names so there is a duplicate 920 1004 // declaration name attempting a second transformation 921 if ( param->type ) throw SemanticError(string( "duplicate declaration name " ) + *param->name );1005 if ( param->type ) SemanticError( param->location, string( "duplicate declaration name " ) + *param->name ); 922 1006 // declaration type reset => declaration already transformed by a parameter name so there is a duplicate 923 1007 // parameter name attempting a second transformation 924 if ( ! decl->type ) throw SemanticError(string( "duplicate parameter name " ) + *param->name );1008 if ( ! decl->type ) SemanticError( param->location, string( "duplicate parameter name " ) + *param->name ); 925 1009 param->type = decl->type; // set copy declaration type to parameter type 926 1010 decl->type = nullptr; // reset declaration type … … 929 1013 } // for 930 1014 // declaration type still set => type not moved to a matching parameter so there is a missing parameter name 931 if ( decl->type ) throw SemanticError(string( "missing name in parameter list " ) + *decl->name );1015 if ( decl->type ) SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name ); 932 1016 } // for 933 1017
Note:
See TracChangeset
for help on using the changeset viewer.