Changes in src/Parser/DeclarationNode.cc [ac71a86:7bf7fb9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rac71a86 r7bf7fb9 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 18 23:48:23201613 // Update Count : 1 8212 // Last Modified On : Sun Aug 7 08:01:55 2016 13 // Update Count : 165 14 14 // 15 15 … … 25 25 #include "SynTree/Expression.h" 26 26 27 #include "Parser.h" 27 28 #include "TypedefTable.h" 28 29 extern TypedefTable typedefTable; … … 41 42 UniqueName DeclarationNode::anonymous( "__anonymous" ); 42 43 43 extern LinkageSpec:: Speclinkage; // defined in parser.yy44 extern LinkageSpec::Type linkage; // defined in parser.yy 44 45 45 46 DeclarationNode *DeclarationNode::clone() const { … … 47 48 newnode->type = maybeClone( type ); 48 49 newnode->name = name; 49 newnode->storageClass = storageClass; 50 newnode->isInline = isInline; 51 newnode->isNoreturn = isNoreturn; 50 newnode->storageClasses = storageClasses; 51 //PAB newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 52 52 newnode->bitfieldWidth = bitfieldWidth; 53 53 newnode->hasEllipsis = hasEllipsis; 54 54 newnode->initializer = initializer; 55 newnode-> set_next( maybeClone( get_next() ));55 newnode->next = maybeClone( next ); 56 56 newnode->linkage = linkage; 57 57 return newnode; 58 58 } // DeclarationNode::clone 59 59 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 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { 71 61 } 72 62 … … 93 83 } // if 94 84 95 if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' '; 96 if(isInline) os << DeclarationNode::storageName[Inline] << ' '; 97 if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' '; 85 printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os ); 98 86 if ( type ) { 99 87 type->print( os, indent ); … … 156 144 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 157 145 DeclarationNode *newnode = new DeclarationNode; 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 newnode->storageClasses.push_back( sc ); 163 147 return newnode; 164 148 } // DeclarationNode::newStorageClass … … 300 284 newnode->type->array->dimension = size; 301 285 newnode->type->array->isStatic = isStatic; 302 if ( newnode->type->array->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {286 if ( newnode->type->array->dimension == 0 || dynamic_cast<ConstantNode *>( newnode->type->array->dimension ) ) { 303 287 newnode->type->array->isVarLen = false; 304 288 } else { … … 376 360 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 377 361 if ( q ) { 378 copyStorageClasses(q);362 storageClasses.splice( storageClasses.end(), q->storageClasses ); 379 363 if ( q->type ) { 380 364 if ( ! type ) { … … 403 387 404 388 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 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 storageClasses = q->storageClasses; 414 390 return this; 415 391 } … … 471 447 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 472 448 if ( o ) { 473 copyStorageClasses( o);449 storageClasses.splice( storageClasses.end(), o->storageClasses ); 474 450 if ( o->type ) { 475 451 if ( ! type ) { … … 494 470 495 471 // there may be typedefs chained onto the type 496 if ( o->get_ next() ) {497 set_l ast( o->get_next()->clone() );472 if ( o->get_link() ) { 473 set_link( o->get_link()->clone() ); 498 474 } // if 499 475 } // if … … 718 694 } // if 719 695 newnode->type->forall = maybeClone( type->forall ); 720 newnode-> copyStorageClasses( this );696 newnode->storageClasses = storageClasses; 721 697 newnode->name = assign_strptr( newName ); 722 698 return newnode; … … 725 701 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 726 702 if ( o ) { 727 o-> copyStorageClasses( this);703 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 728 704 if ( type ) { 729 705 TypeData *srcType = type; … … 758 734 DeclarationNode *newnode = new DeclarationNode; 759 735 newnode->type = maybeClone( type ); 760 newnode-> copyStorageClasses( this );736 newnode->storageClasses = storageClasses; 761 737 newnode->name = assign_strptr( newName ); 762 738 return newnode; … … 765 741 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 766 742 if ( o ) { 767 o-> copyStorageClasses( this);743 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 768 744 if ( type ) { 769 745 TypeData *newType = type->clone(); … … 779 755 } 780 756 757 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) { 758 if ( node != 0 ) { 759 set_link( node ); 760 } // if 761 return this; 762 } 763 781 764 DeclarationNode *DeclarationNode::extractAggregate() const { 782 765 if ( type ) { … … 793 776 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) { 794 777 SemanticError errors; 795 std::back_insert_iterator< std::list< Declaration * 778 std::back_insert_iterator< std::list< Declaration *> > out( outputList ); 796 779 const DeclarationNode *cur = firstNode; 797 780 while ( cur ) { … … 811 794 errors.append( e ); 812 795 } // try 813 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );796 cur = dynamic_cast<DeclarationNode *>( cur->get_link() ); 814 797 } // while 815 798 if ( ! errors.isEmpty() ) { … … 818 801 } 819 802 820 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * 803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ) { 821 804 SemanticError errors; 822 std::back_insert_iterator< std::list< DeclarationWithType * 805 std::back_insert_iterator< std::list< DeclarationWithType *> > out( outputList ); 823 806 const DeclarationNode *cur = firstNode; 824 807 while ( cur ) { … … 834 817 Declaration *decl = cur->build(); 835 818 if ( decl ) { 836 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * 819 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType *>( decl ) ) { 837 820 *out++ = dwt; 838 } else if ( StructDecl *agg = dynamic_cast< StructDecl * 821 } else if ( StructDecl *agg = dynamic_cast< StructDecl *>( decl ) ) { 839 822 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 840 823 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 841 824 delete agg; 842 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * 825 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl *>( decl ) ) { 843 826 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 844 827 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); … … 848 831 errors.append( e ); 849 832 } // try 850 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );833 cur = dynamic_cast< DeclarationNode *>( cur->get_link() ); 851 834 } // while 852 835 if ( ! errors.isEmpty() ) { … … 855 838 } 856 839 857 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * 840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ) { 858 841 SemanticError errors; 859 std::back_insert_iterator< std::list< Type * 842 std::back_insert_iterator< std::list< Type *> > out( outputList ); 860 843 const DeclarationNode *cur = firstNode; 861 844 while ( cur ) { … … 865 848 errors.append( e ); 866 849 } // try 867 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );850 cur = dynamic_cast< DeclarationNode *>( cur->get_link() ); 868 851 } // while 869 852 if ( ! errors.isEmpty() ) { … … 873 856 874 857 Declaration *DeclarationNode::build() const { 875 if( !error.empty() ) throw SemanticError( error, this );876 858 if ( type ) { 877 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );878 } // if 879 if ( ! isInline && ! isNoreturn) {880 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );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 ); 881 863 } // if 882 864 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 917 899 } 918 900 919 //DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {920 //DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;921 //for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {922 //if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers923 //if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ?924 //throw SemanticError( "invalid combination of storage classes in declaration of ", this );925 //} // if926 //ret = *i;927 //} // for928 //return ret;929 //}930 931 //bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {932 //std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );933 //if ( first == storageClasses.end() ) return false; // not found934 //first = std::find( ++first, storageClasses.end(), key ); // found935 //if ( first == storageClasses.end() ) return true; // not found again936 //throw SemanticError( "duplicate function specifier in declaration of ", this );937 //}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 specifiers 905 if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 906 throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 907 } // if 908 ret = *i; 909 } // for 910 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 found 916 first = std::find( ++first, storageClasses.end(), key ); // found 917 if ( first == storageClasses.end() ) return true; // not found again 918 throw SemanticError( "duplicate function specifier in declaration of ", this ); 919 } 938 920 939 921 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.