Changes in / [1f6d4624:7527e63]
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r1f6d4624 r7527e63 48 48 newnode->type = maybeClone( type ); 49 49 newnode->name = name; 50 newnode->storageClass = storageClass; 51 newnode->isInline = isInline; 52 newnode->isNoreturn = isNoreturn; 50 newnode->storageClasses = storageClasses; 53 51 newnode->bitfieldWidth = bitfieldWidth; 54 52 newnode->hasEllipsis = hasEllipsis; … … 59 57 } // DeclarationNode::clone 60 58 61 DeclarationNode::DeclarationNode() 62 : type( 0 ) 63 , storageClass( NoStorageClass ) 64 , isInline( false ) 65 , isNoreturn( false ) 66 , bitfieldWidth( 0 ) 67 , initializer( 0 ) 68 , hasEllipsis( false ) 69 , linkage( ::linkage ) 70 , extension( false ) 71 , error() { 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { 72 60 } 73 61 … … 94 82 } // if 95 83 96 if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' '; 97 if(isInline) os << DeclarationNode::storageName[Inline] << ' '; 98 if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' '; 84 printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os ); 99 85 if ( type ) { 100 86 type->print( os, indent ); … … 157 143 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 158 144 DeclarationNode *newnode = new DeclarationNode; 159 switch (sc) { 160 case Inline: newnode->isInline = true; break; 161 case Noreturn: newnode->isNoreturn = true; break; 162 default: newnode->storageClass = sc; break; 163 } 145 newnode->storageClasses.push_back( sc ); 164 146 return newnode; 165 147 } // DeclarationNode::newStorageClass … … 377 359 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 378 360 if ( q ) { 379 copyStorageClasses(q);361 storageClasses.splice( storageClasses.end(), q->storageClasses ); 380 362 if ( q->type ) { 381 363 if ( ! type ) { … … 404 386 405 387 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 406 isInline = isInline || q->isInline; 407 isNoreturn = isNoreturn || q->isNoreturn; 408 if(storageClass == NoStorageClass) { 409 storageClass = q->storageClass; 410 } 411 else if (q->storageClass != NoStorageClass) { 412 q->error = "invalid combination of storage classes in declaration of "; 413 } 414 if(error.empty()) error = q->error; 388 storageClasses = q->storageClasses; 415 389 return this; 416 390 } … … 472 446 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 473 447 if ( o ) { 474 copyStorageClasses( o);448 storageClasses.splice( storageClasses.end(), o->storageClasses ); 475 449 if ( o->type ) { 476 450 if ( ! type ) { … … 719 693 } // if 720 694 newnode->type->forall = maybeClone( type->forall ); 721 newnode-> copyStorageClasses( this );695 newnode->storageClasses = storageClasses; 722 696 newnode->name = assign_strptr( newName ); 723 697 return newnode; … … 726 700 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 727 701 if ( o ) { 728 o-> copyStorageClasses( this);702 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 729 703 if ( type ) { 730 704 TypeData *srcType = type; … … 759 733 DeclarationNode *newnode = new DeclarationNode; 760 734 newnode->type = maybeClone( type ); 761 newnode-> copyStorageClasses( this );735 newnode->storageClasses = storageClasses; 762 736 newnode->name = assign_strptr( newName ); 763 737 return newnode; … … 766 740 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 767 741 if ( o ) { 768 o-> copyStorageClasses( this);742 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 769 743 if ( type ) { 770 744 TypeData *newType = type->clone(); … … 881 855 882 856 Declaration *DeclarationNode::build() const { 883 if( !error.empty() ) throw SemanticError( error, this );884 857 if ( type ) { 885 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );886 } // if 887 if ( ! isInline && ! isNoreturn) {888 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );858 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 859 } // if 860 if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) { 861 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 889 862 } // if 890 863 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 925 898 } 926 899 927 //DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {928 //DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;929 //for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {930 //if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers931 //if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?932 //throw SemanticError( "invalid combination of storage classes in declaration of ", this );933 //} // if934 //ret = *i;935 //} // for936 //return ret;937 //}938 939 //bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {940 //std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );941 //if ( first == storageClasses.end() ) return false; // not found942 //first = std::find( ++first, storageClasses.end(), key ); // found943 //if ( first == storageClasses.end() ) return true; // not found again944 //throw SemanticError( "duplicate function specifier in declaration of ", this );945 //}900 DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const { 901 DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass; 902 for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 903 if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers 904 if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 905 throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 906 } // if 907 ret = *i; 908 } // for 909 return ret; 910 } 911 912 bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const { 913 std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key ); 914 if ( first == storageClasses.end() ) return false; // not found 915 first = std::find( ++first, storageClasses.end(), key ); // found 916 if ( first == storageClasses.end() ) return true; // not found again 917 throw SemanticError( "duplicate function specifier in declaration of ", this ); 918 } 946 919 947 920 // Local Variables: // -
src/Parser/ParseNode.h
r1f6d4624 r7527e63 271 271 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 272 272 private: 273 //StorageClass buildStorageClass() const;274 //bool buildFuncSpecifier( StorageClass key ) const;273 StorageClass buildStorageClass() const; 274 bool buildFuncSpecifier( StorageClass key ) const; 275 275 276 276 TypeData *type; 277 277 std::string name; 278 // std::list< StorageClass > storageClasses; 279 StorageClass storageClass; 280 bool isInline, isNoreturn; 278 std::list< StorageClass > storageClasses; 281 279 std::list< std::string > attributes; 282 280 ExpressionNode *bitfieldWidth; … … 286 284 LinkageSpec::Type linkage; 287 285 bool extension = false; 288 std::string error;289 286 290 287 static UniqueName anonymous; -
src/tests/.expect/declarationErrors.txt
r1f6d4624 r7527e63 1 1 CFA Version 1.0.0 (debug) 2 Error: invalid combination of storage classes in declaration of x9: static volatile const short int2 Error: invalid combination of storage classes in declaration of x9: static static volatile const short int 3 3 4 Error: invalid combination of storage classes in declaration of x18: static const volatile instance of struct __anonymous04 Error: invalid combination of storage classes in declaration of x18: static static const volatile instance of struct __anonymous0 5 5 with members 6 6 i: int … … 8 8 9 9 10 Error: invalid combination of storage classes in declaration of x19: static const volatile volatile instance of struct __anonymous110 Error: invalid combination of storage classes in declaration of x19: static static const volatile volatile instance of struct __anonymous1 11 11 with members 12 12 i: int … … 14 14 15 15 16 Error: invalid combination of storage classes in declaration of x28: static volatile const instance of type Int16 Error: invalid combination of storage classes in declaration of x28: static static volatile const instance of type Int 17 17 18 18 make: *** [declarationErrors] Error 1
Note: See TracChangeset
for help on using the changeset viewer.