Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r68cd1ce rde62360d  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 13 08:02:03 2015
    13 // Update Count     : 58
     12// Last Modified On : Wed Jun 24 15:29:19 2015
     13// Update Count     : 86
    1414//
    1515
     
    2424#include "SynTree/Declaration.h"
    2525#include "SynTree/Expression.h"
     26
     27#include "Parser.h"
     28#include "TypedefTable.h"
     29extern TypedefTable typedefTable;
    2630
    2731using namespace std;
     
    177181                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
    178182        } // 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
    179191        newnode->type->aggregate->params = formals;
    180192        newnode->type->aggregate->actuals = actuals;
     
    191203                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    192204        } // 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
    193213        newnode->type->enumeration->constants = constants;
    194214        return newnode;
     
    832852Declaration *DeclarationNode::build() const {
    833853        if ( type ) {
    834                 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildInline(), linkage, maybeBuild< Initializer >(initializer) );
     854                Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) );
    835855                return newDecl;
    836856        } // if
    837         if ( ! buildInline() ) {
     857        if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    838858                return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) );
    839859        } // if
    840         throw SemanticError( "invalid inline specification in declaration of ", this );
     860        throw SemanticError( "invalid function specifier in declaration of ", this );
    841861}
    842862
     
    879899        for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    880900          if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
    881 
    882901          if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    883902                        throw SemanticError( "invalid combination of storage classes in declaration of ", this );
     
    888907}
    889908
    890 bool 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 );
     909bool 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 );
    896915}
    897916
Note: See TracChangeset for help on using the changeset viewer.