Changes in src/Parser/DeclarationNode.cc [28307be:b6424d9]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r28307be 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 Aug 29 22:30:56201613 // Update Count : 32712 // Last Modified On : Sun Sep 11 09:24:11 2016 13 // Update Count : 438 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", " " };33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" }; 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 ) 55 , error() { 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 variable.tyClass = DeclarationNode::Type; 56 variable.assertions = nullptr; 57 56 58 attr.expr = nullptr; 57 59 attr.type = nullptr; 58 59 variable.tyClass = DeclarationNode::Type;60 variable.assertions = nullptr;61 60 } 62 61 … … 390 389 391 390 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 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; 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]; 402 398 } // if 403 399 } // for 404 error += " in declaration of ";405 400 } // if 406 401 } // DeclarationNode::checkQualifiers 402 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) { 404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 if ( ! error.empty() ) error += ", "; // separator 406 if ( storageClass == q->storageClass ) { // duplicate qualifier 407 error += string( "duplicate " ) + storageName[ storageClass ]; 408 } 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 418 } // DeclarationNode::copyStorageClasses 419 420 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 421 isInline = isInline | q->isInline; 422 isNoreturn = isNoreturn | q->isNoreturn; 423 // do not overwrite an existing value with NoStorageClass 424 if ( q->storageClass != NoStorageClass ) { 425 assert( storageClass == NoStorageClass || storageClass == q->storageClass ); 426 storageClass = q->storageClass; 427 } // if 428 return this; 429 } // DeclarationNode::copyStorageClasses 407 430 408 431 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 409 432 if ( q ) { 410 copyStorageClasses(q); 433 checkStorageClasses( q ); 434 copyStorageClasses( q ); 411 435 if ( q->type ) { 412 436 if ( ! type ) { … … 433 457 } // if 434 458 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 } // if446 if ( error.empty() ) error = q->error;447 459 return this; 448 460 } … … 504 516 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 505 517 if ( o ) { 518 checkStorageClasses( o ); 506 519 copyStorageClasses( o ); 507 520 if ( o->type ) { … … 751 764 } // if 752 765 newnode->type->forall = maybeClone( type->forall ); 766 assert( storageClass == NoStorageClass ); 753 767 newnode->copyStorageClasses( this ); 754 768 newnode->name = assign_strptr( newName ); … … 791 805 DeclarationNode *newnode = new DeclarationNode; 792 806 newnode->type = maybeClone( type ); 807 assert( storageClass == NoStorageClass ); 793 808 newnode->copyStorageClasses( this ); 794 809 newnode->name = assign_strptr( newName ); … … 798 813 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 799 814 if ( o ) { 815 assert( storageClass == NoStorageClass ); 800 816 o->copyStorageClasses( this ); 801 817 if ( type ) { … … 908 924 909 925 Declaration *DeclarationNode::build() const { 910 if ( ! error.empty() ) throw SemanticError( error , this );926 if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this ); 911 927 if ( type ) { 912 928 if ( type->kind == TypeData::Variable ) { … … 922 938 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 923 939 } // if 924 throw SemanticError( "invalid function specifier in declaration of", this );940 throw SemanticError( "invalid function specifier ", this ); 925 941 } 926 942 … … 971 987 } 972 988 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 specifiers977 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?978 // throw SemanticError( "invalid combination of storage classes in declaration of ", this );979 // } // if980 // ret = *i;981 // } // for982 // 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 found988 // first = std::find( ++first, storageClasses.end(), key ); // found989 // if ( first == storageClasses.end() ) return true; // not found again990 // throw SemanticError( "duplicate function specifier in declaration of ", this );991 // }992 993 989 // Local Variables: // 994 990 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.