Changeset 04cdd9b for src/Parser/ExpressionNode.cc
- Timestamp:
- Aug 19, 2016, 2:42:04 PM (9 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r03da511 r04cdd9b 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 7 09:23:12201613 // Update Count : 4 3712 // Last Modified On : Tue Aug 16 00:09:20 2016 13 // Update Count : 495 14 14 // 15 15 … … 32 32 using namespace std; 33 33 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 } 34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {} 86 35 87 36 //############################################################################## … … 108 57 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 109 58 110 ConstantNode *build_constantInteger(std::string & str ) {59 Expression *build_constantInteger( const std::string & str ) { 111 60 static const BasicType::Kind kind[2][3] = { 112 61 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, … … 171 120 } // if 172 121 173 return new Constant Node( new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str )) );122 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) ); 174 123 } // build_constantInteger 175 124 176 ConstantNode *build_constantFloat(std::string & str ) {125 Expression *build_constantFloat( const std::string & str ) { 177 126 static const BasicType::Kind kind[2][3] = { 178 127 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, … … 201 150 } // if 202 151 203 return new Constant Node( new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str )) );152 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) ); 204 153 } // build_constantFloat 205 154 206 ConstantNode *build_constantChar(std::string & str ) {207 return new Constant Node( new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str )) );155 Expression *build_constantChar( const std::string & str ) { 156 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ); 208 157 } // build_constantChar 209 158 210 Constant Node *build_constantStr(std::string & str ) {159 ConstantExpr *build_constantStr( const std::string & str ) { 211 160 // string should probably be a primitive type 212 161 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( emptyQualifiers, BasicType::Char ), … … 214 163 toString( str.size()+1-2 ) ) ), // +1 for '\0' and -2 for '"' 215 164 false, false ); 216 return new Constant Node( new ConstantExpr( Constant( at, str )) );165 return new ConstantExpr( Constant( at, str ) ); 217 166 } // build_constantStr 218 167 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 //############################################################################## 168 NameExpr * build_varref( const string *name, bool labelp ) { 169 NameExpr *expr = new NameExpr( *name, nullptr ); 170 delete name; 171 return expr; 172 } 322 173 323 174 static const char *OperName[] = { … … 331 182 }; 332 183 333 //############################################################################## 334 335 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node ) { 336 DeclarationNode *decl_node = arg->get_decl(); 337 184 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 338 185 Type *targetType = decl_node->buildType(); 339 if ( dynamic_cast< VoidType * >( targetType ) ) {186 if ( dynamic_cast< VoidType * >( targetType ) ) { 340 187 delete targetType; 341 return new CastExpr( maybe Build<Expression>(expr_node) );188 return new CastExpr( maybeMoveBuild< Expression >(expr_node) ); 342 189 } 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 194 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) { 195 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeMoveBuild< Expression >(expr_node) ); 351 196 delete member; 352 197 return ret; 353 198 } 354 199 355 Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member ) { 356 NameExpr* memberExpr = dynamic_cast<NameExpr*> ( maybeBuild<Expression>( member) ); 357 assert( memberExpr ); 200 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) { 358 201 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 359 deref->get_args().push_back( maybe Build<Expression>(expr_node) );360 UntypedMemberExpr *ret = new UntypedMemberExpr( member Expr->get_name(), deref );202 deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) ); 203 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 361 204 delete member; 362 205 return ret; … … 364 207 365 208 Expression *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 } 211 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 212 return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) ); 213 } 214 Expression *build_sizeOftype( DeclarationNode *decl_node ) { 215 Expression* ret = new SizeofExpr( decl_node->buildType() ); 216 delete decl_node; 217 return ret; 218 } 219 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 220 return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) ); 221 } 222 Expression *build_alignOftype( DeclarationNode *decl_node ) { 223 return new AlignofExpr( decl_node->buildType() ); 224 } 225 Expression *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; 386 230 } 387 231 388 232 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 389 return new LogicalExpr( notZeroExpr( maybe Build<Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind );233 return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind ); 390 234 } 391 235 392 236 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 393 std::list< Expression *> args;394 args.push_back( maybe Build<Expression>(expr_node) );237 std::list< Expression * > args; 238 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 395 239 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 396 240 } 397 241 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 398 std::list< Expression *> args;399 args.push_back( new AddressExpr( maybe Build<Expression>(expr_node) ) );242 std::list< Expression * > args; 243 args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) ); 400 244 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 401 245 } 402 246 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 403 std::list< Expression *> args;404 args.push_back( maybe Build<Expression>(expr_node1) );405 args.push_back( maybe Build<Expression>(expr_node2) );247 std::list< Expression * > args; 248 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 249 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); 406 250 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 407 251 } 408 252 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 409 std::list< Expression *> args;410 args.push_back( new AddressExpr( maybe Build<Expression>(expr_node1) ) );411 args.push_back( maybe Build<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) ); 412 256 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 413 257 } 414 258 415 259 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 416 return new ConditionalExpr( notZeroExpr( maybe Build<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) ); 417 261 } 418 262 419 263 Expression *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 267 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) { 268 return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) ); 269 } 270 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { 271 return new AttrExpr( var, decl_node->buildType() ); 272 } 273 274 Expression *build_tuple( ExpressionNode * expr_node ) { 432 275 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 280 Expression *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 ); 442 284 } 443 285 444 286 Expression *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 290 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) { 291 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 292 } 293 294 Expression *build_valexpr( StatementNode *s ) { 295 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr ); 296 } 297 Expression *build_typevalue( DeclarationNode *decl ) { 576 298 return new TypeExpr( decl->buildType() ); 577 299 } 578 300 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 301 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) { 302 Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type 624 303 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 625 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybe Build<Initializer>(kids) );304 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) ); 626 305 // these types do not have associated type information 627 306 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 628 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybe Build<Initializer>(kids) );307 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) ); 629 308 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 630 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybe Build<Initializer>(kids) );309 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) ); 631 310 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 632 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybe Build<Initializer>(kids) );311 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) ); 633 312 } else { 634 313 assert( false );
Note:
See TracChangeset
for help on using the changeset viewer.