Changes in src/Parser/DeclarationNode.cc [b6424d9:28307be]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rb6424d9 r28307be 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 : Mon Aug 29 22:30:56 2016 13 // Update Count : 327 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" };33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" }; 34 34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 35 35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", }; … … 43 43 extern LinkageSpec::Spec linkage; // defined in parser.yy 44 44 45 DeclarationNode::DeclarationNode() : 46 type( 0 ), 47 storageClass( NoStorageClass ), 48 isInline( false ), 49 isNoreturn( false ), 50 bitfieldWidth( 0 ), 51 initializer( 0 ), 52 hasEllipsis( false ), 53 linkage( ::linkage ), 54 extension( false ) { 45 DeclarationNode::DeclarationNode() 46 : type( 0 ) 47 , storageClass( NoStorageClass ) 48 , isInline( false ) 49 , isNoreturn( false ) 50 , bitfieldWidth( 0 ) 51 , initializer( 0 ) 52 , hasEllipsis( false ) 53 , linkage( ::linkage ) 54 , extension( false ) 55 , error() { 56 attr.expr = nullptr; 57 attr.type = nullptr; 58 55 59 variable.tyClass = DeclarationNode::Type; 56 60 variable.assertions = nullptr; 57 58 attr.expr = nullptr;59 attr.type = nullptr;60 61 } 61 62 … … 389 390 390 391 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 392 393 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]; 392 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; 393 394 if ( (qsrc & qdst).any() ) { // common bits between qualifier masks ? 395 error = "duplicate qualifier "; 396 int j = 0; // separator detector 397 for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) { 398 if ( qsrc[i] & qdst[i] ) { // find specific qualifiers in common 399 if ( j > 0 ) error += ", "; 400 error += DeclarationNode::qualifierName[i]; 401 j += 1; 398 402 } // if 399 403 } // for 404 error += " in declaration of "; 400 405 } // if 401 406 } // DeclarationNode::checkQualifiers 402 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {405 if ( ! error.empty() ) error += ", "; // separator406 if ( storageClass == q->storageClass ) { // duplicate qualifier407 error += string( "duplicate " ) + storageName[ storageClass ];408 } else { // only one storage class409 error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];410 q->storageClass = storageClass; // FIX ERROR411 } // if412 if ( ! q->error.empty() ) error += ", " + q->error; // separator413 } else {414 if ( ! error.empty() ) {415 if ( ! q->error.empty() ) error += ", " + q->error; // separator416 } else if ( ! q->error.empty() ) error += q->error;417 } // if418 } // DeclarationNode::copyStorageClasses419 420 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {421 isInline = isInline | q->isInline;422 isNoreturn = isNoreturn | q->isNoreturn;423 // do not overwrite an existing value with NoStorageClass424 if ( q->storageClass != NoStorageClass ) {425 assert( storageClass == NoStorageClass || storageClass == q->storageClass );426 storageClass = q->storageClass;427 } // if428 return this;429 } // DeclarationNode::copyStorageClasses430 407 431 408 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 432 409 if ( q ) { 433 checkStorageClasses( q ); 434 copyStorageClasses( q ); 410 copyStorageClasses(q); 435 411 if ( q->type ) { 436 412 if ( ! type ) { … … 457 433 } // if 458 434 delete q; 435 return this; 436 } 437 438 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 439 isInline = isInline || q->isInline; 440 isNoreturn = isNoreturn || q->isNoreturn; 441 if ( storageClass == NoStorageClass ) { 442 storageClass = q->storageClass; 443 } else if ( q->storageClass != NoStorageClass ) { 444 q->error = "invalid combination of storage classes in declaration of "; 445 } // if 446 if ( error.empty() ) error = q->error; 459 447 return this; 460 448 } … … 516 504 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 517 505 if ( o ) { 518 checkStorageClasses( o );519 506 copyStorageClasses( o ); 520 507 if ( o->type ) { … … 764 751 } // if 765 752 newnode->type->forall = maybeClone( type->forall ); 766 assert( storageClass == NoStorageClass );767 753 newnode->copyStorageClasses( this ); 768 754 newnode->name = assign_strptr( newName ); … … 805 791 DeclarationNode *newnode = new DeclarationNode; 806 792 newnode->type = maybeClone( type ); 807 assert( storageClass == NoStorageClass );808 793 newnode->copyStorageClasses( this ); 809 794 newnode->name = assign_strptr( newName ); … … 813 798 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 814 799 if ( o ) { 815 assert( storageClass == NoStorageClass );816 800 o->copyStorageClasses( this ); 817 801 if ( type ) { … … 924 908 925 909 Declaration *DeclarationNode::build() const { 926 if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );910 if ( ! error.empty() ) throw SemanticError( error, this ); 927 911 if ( type ) { 928 912 if ( type->kind == TypeData::Variable ) { … … 938 922 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 939 923 } // if 940 throw SemanticError( "invalid function specifier ", this );924 throw SemanticError( "invalid function specifier in declaration of ", this ); 941 925 } 942 926 … … 987 971 } 988 972 973 // DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const { 974 // DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass; 975 // for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 976 // if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers 977 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 978 // throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 979 // } // if 980 // ret = *i; 981 // } // for 982 // return ret; 983 // } 984 985 // bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const { 986 // std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key ); 987 // if ( first == storageClasses.end() ) return false; // not found 988 // first = std::find( ++first, storageClasses.end(), key ); // found 989 // if ( first == storageClasses.end() ) return true; // not found again 990 // throw SemanticError( "duplicate function specifier in declaration of ", this ); 991 // } 992 989 993 // Local Variables: // 990 994 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.