Ignore:
Timestamp:
Aug 19, 2016, 2:42:04 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
e85a8631
Parents:
03da511 (diff), ac71a86 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ctor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r03da511 r04cdd9b  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  7 09:23:12 2016
    13 // Update Count     : 437
     12// Last Modified On : Tue Aug 16 00:09:20 2016
     13// Update Count     : 495
    1414//
    1515
     
    3232using namespace std;
    3333
    34 ExpressionNode::ExpressionNode() : ParseNode() {}
    35 
    36 ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ) {}
    37 
    38 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ), extension( other.extension ) {
    39         if ( other.argName ) {
    40                 std::cout << "ExpressionNode" << std::endl;
    41                 argName = other.argName->clone();
    42         } else {
    43                 argName = 0;
    44         } // if
    45 }
    46 
    47 ExpressionNode * ExpressionNode::set_argName( const std::string *aName ) {
    48         argName = new VarRefNode( aName );
    49         return this;
    50 }
    51 
    52 ExpressionNode * ExpressionNode::set_argName( ExpressionNode *aDesignator ) {
    53         argName = aDesignator;
    54         return this;
    55 }
    56 
    57 void ExpressionNode::printDesignation( std::ostream &os, int indent ) const {
    58         if ( argName ) {
    59                 os << string( indent, ' ' ) << "(designated by:  ";
    60                 argName->printOneLine( os, indent );
    61                 os << ")" << std::endl;
    62         } // if
    63 }
    64 
    65 //##############################################################################
    66 
    67 NullExprNode::NullExprNode() {}
    68 
    69 NullExprNode *NullExprNode::clone() const {
    70         return new NullExprNode();
    71 }
    72 
    73 void NullExprNode::print( std::ostream & os, int indent ) const {
    74         printDesignation( os );
    75         os << "null expression";
    76 }
    77 
    78 void NullExprNode::printOneLine( std::ostream & os, int indent ) const {
    79         printDesignation( os );
    80         os << "null";
    81 }
    82 
    83 Expression *NullExprNode::build() const {
    84         return 0;
    85 }
     34ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {}
    8635
    8736//##############################################################################
     
    10857static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    10958
    110 ConstantNode *build_constantInteger( std::string & str ) {
     59Expression *build_constantInteger( const std::string & str ) {
    11160        static const BasicType::Kind kind[2][3] = {
    11261                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     
    171120        } // if
    172121
    173         return new ConstantNode( new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) ) );
     122        return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) );
    174123} // build_constantInteger
    175124
    176 ConstantNode *build_constantFloat( std::string & str ) {
     125Expression *build_constantFloat( const std::string & str ) {
    177126        static const BasicType::Kind kind[2][3] = {
    178127                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
     
    201150        } // if
    202151
    203         return new ConstantNode( new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) ) );
     152        return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) );
    204153} // build_constantFloat
    205154
    206 ConstantNode *build_constantChar( std::string & str ) {
    207         return new ConstantNode( new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ) );
     155Expression *build_constantChar( const std::string & str ) {
     156        return new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) );
    208157} // build_constantChar
    209158
    210 ConstantNode *build_constantStr( std::string & str ) {
     159ConstantExpr *build_constantStr( const std::string & str ) {
    211160        // string should probably be a primitive type
    212161        ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( emptyQualifiers, BasicType::Char ),
     
    214163                                                                                        toString( str.size()+1-2 ) ) ),  // +1 for '\0' and -2 for '"'
    215164                                                                   false, false );
    216         return new ConstantNode( new ConstantExpr( Constant( at, str ) ) );
     165        return new ConstantExpr( Constant( at, str ) );
    217166} // build_constantStr
    218167
    219 //##############################################################################
    220 
    221 //Expression *build_varref( ExpressionNode expr ) {
    222 //      return new NameExpr( get_name(), maybeBuild<Expression>( get_argName() ) );
    223 //}
    224 
    225 VarRefNode::VarRefNode( const string *name, bool labelp ) : ExpressionNode( name ), isLabel( labelp ) {}
    226 
    227 VarRefNode::VarRefNode( const VarRefNode &other ) : ExpressionNode( other ), isLabel( other.isLabel ) {
    228 }
    229 
    230 Expression *VarRefNode::build() const {
    231         return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) );
    232 }
    233 
    234 void VarRefNode::printOneLine( std::ostream &os, int indent ) const {
    235         printDesignation( os );
    236         os << get_name() << ' ';
    237 }
    238 
    239 void VarRefNode::print( std::ostream &os, int indent ) const {
    240         printDesignation( os );
    241         os << string( indent, ' ' ) << "Referencing: ";
    242         os << "Variable: " << get_name();
    243         os << endl;
    244 }
    245 
    246 //##############################################################################
    247 
    248 DesignatorNode::DesignatorNode( ExpressionNode *expr, bool isArrayIndex ) : isArrayIndex( isArrayIndex ) {
    249         set_argName( expr );
    250         assert( get_argName() );
    251 
    252         if ( ! isArrayIndex ) {
    253                 if ( VarRefNode * var = dynamic_cast< VarRefNode * >( expr ) ) {
    254 
    255                         stringstream ss( var->get_name() );
    256                         double value;
    257                         if ( ss >> value ) {
    258                                 // this is a floating point constant. It MUST be ".0" or ".1", otherwise the program is invalid
    259                                 if ( ! (var->get_name() == ".0" || var->get_name() == ".1") ) {
    260                                         throw SemanticError( "invalid designator name: " + var->get_name() );
    261                                 } // if
    262                                 var->set_name( var->get_name().substr(1) );
    263                         } // if
    264                 } // if
    265         } // if
    266 }
    267 
    268 DesignatorNode::DesignatorNode( const DesignatorNode &other ) : ExpressionNode( other ), isArrayIndex( other.isArrayIndex ) {
    269 }
    270 
    271 class DesignatorFixer : public Mutator {
    272 public:
    273         virtual Expression* mutate( NameExpr *nameExpr ) {
    274                 if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
    275                         Constant val( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nameExpr->get_name() );
    276                         delete nameExpr;
    277                         return new ConstantExpr( val );
    278                 }
    279                 return nameExpr;
    280         }
    281 };
    282 
    283 Expression *DesignatorNode::build() const {
    284         Expression * ret = maybeBuild<Expression>(get_argName());
    285 
    286         if ( isArrayIndex ) {
    287                 // need to traverse entire structure and change any instances of 0 or 1 to ConstantExpr
    288                 DesignatorFixer fixer;
    289                 ret = ret->acceptMutator( fixer );
    290         } // if
    291 
    292         return ret;
    293 }
    294 
    295 void DesignatorNode::printOneLine( std::ostream &os, int indent ) const {
    296         if ( get_argName() ) {
    297                 if ( isArrayIndex ) {
    298                         os << "[";
    299                         get_argName()->printOneLine( os, indent );
    300                         os << "]";
    301                 } else {
    302                         os << ".";
    303                         get_argName()->printOneLine( os, indent );
    304                 }
    305         } // if
    306 }
    307 
    308 void DesignatorNode::print( std::ostream &os, int indent ) const {
    309         if ( get_argName() ) {
    310                 if ( isArrayIndex ) {
    311                         os << "[";
    312                         get_argName()->print( os, indent );
    313                         os << "]";
    314                 } else {
    315                         os << ".";
    316                         get_argName()->print( os, indent );
    317                 }
    318         } // if
    319 }
    320 
    321 //##############################################################################
     168NameExpr * build_varref( const string *name, bool labelp ) {
     169        NameExpr *expr = new NameExpr( *name, nullptr );
     170        delete name;
     171        return expr;
     172}
    322173
    323174static const char *OperName[] = {
     
    331182};
    332183
    333 //##############################################################################
    334 
    335 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node ) {
    336         DeclarationNode *decl_node = arg->get_decl();
    337 
     184Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    338185        Type *targetType = decl_node->buildType();
    339         if ( dynamic_cast< VoidType* >( targetType ) ) {
     186        if ( dynamic_cast< VoidType * >( targetType ) ) {
    340187                delete targetType;
    341                 return new CastExpr( maybeBuild<Expression>(expr_node) );
     188                return new CastExpr( maybeMoveBuild< Expression >(expr_node) );
    342189        } else {
    343                 return new CastExpr( maybeBuild<Expression>(expr_node), targetType );
    344         } // if
    345 }
    346 
    347 Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member ) {
    348         NameExpr* memberExpr = dynamic_cast<NameExpr*> ( maybeBuild<Expression>( member) );
    349         assert( memberExpr );
    350         UntypedMemberExpr *ret = new UntypedMemberExpr( memberExpr->get_name(), maybeBuild<Expression>(expr_node) );
     190                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
     191        } // if
     192}
     193
     194Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) {
     195        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeMoveBuild< Expression >(expr_node) );
    351196        delete member;
    352197        return ret;
    353198}
    354199
    355 Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member ) {
    356         NameExpr* memberExpr = dynamic_cast<NameExpr*> ( maybeBuild<Expression>( member) );
    357         assert( memberExpr );
     200Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) {
    358201        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    359         deref->get_args().push_back( maybeBuild<Expression>(expr_node) );
    360         UntypedMemberExpr *ret = new UntypedMemberExpr( memberExpr->get_name(), deref );
     202        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
     203        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
    361204        delete member;
    362205        return ret;
     
    364207
    365208Expression *build_addressOf( ExpressionNode *expr_node ) {
    366                 return new AddressExpr( maybeBuild<Expression>(expr_node) );
    367 }
    368 Expression *build_sizeOf( ExpressionNode *expr_node ) {
    369         if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( expr_node ) ) {
    370                 return new SizeofExpr( arg->get_decl()->buildType() );
    371         } else {
    372                 return new SizeofExpr( maybeBuild<Expression>(expr_node) );
    373         } // if
    374 }
    375 Expression *build_alignOf( ExpressionNode *expr_node ) {
    376         if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( expr_node ) ) {
    377                 return new AlignofExpr( arg->get_decl()->buildType() );
    378         } else {
    379                 return new AlignofExpr( maybeBuild<Expression>(expr_node) );
    380         } // if
    381 }
    382 Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member ) {
    383         NameExpr *memberExpr = dynamic_cast<NameExpr *>( maybeBuild<Expression>( member ) );
    384         assert( memberExpr );
    385         return new UntypedOffsetofExpr( arg->get_decl()->buildType(), memberExpr->get_name() );
     209                return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
     210}
     211Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
     212        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
     213}
     214Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     215        Expression* ret = new SizeofExpr( decl_node->buildType() );
     216        delete decl_node;
     217        return ret;
     218}
     219Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
     220        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
     221}
     222Expression *build_alignOftype( DeclarationNode *decl_node ) {
     223        return new AlignofExpr( decl_node->buildType() );
     224}
     225Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
     226        Expression* ret = new UntypedOffsetofExpr( decl_node->buildType(), member->get_name() );
     227        delete decl_node;
     228        delete member;
     229        return ret;
    386230}
    387231
    388232Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
    389         return new LogicalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind );
     233        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
    390234}
    391235
    392236Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
    393         std::list<Expression *> args;
    394         args.push_back( maybeBuild<Expression>(expr_node) );
     237        std::list< Expression * > args;
     238        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    395239        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    396240}
    397241Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
    398         std::list<Expression *> args;
    399         args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node) ) );
     242        std::list< Expression * > args;
     243        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) );
    400244        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    401245}
    402246Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    403         std::list<Expression *> args;
    404         args.push_back( maybeBuild<Expression>(expr_node1) );
    405         args.push_back( maybeBuild<Expression>(expr_node2) );
     247        std::list< Expression * > args;
     248        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
     249        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    406250        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    407251}
    408252Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    409         std::list<Expression *> args;
    410         args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node1) ) );
    411         args.push_back( maybeBuild<Expression>(expr_node2) );
     253        std::list< Expression * > args;
     254        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) );
     255        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    412256        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    413257}
    414258
    415259Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
    416         return new ConditionalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) );
     260        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
    417261}
    418262
    419263Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    420         return new CommaExpr( maybeBuild<Expression>(expr_node1), maybeBuild<Expression>(expr_node2) );
    421 }
    422 
    423 Expression *build_attr( VarRefNode *var, ExpressionNode * expr ) {
    424         if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( expr ) ) {
    425                 return new AttrExpr( maybeBuild<Expression>(var), arg->get_decl()->buildType() );
    426         } else {
    427                 return new AttrExpr( maybeBuild<Expression>(var), maybeBuild<Expression>(expr) );
    428         } // if
    429 }
    430 
    431 Expression *build_tuple( ExpressionNode * expr ) {
     264        return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
     265}
     266
     267Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
     268        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
     269}
     270Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     271        return new AttrExpr( var, decl_node->buildType() );
     272}
     273
     274Expression *build_tuple( ExpressionNode * expr_node ) {
    432275        TupleExpr *ret = new TupleExpr();
    433         buildList( expr, ret->get_exprs() );
    434         return ret;
    435 }
    436 
    437 Expression *build_func( ExpressionNode * function, ExpressionNode * expr ) {
    438         std::list<Expression *> args;
    439 
    440         buildList( expr, args );
    441         return new UntypedExpr( maybeBuild<Expression>(function), args, nullptr );
     276        buildMoveList( expr_node, ret->get_exprs() );
     277        return ret;
     278}
     279
     280Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
     281        std::list< Expression * > args;
     282        buildMoveList( expr_node, args );
     283        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    442284}
    443285
    444286Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
    445         Expression *low_cexpr = maybeBuild<Expression>( low );
    446         Expression *high_cexpr = maybeBuild<Expression>( high );
    447         return new RangeExpr( low_cexpr, high_cexpr );
    448 }
    449 
    450 //##############################################################################
    451 
    452 Expression *AsmExprNode::build() const {
    453         return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)maybeBuild<Expression>(constraint), maybeBuild<Expression>(operand) );
    454 }
    455 
    456 void AsmExprNode::print( std::ostream &os, int indent ) const {
    457         os << string( indent, ' ' ) << "Assembler Expression:" << endl;
    458         if ( inout ) {
    459                 os << string( indent, ' ' ) << "inout: " << std::endl;
    460                 inout->print( os, indent + 2 );
    461         } // if
    462         if ( constraint ) {
    463                 os << string( indent, ' ' ) << "constraint: " << std::endl;
    464                 constraint->print( os, indent + 2 );
    465         } // if
    466         if ( operand ) {
    467                 os << string( indent, ' ' ) << "operand: " << std::endl;
    468                 operand->print( os, indent + 2 );
    469         } // if
    470 }
    471 
    472 void AsmExprNode::printOneLine( std::ostream &os, int indent ) const {
    473         printDesignation( os );
    474         os << "( ";
    475         if ( inout ) inout->printOneLine( os, indent + 2 );
    476         os << ", ";
    477         if ( constraint ) constraint->printOneLine( os, indent + 2 );
    478         os << ", ";
    479         if ( operand ) operand->printOneLine( os, indent + 2 );
    480         os << ") ";
    481 }
    482 
    483 //##############################################################################
    484 
    485 void LabelNode::print( std::ostream &os, int indent ) const {}
    486 
    487 void LabelNode::printOneLine( std::ostream &os, int indent ) const {}
    488 
    489 //##############################################################################
    490 
    491 ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
    492 
    493 ValofExprNode::ValofExprNode( const ValofExprNode &other ) : ExpressionNode( other ), body( maybeClone( body ) ) {
    494 }
    495 
    496 ValofExprNode::~ValofExprNode() {
    497         delete body;
    498 }
    499 
    500 void ValofExprNode::print( std::ostream &os, int indent ) const {
    501         printDesignation( os );
    502         os << string( indent, ' ' ) << "Valof Expression:" << std::endl;
    503         get_body()->print( os, indent + 4);
    504 }
    505 
    506 void ValofExprNode::printOneLine( std::ostream &, int indent ) const {
    507         assert( false );
    508 }
    509 
    510 Expression *ValofExprNode::build() const {
    511         return new UntypedValofExpr ( maybeBuild<Statement>(get_body()), maybeBuild< Expression >( get_argName() ) );
    512 }
    513 
    514 //##############################################################################
    515 
    516 ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
    517         if ( init_ == 0 )
    518                 init = 0;
    519         else {
    520                 DeclarationNode *decl;
    521                 ExpressionNode *exp;
    522 
    523                 if (( decl = dynamic_cast<DeclarationNode *>(init_) ) != 0)
    524                         init = new StatementNode( decl );
    525                 else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0)
    526                         init = new StatementNode( StatementNode::Exp, exp );
    527                 else
    528                         throw SemanticError("Error in for control expression");
    529         }
    530 }
    531 
    532 ForCtlExprNode::ForCtlExprNode( const ForCtlExprNode &other )
    533         : ExpressionNode( other ), init( maybeClone( other.init ) ), condition( maybeClone( other.condition ) ), change( maybeClone( other.change ) ) {
    534 }
    535 
    536 ForCtlExprNode::~ForCtlExprNode() {
    537         delete init;
    538         delete condition;
    539         delete change;
    540 }
    541 
    542 Expression *ForCtlExprNode::build() const {
    543         // this shouldn't be used!
    544         assert( false );
    545         return 0;
    546 }
    547 
    548 void ForCtlExprNode::print( std::ostream &os, int indent ) const{
    549         os << string( indent,' ' ) << "For Control Expression -- :" << endl;
    550 
    551         os << string( indent + 2, ' ' ) << "initialization:" << endl;
    552         if ( init != 0 )
    553                 init->printList( os, indent + 4 );
    554 
    555         os << string( indent + 2, ' ' ) << "condition: " << endl;
    556         if ( condition != 0 )
    557                 condition->print( os, indent + 4 );
    558         os << string( indent + 2, ' ' ) << "increment: " << endl;
    559         if ( change != 0 )
    560                 change->print( os, indent + 4 );
    561 }
    562 
    563 void ForCtlExprNode::printOneLine( std::ostream &, int indent ) const {
    564         assert( false );
    565 }
    566 
    567 //##############################################################################
    568 
    569 TypeValueNode::TypeValueNode( DeclarationNode *decl ) : decl( decl ) {
    570 }
    571 
    572 TypeValueNode::TypeValueNode( const TypeValueNode &other ) : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
    573 }
    574 
    575 Expression *TypeValueNode::build() const {
     287        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
     288}
     289
     290Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
     291        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
     292}
     293
     294Expression *build_valexpr( StatementNode *s ) {
     295        return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr );
     296}
     297Expression *build_typevalue( DeclarationNode *decl ) {
    576298        return new TypeExpr( decl->buildType() );
    577299}
    578300
    579 void TypeValueNode::print( std::ostream &os, int indent ) const {
    580         os << std::string( indent, ' ' ) << "Type:";
    581         get_decl()->print( os, indent + 2);
    582 }
    583 
    584 void TypeValueNode::printOneLine( std::ostream &os, int indent ) const {
    585         os << "Type:";
    586         get_decl()->print( os, indent + 2);
    587 }
    588 
    589 
    590 CompoundLiteralNode::CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ) : type( type ), kids( kids ) {}
    591 CompoundLiteralNode::CompoundLiteralNode( const CompoundLiteralNode &other ) : ExpressionNode( other ), type( other.type ), kids( other.kids ) {}
    592 
    593 CompoundLiteralNode::~CompoundLiteralNode() {
    594         delete kids;
    595         delete type;
    596 }
    597 
    598 CompoundLiteralNode *CompoundLiteralNode::clone() const {
    599         return new CompoundLiteralNode( *this );
    600 }
    601 
    602 void CompoundLiteralNode::print( std::ostream &os, int indent ) const {
    603         os << string( indent,' ' ) << "CompoundLiteralNode:" << endl;
    604 
    605         os << string( indent + 2, ' ' ) << "type:" << endl;
    606         if ( type != 0 )
    607                 type->print( os, indent + 4 );
    608 
    609         os << string( indent + 2, ' ' ) << "initialization:" << endl;
    610         if ( kids != 0 )
    611                 kids->printList( os, indent + 4 );
    612 }
    613 
    614 void CompoundLiteralNode::printOneLine( std::ostream &os, int indent ) const {
    615         os << "( ";
    616         if ( type ) type->print( os );
    617         os << ", ";
    618         if ( kids ) kids->printOneLine( os );
    619         os << ") ";
    620 }
    621 
    622 Expression *CompoundLiteralNode::build() const {
    623         Declaration * newDecl = maybeBuild<Declaration>(type); // compound literal type
     301Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
     302        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    624303        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
    625                 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) );
     304                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
    626305        // these types do not have associated type information
    627306        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
    628                 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) );
     307                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    629308        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
    630                 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) );
     309                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    631310        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
    632                 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) );
     311                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    633312        } else {
    634313                assert( false );
Note: See TracChangeset for help on using the changeset viewer.