Changeset e869d663
- Timestamp:
- Aug 12, 2015, 2:26:44 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 43ee2a8, d60ccbf
- Parents:
- d58ebf3
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rd58ebf3 re869d663 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Aug 11 15:13:48201513 // Update Count : 2 0011 // Last Modified By : Rob Schluntz 12 // 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 ) { … … 290 290 DesignatorNode::DesignatorNode( ExpressionNode *expr, bool isArrayIndex ) : isArrayIndex( isArrayIndex ) { 291 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 292 309 } 293 310 … … 295 312 } 296 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 297 326 Expression *DesignatorNode::build() const { 327 Expression * ret = get_argName()->build(); 328 298 329 if ( isArrayIndex ) { 299 return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) ); 300 } else { 301 return new NameExpr( get_name(), maybeBuild< Expression >( get_argName() ) ); 302 } // if 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; 303 337 } 304 338 -
src/Parser/ParseNode.cc
rd58ebf3 re869d663 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:26:29 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jul 30 14:55:54201513 // Update Count : 2611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 13:26:00 2015 13 // Update Count : 36 14 14 // 15 15 … … 20 20 int ParseNode::indent_by = 4; 21 21 22 ParseNode::ParseNode() : name( 0 ), next( 0 ) {}; 23 ParseNode::ParseNode( const string *name_ ) : name( name_ ), next( 0 ) {} 22 ParseNode::ParseNode() : next( 0 ) {}; 23 ParseNode::ParseNode( const string *name ) : name( *name ), next( 0 ) { delete name; } 24 ParseNode::ParseNode( const string &name ) : name( name ), next( 0 ) { } 24 25 25 26 ParseNode::~ParseNode() { 26 delete next; delete name;27 delete next; 27 28 }; 28 29 -
src/Parser/ParseNode.h
rd58ebf3 re869d663 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Aug 11 15:11:29201513 // Update Count : 1 4511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 13:27:11 2015 13 // Update Count : 172 14 14 // 15 15 … … 40 40 ParseNode(); 41 41 ParseNode( const std::string * ); 42 ParseNode( const std::string & ); // for copy constructing subclasses 42 43 virtual ~ParseNode(); 43 44 … … 49 50 virtual ParseNode *clone() const { return 0; }; 50 51 51 const std::string &get_name() const { return *name; } 52 const std::string &get_name() const { return name; } 53 void set_name( const std::string &newValue ) { name = newValue; } 54 52 55 virtual void print( std::ostream &, int indent = 0 ) const; 53 56 virtual void printList( std::ostream &, int indent = 0 ) const; … … 55 58 ParseNode &operator,( ParseNode &); 56 59 protected: 57 const std::string *name;60 std::string name; 58 61 ParseNode *next; 59 62 static int indent_by;
Note: See TracChangeset
for help on using the changeset viewer.