Changeset 28307be


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

Location:
src/Parser
Files:
4 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 );
  • src/Parser/ParseNode.h

    r8f6f47d7 r28307be  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 10:19:01 2016
    13 // Update Count     : 579
     12// Last Modified On : Mon Aug 29 21:45:43 2016
     13// Update Count     : 583
    1414//
    1515
     
    290290        // bool buildFuncSpecifier( StorageClass key ) const;
    291291
     292        struct Enumeration_t {
     293                std::string name;
     294                DeclarationNode * constants;
     295        };
     296        Enumeration_t enumeration;
     297
     298        struct Variable_t {
     299                DeclarationNode::TypeClass tyClass;
     300                std::string name;
     301                DeclarationNode * assertions;
     302        };
     303        Variable_t variable;
     304
     305        struct Attr_t {
     306                std::string name;
     307                ExpressionNode * expr;
     308                DeclarationNode * type;
     309        };
     310        Attr_t attr;
     311
    292312        BuiltinType builtin;
    293313
  • src/Parser/TypeData.cc

    r8f6f47d7 r28307be  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 15:54:55 2016
    13 // Update Count     : 266
     12// Last Modified On : Mon Aug 29 22:31:53 2016
     13// Update Count     : 277
    1414//
    1515
     
    7474          case Variable:
    7575                // variable = new Variable_t;
    76                 variable.tyClass = DeclarationNode::Type;
    77                 variable.assertions = 0;
     76                // variable.tyClass = DeclarationNode::Type;
     77                // variable.assertions = 0;
    7878                break;
    7979          case Tuple:
     
    8585                typeexpr = nullptr;
    8686                break;
     87          case Attr:
     88                // attr = new Attr_t;
     89                // attr.expr = nullptr;
     90                // attr.type = nullptr;
     91                break;
    8792          case Builtin:
    8893                // builtin = new Builtin_t;
    89                 break;
    90           case Attr:
    91                 // attr = new Attr_t;
    92                 attr.expr = nullptr;
    93                 attr.type = nullptr;
    9494                break;
    9595        } // switch
     
    143143                break;
    144144          case Variable:
    145                 delete variable.assertions;
     145                // delete variable.assertions;
    146146                // delete variable;
    147147                break;
     
    154154                delete typeexpr;
    155155                break;
     156          case Attr:
     157                // delete attr.expr;
     158                // delete attr.type;
     159                // delete attr;
     160                break;
    156161          case Builtin:
    157162                // delete builtin;
    158                 break;
    159           case Attr:
    160                 delete attr.expr;
    161                 delete attr.type;
    162                 // delete attr;
    163163                break;
    164164        } // switch
     
    219219                break;
    220220          case Variable:
    221                 newtype->variable.assertions = maybeClone( variable.assertions );
    222                 newtype->variable.name = variable.name;
    223                 newtype->variable.tyClass = variable.tyClass;
     221                assert( false );
     222                // newtype->variable.assertions = maybeClone( variable.assertions );
     223                // newtype->variable.name = variable.name;
     224                // newtype->variable.tyClass = variable.tyClass;
    224225                break;
    225226          case Tuple:
     
    229230                newtype->typeexpr = maybeClone( typeexpr );
    230231                break;
     232          case Attr:
     233                assert( false );
     234                // newtype->attr.expr = maybeClone( attr.expr );
     235                // newtype->attr.type = maybeClone( attr.type );
     236                break;
    231237          case Builtin:
     238                assert( false );
    232239                // newtype->builtin = builtin;
    233                 break;
    234           case Attr:
    235                 newtype->attr.expr = maybeClone( attr.expr );
    236                 newtype->attr.type = maybeClone( attr.type );
    237240                break;
    238241        } // switch
     
    382385                break;
    383386          case Variable:
    384                 os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";
    385                 if ( variable.assertions ) {
    386                         os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    387                         variable.assertions->printList( os, indent + 4 );
    388                         os << string( indent + 2, ' ' );
    389                 } // if
     387                // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";
     388                // if ( variable.assertions ) {
     389                //      os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
     390                //      variable.assertions->printList( os, indent + 4 );
     391                //      os << string( indent + 2, ' ' );
     392                // } // if
    390393                break;
    391394          case Tuple:
     
    403406                break;
    404407          case Attr:
    405                 os << "attribute type decl " << attr.name << " applied to ";
    406                 if ( attr.expr ) {
    407                         attr.expr->print( os, indent + 2 );
    408                 } // if
    409                 if ( attr.type ) {
    410                         attr.type->print( os, indent + 2 );
    411                 } // if
     408                // os << "attribute type decl " << attr.name << " applied to ";
     409                // if ( attr.expr ) {
     410                //      attr.expr->print( os, indent + 2 );
     411                // } // if
     412                // if ( attr.type ) {
     413                //      attr.type->print( os, indent + 2 );
     414                // } // if
    412415                break;
    413416          case Builtin:
     
    479482                return new VarArgsType( buildQualifiers( td ) );
    480483          case TypeData::Attr:
     484                assert( false );
    481485                return buildAttr( td );
    482486          case TypeData::Symbolic:
     
    824828
    825829TypeDecl * buildVariable( const TypeData * td ) {
    826         assert( td->kind == TypeData::Variable );
    827         static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    828 
    829         TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );
    830         buildList( td->variable.assertions, ret->get_assertions() );
    831         return ret;
     830        assert( false );
     831        return nullptr;
     832        // assert( td->kind == TypeData::Variable );
     833        // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     834
     835        // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );
     836        // buildList( td->variable.assertions, ret->get_assertions() );
     837        // return ret;
    832838} // buildSymbolic
    833839
     
    870876
    871877AttrType * buildAttr( const TypeData * td ) {
    872         assert( td->kind == TypeData::Attr );
    873         // assert( td->attr );
    874         AttrType * ret;
    875         if ( td->attr.expr ) {
    876                 ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() );
    877         } else {
    878                 assert( td->attr.type );
    879                 ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() );
    880         } // if
    881         return ret;
     878        assert( false );
     879        return nullptr;
     880        // assert( td->kind == TypeData::Attr );
     881        // // assert( td->attr );
     882        // AttrType * ret;
     883        // if ( td->attr.expr ) {
     884        //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() );
     885        // } else {
     886        //      assert( td->attr.type );
     887        //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() );
     888        // } // if
     889        // return ret;
    882890} // buildAttr
    883891
     
    912920                return buildSymbolic( td, name, sc );
    913921        } else if ( td->kind == TypeData::Variable ) {
     922                assert( false );
    914923                return buildVariable( td );
    915924        } else {
  • src/Parser/TypeData.h

    r8f6f47d7 r28307be  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 15:54:00 2016
    13 // Update Count     : 106
     12// Last Modified On : Mon Aug 29 22:31:52 2016
     13// Update Count     : 110
    1414//
    1515
     
    2424struct TypeData {
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    26                                 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;
     26                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
    2727
    2828        struct Basic_t {
     
    7373        };
    7474
    75         struct Variable_t {
    76                 DeclarationNode::TypeClass tyClass;
    77                 std::string name;
    78                 DeclarationNode * assertions;
    79         };
    80 
    8175        // struct Tuple_t {
    8276        //      DeclarationNode * members;
     
    9185        // };
    9286
    93         struct Attr_t {
    94                 std::string name;
    95                 ExpressionNode * expr;
    96                 DeclarationNode * type;
    97         };
    98 
     87        Kind kind;
    9988        TypeData * base;
    10089        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     
    10998                Function_t function;
    11099                Symbolic_t symbolic;
    111                 Variable_t variable;
    112100                DeclarationNode * tuple;
    113101                ExpressionNode * typeexpr;
    114                 Attr_t attr;
     102                //Attr_t attr;
    115103                // DeclarationNode::BuiltinType builtin;
    116104
Note: See TracChangeset for help on using the changeset viewer.