Changes in src/Parser/DeclarationNode.cc [5b639ee:b6424d9]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r5b639ee rb6424d9 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 12 21:03:18201613 // Update Count : 4 9112 // Last Modified On : Sun Sep 11 09:24:11 2016 13 // Update Count : 438 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", "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" }; 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" }; 39 37 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 40 const char *DeclarationNode::typeClassName[] = { " otype", "dtype", "ftype" };38 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" }; 41 39 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" }; 42 40 … … 55 53 linkage( ::linkage ), 56 54 extension( false ) { 57 variable.tyClass = DeclarationNode:: Otype;55 variable.tyClass = DeclarationNode::Type; 58 56 variable.assertions = nullptr; 59 57 … … 190 188 DeclarationNode *newnode = new DeclarationNode; 191 189 newnode->type = new TypeData( TypeData::Basic ); 192 newnode->type->basic type = bt;190 newnode->type->basic.typeSpec.push_back( bt ); 193 191 return newnode; 194 192 } // DeclarationNode::newBasicType 195 193 196 DeclarationNode * DeclarationNode::new ComplexType( ComplexType ct) {194 DeclarationNode * DeclarationNode::newModifier( Modifier mod ) { 197 195 DeclarationNode *newnode = new DeclarationNode; 198 196 newnode->type = new TypeData( TypeData::Basic ); 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 197 newnode->type->basic.modifiers.push_back( mod ); 198 return newnode; 199 } // DeclarationNode::newModifier 216 200 217 201 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { … … 404 388 } 405 389 406 void appendError( string & dst, const string & src ) {407 if ( src.empty() ) return;408 if ( dst.empty() ) { dst = src; return; }409 dst += ", " + src;410 } // appendError411 412 390 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 413 391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 414 392 415 393 if ( (qsrc & qdst).any() ) { // common qualifier ? 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] ); 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]; 419 398 } // if 420 399 } // for … … 424 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) { 425 404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 if ( ! error.empty() ) error += ", "; // separator 426 406 if ( storageClass == q->storageClass ) { // duplicate qualifier 427 appendError( error, string( "duplicate " ) + storageName[ storageClass ] );407 error += string( "duplicate " ) + storageName[ storageClass ]; 428 408 } else { // only one storage class 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 ); 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 434 418 } // DeclarationNode::copyStorageClasses 435 419 436 420 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 437 isInline = isInline | |q->isInline;438 isNoreturn = isNoreturn | |q->isNoreturn;421 isInline = isInline | q->isInline; 422 isNoreturn = isNoreturn | q->isNoreturn; 439 423 // do not overwrite an existing value with NoStorageClass 440 424 if ( q->storageClass != NoStorageClass ) { … … 499 483 if ( src->kind != TypeData::Unknown ) { 500 484 assert( src->kind == TypeData::Basic ); 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 ); 485 dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers ); 486 dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec ); 523 487 } // if 524 488 break; … … 911 875 while ( cur ) { 912 876 try { 877 /// if ( DeclarationNode *extr = cur->extractAggregate() ) { 878 /// // handle the case where a structure declaration is contained within an object or type 879 /// // declaration 880 /// Declaration *decl = extr->build(); 881 /// if ( decl ) { 882 /// *out++ = decl; 883 /// } 884 /// } 913 885 Declaration *decl = cur->build(); 914 886 if ( decl ) {
Note:
See TracChangeset
for help on using the changeset viewer.