Changeset 5b639ee for src/Parser/DeclarationNode.cc
- Timestamp:
- Sep 12, 2016, 9:52:12 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 101e0bd
- Parents:
- b6424d9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rb6424d9 r5b639ee 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 : 4 3812 // Last Modified On : Mon Sep 12 21:03:18 2016 13 // Update Count : 491 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 ) { … … 388 404 } 389 405 406 void appendError( string & dst, const string & src ) { 407 if ( src.empty() ) return; 408 if ( dst.empty() ) { dst = src; return; } 409 dst += ", " + src; 410 } // appendError 411 390 412 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 391 413 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 392 414 393 415 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]; 416 for ( int i = 0; i < NoQualifier; i += 1 ) { // find common qualifiers 417 if ( qsrc[i] && qdst[i] ) { 418 appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] ); 398 419 } // if 399 420 } // for … … 403 424 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) { 404 425 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 if ( ! error.empty() ) error += ", "; // separator406 426 if ( storageClass == q->storageClass ) { // duplicate qualifier 407 error += string( "duplicate " ) + storageName[ storageClass ];427 appendError( error, string( "duplicate " ) + storageName[ storageClass ] ); 408 428 } 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 429 appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] ); 430 q->storageClass = storageClass; // FIX ERROR, prevent assertions from triggering 431 } // if 432 } // if 433 appendError( error, q->error ); 418 434 } // DeclarationNode::copyStorageClasses 419 435 420 436 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 421 isInline = isInline | q->isInline;422 isNoreturn = isNoreturn | q->isNoreturn;437 isInline = isInline || q->isInline; 438 isNoreturn = isNoreturn || q->isNoreturn; 423 439 // do not overwrite an existing value with NoStorageClass 424 440 if ( q->storageClass != NoStorageClass ) { … … 483 499 if ( src->kind != TypeData::Unknown ) { 484 500 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 ); 501 502 if ( dst->basictype == DeclarationNode::NoBasicType ) { 503 dst->basictype = src->basictype; 504 } else if ( src->basictype != DeclarationNode::NoBasicType ) 505 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src ); 506 507 if ( dst->complextype == DeclarationNode::NoComplexType ) { 508 dst->complextype = src->complextype; 509 } else if ( src->complextype != DeclarationNode::NoComplexType ) 510 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src ); 511 512 if ( dst->signedness == DeclarationNode::NoSignedness ) { 513 dst->signedness = src->signedness; 514 } else if ( src->signedness != DeclarationNode::NoSignedness ) 515 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src ); 516 517 if ( dst->length == DeclarationNode::NoLength ) { 518 dst->length = src->length; 519 } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) { 520 dst->length = DeclarationNode::LongLong; 521 } else if ( src->length != DeclarationNode::NoLength ) 522 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src ); 487 523 } // if 488 524 break; … … 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.