Changeset d9e2280 for src/Parser/ExpressionNode.cc
- Timestamp:
- Aug 5, 2016, 3:56:24 PM (8 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, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 35f9114
- Parents:
- 71a3593
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r71a3593 rd9e2280 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 5 1 1:39:25201613 // Update Count : 39112 // Last Modified On : Fri Aug 5 15:07:19 2016 13 // Update Count : 409 14 14 // 15 15 … … 238 238 //############################################################################## 239 239 240 static const char *opName[] = { 241 "TupleC", "Comma", "TupleFieldSel", // "TuplePFieldSel", // n-adic 242 // triadic 243 "Cond", "NCond", 240 static const char *OperName[] = { 244 241 // diadic 245 242 "SizeOf", "AlignOf", "OffsetOf", "Attr", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&", 246 243 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?", 247 244 "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?", 248 "?[?]", " FieldSel", "PFieldSel", "...",245 "?[?]", "...", 249 246 // monadic 250 247 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&" 251 248 }; 252 249 253 OperatorNode::OperatorNode( Type t ) : type( t ) {} 254 255 OperatorNode::OperatorNode( const OperatorNode &other ) : ExpressionNode( other ), type( other.type ) { 256 } 257 258 OperatorNode::~OperatorNode() {} 259 260 OperatorNode::Type OperatorNode::get_type( void ) const { 261 return type; 262 } 263 264 void OperatorNode::printOneLine( std::ostream &os, int indent ) const { 265 printDesignation( os ); 266 os << opName[ type ] << ' '; 267 } 268 269 void OperatorNode::print( std::ostream &os, int indent ) const{ 270 printDesignation( os ); 271 os << string( indent, ' ' ) << "Operator: " << opName[type] << endl; 272 return; 273 } 274 275 const char *OperatorNode::get_typename( void ) const{ 276 return opName[ type ]; 277 } 278 279 //############################################################################## 280 281 CompositeExprNode::CompositeExprNode() : ExpressionNode(), function( 0 ), arguments( 0 ) { 282 } 283 284 CompositeExprNode::CompositeExprNode( const string *name_ ) : ExpressionNode( name_ ), function( 0 ), arguments( 0 ) { 285 } 286 287 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *args ): 288 function( f ), arguments( args ) { 289 } 290 291 CompositeExprNode::CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ): 292 function( f ), arguments( arg1 ) { 293 arguments->set_link( arg2 ); 294 } 295 296 CompositeExprNode::CompositeExprNode( const CompositeExprNode &other ) : ExpressionNode( other ), function( maybeClone( other.function ) ), arguments( 0 ) { 297 ParseNode *cur = other.arguments; 298 while ( cur ) { 299 if ( arguments ) { 300 arguments->set_link( cur->clone() ); 301 } else { 302 arguments = ( ExpressionNode*)cur->clone(); 303 } // if 304 cur = cur->get_link(); 305 } 306 } 307 308 CompositeExprNode::~CompositeExprNode() { 309 delete function; 310 delete arguments; 311 } 312 250 //############################################################################## 251 252 CompositeExprNode::CompositeExprNode( Expression *expr ) : expr( expr ) {} 253 CompositeExprNode::CompositeExprNode( const CompositeExprNode &other ) : expr( other.expr->clone() ) {} 254 CompositeExprNode::~CompositeExprNode() { delete expr; } 255 void CompositeExprNode::print( std::ostream &, int indent ) const { assert( false ); } 256 void CompositeExprNode::printOneLine( std::ostream &, int indent ) const { assert( false ); } 313 257 314 258 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node ) { … … 369 313 } 370 314 371 Expression *build_unary_val( Oper atorNode::Typeop, ExpressionNode *expr_node ) {315 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 372 316 std::list<Expression *> args; 373 317 args.push_back( maybeBuild<Expression>(expr_node) ); 374 return new UntypedExpr( new NameExpr( opName[op ] ), args );375 } 376 Expression *build_unary_ptr( Oper atorNode::Typeop, ExpressionNode *expr_node ) {318 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 319 } 320 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 377 321 std::list<Expression *> args; 378 322 args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node) ) ); 379 return new UntypedExpr( new NameExpr( opName[op ] ), args );380 } 381 Expression *build_binary_val( Oper atorNode::Typeop, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {323 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 324 } 325 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 382 326 std::list<Expression *> args; 383 327 args.push_back( maybeBuild<Expression>(expr_node1) ); 384 328 args.push_back( maybeBuild<Expression>(expr_node2) ); 385 return new UntypedExpr( new NameExpr( opName[op ] ), args );386 } 387 Expression *build_binary_ptr( Oper atorNode::Typeop, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {329 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 330 } 331 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 388 332 std::list<Expression *> args; 389 333 args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node1) ) ); 390 334 args.push_back( maybeBuild<Expression>(expr_node2) ); 391 return new UntypedExpr( new NameExpr( opName[op ] ), args );335 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 392 336 } 393 337 … … 421 365 } 422 366 423 CompositeExprNode2::CompositeExprNode2( Expression *expr ) : expr( expr ) {} 424 CompositeExprNode2::CompositeExprNode2( const CompositeExprNode2 &other ) : expr( other.expr->clone() ) {} 425 CompositeExprNode2::~CompositeExprNode2() { delete expr; } 426 void CompositeExprNode2::print( std::ostream &, int indent ) const { assert( false ); } 427 void CompositeExprNode2::printOneLine( std::ostream &, int indent ) const { assert( false ); } 428 429 430 Expression *CompositeExprNode::build() const { 431 OperatorNode *op; 432 std::list<Expression *> args; 433 434 buildList( get_args(), args ); 435 436 if ( ! ( op = dynamic_cast<OperatorNode *>( function ) ) ) { // function as opposed to operator 437 return new UntypedExpr( maybeBuild<Expression>(function), args, maybeBuild< Expression >( get_argName() )); 438 } // if 439 440 assert( ((void)"CompositeExprNode::build", false) ); 441 return nullptr; 442 } 443 444 void CompositeExprNode::printOneLine( std::ostream &os, int indent ) const { 445 printDesignation( os ); 446 os << "( "; 447 function->printOneLine( os, indent ); 448 for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) { 449 cur->printOneLine( os, indent ); 450 } // for 451 os << ") "; 452 } 453 454 void CompositeExprNode::print( std::ostream &os, int indent ) const { 455 printDesignation( os ); 456 os << string( indent, ' ' ) << "Application of: " << endl; 457 function->print( os, indent + ParseNode::indent_by ); 458 459 os << string( indent, ' ' ) ; 460 if ( arguments ) { 461 os << "... on arguments: " << endl; 462 arguments->printList( os, indent + ParseNode::indent_by ); 463 } else 464 os << "... on no arguments: " << endl; 465 } 466 467 void CompositeExprNode::set_function( ExpressionNode *f ) { 468 function = f; 469 } 470 471 void CompositeExprNode::set_args( ExpressionNode *args ) { 472 arguments = args; 473 } 474 475 ExpressionNode *CompositeExprNode::get_function( void ) const { 476 return function; 477 } 478 479 ExpressionNode *CompositeExprNode::get_args( void ) const { 480 return arguments; 481 } 482 483 void CompositeExprNode::add_arg( ExpressionNode *arg ) { 484 if ( arguments ) 485 arguments->set_link( arg ); 486 else 487 set_args( arg ); 367 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) { 368 Expression *low_cexpr = maybeBuild<Expression>( low ); 369 Expression *high_cexpr = maybeBuild<Expression>( high ); 370 return new RangeExpr( low_cexpr, high_cexpr ); 488 371 } 489 372 … … 676 559 } 677 560 678 ExpressionNode *flattenCommas( ExpressionNode *list ) {679 if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {680 OperatorNode *op;681 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) ) {682 if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )683 composite->add_arg( next );684 return flattenCommas( composite->get_args() );685 } // if686 } // if687 688 if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )689 list->set_next( flattenCommas( next ) );690 691 return list;692 }693 694 ExpressionNode *tupleContents( ExpressionNode *tuple ) {695 if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( tuple ) ) {696 OperatorNode *op = 0;697 if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::TupleC ) )698 return composite->get_args();699 } // if700 return tuple;701 }702 703 561 // Local Variables: // 704 562 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.