Changeset 29917c6 for src/Parser
- Timestamp:
- Aug 16, 2016, 6:09:36 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 08ac489
- Parents:
- 0da3e2c (diff), b7ea418 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r0da3e2c r29917c6 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 15 20:48:55201613 // Update Count : 17 812 // Last Modified On : Tue Aug 16 18:00:34 2016 13 // Update Count : 179 14 14 // 15 15 … … 25 25 #include "SynTree/Expression.h" 26 26 27 #include "Parser.h"28 27 #include "TypedefTable.h" 29 28 extern TypedefTable typedefTable; … … 48 47 newnode->type = maybeClone( type ); 49 48 newnode->name = name; 50 newnode->storageClasses = storageClasses; 49 newnode->storageClass = storageClass; 50 newnode->isInline = isInline; 51 newnode->isNoreturn = isNoreturn; 51 52 newnode->bitfieldWidth = bitfieldWidth; 52 53 newnode->hasEllipsis = hasEllipsis; … … 57 58 } // DeclarationNode::clone 58 59 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { 60 DeclarationNode::DeclarationNode() 61 : type( 0 ) 62 , storageClass( NoStorageClass ) 63 , isInline( false ) 64 , isNoreturn( false ) 65 , bitfieldWidth( 0 ) 66 , initializer( 0 ) 67 , hasEllipsis( false ) 68 , linkage( ::linkage ) 69 , extension( false ) 70 , error() { 60 71 } 61 72 … … 82 93 } // if 83 94 84 printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os ); 95 if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' '; 96 if(isInline) os << DeclarationNode::storageName[Inline] << ' '; 97 if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' '; 85 98 if ( type ) { 86 99 type->print( os, indent ); … … 143 156 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 144 157 DeclarationNode *newnode = new DeclarationNode; 145 newnode->storageClasses.push_back( sc ); 158 switch (sc) { 159 case Inline: newnode->isInline = true; break; 160 case Noreturn: newnode->isNoreturn = true; break; 161 default: newnode->storageClass = sc; break; 162 } 146 163 return newnode; 147 164 } // DeclarationNode::newStorageClass … … 359 376 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 360 377 if ( q ) { 361 storageClasses.splice( storageClasses.end(), q->storageClasses);378 copyStorageClasses(q); 362 379 if ( q->type ) { 363 380 if ( ! type ) { … … 386 403 387 404 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 388 storageClasses = q->storageClasses; 405 isInline = isInline || q->isInline; 406 isNoreturn = isNoreturn || q->isNoreturn; 407 if(storageClass == NoStorageClass) { 408 storageClass = q->storageClass; 409 } 410 else if (q->storageClass != NoStorageClass) { 411 q->error = "invalid combination of storage classes in declaration of "; 412 } 413 if(error.empty()) error = q->error; 389 414 return this; 390 415 } … … 446 471 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 447 472 if ( o ) { 448 storageClasses.splice( storageClasses.end(), o->storageClasses);473 copyStorageClasses( o ); 449 474 if ( o->type ) { 450 475 if ( ! type ) { … … 693 718 } // if 694 719 newnode->type->forall = maybeClone( type->forall ); 695 newnode-> storageClasses = storageClasses;720 newnode->copyStorageClasses( this ); 696 721 newnode->name = assign_strptr( newName ); 697 722 return newnode; … … 700 725 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 701 726 if ( o ) { 702 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());727 o->copyStorageClasses( this ); 703 728 if ( type ) { 704 729 TypeData *srcType = type; … … 733 758 DeclarationNode *newnode = new DeclarationNode; 734 759 newnode->type = maybeClone( type ); 735 newnode-> storageClasses = storageClasses;760 newnode->copyStorageClasses( this ); 736 761 newnode->name = assign_strptr( newName ); 737 762 return newnode; … … 740 765 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 741 766 if ( o ) { 742 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());767 o->copyStorageClasses( this ); 743 768 if ( type ) { 744 769 TypeData *newType = type->clone(); … … 855 880 856 881 Declaration *DeclarationNode::build() const { 882 if( !error.empty() ) throw SemanticError( error, this ); 857 883 if ( type ) { 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 );884 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 885 } // if 886 if ( ! isInline && ! isNoreturn ) { 887 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 862 888 } // if 863 889 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 898 924 } 899 925 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 specifiers904 if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?905 throw SemanticError( "invalid combination of storage classes in declaration of ", this );906 } // if907 ret = *i;908 } // for909 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 found915 first = std::find( ++first, storageClasses.end(), key ); // found916 if ( first == storageClasses.end() ) return true; // not found again917 throw SemanticError( "duplicate function specifier in declaration of ", this );918 }926 // DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const { 927 // DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass; 928 // for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 929 // if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers 930 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 931 // throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 932 // } // if 933 // ret = *i; 934 // } // for 935 // return ret; 936 // } 937 938 // bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const { 939 // std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key ); 940 // if ( first == storageClasses.end() ) return false; // not found 941 // first = std::find( ++first, storageClasses.end(), key ); // found 942 // if ( first == storageClasses.end() ) return true; // not found again 943 // throw SemanticError( "duplicate function specifier in declaration of ", this ); 944 // } 919 945 920 946 // Local Variables: // -
src/Parser/ParseNode.h
r0da3e2c r29917c6 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; 278 // std::list< StorageClass > storageClasses; 279 StorageClass storageClass; 280 bool isInline, isNoreturn; 279 281 std::list< std::string > attributes; 280 282 ExpressionNode *bitfieldWidth; … … 284 286 LinkageSpec::Type linkage; 285 287 bool extension = false; 288 std::string error; 286 289 287 290 static UniqueName anonymous;
Note: See TracChangeset
for help on using the changeset viewer.