Changes in / [cb98d9d:d3a49864]


Ignore:
Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rcb98d9d rd3a49864  
    5353        linkage( ::linkage ) {
    5454
     55//      variable.name = nullptr;
    5556        variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;
    5657        variable.assertions = nullptr;
     
    6465        delete name;
    6566
     67//      delete variable.name;
    6668        delete variable.assertions;
    6769        delete variable.initializer;
    6870
    69         delete type;
     71//      delete type;
    7072        delete bitfieldWidth;
    7173
     
    98100        newnode->error = error;
    99101
     102//      newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
    100103        newnode->variable.tyClass = variable.tyClass;
    101104        newnode->variable.assertions = maybeCopy( variable.assertions );
     
    225228} // DeclarationNode::newEnumValueGeneric
    226229
    227 DeclarationNode * DeclarationNode::newEnumInLine( const std::string * name ) {
    228         DeclarationNode * newnode = newName( name );
     230DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
     231        DeclarationNode * newnode = newName( new std::string(name) );
    229232        newnode->enumInLine = true;
    230233        return newnode;
     
    457460                SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, TypeData::builtinTypeNames[builtin] );
    458461        } // if
    459         type = ::addQualifiers( type, q->type );
     462        type = ::addQualifiers( q->type, type );
    460463        q->type = nullptr;
    461464
     
    470473        copySpecifiers( o, copyattr );
    471474        if ( o->type ) {
    472                 type = ::addType( type, o->type, o->attributes );
     475                type = ::addType( o->type, type, o->attributes );
    473476                o->type = nullptr;
    474477        } // if
     
    581584DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    582585        if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
    583                 extend( variable.assertions, assertions );
     586                if ( variable.assertions ) {
     587                        variable.assertions->set_last( assertions );
     588                } else {
     589                        variable.assertions = assertions;
     590                } // if
    584591                return this;
    585592        } // if
    586593
    587594        assert( type );
    588         assert( TypeData::Symbolic == type->kind );
    589         extend( type->symbolic.assertions, assertions );
     595        switch ( type->kind ) {
     596        case TypeData::Symbolic:
     597                if ( type->symbolic.assertions ) {
     598                        type->symbolic.assertions->set_last( assertions );
     599                } else {
     600                        type->symbolic.assertions = assertions;
     601                } // if
     602                break;
     603        default:
     604                assert( false );
     605        } // switch
    590606
    591607        return this;
     
    672688
    673689DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
    674         if ( !p ) return this;
    675         assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
    676         if ( type ) {
    677                 p->type->base = makeNewBase( type );
    678                 type = nullptr;
    679         } // if
    680         delete this;
    681         return p;
     690        if ( p ) {
     691                assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference );
     692                if ( type ) {
     693                        p->type->base = makeNewBase( type );
     694                        type = nullptr;
     695                } // if
     696                delete this;
     697                return p;
     698        } else {
     699                return this;
     700        } // if
    682701}
    683702
    684703DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
    685         if ( !a ) return this;
     704        if ( ! a ) return this;
    686705        assert( a->type->kind == TypeData::Array );
    687706        if ( type ) {
     
    755774                        if ( ret->kind == TypeData::Aggregate ) {
    756775                                newnode->attributes.swap( ret->aggregate.attributes );
    757                         } // if
     776                        } // if 
    758777                        return newnode;
    759778                } // if
  • src/Parser/DeclarationNode.h

    rcb98d9d rd3a49864  
    3030        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    3131        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
    32         static DeclarationNode * newEnumInLine( const std::string * name );
     32        static DeclarationNode * newEnumInLine( const std::string name );
    3333        static DeclarationNode * newName( const std::string * );
    3434        static DeclarationNode * newTypeParam( ast::TypeDecl::Kind, const std::string * );
     
    9999
    100100        struct Variable_t {
     101//              const std::string * name;
    101102                ast::TypeDecl::Kind tyClass;
    102103                DeclarationNode * assertions;
  • src/Parser/ParseNode.h

    rcb98d9d rd3a49864  
    8282};
    8383
    84 template<typename Node>
    85 void extend( Node *& list, Node * value ) {
    86         if ( list ) {
    87                 extend( list->next, value );
    88         } else {
    89                 list = value;
    90         }
    91 }
    92 
    9384// Must harmonize with OperName.
    9485enum class OperKinds {
  • src/Parser/TypeData.cc

    rcb98d9d rd3a49864  
    475475
    476476
    477 // Wrap an aggregate up in an instance. Takes and gives ownership.
    478 static TypeData * makeInstance( TypeData * type ) {
    479         assert( TypeData::Aggregate == type->kind );
    480         TypeData * out = new TypeData( TypeData::AggregateInst );
    481         out->aggInst.aggregate = type;
    482         out->aggInst.params = maybeCopy( type->aggregate.actuals );
    483         out->aggInst.hoistType = type->aggregate.body;
    484         out->qualifiers |= type->qualifiers;
    485         return out;
    486 }
    487 
    488 
    489477TypeData * build_type_qualifier( ast::CV::Qualifiers tq ) {
    490478        TypeData * type = new TypeData;
     
    576564
    577565// Takes ownership of all arguments, gives ownership of return value.
    578 TypeData * addQualifiers( TypeData * dst, TypeData * src ) {
    579         if ( src->forall ) {
    580                 if ( dst->forall || TypeData::Aggregate != dst->kind ) {
    581                         extend( dst->forall, src->forall );
     566TypeData * addQualifiers( TypeData * ltype, TypeData * rtype ) {
     567        if ( ltype->forall ) {
     568                if ( rtype->forall ) {
     569                        rtype->forall->set_last( ltype->forall );
     570                } else if ( TypeData::Aggregate != rtype->kind ) {
     571                        rtype->forall = ltype->forall;
     572                } else if ( rtype->aggregate.params ) {
     573                        rtype->aggregate.params->set_last( ltype->forall );
    582574                } else {
    583                         extend( dst->aggregate.params, src->forall );
     575                        rtype->aggregate.params = ltype->forall;
    584576                }
    585                 src->forall = nullptr;
     577                ltype->forall = nullptr;
    586578        }
    587579
    588         addQualifiersToType( dst, src );
    589         return dst;
     580        addQualifiersToType( rtype, ltype );
     581        return rtype;
    590582}
    591583
     
    593585static void addTypeToType( TypeData *& dst, TypeData *& src ) {
    594586        if ( src->forall && dst->kind == TypeData::Function ) {
    595                 extend( dst->forall, src->forall );
     587                if ( dst->forall ) {
     588                        dst->forall->set_last( src->forall );
     589                } else {
     590                        dst->forall = src->forall;
     591                } // if
    596592                src->forall = nullptr;
    597593        } // if
     
    645641                break;
    646642        default:
    647                 if ( TypeData::Aggregate == src->kind ) {
    648                         dst->base = makeInstance( src );
    649                 } else {
    650                         extend( dst->forall, src->forall );
     643                switch ( src->kind ) {
     644                case TypeData::Aggregate:
     645                        dst->base = new TypeData( TypeData::AggregateInst );
     646                        dst->base->aggInst.aggregate = src;
     647                        if ( src->kind == TypeData::Aggregate ) {
     648                                dst->base->aggInst.params = maybeCopy( src->aggregate.actuals );
     649                        } // if
     650                        dst->base->qualifiers |= src->qualifiers;
     651                        src = nullptr;
     652                        break;
     653                default:
     654                        if ( dst->forall ) {
     655                                dst->forall->set_last( src->forall );
     656                        } else {
     657                                dst->forall = src->forall;
     658                        } // if
    651659                        src->forall = nullptr;
    652660                        dst->base = src;
    653                 }
    654                 src = nullptr;
     661                        src = nullptr;
     662                } // switch
    655663        } // switch
    656664}
    657665
    658666// Takes ownership of all arguments, gives ownership of return value.
    659 TypeData * addType( TypeData * dst, TypeData * src, std::vector<ast::ptr<ast::Attribute>> & attributes ) {
    660         if ( dst ) {
    661                 addTypeToType( dst, src );
    662         } else if ( src->kind == TypeData::Aggregate ) {
    663                 // Hide type information aggregate instances.
    664                 dst = makeInstance( src );
    665                 dst->aggInst.aggregate->aggregate.attributes.swap( attributes );
     667TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & attributes ) {
     668        if ( rtype ) {
     669                addTypeToType( rtype, ltype );
     670                return rtype;
    666671        } else {
    667                 dst = src;
     672                if ( ltype->kind == TypeData::Aggregate ) {
     673                        // Hide type information aggregate instances.
     674                        rtype = new TypeData( TypeData::AggregateInst );
     675                        rtype->aggInst.aggregate = ltype;
     676                        rtype->aggInst.aggregate->aggregate.attributes.swap( attributes ); // change ownership
     677                        rtype->aggInst.hoistType = ltype->aggregate.body;
     678                        rtype->aggInst.params = maybeCopy( ltype->aggregate.actuals );
     679                        rtype->qualifiers |= ltype->qualifiers;
     680                } else {
     681                        rtype = ltype;
     682                } // if
     683                return rtype;
    668684        } // if
    669         return dst;
    670 }
    671 
    672 TypeData * addType( TypeData * dst, TypeData * src ) {
     685}
     686
     687TypeData * addType( TypeData * ltype, TypeData * rtype ) {
    673688        std::vector<ast::ptr<ast::Attribute>> attributes;
    674         return addType( dst, src, attributes );
     689        return addType( ltype, rtype, attributes );
    675690}
    676691
     
    698713
    699714TypeData * makeNewBase( TypeData * type ) {
    700         return ( TypeData::Aggregate == type->kind ) ? makeInstance( type ) : type;
     715        switch ( type->kind ) {
     716        case TypeData::Aggregate: {
     717                TypeData * out = new TypeData( TypeData::AggregateInst );
     718                out->aggInst.aggregate = type;
     719                if ( TypeData::Aggregate == type->kind ) {
     720                        out->aggInst.params = maybeCopy( type->aggregate.actuals );
     721                }
     722                out->qualifiers |= type->qualifiers;
     723                return out;
     724        }
     725        default:
     726                return type;
     727        } // switch
    701728}
    702729
  • src/Parser/parser.yy

    rcb98d9d rd3a49864  
    28152815                { $$ = DeclarationNode::newEnumValueGeneric( $2, $3 ); }
    28162816        | INLINE type_name
    2817                 {
    2818                         $$ = DeclarationNode::newEnumInLine( $2->symbolic.name );
    2819                         $2->symbolic.name = nullptr;
    2820                         delete $2;
    2821                 }
     2817                { $$ = DeclarationNode::newEnumInLine( *$2->symbolic.name ); }
    28222818        | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt
    28232819                { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }
Note: See TracChangeset for help on using the changeset viewer.