Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r7d05e7e r28307be  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  9 23:21:47 2016
    13 // Update Count     : 402
     12// Last Modified On : Mon Aug 29 22:30:56 2016
     13// Update Count     : 327
    1414//
    1515
     
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
    4444
    45 DeclarationNode::DeclarationNode() :
    46                 type( 0 ),
    47                 storageClass( NoStorageClass ),
    48                 isInline( false ),
    49                 isNoreturn( false ),
    50                 bitfieldWidth( 0 ),
    51                 initializer( 0 ),
    52                 hasEllipsis( false ),
    53                 linkage( ::linkage ),
    54                 extension( false ) {
     45DeclarationNode::DeclarationNode()
     46                : type( 0 )
     47                , storageClass( NoStorageClass )
     48                , isInline( false )
     49                , isNoreturn( false )
     50                , bitfieldWidth( 0 )
     51                , initializer( 0 )
     52                , hasEllipsis( false )
     53                , linkage( ::linkage )
     54                , extension( false )
     55                , error() {
     56        attr.expr = nullptr;
     57        attr.type = nullptr;
     58
    5559        variable.tyClass = DeclarationNode::Type;
    5660        variable.assertions = nullptr;
    57 
    58         attr.expr = nullptr;
    59         attr.type = nullptr;
    6061}
    6162
     
    392393
    393394        if ( (qsrc & qdst).any() ) {                                            // common bits between qualifier masks ?
    394                 for ( int i = 0; i < NoOfQualifier; i += 1 ) {  // find common qualifiers
    395                         if ( qsrc[i] & qdst[i] ) {
    396                                 error += string(error.empty() ? "" : ", ") + "duplicate " + DeclarationNode::qualifierName[i];
     395                error = "duplicate qualifier ";
     396                int j = 0;                                                                              // separator detector
     397                for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) {
     398                        if ( qsrc[i] & qdst[i] ) {                                      // find specific qualifiers in common
     399                                if ( j > 0 ) error += ", ";
     400                                error += DeclarationNode::qualifierName[i];
     401                                j += 1;
    397402                        } // if
    398403                } // for
     404                error += " in declaration of ";
    399405        } // if
    400406} // DeclarationNode::checkQualifiers
     
    436442                storageClass = q->storageClass;
    437443        } else if ( q->storageClass != NoStorageClass ) {
    438                 if ( storageClass == q->storageClass ) {
    439                         q->error += string( "duplicate " ) + storageName[ storageClass ];
    440                 } else {                                                                                // can only have one storage class
    441                         q->error += string( "multiple " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];
    442                 } // if
    443         } // if
    444         if ( ! q->error.empty() ) {
    445                 error += (! error.empty() ? ", " : "") + q->error;
    446         } // if
    447         return this;
    448 } // DeclarationNode::copyStorageClasses
     444                q->error = "invalid combination of storage classes in declaration of ";
     445        } // if
     446        if ( error.empty() ) error = q->error;
     447        return this;
     448}
    449449
    450450static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     
    908908
    909909Declaration *DeclarationNode::build() const {
    910         if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
     910        if ( ! error.empty() ) throw SemanticError( error, this );
    911911        if ( type ) {
    912912                if ( type->kind == TypeData::Variable ) {
     
    922922                return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    923923        } // if
    924         throw SemanticError( "invalid function specifier ", this );
     924        throw SemanticError( "invalid function specifier in declaration of ", this );
    925925}
    926926
     
    971971}
    972972
     973// DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
     974//      DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
     975//      for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
     976//        if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
     977//        if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
     978//                      throw SemanticError( "invalid combination of storage classes in declaration of ", this );
     979//              } // if
     980//              ret = *i;
     981//      } // for
     982//      return ret;
     983// }
     984
     985// bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
     986//      std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
     987//   if ( first == storageClasses.end() ) return false; // not found
     988//      first = std::find( ++first, storageClasses.end(), key ); // found
     989//   if ( first == storageClasses.end() ) return true;          // not found again
     990//      throw SemanticError( "duplicate function specifier in declaration of ", this );
     991// }
     992
    973993// Local Variables: //
    974994// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.