Changes in src/Parser/ExpressionNode.cc [e869d663:1869adf]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
re869d663 r1869adf 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 13:51:11201513 // Update Count : 25412 // Last Modified On : Wed Jun 24 16:20:00 2015 13 // Update Count : 158 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 rgName( const std::string *aName ) {44 ExpressionNode * ExpressionNode::set_asArgName( const std::string *aName ) { 45 45 argName = new VarRefNode( aName ); 46 46 return this; 47 47 } 48 48 49 ExpressionNode * ExpressionNode::set_a rgName( ExpressionNode *aDesignator ) {49 ExpressionNode * ExpressionNode::set_asArgName( ExpressionNode *aDesignator ) { 50 50 argName = aDesignator; 51 51 return this; … … 210 210 assert( type == String ); 211 211 212 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.212 // "abc" "def" "ghi" => "abcdefghi", so 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 be301 // ".0" or ".1", otherwise the program is invalid302 if ( ! (var->get_name() == ".0" || var->get_name() == ".1") ) {303 throw SemanticError( "invalid designator name: " + var->get_name() );304 } // if305 var->set_name( var->get_name().substr(1) );306 } // if307 } // if308 } // if309 }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 to331 // ConstantExpr332 DesignatorFixer fixer;333 ret = ret->acceptMutator( fixer );334 } // if335 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 } // if350 }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 } // if363 286 } 364 287 … … 407 330 //############################################################################## 408 331 409 CompositeExprNode::CompositeExprNode( ) : ExpressionNode(), function( 0 ), arguments( 0 ) {332 CompositeExprNode::CompositeExprNode( void ) : ExpressionNode(), function( 0 ), arguments( 0 ) { 410 333 } 411 334 … … 618 541 { 619 542 assert( args.size() == 3); 620 std::list< Expression * >::const_iterator i = args.begin();543 std::list< Expression* >::const_iterator i = args.begin(); 621 544 Expression *arg1 = notZeroExpr( *i++ ); 622 545 Expression *arg2 = *i++; … … 629 552 { 630 553 assert( args.size() == 2); 631 std::list< Expression * >::const_iterator i = args.begin();554 std::list< Expression* >::const_iterator i = args.begin(); 632 555 Expression *ret = *i++; 633 556 while ( i != args.end() ) { … … 694 617 set_args( arg ); 695 618 } 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 } // if709 if ( constraint ) {710 os << string( indent, ' ' ) << "constraint: " << std::endl;711 constraint->print( os, indent + 2 );712 } // if713 if ( operand ) {714 os << string( indent, ' ' ) << "operand: " << std::endl;715 operand->print( os, indent + 2 );716 } // if717 }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 {}735 619 736 620 //##############################################################################
Note:
See TracChangeset
for help on using the changeset viewer.