Changeset ba7aa2d
 Timestamp:
 Sep 16, 2016, 11:30:05 AM (8 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 1b77274
 Parents:
 101e0bd
 Location:
 src/Parser
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/Parser/DeclarationNode.cc
r101e0bd rba7aa2d 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Sep 14 23:13:28201613 // Update Count : 5 0212 // Last Modified On : Thu Sep 15 23:36:02 2016 13 // Update Count : 515 14 14 // 15 15 … … 31 31 32 32 // These must remain in the same order as the corresponding DeclarationNode enumerations. 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", "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" };39 const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" };40 const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };41 const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };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", "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" }; 39 const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 40 const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" }; 41 const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" }; 42 42 43 43 UniqueName DeclarationNode::anonymous( "__anonymous" ); … … 70 70 } 71 71 72 DeclarationNode * DeclarationNode::clone() const {73 DeclarationNode * newnode = new DeclarationNode;72 DeclarationNode * DeclarationNode::clone() const { 73 DeclarationNode * newnode = new DeclarationNode; 74 74 newnode>type = maybeClone( type ); 75 75 newnode>name = name; … … 139 139 } 140 140 141 DeclarationNode * DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) {142 DeclarationNode * newnode = new DeclarationNode;141 DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) { 142 DeclarationNode * newnode = new DeclarationNode; 143 143 newnode>name = assign_strptr( name ); 144 144 … … 163 163 164 164 DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) { 165 DeclarationNode * newnode = new DeclarationNode;165 DeclarationNode * newnode = new DeclarationNode; 166 166 newnode>type = new TypeData(); 167 167 newnode>type>qualifiers[ q ] = 1; … … 169 169 } // DeclarationNode::newQualifier 170 170 171 DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {172 DeclarationNode * newnode = new DeclarationNode;171 DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) { 172 DeclarationNode * newnode = new DeclarationNode; 173 173 newnode>type = new TypeData( TypeData::Unknown ); 174 174 newnode>type>forall = forall; … … 177 177 178 178 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 179 DeclarationNode *newnode = new DeclarationNode; 180 //switch (sc) { 181 // case Inline: newnode>isInline = true; break; 182 // case Noreturn: newnode>isNoreturn = true; break; 183 // default: newnode>storageClass = sc; break; 184 //} 179 DeclarationNode * newnode = new DeclarationNode; 185 180 newnode>storageClass = sc; 186 181 return newnode; … … 188 183 189 184 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) { 190 DeclarationNode * newnode = new DeclarationNode;185 DeclarationNode * newnode = new DeclarationNode; 191 186 newnode>type = new TypeData( TypeData::Basic ); 192 187 newnode>type>basictype = bt; … … 195 190 196 191 DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) { 197 DeclarationNode * newnode = new DeclarationNode;192 DeclarationNode * newnode = new DeclarationNode; 198 193 newnode>type = new TypeData( TypeData::Basic ); 199 194 newnode>type>complextype = ct; … … 202 197 203 198 DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) { 204 DeclarationNode * newnode = new DeclarationNode;199 DeclarationNode * newnode = new DeclarationNode; 205 200 newnode>type = new TypeData( TypeData::Basic ); 206 201 newnode>type>signedness = sn; … … 209 204 210 205 DeclarationNode * DeclarationNode::newLength( Length lnth ) { 211 DeclarationNode * newnode = new DeclarationNode;206 DeclarationNode * newnode = new DeclarationNode; 212 207 newnode>type = new TypeData( TypeData::Basic ); 213 208 newnode>type>length = lnth; … … 215 210 } // DeclarationNode::newLength 216 211 217 DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) {218 DeclarationNode * newnode = new DeclarationNode;212 DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) { 213 DeclarationNode * newnode = new DeclarationNode; 219 214 newnode>type = new TypeData( TypeData::SymbolicInst ); 220 215 newnode>type>symbolic.name = assign_strptr( name ); … … 224 219 } // DeclarationNode::newFromTypedef 225 220 226 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {227 DeclarationNode * newnode = new DeclarationNode;221 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 222 DeclarationNode * newnode = new DeclarationNode; 228 223 newnode>type = new TypeData( TypeData::Aggregate ); 229 224 newnode>type>aggregate.kind = kind; … … 238 233 } // DeclarationNode::newAggregate 239 234 240 DeclarationNode * DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {241 DeclarationNode * newnode = new DeclarationNode;235 DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) { 236 DeclarationNode * newnode = new DeclarationNode; 242 237 newnode>name = assign_strptr( name ); 243 238 newnode>type = new TypeData( TypeData::Enum ); … … 250 245 } // DeclarationNode::newEnum 251 246 252 DeclarationNode * DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {253 DeclarationNode * newnode = new DeclarationNode;247 DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) { 248 DeclarationNode * newnode = new DeclarationNode; 254 249 newnode>name = assign_strptr( name ); 255 250 newnode>enumeratorValue.reset( constant ); … … 258 253 } // DeclarationNode::newEnumConstant 259 254 260 DeclarationNode * DeclarationNode::newName( std::string *name ) {261 DeclarationNode * newnode = new DeclarationNode;255 DeclarationNode * DeclarationNode::newName( std::string * name ) { 256 DeclarationNode * newnode = new DeclarationNode; 262 257 newnode>name = assign_strptr( name ); 263 258 return newnode; 264 259 } // DeclarationNode::newName 265 260 266 DeclarationNode * DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {267 DeclarationNode * newnode = new DeclarationNode;261 DeclarationNode * DeclarationNode::newFromTypeGen( std::string * name, ExpressionNode * params ) { 262 DeclarationNode * newnode = new DeclarationNode; 268 263 newnode>type = new TypeData( TypeData::SymbolicInst ); 269 264 newnode>type>symbolic.name = assign_strptr( name ); … … 273 268 } // DeclarationNode::newFromTypeGen 274 269 275 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {276 DeclarationNode * newnode = new DeclarationNode;270 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) { 271 DeclarationNode * newnode = new DeclarationNode; 277 272 newnode>name = assign_strptr( name ); 278 273 newnode>type = new TypeData( TypeData::Variable ); 274 // newnode>type = nullptr; 279 275 newnode>variable.tyClass = tc; 280 276 newnode>variable.name = newnode>name; … … 282 278 } // DeclarationNode::newTypeParam 283 279 284 DeclarationNode * DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {285 DeclarationNode * newnode = new DeclarationNode;280 DeclarationNode * DeclarationNode::newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts ) { 281 DeclarationNode * newnode = new DeclarationNode; 286 282 newnode>type = new TypeData( TypeData::Aggregate ); 287 283 newnode>type>aggregate.kind = Trait; … … 292 288 } // DeclarationNode::newTrait 293 289 294 DeclarationNode * DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {295 DeclarationNode * newnode = new DeclarationNode;290 DeclarationNode * DeclarationNode::newTraitUse( std::string * name, ExpressionNode * params ) { 291 DeclarationNode * newnode = new DeclarationNode; 296 292 newnode>type = new TypeData( TypeData::AggregateInst ); 297 293 newnode>type>aggInst.aggregate = new TypeData( TypeData::Aggregate ); … … 302 298 } // DeclarationNode::newTraitUse 303 299 304 DeclarationNode * DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {305 DeclarationNode * newnode = new DeclarationNode;300 DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) { 301 DeclarationNode * newnode = new DeclarationNode; 306 302 newnode>name = assign_strptr( name ); 307 303 newnode>type = new TypeData( TypeData::Symbolic ); … … 312 308 } // DeclarationNode::newTypeDecl 313 309 314 DeclarationNode * DeclarationNode::newPointer( DeclarationNode *qualifiers ) {315 DeclarationNode * newnode = new DeclarationNode;310 DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) { 311 DeclarationNode * newnode = new DeclarationNode; 316 312 newnode>type = new TypeData( TypeData::Pointer ); 317 313 return newnode>addQualifiers( qualifiers ); 318 314 } // DeclarationNode::newPointer 319 315 320 DeclarationNode * DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {321 DeclarationNode * newnode = new DeclarationNode;316 DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) { 317 DeclarationNode * newnode = new DeclarationNode; 322 318 newnode>type = new TypeData( TypeData::Array ); 323 319 newnode>type>array.dimension = size; 324 320 newnode>type>array.isStatic = isStatic; 325 if ( newnode>type>array.dimension == 0  newnode>type>array.dimension>isExpressionType<ConstantExpr * >() ) {321 if ( newnode>type>array.dimension == 0  newnode>type>array.dimension>isExpressionType<ConstantExpr * >() ) { 326 322 newnode>type>array.isVarLen = false; 327 323 } else { … … 331 327 } // DeclarationNode::newArray 332 328 333 DeclarationNode * DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {334 DeclarationNode * newnode = new DeclarationNode;329 DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) { 330 DeclarationNode * newnode = new DeclarationNode; 335 331 newnode>type = new TypeData( TypeData::Array ); 336 332 newnode>type>array.dimension = 0; … … 340 336 } 341 337 342 DeclarationNode * DeclarationNode::newBitfield( ExpressionNode *size ) {343 DeclarationNode * newnode = new DeclarationNode;338 DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) { 339 DeclarationNode * newnode = new DeclarationNode; 344 340 newnode>bitfieldWidth = size; 345 341 return newnode; 346 342 } 347 343 348 DeclarationNode * DeclarationNode::newTuple( DeclarationNode *members ) {349 DeclarationNode * newnode = new DeclarationNode;344 DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) { 345 DeclarationNode * newnode = new DeclarationNode; 350 346 newnode>type = new TypeData( TypeData::Tuple ); 351 347 newnode>type>tuple = members; … … 353 349 } 354 350 355 DeclarationNode * DeclarationNode::newTypeof( ExpressionNode *expr ) {356 DeclarationNode * newnode = new DeclarationNode;351 DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr ) { 352 DeclarationNode * newnode = new DeclarationNode; 357 353 newnode>type = new TypeData( TypeData::Typeof ); 358 354 newnode>type>typeexpr = expr; … … 361 357 362 358 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 363 DeclarationNode * newnode = new DeclarationNode;359 DeclarationNode * newnode = new DeclarationNode; 364 360 newnode>type = new TypeData( TypeData::Builtin ); 365 361 newnode>builtin = bt; … … 367 363 } // DeclarationNode::newBuiltinType 368 364 369 DeclarationNode * DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {370 DeclarationNode * newnode = new DeclarationNode;365 DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) { 366 DeclarationNode * newnode = new DeclarationNode; 371 367 newnode>type = new TypeData( TypeData::Attr ); 368 // newnode>type = nullptr; 372 369 newnode>attr.name = assign_strptr( name ); 373 370 newnode>attr.expr = expr; … … 375 372 } 376 373 377 DeclarationNode * DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) {378 DeclarationNode * newnode = new DeclarationNode;374 DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) { 375 DeclarationNode * newnode = new DeclarationNode; 379 376 newnode>type = new TypeData( TypeData::Attr ); 377 // newnode>type = nullptr; 380 378 newnode>attr.name = assign_strptr( name ); 381 379 newnode>attr.type = type; … … 389 387 } // appendError 390 388 391 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData *dst ) {389 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 392 390 TypeData::Qualifiers qsrc = src>qualifiers, qdst = dst>qualifiers; // optimization 393 391 … … 401 399 } // DeclarationNode::checkQualifiers 402 400 403 void DeclarationNode::checkStorageClasses( DeclarationNode * q ) {401 void DeclarationNode::checkStorageClasses( DeclarationNode * q ) { 404 402 if ( storageClass != NoStorageClass && q>storageClass != NoStorageClass ) { 405 403 if ( storageClass == q>storageClass ) { // duplicate qualifier … … 413 411 } // DeclarationNode::copyStorageClasses 414 412 415 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode *q ) {413 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) { 416 414 isInline = isInline  q>isInline; 417 415 isNoreturn = isNoreturn  q>isNoreturn; … … 424 422 } // DeclarationNode::copyStorageClasses 425 423 426 static void addQualifiersToType( TypeData *&src, TypeData * dst ) {424 static void addQualifiersToType( TypeData *&src, TypeData * dst ) { 427 425 if ( src>forall && dst>kind == TypeData::Function ) { 428 426 if ( dst>forall ) { … … 443 441 } // addQualifiersToType 444 442 445 DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode *q ) {443 DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) { 446 444 if ( ! q ) return this; 447 445 … … 550 548 } 551 549 552 DeclarationNode * DeclarationNode::addType( DeclarationNode *o ) {550 DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) { 553 551 if ( o ) { 554 552 checkStorageClasses( o ); … … 584 582 } 585 583 586 DeclarationNode * DeclarationNode::addTypedef() {587 TypeData * newtype = new TypeData( TypeData::Symbolic );584 DeclarationNode * DeclarationNode::addTypedef() { 585 TypeData * newtype = new TypeData( TypeData::Symbolic ); 588 586 newtype>symbolic.params = 0; 589 587 newtype>symbolic.isTypedef = true; … … 594 592 } 595 593 596 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode *assertions ) {594 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 597 595 assert( type ); 598 596 switch ( type>kind ) { … … 618 616 } 619 617 620 DeclarationNode * DeclarationNode::addName( std::string *newname ) {618 DeclarationNode * DeclarationNode::addName( std::string * newname ) { 621 619 name = assign_strptr( newname ); 622 620 return this; 623 621 } 624 622 625 DeclarationNode * DeclarationNode::addBitfield( ExpressionNode *size ) {623 DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) { 626 624 bitfieldWidth = size; 627 625 return this; 628 626 } 629 627 630 DeclarationNode * DeclarationNode::addVarArgs() {628 DeclarationNode * DeclarationNode::addVarArgs() { 631 629 assert( type ); 632 630 hasEllipsis = true; … … 634 632 } 635 633 636 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode *body ) {634 DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) { 637 635 assert( type ); 638 636 assert( type>kind == TypeData::Function ); … … 643 641 } 644 642 645 DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode *list ) {643 DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) { 646 644 assert( type ); 647 645 assert( type>kind == TypeData::Function ); … … 651 649 } 652 650 653 static void setBase( TypeData *&type, TypeData * newType ) {651 static void setBase( TypeData *&type, TypeData * newType ) { 654 652 if ( type ) { 655 TypeData * prevBase = type;656 TypeData * curBase = type>base;653 TypeData * prevBase = type; 654 TypeData * curBase = type>base; 657 655 while ( curBase != 0 ) { 658 656 prevBase = curBase; … … 665 663 } 666 664 667 DeclarationNode * DeclarationNode::addPointer( DeclarationNode *p ) {665 DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) { 668 666 if ( p ) { 669 667 assert( p>type>kind == TypeData::Pointer ); … … 675 673 } 676 674 677 DeclarationNode * DeclarationNode::addArray( DeclarationNode *a ) {675 DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) { 678 676 if ( a ) { 679 677 assert( a>type>kind == TypeData::Array ); … … 685 683 } 686 684 687 DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode *p ) {685 DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) { 688 686 if ( p ) { 689 687 assert( p>type>kind == TypeData::Pointer ); … … 712 710 } 713 711 714 static TypeData * findLast( TypeData *a ) {712 static TypeData * findLast( TypeData * a ) { 715 713 assert( a ); 716 TypeData * cur = a;714 TypeData * cur = a; 717 715 while ( cur>base ) { 718 716 cur = cur>base; … … 721 719 } 722 720 723 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode *a ) {721 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) { 724 722 if ( a ) { 725 723 assert( a>type>kind == TypeData::Array ); 726 TypeData * lastArray = findLast( a>type );724 TypeData * lastArray = findLast( a>type ); 727 725 if ( type ) { 728 726 switch ( type>kind ) { … … 748 746 } 749 747 750 DeclarationNode * DeclarationNode::addParamList( DeclarationNode *params ) {751 TypeData * ftype = new TypeData( TypeData::Function );748 DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) { 749 TypeData * ftype = new TypeData( TypeData::Function ); 752 750 ftype>function.params = params; 753 751 setBase( type, ftype ); … … 755 753 } 756 754 757 static TypeData * addIdListToType( TypeData *type, DeclarationNode *ids ) {755 static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) { 758 756 if ( type ) { 759 757 if ( type>kind != TypeData::Function ) { … … 764 762 return type; 765 763 } else { 766 TypeData * newtype = new TypeData( TypeData::Function );764 TypeData * newtype = new TypeData( TypeData::Function ); 767 765 newtype>function.idList = ids; 768 766 return newtype; … … 770 768 } 771 769 772 DeclarationNode * DeclarationNode::addIdList( DeclarationNode *ids ) {770 DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) { 773 771 type = addIdListToType( type, ids ); 774 772 return this; 775 773 } 776 774 777 DeclarationNode * DeclarationNode::addInitializer( InitializerNode *init ) {775 DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) { 778 776 //assert 779 777 initializer = init; … … 781 779 } 782 780 783 DeclarationNode * DeclarationNode::cloneBaseType( string *newName ) {784 DeclarationNode * newnode = new DeclarationNode;785 TypeData * srcType = type;781 DeclarationNode * DeclarationNode::cloneBaseType( string * newName ) { 782 DeclarationNode * newnode = new DeclarationNode; 783 TypeData * srcType = type; 786 784 while ( srcType>base ) { 787 785 srcType = srcType>base; … … 806 804 } 807 805 808 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode *o ) {806 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) { 809 807 if ( o ) { 810 808 o>copyStorageClasses( this ); 811 809 if ( type ) { 812 TypeData * srcType = type;810 TypeData * srcType = type; 813 811 while ( srcType>base ) { 814 812 srcType = srcType>base; 815 813 } // while 816 TypeData * newType = srcType>clone();814 TypeData * newType = srcType>clone(); 817 815 if ( newType>kind == TypeData::AggregateInst ) { 818 816 // don't duplicate members … … 838 836 } 839 837 840 DeclarationNode * DeclarationNode::cloneType( string *newName ) {841 DeclarationNode * newnode = new DeclarationNode;838 DeclarationNode * DeclarationNode::cloneType( string * newName ) { 839 DeclarationNode * newnode = new DeclarationNode; 842 840 newnode>type = maybeClone( type ); 843 841 assert( storageClass == NoStorageClass ); 844 842 newnode>copyStorageClasses( this ); 843 assert( newName ); 845 844 newnode>name = assign_strptr( newName ); 846 845 return newnode; 847 846 } 848 847 849 DeclarationNode * DeclarationNode::cloneType( DeclarationNode *o ) {848 DeclarationNode * DeclarationNode::cloneType( DeclarationNode * o ) { 850 849 if ( o ) { 851 850 assert( storageClass == NoStorageClass ); 852 851 o>copyStorageClasses( this ); 853 852 if ( type ) { 854 TypeData * newType = type>clone();853 TypeData * newType = type>clone(); 855 854 if ( ! o>type ) { 856 855 o>type = newType; … … 865 864 } 866 865 867 DeclarationNode * DeclarationNode::extractAggregate() const {866 DeclarationNode * DeclarationNode::extractAggregate() const { 868 867 if ( type ) { 869 TypeData * ret = typeextractAggregate( type );868 TypeData * ret = typeextractAggregate( type ); 870 869 if ( ret ) { 871 DeclarationNode * newnode = new DeclarationNode;870 DeclarationNode * newnode = new DeclarationNode; 872 871 newnode>type = ret; 873 872 return newnode; … … 877 876 } 878 877 879 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {878 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) { 880 879 SemanticError errors; 881 880 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 882 const DeclarationNode * cur = firstNode;881 const DeclarationNode * cur = firstNode; 883 882 while ( cur ) { 884 883 try { 885 if ( DeclarationNode * extr = cur>extractAggregate() ) {884 if ( DeclarationNode * extr = cur>extractAggregate() ) { 886 885 // handle the case where a structure declaration is contained within an object or type declaration 887 Declaration * decl = extr>build();886 Declaration * decl = extr>build(); 888 887 if ( decl ) { 889 * out++ = decl;888 * out++ = decl; 890 889 } // if 891 890 delete extr; 892 891 } // if 893 Declaration * decl = cur>build();892 Declaration * decl = cur>build(); 894 893 if ( decl ) { 895 * out++ = decl;894 * out++ = decl; 896 895 } // if 897 896 } catch( SemanticError &e ) { … … 905 904 } 906 905 907 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {906 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) { 908 907 SemanticError errors; 909 908 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 910 const DeclarationNode * cur = firstNode;909 const DeclarationNode * cur = firstNode; 911 910 while ( cur ) { 912 911 try { 913 Declaration * decl = cur>build();912 Declaration * decl = cur>build(); 914 913 if ( decl ) { 915 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {916 * out++ = dwt;917 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {918 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg>get_name() );919 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );914 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 915 * out++ = dwt; 916 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 917 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg>get_name() ); 918 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 920 919 delete agg; 921 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {922 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg>get_name() );923 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );920 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 921 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg>get_name() ); 922 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 924 923 } // if 925 924 } // if … … 934 933 } 935 934 936 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {935 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) { 937 936 SemanticError errors; 938 937 std::back_insert_iterator< std::list< Type * > > out( outputList ); 939 const DeclarationNode * cur = firstNode;938 const DeclarationNode * cur = firstNode; 940 939 while ( cur ) { 941 940 try { 942 * out++ = cur>buildType();941 * out++ = cur>buildType(); 943 942 } catch( SemanticError &e ) { 944 943 errors.append( e ); … … 951 950 } 952 951 953 Declaration * DeclarationNode::build() const {952 Declaration * DeclarationNode::build() const { 954 953 if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this ); 955 954 if ( type ) { … … 969 968 } 970 969 971 Type * DeclarationNode::buildType() const {970 Type * DeclarationNode::buildType() const { 972 971 assert( type ); 973 972 … … 976 975 return new EnumInstType( buildQualifiers( type ), type>enumeration.name ); 977 976 case TypeData::Aggregate: { 978 ReferenceToType * ret;977 ReferenceToType * ret; 979 978 switch ( type>aggregate.kind ) { 980 979 case DeclarationNode::Struct: … … 994 993 } 995 994 case TypeData::Symbolic: { 996 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), type>symbolic.name, false );995 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), type>symbolic.name, false ); 997 996 buildList( type>symbolic.actuals, ret>get_parameters() ); 998 997 return ret; 
src/Parser/TypeData.cc
r101e0bd rba7aa2d 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 12 21:11:22201613 // Update Count : 3 7712 // Last Modified On : Thu Sep 15 23:05:01 2016 13 // Update Count : 384 14 14 // 15 15 … … 487 487 return new VarArgsType( buildQualifiers( td ) ); 488 488 case TypeData::Attr: 489 assert( false );490 return buildAttr( td );491 489 case TypeData::Symbolic: 492 490 case TypeData::Enum:
Note: See TracChangeset
for help on using the changeset viewer.