Changeset 13e3b50 for src/Parser
- Timestamp:
- Aug 16, 2016, 2:41:17 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:
- 1f6d4624
- Parents:
- 7880579
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r7880579 r13e3b50 48 48 newnode->type = maybeClone( type ); 49 49 newnode->name = name; 50 newnode->storageClasses = storageClasses; 50 newnode->storageClass = storageClass; 51 newnode->isInline = isInline; 52 newnode->isNoreturn = isNoreturn; 51 53 newnode->bitfieldWidth = bitfieldWidth; 52 54 newnode->hasEllipsis = hasEllipsis; … … 57 59 } // DeclarationNode::clone 58 60 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { 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() { 60 72 } 61 73 … … 82 94 } // if 83 95 84 printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os ); 96 if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' '; 97 if(isInline) os << DeclarationNode::storageName[Inline] << ' '; 98 if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' '; 85 99 if ( type ) { 86 100 type->print( os, indent ); … … 143 157 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 144 158 DeclarationNode *newnode = new DeclarationNode; 145 newnode->storageClasses.push_back( sc ); 159 switch (sc) { 160 case Inline: newnode->isInline = true; break; 161 case Noreturn: newnode->isNoreturn = true; break; 162 default: newnode->storageClass = sc; break; 163 } 146 164 return newnode; 147 165 } // DeclarationNode::newStorageClass … … 359 377 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 360 378 if ( q ) { 361 storageClasses.splice( storageClasses.end(), q->storageClasses);379 copyStorageClasses(q); 362 380 if ( q->type ) { 363 381 if ( ! type ) { … … 386 404 387 405 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 388 storageClasses = q->storageClasses; 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; 389 415 return this; 390 416 } … … 446 472 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 447 473 if ( o ) { 448 storageClasses.splice( storageClasses.end(), o->storageClasses);474 copyStorageClasses( o ); 449 475 if ( o->type ) { 450 476 if ( ! type ) { … … 693 719 } // if 694 720 newnode->type->forall = maybeClone( type->forall ); 695 newnode-> storageClasses = storageClasses;721 newnode->copyStorageClasses( this ); 696 722 newnode->name = assign_strptr( newName ); 697 723 return newnode; … … 700 726 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 701 727 if ( o ) { 702 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());728 o->copyStorageClasses( this ); 703 729 if ( type ) { 704 730 TypeData *srcType = type; … … 733 759 DeclarationNode *newnode = new DeclarationNode; 734 760 newnode->type = maybeClone( type ); 735 newnode-> storageClasses = storageClasses;761 newnode->copyStorageClasses( this ); 736 762 newnode->name = assign_strptr( newName ); 737 763 return newnode; … … 740 766 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 741 767 if ( o ) { 742 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());768 o->copyStorageClasses( this ); 743 769 if ( type ) { 744 770 TypeData *newType = type->clone(); … … 855 881 856 882 Declaration *DeclarationNode::build() const { 883 if( !error.empty() ) throw SemanticError( error, this ); 857 884 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 );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 ); 862 889 } // if 863 890 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 898 925 } 899 926 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 }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 specifiers 931 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 932 // throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 933 // } // if 934 // ret = *i; 935 // } // for 936 // 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 found 942 // first = std::find( ++first, storageClasses.end(), key ); // found 943 // if ( first == storageClasses.end() ) return true; // not found again 944 // throw SemanticError( "duplicate function specifier in declaration of ", this ); 945 // } 919 946 920 947 // Local Variables: // -
src/Parser/ParseNode.h
r7880579 r13e3b50 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.