Changes in src/Parser/ExpressionNode.cc [1869adf:e869d663]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r1869adf re869d663 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:20:00201513 // Update Count : 15812 // Last Modified On : Wed Aug 12 13:51:11 2015 13 // Update Count : 254 14 14 // 15 15 … … 32 32 ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {} 33 33 34 ExpressionNode::ExpressionNode( const string *name _ ) : ParseNode( name_), argName( 0 ) {}34 ExpressionNode::ExpressionNode( const string *name ) : ParseNode( name ), argName( 0 ) {} 35 35 36 36 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ) { … … 42 42 } 43 43 44 ExpressionNode * ExpressionNode::set_a sArgName( const std::string *aName ) {44 ExpressionNode * ExpressionNode::set_argName( const std::string *aName ) { 45 45 argName = new VarRefNode( aName ); 46 46 return this; 47 47 } 48 48 49 ExpressionNode * ExpressionNode::set_a sArgName( ExpressionNode *aDesignator ) {49 ExpressionNode * ExpressionNode::set_argName( ExpressionNode *aDesignator ) { 50 50 argName = aDesignator; 51 51 return this; … … 210 210 assert( type == String ); 211 211 212 // "abc" "def" "ghi" => "abcdefghi", soremove new text from quotes and insert before last quote in old string.212 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 213 213 value.insert( value.length() - 1, newValue->substr( 1, newValue->length() - 2 ) ); 214 214 … … 284 284 os << "Variable: " << get_name(); 285 285 os << endl; 286 } 287 288 //############################################################################## 289 290 DesignatorNode::DesignatorNode( ExpressionNode *expr, bool isArrayIndex ) : isArrayIndex( isArrayIndex ) { 291 set_argName( expr ); 292 assert( get_argName() ); 293 294 if ( ! isArrayIndex ) { 295 if ( VarRefNode * var = dynamic_cast< VarRefNode * >( expr ) ) { 296 297 stringstream ss( var->get_name() ); 298 double value; 299 if ( ss >> value ) { 300 // this is a floating point constant. It MUST be 301 // ".0" or ".1", otherwise the program is invalid 302 if ( ! (var->get_name() == ".0" || var->get_name() == ".1") ) { 303 throw SemanticError( "invalid designator name: " + var->get_name() ); 304 } // if 305 var->set_name( var->get_name().substr(1) ); 306 } // if 307 } // if 308 } // if 309 } 310 311 DesignatorNode::DesignatorNode( const DesignatorNode &other ) : ExpressionNode( other ), isArrayIndex( other.isArrayIndex ) { 312 } 313 314 class DesignatorFixer : public Mutator { 315 public: 316 virtual Expression* mutate( NameExpr *nameExpr ) { 317 if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) { 318 Constant val( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nameExpr->get_name() ); 319 delete nameExpr; 320 return new ConstantExpr( val ); 321 } 322 return nameExpr; 323 } 324 }; 325 326 Expression *DesignatorNode::build() const { 327 Expression * ret = get_argName()->build(); 328 329 if ( isArrayIndex ) { 330 // need to traverse entire structure and change any instances of 0 or 1 to 331 // ConstantExpr 332 DesignatorFixer fixer; 333 ret = ret->acceptMutator( fixer ); 334 } // if 335 336 return ret; 337 } 338 339 void DesignatorNode::printOneLine( std::ostream &os, int indent ) const { 340 if ( get_argName() ) { 341 if ( isArrayIndex ) { 342 os << "["; 343 get_argName()->printOneLine( os, indent ); 344 os << "]"; 345 } else { 346 os << "."; 347 get_argName()->printOneLine( os, indent ); 348 } 349 } // if 350 } 351 352 void DesignatorNode::print( std::ostream &os, int indent ) const { 353 if ( get_argName() ) { 354 if ( isArrayIndex ) { 355 os << "["; 356 get_argName()->print( os, indent ); 357 os << "]"; 358 } else { 359 os << "."; 360 get_argName()->print( os, indent ); 361 } 362 } // if 286 363 } 287 364 … … 330 407 //############################################################################## 331 408 332 CompositeExprNode::CompositeExprNode( void) : ExpressionNode(), function( 0 ), arguments( 0 ) {409 CompositeExprNode::CompositeExprNode() : ExpressionNode(), function( 0 ), arguments( 0 ) { 333 410 } 334 411 … … 541 618 { 542 619 assert( args.size() == 3); 543 std::list< Expression * >::const_iterator i = args.begin();620 std::list< Expression * >::const_iterator i = args.begin(); 544 621 Expression *arg1 = notZeroExpr( *i++ ); 545 622 Expression *arg2 = *i++; … … 552 629 { 553 630 assert( args.size() == 2); 554 std::list< Expression * >::const_iterator i = args.begin();631 std::list< Expression * >::const_iterator i = args.begin(); 555 632 Expression *ret = *i++; 556 633 while ( i != args.end() ) { … … 617 694 set_args( arg ); 618 695 } 696 697 //############################################################################## 698 699 Expression *AsmExprNode::build() const { 700 return new AsmExpr( maybeBuild< Expression >( inout ), (ConstantExpr *)constraint->build(), operand->build() ); 701 } 702 703 void AsmExprNode::print( std::ostream &os, int indent ) const { 704 os << string( indent, ' ' ) << "Assembler Expression:" << endl; 705 if ( inout ) { 706 os << string( indent, ' ' ) << "inout: " << std::endl; 707 inout->print( os, indent + 2 ); 708 } // if 709 if ( constraint ) { 710 os << string( indent, ' ' ) << "constraint: " << std::endl; 711 constraint->print( os, indent + 2 ); 712 } // if 713 if ( operand ) { 714 os << string( indent, ' ' ) << "operand: " << std::endl; 715 operand->print( os, indent + 2 ); 716 } // if 717 } 718 719 void AsmExprNode::printOneLine( std::ostream &os, int indent ) const { 720 printDesignation( os ); 721 os << "( "; 722 if ( inout ) inout->printOneLine( os, indent + 2 ); 723 os << ", "; 724 if ( constraint ) constraint->printOneLine( os, indent + 2 ); 725 os << ", "; 726 if ( operand ) operand->printOneLine( os, indent + 2 ); 727 os << ") "; 728 } 729 730 //############################################################################## 731 732 void LabelNode::print( std::ostream &os, int indent ) const {} 733 734 void LabelNode::printOneLine( std::ostream &os, int indent ) const {} 619 735 620 736 //##############################################################################
Note:
See TracChangeset
for help on using the changeset viewer.