Changes in src/Parser/DeclarationNode.cc [e82aa9df:2037f82]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
re82aa9df r2037f82 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 14:30:25201613 // Update Count : 1 7212 // Last Modified On : Thu Aug 18 23:48:23 2016 13 // Update Count : 182 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; … … 42 41 UniqueName DeclarationNode::anonymous( "__anonymous" ); 43 42 44 extern LinkageSpec:: Typelinkage; // defined in parser.yy43 extern LinkageSpec::Spec linkage; // defined in parser.yy 45 44 46 45 DeclarationNode *DeclarationNode::clone() const { … … 48 47 newnode->type = maybeClone( type ); 49 48 newnode->name = name; 50 newnode->storageClasses = storageClasses; 51 //PAB newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 49 newnode->storageClass = storageClass; 50 newnode->isInline = isInline; 51 newnode->isNoreturn = isNoreturn; 52 52 newnode->bitfieldWidth = bitfieldWidth; 53 53 newnode->hasEllipsis = hasEllipsis; 54 54 newnode->initializer = initializer; 55 newnode-> next = maybeClone( next);55 newnode->set_next( maybeClone( get_next() ) ); 56 56 newnode->linkage = linkage; 57 57 return newnode; 58 58 } // DeclarationNode::clone 59 59 60 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() { 61 71 } 62 72 … … 83 93 } // if 84 94 85 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] << ' '; 86 98 if ( type ) { 87 99 type->print( os, indent ); … … 144 156 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 145 157 DeclarationNode *newnode = new DeclarationNode; 146 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 } 147 163 return newnode; 148 164 } // DeclarationNode::newStorageClass … … 284 300 newnode->type->array->dimension = size; 285 301 newnode->type->array->isStatic = isStatic; 286 if ( newnode->type->array->dimension == 0 || dynamic_cast<ConstantExpr *>( newnode->type->array->dimension->build()) ) {302 if ( newnode->type->array->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) { 287 303 newnode->type->array->isVarLen = false; 288 304 } else { … … 360 376 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 361 377 if ( q ) { 362 storageClasses.splice( storageClasses.end(), q->storageClasses);378 copyStorageClasses(q); 363 379 if ( q->type ) { 364 380 if ( ! type ) { … … 387 403 388 404 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 389 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; 390 414 return this; 391 415 } … … 447 471 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 448 472 if ( o ) { 449 storageClasses.splice( storageClasses.end(), o->storageClasses);473 copyStorageClasses( o ); 450 474 if ( o->type ) { 451 475 if ( ! type ) { … … 694 718 } // if 695 719 newnode->type->forall = maybeClone( type->forall ); 696 newnode-> storageClasses = storageClasses;720 newnode->copyStorageClasses( this ); 697 721 newnode->name = assign_strptr( newName ); 698 722 return newnode; … … 701 725 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 702 726 if ( o ) { 703 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());727 o->copyStorageClasses( this ); 704 728 if ( type ) { 705 729 TypeData *srcType = type; … … 734 758 DeclarationNode *newnode = new DeclarationNode; 735 759 newnode->type = maybeClone( type ); 736 newnode-> storageClasses = storageClasses;760 newnode->copyStorageClasses( this ); 737 761 newnode->name = assign_strptr( newName ); 738 762 return newnode; … … 741 765 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 742 766 if ( o ) { 743 o-> storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end());767 o->copyStorageClasses( this ); 744 768 if ( type ) { 745 769 TypeData *newType = type->clone(); … … 752 776 } // if 753 777 } // if 778 delete o; 754 779 return o; 755 }756 757 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) {758 if ( node != 0 ) {759 set_last( node );760 } // if761 return this;762 780 } 763 781 … … 776 794 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) { 777 795 SemanticError errors; 778 std::back_insert_iterator< std::list< Declaration * > > out( outputList );796 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 779 797 const DeclarationNode *cur = firstNode; 780 798 while ( cur ) { … … 794 812 errors.append( e ); 795 813 } // try 796 cur = dynamic_cast< DeclarationNode *>( cur->get_next() );814 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 797 815 } // while 798 816 if ( ! errors.isEmpty() ) { … … 801 819 } 802 820 803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {821 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) { 804 822 SemanticError errors; 805 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );823 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 806 824 const DeclarationNode *cur = firstNode; 807 825 while ( cur ) { … … 817 835 Declaration *decl = cur->build(); 818 836 if ( decl ) { 819 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {837 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 820 838 *out++ = dwt; 821 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {839 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) { 822 840 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 823 841 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 824 842 delete agg; 825 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {843 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) { 826 844 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 827 845 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); … … 831 849 errors.append( e ); 832 850 } // try 833 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );851 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 834 852 } // while 835 853 if ( ! errors.isEmpty() ) { … … 838 856 } 839 857 840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {858 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) { 841 859 SemanticError errors; 842 std::back_insert_iterator< std::list< Type * > > out( outputList );860 std::back_insert_iterator< std::list< Type * > > out( outputList ); 843 861 const DeclarationNode *cur = firstNode; 844 862 while ( cur ) { … … 848 866 errors.append( e ); 849 867 } // try 850 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );868 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 851 869 } // while 852 870 if ( ! errors.isEmpty() ) { … … 856 874 857 875 Declaration *DeclarationNode::build() const { 876 if( !error.empty() ) throw SemanticError( error, this ); 858 877 if ( type ) { 859 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );860 } // if 861 if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn )) {862 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );878 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 879 } // if 880 if ( ! isInline && ! isNoreturn ) { 881 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 863 882 } // if 864 883 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 899 918 } 900 919 901 DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {902 DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;903 for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {904 if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers905 if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?906 throw SemanticError( "invalid combination of storage classes in declaration of ", this );907 } // if908 ret = *i;909 } // for910 return ret;911 }912 913 bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {914 std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );915 if ( first == storageClasses.end() ) return false; // not found916 first = std::find( ++first, storageClasses.end(), key ); // found917 if ( first == storageClasses.end() ) return true; // not found again918 throw SemanticError( "duplicate function specifier in declaration of ", this );919 }920 // DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const { 921 // DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass; 922 // for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 923 // if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers 924 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 925 // throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 926 // } // if 927 // ret = *i; 928 // } // for 929 // return ret; 930 // } 931 932 // bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const { 933 // std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key ); 934 // if ( first == storageClasses.end() ) return false; // not found 935 // first = std::find( ++first, storageClasses.end(), key ); // found 936 // if ( first == storageClasses.end() ) return true; // not found again 937 // throw SemanticError( "duplicate function specifier in declaration of ", this ); 938 // } 920 939 921 940 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.