Ignore:
Timestamp:
Aug 29, 2016, 10:52:33 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
3403534
Parents:
8f6f47d7
Message:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r8f6f47d7 r28307be  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 15:55:12 2016
    13 // Update Count     : 311
     12// Last Modified On : Mon Aug 29 22:30:56 2016
     13// Update Count     : 327
    1414//
    1515
     
    4242
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
     44
     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
     59        variable.tyClass = DeclarationNode::Type;
     60        variable.assertions = nullptr;
     61}
     62
     63DeclarationNode::~DeclarationNode() {
     64        delete attr.expr;
     65        delete attr.type;
     66        delete type;
     67        delete bitfieldWidth;
     68        delete initializer;
     69}
    4470
    4571DeclarationNode *DeclarationNode::clone() const {
     
    5581        newnode->set_next( maybeClone( get_next() ) );
    5682        newnode->linkage = linkage;
     83
     84        newnode->variable.assertions = maybeClone( variable.assertions );
     85        newnode->variable.name = variable.name;
     86        newnode->variable.tyClass = variable.tyClass;
     87
     88        newnode->attr.expr = maybeClone( attr.expr );
     89        newnode->attr.type = maybeClone( attr.type );
    5790        return newnode;
    5891} // DeclarationNode::clone
    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() {
    71 }
    72 
    73 DeclarationNode::~DeclarationNode() {
    74         delete type;
    75         delete bitfieldWidth;
    76         delete initializer;
    77 }
    7892
    7993bool DeclarationNode::get_hasEllipsis() const {
     
    248262        newnode->name = assign_strptr( name );
    249263        newnode->type = new TypeData( TypeData::Variable );
    250         newnode->type->variable.tyClass = tc;
    251         newnode->type->variable.name = newnode->name;
     264        newnode->variable.tyClass = tc;
     265        newnode->variable.name = newnode->name;
    252266        return newnode;
    253267} // DeclarationNode::newTypeParam
     
    341355        DeclarationNode *newnode = new DeclarationNode;
    342356        newnode->type = new TypeData( TypeData::Attr );
    343         newnode->type->attr.name = assign_strptr( name );
    344         newnode->type->attr.expr = expr;
     357        newnode->attr.name = assign_strptr( name );
     358        newnode->attr.expr = expr;
    345359        return newnode;
    346360}
     
    349363        DeclarationNode *newnode = new DeclarationNode;
    350364        newnode->type = new TypeData( TypeData::Attr );
    351         newnode->type->attr.name = assign_strptr( name );
    352         newnode->type->attr.type = type;
     365        newnode->attr.name = assign_strptr( name );
     366        newnode->attr.type = type;
    353367        return newnode;
    354368}
     
    542556                break;
    543557          case TypeData::Variable:
    544                 if ( type->variable.assertions ) {
    545                         type->variable.assertions->appendList( assertions );
     558                if ( variable.assertions ) {
     559                        variable.assertions->appendList( assertions );
    546560                } else {
    547                         type->variable.assertions = assertions;
     561                        variable.assertions = assertions;
    548562                } // if
    549563                break;
     
    896910        if ( ! error.empty() ) throw SemanticError( error, this );
    897911        if ( type ) {
    898                 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     912                if ( type->kind == TypeData::Variable ) {
     913                        static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     914                        TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] );
     915                        buildList( variable.assertions, ret->get_assertions() );
     916                        return ret;
     917                } else {
     918                        return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     919                } // if
    899920        } // if
    900921        if ( ! isInline && ! isNoreturn ) {
     
    933954                  return ret;
    934955          }
     956          case TypeData::Attr: {
     957                  assert( type->kind == TypeData::Attr );
     958                  // assert( type->attr );
     959                  AttrType * ret;
     960                  if ( attr.expr ) {
     961                          ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );
     962                  } else {
     963                          assert( attr.type );
     964                          ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );
     965                  } // if
     966                  return ret;
     967          }
    935968          default:
    936969                return typebuild( type );
Note: See TracChangeset for help on using the changeset viewer.