Changeset 04cdd9b for src/Parser/DeclarationNode.cc
- Timestamp:
- Aug 19, 2016, 2:42:04 PM (9 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, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e85a8631
- Parents:
- 03da511 (diff), ac71a86 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r03da511 r04cdd9b 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 7 08:01:55201613 // Update Count : 1 6512 // 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<ConstantNode *>( newnode->type->array->dimension) ) {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 ) { … … 470 494 471 495 // there may be typedefs chained onto the type 472 if ( o->get_ link() ) {473 set_l ink( o->get_link()->clone() );496 if ( o->get_next() ) { 497 set_last( o->get_next()->clone() ); 474 498 } // if 475 499 } // if … … 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(); … … 755 779 } 756 780 757 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) {758 if ( node != 0 ) {759 set_link( node );760 } // if761 return this;762 }763 764 781 DeclarationNode *DeclarationNode::extractAggregate() const { 765 782 if ( type ) { … … 776 793 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) { 777 794 SemanticError errors; 778 std::back_insert_iterator< std::list< Declaration * > > out( outputList );795 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 779 796 const DeclarationNode *cur = firstNode; 780 797 while ( cur ) { … … 794 811 errors.append( e ); 795 812 } // try 796 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );813 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 797 814 } // while 798 815 if ( ! errors.isEmpty() ) { … … 801 818 } 802 819 803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {820 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) { 804 821 SemanticError errors; 805 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );822 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 806 823 const DeclarationNode *cur = firstNode; 807 824 while ( cur ) { … … 817 834 Declaration *decl = cur->build(); 818 835 if ( decl ) { 819 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {836 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 820 837 *out++ = dwt; 821 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {838 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) { 822 839 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 823 840 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 824 841 delete agg; 825 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {842 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) { 826 843 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 827 844 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); … … 831 848 errors.append( e ); 832 849 } // try 833 cur = dynamic_cast< DeclarationNode * >( cur->get_link() );850 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 834 851 } // while 835 852 if ( ! errors.isEmpty() ) { … … 838 855 } 839 856 840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {857 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) { 841 858 SemanticError errors; 842 std::back_insert_iterator< std::list< Type * > > out( outputList );859 std::back_insert_iterator< std::list< Type * > > out( outputList ); 843 860 const DeclarationNode *cur = firstNode; 844 861 while ( cur ) { … … 848 865 errors.append( e ); 849 866 } // try 850 cur = dynamic_cast< DeclarationNode * >( cur->get_link() );867 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 851 868 } // while 852 869 if ( ! errors.isEmpty() ) { … … 856 873 857 874 Declaration *DeclarationNode::build() const { 875 if( !error.empty() ) throw SemanticError( error, this ); 858 876 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 );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 ); 863 881 } // if 864 882 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 899 917 } 900 918 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 }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 specifiers 923 // if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 924 // throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 925 // } // if 926 // ret = *i; 927 // } // for 928 // 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 found 934 // first = std::find( ++first, storageClasses.end(), key ); // found 935 // if ( first == storageClasses.end() ) return true; // not found again 936 // throw SemanticError( "duplicate function specifier in declaration of ", this ); 937 // } 920 938 921 939 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.