Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rde62360d r68cd1ce  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 24 15:29:19 2015
    13 // Update Count     : 86
     12// Last Modified On : Sat Jun 13 08:02:03 2015
     13// Update Count     : 58
    1414//
    1515
     
    2424#include "SynTree/Declaration.h"
    2525#include "SynTree/Expression.h"
    26 
    27 #include "Parser.h"
    28 #include "TypedefTable.h"
    29 extern TypedefTable typedefTable;
    3026
    3127using namespace std;
     
    181177                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
    182178        } // if
    183 
    184         // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified by
    185         // "struct"
    186         typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD );
    187         DeclarationNode *typedf = new DeclarationNode;
    188         typedf->name = newnode->type->aggregate->name;
    189         newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
    190 
    191179        newnode->type->aggregate->params = formals;
    192180        newnode->type->aggregate->actuals = actuals;
     
    203191                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    204192        } // if
    205 
    206         // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be qualified
    207         // by "enum"
    208         typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );
    209         DeclarationNode *typedf = new DeclarationNode;
    210         typedf->name = newnode->type->enumeration->name;
    211         newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
    212 
    213193        newnode->type->enumeration->constants = constants;
    214194        return newnode;
     
    852832Declaration *DeclarationNode::build() const {
    853833        if ( type ) {
    854                 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) );
     834                Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildInline(), linkage, maybeBuild< Initializer >(initializer) );
    855835                return newDecl;
    856836        } // if
    857         if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
     837        if ( ! buildInline() ) {
    858838                return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) );
    859839        } // if
    860         throw SemanticError( "invalid function specifier in declaration of ", this );
     840        throw SemanticError( "invalid inline specification in declaration of ", this );
    861841}
    862842
     
    899879        for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    900880          if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
     881
    901882          if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    902883                        throw SemanticError( "invalid combination of storage classes in declaration of ", this );
     
    907888}
    908889
    909 bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
    910         std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
    911   if ( first == storageClasses.end() ) return false;    // not found
    912         first = std::find( ++first, storageClasses.end(), key ); // found
    913   if ( first == storageClasses.end() ) return true;             // not found again
    914         throw SemanticError( "duplicate function specifier in declaration of ", this );
     890bool DeclarationNode::buildInline() const {
     891        std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), DeclarationNode::Inline );
     892  if ( first == storageClasses.end() ) return false;
     893        std::list< DeclarationNode::StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(), DeclarationNode::Inline );
     894  if ( next == storageClasses.end() ) return true;
     895        throw SemanticError( "duplicate inline specification in declaration of ", this );
    915896}
    916897
Note: See TracChangeset for help on using the changeset viewer.