Changeset cd623a4


Ignore:
Timestamp:
Jun 7, 2015, 7:59:43 AM (9 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, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
5f2f2d7
Parents:
59db689
Message:

constant types, second attempt

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r59db689 rcd623a4  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 23:18:19 2015
    13 // Update Count     : 128
     12// Last Modified On : Sun Jun  7 07:58:00 2015
     13// Update Count     : 135
    1414//
    1515
     
    6060}
    6161
     62//##############################################################################
     63
    6264NullExprNode::NullExprNode() {}
    6365
     
    8486}
    8587
    86 static inline bool checku( char c ) { return c == 'u' || c == 'U'; }
    87 static inline bool checkl( char c ) { return c == 'l' || c == 'L'; }
    88 static inline bool checkf( char c ) { return c == 'f' || c == 'F'; }
    89 static inline bool checkx( char c ) { return c == 'x' || c == 'X'; }
     88//##############################################################################
     89
     90static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
     91static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
     92static inline bool checkF( char c ) { return c == 'f' || c == 'F'; }
     93static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
     94
     95// Very difficult to separate extra parts of constants during lexing because actions are not allow in the middle of
     96// patterns:
     97//
     98//              prefix action constant action suffix
     99//
     100// Alternatively, breaking a pattern using BEGIN does not work if the following pattern can be empty:
     101//
     102//              constant BEGIN CONT ...
     103//              <CONT>(...)? BEGIN 0 ... // possible empty suffix
     104//
     105// because the CONT rule is NOT triggered if the pattern is empty. Hence, constants are reparsed here to determine their
     106// type.
    90107
    91108ConstantNode::ConstantNode( Type t, string *inVal ) : type( t ), value( *inVal ) {
     109        // lexing divides constants into 4 kinds
    92110        switch ( type ) {
    93           case Float:
    94                 {
    95                         size_t len = value.length() - 1;
    96 
    97                         btype = BasicType::Double;                                      // default
    98                         if ( checkf( value[len] ) ) {
    99                                 btype = BasicType::Float;
    100                         } // if
    101                         if ( checkl( value[len] ) ) {
    102                                 btype = BasicType::LongDouble;
    103                         } // if
    104                         break;
    105                 }
    106111          case Integer:
    107112                {
     
    115120                        int size;                                                                       // 0 => int, 1 => long, 2 => long long
    116121
    117                         if ( value[0] == '0' ) {                                        // octal ?
     122                        if ( value[0] == '0' ) {                                        // octal constant ?
    118123                                dec = false;
    119                                 if ( last != 0 && checkx( value[1] ) ) { // hex ?
     124                                if ( last != 0 && checkX( value[1] ) ) { // hex constant ?
    120125                                        sscanf( (char *)value.c_str(), "%llx", &v );
    121126                                        //printf( "%llx %llu\n", v, v );
     
    124129                                        //printf( "%llo %llu\n", v, v );
    125130                                } // if
    126                         } else {                                                                        // decimal ?
     131                        } else {                                                                        // decimal constant ?
    127132                                sscanf( (char *)value.c_str(), "%lld", &v );
    128133                                //printf( "%llu %llu\n", v, v );
     
    146151                        } // if
    147152
    148                         if ( checku( value[last] ) ) {                          // suffix 'u' ?
     153                        if ( checkU( value[last] ) ) {                          // suffix 'u' ?
    149154                                Unsigned = true;
    150                                 if ( checkl( value[ last - 1 ] ) ) {    // suffix 'l' ?
     155                                if ( checkL( value[ last - 1 ] ) ) {    // suffix 'l' ?
    151156                                        size = 1;
    152                                         if ( checkl( value[ last - 1 ] ) ) { // suffix 'll' ?
     157                                        if ( checkL( value[ last - 1 ] ) ) { // suffix 'll' ?
    153158                                                size = 2;
    154159                                        } // if
    155160                                } // if
    156                         } else if ( checkl( value[ last ] ) ) {         // suffix 'l' ?
     161                        } else if ( checkL( value[ last ] ) ) {         // suffix 'l' ?
    157162                                size = 1;
    158                                 if ( checkl( value[ last - 1 ] ) ) {    // suffix 'll' ?
     163                                if ( checkL( value[ last - 1 ] ) ) {    // suffix 'll' ?
    159164                                        size = 2;
    160165                                } // if
    161                                 if ( checku( value[ last - 1 ] ) ) {    // suffix 'u' ?
     166                                if ( checkU( value[ last - 1 ] ) ) {    // suffix 'u' ?
    162167                                        Unsigned = true;
    163168                                } // if
    164169                        } // if
    165                         btype = kind[Unsigned][size];                           // loopup type of constant
     170                        btype = kind[Unsigned][size];                           // lookup constant type
     171                        break;
     172                }
     173          case Float:
     174                {
     175                        size_t len = value.length() - 1;
     176
     177                        btype = BasicType::Double;                                      // default
     178                        if ( checkF( value[len] ) ) {                           // float ?
     179                                btype = BasicType::Float;
     180                        } // if
     181                        if ( checkL( value[len] ) ) {                           // long double ?
     182                                btype = BasicType::LongDouble;
     183                        } // if
    166184                        break;
    167185                }
     
    185203} // ConstantNode::ConstantNode
    186204
    187 ConstantNode::Type ConstantNode::get_type( void ) const {
    188         return type;
    189 }
    190 
    191205ConstantNode *ConstantNode::appendstr( const std::string *newValue ) {
    192206        assert( newValue != 0 );
    193207        assert( type == String );
    194208
    195         //printf( "%lu \"%s\" \"%s\"\n", value.length() - 1, value.c_str(), newValue->substr( 1, newValue->length() - 2 ).c_str() );
     209        // "abc" "def" "ghi" => "abcdefghi", so remove new text from quotes and insert before last quote in old string.
    196210        value.insert( value.length() - 1, newValue->substr( 1, newValue->length() - 2 ) );
    197211       
    198         delete newValue;                                                                        // allocated by yacc
     212        delete newValue;                                                                        // allocated by lexer
    199213        return this;
    200214}
     
    226240
    227241Expression *ConstantNode::build() const {
    228         ::Type::Qualifiers q;
    229         BasicType *bt;
     242        ::Type::Qualifiers q;                                                           // no qualifiers on constants
    230243
    231244        switch ( get_type() ) {
     
    241254                }
    242255          default:
    243                 bt = new BasicType( q, btype );
    244                 return new ConstantExpr( Constant( bt, get_value() ), maybeBuild< Expression >( get_argName() ) );
     256                return new ConstantExpr( Constant( new BasicType( q, btype ), get_value() ), maybeBuild< Expression >( get_argName() ) );
    245257        }
    246258}
     259
     260//##############################################################################
    247261
    248262VarRefNode::VarRefNode() : isLabel( false ) {}
     
    268282        os << endl;
    269283}
     284
     285//##############################################################################
    270286
    271287OperatorNode::OperatorNode( Type t ) : type( t ) {}
     
    300316        "Cond",   "NCond",
    301317        // diadic
    302         "SizeOf",      "AlignOf", "Attr", "CompLit", "Plus",    "Minus",   "Mul",     "Div",     "Mod",      "Or",
     318        "SizeOf",     "AlignOf", "Attr", "CompLit", "Plus",    "Minus",   "Mul",     "Div",     "Mod",      "Or",
    303319        "And",       "BitOr",   "BitAnd",  "Xor",     "Cast",    "LShift",  "RShift",  "LThan",   "GThan",
    304320        "LEThan",    "GEThan", "Eq",      "Neq",     "Assign",  "MulAssn", "DivAssn", "ModAssn", "PlusAssn",
     
    308324        "UnPlus", "UnMinus", "AddressOf", "PointTo", "Neg", "BitNeg", "Incr", "IncrPost", "Decr", "DecrPost", "LabelAddress"
    309325};
     326
     327//##############################################################################
    310328
    311329CompositeExprNode::CompositeExprNode( void ) : ExpressionNode(), function( 0 ), arguments( 0 ) {
     
    362380        buildList( get_args(), args );
    363381
    364         if ( ! ( op = dynamic_cast<OperatorNode *>( function )) ) {
    365                 // a function as opposed to an operator
     382        if ( ! ( op = dynamic_cast<OperatorNode *>( function ) ) ) { // function as opposed to operator
    366383                return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));
    367         } else {
    368                 switch ( op->get_type()) {
    369                   case OperatorNode::Incr:
    370                   case OperatorNode::Decr:
    371                   case OperatorNode::IncrPost:
    372                   case OperatorNode::DecrPost:
    373                   case OperatorNode::Assign:
    374                   case OperatorNode::MulAssn:
    375                   case OperatorNode::DivAssn:
    376                   case OperatorNode::ModAssn:
    377                   case OperatorNode::PlusAssn:
    378                   case OperatorNode::MinusAssn:
    379                   case OperatorNode::LSAssn:
    380                   case OperatorNode::RSAssn:
    381                   case OperatorNode::AndAssn:
    382                   case OperatorNode::ERAssn:
    383                   case OperatorNode::OrAssn:
    384                         // the rewrite rules for these expressions specify that the first argument has its address taken
    385                         assert( ! args.empty() );
    386                         args.front() = new AddressExpr( args.front() );
    387                         break;
    388                   default:
    389                         /* do nothing */
    390                         ;
    391                 }
    392 
    393                 switch ( op->get_type() ) {
    394                   case OperatorNode::Incr:
    395                   case OperatorNode::Decr:
    396                   case OperatorNode::IncrPost:
    397                   case OperatorNode::DecrPost:
    398                   case OperatorNode::Assign:
    399                   case OperatorNode::MulAssn:
    400                   case OperatorNode::DivAssn:
    401                   case OperatorNode::ModAssn:
    402                   case OperatorNode::PlusAssn:
    403                   case OperatorNode::MinusAssn:
    404                   case OperatorNode::LSAssn:
    405                   case OperatorNode::RSAssn:
    406                   case OperatorNode::AndAssn:
    407                   case OperatorNode::ERAssn:
    408                   case OperatorNode::OrAssn:
    409                   case OperatorNode::Plus:
    410                   case OperatorNode::Minus:
    411                   case OperatorNode::Mul:
    412                   case OperatorNode::Div:
    413                   case OperatorNode::Mod:
    414                   case OperatorNode::BitOr:
    415                   case OperatorNode::BitAnd:
    416                   case OperatorNode::Xor:
    417                   case OperatorNode::LShift:
    418                   case OperatorNode::RShift:
    419                   case OperatorNode::LThan:
    420                   case OperatorNode::GThan:
    421                   case OperatorNode::LEThan:
    422                   case OperatorNode::GEThan:
    423                   case OperatorNode::Eq:
    424                   case OperatorNode::Neq:
    425                   case OperatorNode::Index:
    426                   case OperatorNode::Range:
    427                   case OperatorNode::UnPlus:
    428                   case OperatorNode::UnMinus:
    429                   case OperatorNode::PointTo:
    430                   case OperatorNode::Neg:
    431                   case OperatorNode::BitNeg:
    432                   case OperatorNode::LabelAddress:
    433                         return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args );
    434                   case OperatorNode::AddressOf:
    435                         assert( args.size() == 1 );
    436                         assert( args.front() );
    437 
    438                         return new AddressExpr( args.front() );
    439                   case OperatorNode::Cast:
    440                         {
    441                                 TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());
    442                                 assert( arg );
    443 
    444                                 DeclarationNode *decl_node = arg->get_decl();
    445                                 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());
    446 
    447                                 Type *targetType = decl_node->buildType();
    448                                 if ( dynamic_cast< VoidType* >( targetType ) ) {
    449                                         delete targetType;
    450                                         return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
    451                                 } else {
    452                                         return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
    453                                 } // if
    454                         }
    455                   case OperatorNode::FieldSel:
    456                         {
    457                                 assert( args.size() == 2 );
    458 
    459                                 NameExpr *member = dynamic_cast<NameExpr *>( args.back());
    460                                 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back());
    461 
    462                                 if ( member != 0 ) {
    463                                         UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front());
    464                                         delete member;
    465                                         return ret;
    466                                         /* else if ( memberTup != 0 )
    467                                            {
    468                                            UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());
    469                                            delete member;
    470                                            return ret;
    471                                            } */
    472                                 } else
    473                                         assert( false );
    474                         }
    475                   case OperatorNode::PFieldSel:
    476                         {
    477                                 assert( args.size() == 2 );
    478 
    479                                 NameExpr *member = dynamic_cast<NameExpr *>( args.back());  // modify for Tuples   xxx
    480                                 assert( member != 0 );
    481 
    482                                 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    483                                 deref->get_args().push_back( args.front() );
    484 
    485                                 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
     384        } // if
     385
     386        switch ( op->get_type()) {
     387          case OperatorNode::Incr:
     388          case OperatorNode::Decr:
     389          case OperatorNode::IncrPost:
     390          case OperatorNode::DecrPost:
     391          case OperatorNode::Assign:
     392          case OperatorNode::MulAssn:
     393          case OperatorNode::DivAssn:
     394          case OperatorNode::ModAssn:
     395          case OperatorNode::PlusAssn:
     396          case OperatorNode::MinusAssn:
     397          case OperatorNode::LSAssn:
     398          case OperatorNode::RSAssn:
     399          case OperatorNode::AndAssn:
     400          case OperatorNode::ERAssn:
     401          case OperatorNode::OrAssn:
     402                // the rewrite rules for these expressions specify that the first argument has its address taken
     403                assert( ! args.empty() );
     404                args.front() = new AddressExpr( args.front() );
     405                break;
     406          default:
     407                /* do nothing */
     408                ;
     409        }
     410
     411        switch ( op->get_type() ) {
     412          case OperatorNode::Incr:
     413          case OperatorNode::Decr:
     414          case OperatorNode::IncrPost:
     415          case OperatorNode::DecrPost:
     416          case OperatorNode::Assign:
     417          case OperatorNode::MulAssn:
     418          case OperatorNode::DivAssn:
     419          case OperatorNode::ModAssn:
     420          case OperatorNode::PlusAssn:
     421          case OperatorNode::MinusAssn:
     422          case OperatorNode::LSAssn:
     423          case OperatorNode::RSAssn:
     424          case OperatorNode::AndAssn:
     425          case OperatorNode::ERAssn:
     426          case OperatorNode::OrAssn:
     427          case OperatorNode::Plus:
     428          case OperatorNode::Minus:
     429          case OperatorNode::Mul:
     430          case OperatorNode::Div:
     431          case OperatorNode::Mod:
     432          case OperatorNode::BitOr:
     433          case OperatorNode::BitAnd:
     434          case OperatorNode::Xor:
     435          case OperatorNode::LShift:
     436          case OperatorNode::RShift:
     437          case OperatorNode::LThan:
     438          case OperatorNode::GThan:
     439          case OperatorNode::LEThan:
     440          case OperatorNode::GEThan:
     441          case OperatorNode::Eq:
     442          case OperatorNode::Neq:
     443          case OperatorNode::Index:
     444          case OperatorNode::Range:
     445          case OperatorNode::UnPlus:
     446          case OperatorNode::UnMinus:
     447          case OperatorNode::PointTo:
     448          case OperatorNode::Neg:
     449          case OperatorNode::BitNeg:
     450          case OperatorNode::LabelAddress:
     451                return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args );
     452          case OperatorNode::AddressOf:
     453                assert( args.size() == 1 );
     454                assert( args.front() );
     455
     456                return new AddressExpr( args.front() );
     457          case OperatorNode::Cast:
     458                {
     459                        TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());
     460                        assert( arg );
     461
     462                        DeclarationNode *decl_node = arg->get_decl();
     463                        ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());
     464
     465                        Type *targetType = decl_node->buildType();
     466                        if ( dynamic_cast< VoidType* >( targetType ) ) {
     467                                delete targetType;
     468                                return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
     469                        } else {
     470                                return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
     471                        } // if
     472                }
     473          case OperatorNode::FieldSel:
     474                {
     475                        assert( args.size() == 2 );
     476
     477                        NameExpr *member = dynamic_cast<NameExpr *>( args.back());
     478                        // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back());
     479
     480                        if ( member != 0 ) {
     481                                UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front());
    486482                                delete member;
    487483                                return ret;
     484                                /* else if ( memberTup != 0 )
     485                                   {
     486                                   UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());
     487                                   delete member;
     488                                   return ret;
     489                                   } */
     490                        } else
     491                                assert( false );
     492                }
     493          case OperatorNode::PFieldSel:
     494                {
     495                        assert( args.size() == 2 );
     496
     497                        NameExpr *member = dynamic_cast<NameExpr *>( args.back());  // modify for Tuples   xxx
     498                        assert( member != 0 );
     499
     500                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     501                        deref->get_args().push_back( args.front() );
     502
     503                        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
     504                        delete member;
     505                        return ret;
     506                }
     507          case OperatorNode::AlignOf:
     508          case OperatorNode::SizeOf:
     509                {
     510///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
     511
     512                        if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
     513                                return new SizeofExpr( arg->get_decl()->buildType());
     514                        } else {
     515                                return new SizeofExpr( args.front());
     516                        } // if
     517                }
     518          case OperatorNode::Attr:
     519                {
     520                        VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());
     521                        assert( var );
     522                        if ( ! get_args()->get_link() ) {
     523                                return new AttrExpr( var->build(), ( Expression*)0);
     524                        } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
     525                                return new AttrExpr( var->build(), arg->get_decl()->buildType());
     526                        } else {
     527                                return new AttrExpr( var->build(), args.back());
     528                        } // if
     529                }
     530          case OperatorNode::CompLit:
     531                throw UnimplementedError( "C99 compound literals" );
     532                // the short-circuited operators
     533          case OperatorNode::Or:
     534          case OperatorNode::And:
     535                assert( args.size() == 2);
     536                return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );
     537          case OperatorNode::Cond:
     538                {
     539                        assert( args.size() == 3);
     540                        std::list< Expression* >::const_iterator i = args.begin();
     541                        Expression *arg1 = notZeroExpr( *i++ );
     542                        Expression *arg2 = *i++;
     543                        Expression *arg3 = *i++;
     544                        return new ConditionalExpr( arg1, arg2, arg3 );
     545                }
     546          case OperatorNode::NCond:
     547                throw UnimplementedError( "GNU 2-argument conditional expression" );
     548          case OperatorNode::Comma:
     549                {
     550                        assert( args.size() == 2);
     551                        std::list< Expression* >::const_iterator i = args.begin();
     552                        Expression *ret = *i++;
     553                        while ( i != args.end() ) {
     554                                ret = new CommaExpr( ret, *i++ );
    488555                        }
    489                   case OperatorNode::AlignOf:
    490                   case OperatorNode::SizeOf:
    491                         {
    492 ///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
    493 
    494                                 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
    495                                         return new SizeofExpr( arg->get_decl()->buildType());
    496                                 } else {
    497                                         return new SizeofExpr( args.front());
    498                                 } // if
    499                         }
    500                   case OperatorNode::Attr:
    501                         {
    502                                 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());
    503                                 assert( var );
    504                                 if ( ! get_args()->get_link() ) {
    505                                         return new AttrExpr( var->build(), ( Expression*)0);
    506                                 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
    507                                         return new AttrExpr( var->build(), arg->get_decl()->buildType());
    508                                 } else {
    509                                         return new AttrExpr( var->build(), args.back());
    510                                 } // if
    511                         }
    512                   case OperatorNode::CompLit:
    513                         throw UnimplementedError( "C99 compound literals" );
    514                         // the short-circuited operators
    515                   case OperatorNode::Or:
    516                   case OperatorNode::And:
    517                         assert( args.size() == 2);
    518                         return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );
    519                   case OperatorNode::Cond:
    520                         {
    521                                 assert( args.size() == 3);
    522                                 std::list< Expression* >::const_iterator i = args.begin();
    523                                 Expression *arg1 = notZeroExpr( *i++ );
    524                                 Expression *arg2 = *i++;
    525                                 Expression *arg3 = *i++;
    526                                 return new ConditionalExpr( arg1, arg2, arg3 );
    527                         }
    528                   case OperatorNode::NCond:
    529                         throw UnimplementedError( "GNU 2-argument conditional expression" );
    530                   case OperatorNode::Comma:
    531                         {
    532                                 assert( args.size() == 2);
    533                                 std::list< Expression* >::const_iterator i = args.begin();
    534                                 Expression *ret = *i++;
    535                                 while ( i != args.end() ) {
    536                                         ret = new CommaExpr( ret, *i++ );
    537                                 }
    538                                 return ret;
    539                         }
    540                         // Tuples
    541                   case OperatorNode::TupleC:
    542                         {
    543                                 TupleExpr *ret = new TupleExpr();
    544                                 std::copy( args.begin(), args.end(), back_inserter( ret->get_exprs() ) );
    545                                 return ret;
    546                         }
    547                   default:
    548                         // shouldn't happen
    549                         return 0;
    550                 }
    551         }
     556                        return ret;
     557                }
     558                // Tuples
     559          case OperatorNode::TupleC:
     560                {
     561                        TupleExpr *ret = new TupleExpr();
     562                        std::copy( args.begin(), args.end(), back_inserter( ret->get_exprs() ) );
     563                        return ret;
     564                }
     565          default:
     566                // shouldn't happen
     567                return 0;
     568        } // switch
    552569}
    553570
     
    598615}
    599616
     617//##############################################################################
     618
    600619CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode( OperatorNode::Comma )) {}
    601620
     
    615634}
    616635
     636//##############################################################################
     637
    617638ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
    618639
     
    637658        return new UntypedValofExpr ( get_body()->build(), maybeBuild< Expression >( get_argName() ) );
    638659}
     660
     661//##############################################################################
    639662
    640663ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
     
    689712}
    690713
    691 TypeValueNode::TypeValueNode( DeclarationNode *decl )
    692         : decl( decl ) {
    693 }
    694 
    695 TypeValueNode::TypeValueNode( const TypeValueNode &other )
    696         : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
     714//##############################################################################
     715
     716TypeValueNode::TypeValueNode( DeclarationNode *decl ) : decl( decl ) {
     717}
     718
     719TypeValueNode::TypeValueNode( const TypeValueNode &other ) : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
    697720}
    698721
     
    712735
    713736ExpressionNode *flattenCommas( ExpressionNode *list ) {
    714         if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) )
    715                 {
    716                         OperatorNode *op;
    717                         if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) )
    718                                 {
    719                                         if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
    720                                                 composite->add_arg( next );
    721                                         return flattenCommas( composite->get_args() );
    722                                 }
    723                 }
     737        if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {
     738                OperatorNode *op;
     739                if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) ) {
     740                        if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
     741                                composite->add_arg( next );
     742                        return flattenCommas( composite->get_args() );
     743                } // if
     744        } // if
    724745
    725746        if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
     
    734755                if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::TupleC ) )
    735756                        return composite->get_args();
    736         }
     757        } // if
    737758        return tuple;
    738759}
  • src/Parser/ParseNode.h

    r59db689 rcd623a4  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 23:35:33 2015
    13 // Update Count     : 60
     12// Last Modified On : Sun Jun  7 07:42:50 2015
     13// Update Count     : 64
    1414//
    1515
     
    101101class ConstantNode : public ExpressionNode {
    102102  public:
    103         enum Type {
    104                 Integer, Float, Character, String /* , Range, EnumConstant  */
    105         };
     103        enum Type { Integer, Float, Character, String };
    106104
    107105        ConstantNode( Type, std::string * );
    108106
    109107        virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
    110 
    111         Type get_type() const ;
     108        Type get_type( void ) const { return type; }
    112109        virtual void print( std::ostream &, int indent = 0) const;
    113110        virtual void printOneLine( std::ostream &, int indent = 0) const;
  • src/Parser/lex.cc

    r59db689 rcd623a4  
    13901390 * Created On       : Sat Sep 22 08:58:10 2001
    13911391 * Last Modified By : Peter A. Buhr
    1392  * Last Modified On : Fri Jun  5 17:50:17 2015
    1393  * Update Count     : 373
     1392 * Last Modified On : Sun Jun  7 07:14:16 2015
     1393 * Update Count     : 374
    13941394 */
    13951395#line 19 "lex.ll"
     
    17791779;
    17801780        YY_BREAK
    1781 /* ignore C style comments */
     1781/* ignore C style comments (ALSO HANDLED BY CPP) */
    17821782case 3:
    17831783YY_RULE_SETUP
     
    17961796{ BEGIN 0; }
    17971797        YY_BREAK
    1798 /* ignore C++ style comments */
     1798/* ignore C++ style comments (ALSO HANDLED BY CPP) */
    17991799case 6:
    18001800/* rule 6 can match eol */
     
    23542354YY_RULE_SETUP
    23552355#line 299 "lex.ll"
    2356 {}                                              // continuation
     2356{}                                              // continuation (ALSO HANDLED BY CPP)
    23572357        YY_BREAK
    23582358case 115:
  • src/Parser/lex.ll

    r59db689 rcd623a4  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Fri Jun  5 17:50:17 2015
    13  * Update Count     : 373
     12 * Last Modified On : Sun Jun  7 07:14:16 2015
     13 * Update Count     : 374
    1414 */
    1515
     
    167167^{h_white}*"#"[^\n]*"\n" ;
    168168
    169                                 /* ignore C style comments */
     169                                /* ignore C style comments (ALSO HANDLED BY CPP) */
    170170"/*"                    { BEGIN COMMENT; }
    171 <COMMENT>.|\n           ;
    172 <COMMENT>"*/"           { BEGIN 0; }
    173 
    174                                 /* ignore C++ style comments */
    175 "//"[^\n]*"\n"          ;
     171<COMMENT>.|\n   ;
     172<COMMENT>"*/"   { BEGIN 0; }
     173
     174                                /* ignore C++ style comments (ALSO HANDLED BY CPP) */
     175"//"[^\n]*"\n"  ;
    176176
    177177                                /* ignore whitespace */
     
    297297                                /* common character/string constant */
    298298<QUOTE,STRING>{escape_seq} { rm_underscore(); *strtext += std::string( yytext ); }
    299 <QUOTE,STRING>"\\"{h_white}*"\n" {}                                             // continuation
     299<QUOTE,STRING>"\\"{h_white}*"\n" {}                                             // continuation (ALSO HANDLED BY CPP)
    300300<QUOTE,STRING>"\\" { *strtext += std::string( yytext ); } // unknown escape character
    301301
  • src/SynTree/Expression.cc

    r59db689 rcd623a4  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 14:13:39 2015
    13 // Update Count     : 14
     12// Last Modified On : Sat Jun  6 23:43:22 2015
     13// Update Count     : 15
    1414//
    1515
     
    7272
    7373void ConstantExpr::print( std::ostream &os, int indent ) const {
    74         os << std::string( indent, ' ' ) << "constant expression: " ;
     74        os << "constant expression: " ;
    7575        constant.print( os );
    7676        Expression::print( os, indent );
Note: See TracChangeset for help on using the changeset viewer.