Changeset 1a18423 for src/SynTree
- Timestamp:
- Jun 22, 2017, 9:43:02 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 7d9c987
- Parents:
- 405c592 (diff), e9a3b20b (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. - Location:
- src/SynTree
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/BaseSyntaxNode.h
r405c592 r1a18423 24 24 CodeLocation location; 25 25 26 virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast 26 virtual ~BaseSyntaxNode() {} 27 28 virtual void accept( Visitor & v ) = 0; 27 29 }; 28 30 -
src/SynTree/Constant.cc
r405c592 r1a18423 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 30 15:18:38 201513 // Update Count : 1212 // Last Modified On : Wed Jun 21 16:44:48 2017 13 // Update Count : 27 14 14 // 15 15 … … 21 21 #include "Type.h" 22 22 23 Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {} 23 Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {} 24 Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {} 24 25 25 Constant::Constant( const Constant &other ) {26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) { 26 27 type = other.type->clone(); 27 value = other.value;28 28 } 29 29 … … 31 31 32 32 Constant Constant::from_int( int i ) { 33 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) );33 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); 34 34 } 35 35 36 36 Constant Constant::from_ulong( unsigned long i ) { 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) );37 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i ); 38 38 } 39 39 40 40 Constant Constant::from_double( double d ) { 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) );41 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d ); 42 42 } 43 43 44 Constant *Constant::clone() const { assert( false ); return 0; }45 46 44 void Constant::print( std::ostream &os ) const { 47 os << "(" << value;45 os << "(" << rep << " " << val.ival; 48 46 if ( type ) { 49 47 os << ": "; -
src/SynTree/Constant.h
r405c592 r1a18423 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 30 13:33:17 201613 // Update Count : 612 // Last Modified On : Wed Jun 21 16:44:48 2017 13 // Update Count : 14 14 14 // 15 15 … … 23 23 class Constant { 24 24 public: 25 Constant( Type *type, std::string value ); 26 Constant( const Constant &other ); 25 Constant( Type * type, std::string rep, unsigned long long val ); 26 Constant( Type * type, std::string rep, double val ); 27 Constant( const Constant & other ); 27 28 virtual ~Constant(); 28 29 29 Type * get_type() { return type; }30 void set_type( Type * newValue ) { type = newValue; }31 std::string & get_value() { return value; }32 void set_value( std::string newValue ) { value= newValue; }30 Type * get_type() { return type; } 31 void set_type( Type * newValue ) { type = newValue; } 32 std::string & get_value() { return rep; } 33 void set_value( std::string newValue ) { rep = newValue; } 33 34 34 35 /// generates an integer constant of the given int … … 39 40 static Constant from_double( double d ); 40 41 41 virtual Constant *clone() const; 42 virtual void accept( Visitor &v ) { v.visit( this ); } 43 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 44 virtual void print( std::ostream &os ) const; 42 virtual void accept( Visitor & v ) { v.visit( this ); } 43 virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); } 44 virtual void print( std::ostream & os ) const; 45 45 private: 46 Type *type; 47 std::string value; 46 Type * type; 47 std::string rep; 48 union Val { 49 unsigned long long ival; 50 double dval; 51 Val( unsigned long long ival ) : ival( ival ) {} 52 Val( double dval ) : dval( dval ) {} 53 } val; 48 54 }; 49 55 -
src/SynTree/Expression.cc
r405c592 r1a18423 288 288 } 289 289 290 // CastExpr *CastExpr::clone() const { return 0; }291 292 290 void CastExpr::print( std::ostream &os, int indent ) const { 293 291 os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); … … 355 353 } 356 354 357 //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...358 355 MemberExpr::MemberExpr( const MemberExpr &other ) : 359 356 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { … … 361 358 362 359 MemberExpr::~MemberExpr() { 363 // d elete member;360 // don't delete the member declaration, since it points somewhere else in the tree 364 361 delete aggregate; 365 362 } … … 591 588 } 592 589 593 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}594 595 UntypedValofExpr::~UntypedValofExpr() { delete body; }596 597 void UntypedValofExpr::print( std::ostream &os, int indent ) const {598 os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;599 if ( get_body() != 0 )600 get_body()->print( os, indent + 2 );601 }602 603 590 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 604 591 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} -
src/SynTree/Expression.h
r405c592 r1a18423 226 226 }; 227 227 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer. 229 /// Does not take ownership of member. 229 230 class MemberExpr : public Expression { 230 231 public: … … 247 248 }; 248 249 249 /// VariableExpr represents an expression that simply refers to the value of a named variable 250 /// VariableExpr represents an expression that simply refers to the value of a named variable. 251 /// Does not take ownership of var. 250 252 class VariableExpr : public Expression { 251 253 public: … … 598 600 }; 599 601 600 /// ValofExpr represents a GCC 'lambda expression'601 class UntypedValofExpr : public Expression {602 public:603 UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}604 UntypedValofExpr( const UntypedValofExpr & other );605 virtual ~UntypedValofExpr();606 607 Expression * get_value();608 Statement * get_body() const { return body; }609 610 virtual UntypedValofExpr * clone() const { return new UntypedValofExpr( * this ); }611 virtual void accept( Visitor & v ) { v.visit( this ); }612 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }613 virtual void print( std::ostream & os, int indent = 0 ) const;614 private:615 Statement * body;616 };617 618 602 /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' 619 603 class RangeExpr : public Expression { -
src/SynTree/Mutator.cc
r405c592 r1a18423 380 380 } 381 381 382 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {383 valofExpr->set_env( maybeMutate( valofExpr->get_env(), *this ) );384 valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );385 return valofExpr;386 }387 388 382 Expression *Mutator::mutate( RangeExpr *rangeExpr ) { 389 383 rangeExpr->set_env( maybeMutate( rangeExpr->get_env(), *this ) ); -
src/SynTree/Mutator.h
r405c592 r1a18423 78 78 virtual Expression* mutate( ConstructorExpr *ctorExpr ); 79 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); 80 virtual Expression* mutate( UntypedValofExpr *valofExpr );81 80 virtual Expression* mutate( RangeExpr *rangeExpr ); 82 81 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ); -
src/SynTree/ObjectDecl.cc
r405c592 r1a18423 56 56 57 57 if ( init ) { 58 os << " with initializer " ;59 init->print( os, indent );60 os << std::endl << std::string(indent , ' ');58 os << " with initializer " << std::endl; 59 init->print( os, indent+2 ); 60 os << std::endl << std::string(indent+2, ' '); 61 61 os << "maybeConstructed? " << init->get_maybeConstructed(); 62 62 } // if -
src/SynTree/Statement.cc
r405c592 r1a18423 313 313 } 314 314 315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< Statement *> &_handlers, FinallyStmt *_finallyBlock ) :315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) : 316 316 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 317 317 } … … 334 334 // handlers 335 335 os << string( indent + 2, ' ' ) << "and handlers: " << endl; 336 for ( std::list< Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)336 for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) 337 337 (*i )->print( os, indent + 4 ); 338 338 -
src/SynTree/Statement.h
r405c592 r1a18423 315 315 class TryStmt : public Statement { 316 316 public: 317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< Statement *> &handlers, FinallyStmt *finallyBlock = 0 );317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 318 318 TryStmt( const TryStmt &other ); 319 319 virtual ~TryStmt(); … … 321 321 CompoundStmt *get_block() const { return block; } 322 322 void set_block( CompoundStmt *newValue ) { block = newValue; } 323 std::list< Statement *>& get_catchers() { return handlers; }323 std::list<CatchStmt *>& get_catchers() { return handlers; } 324 324 325 325 FinallyStmt *get_finally() const { return finallyBlock; } … … 333 333 private: 334 334 CompoundStmt *block; 335 std::list< Statement *> handlers;335 std::list<CatchStmt *> handlers; 336 336 FinallyStmt *finallyBlock; 337 337 }; -
src/SynTree/Visitor.cc
r405c592 r1a18423 301 301 } 302 302 303 void Visitor::visit( UntypedValofExpr *valofExpr ) {304 maybeAccept( valofExpr->get_result(), *this );305 maybeAccept( valofExpr->get_body(), *this );306 }307 308 303 void Visitor::visit( RangeExpr *rangeExpr ) { 309 304 maybeAccept( rangeExpr->get_low(), *this ); -
src/SynTree/Visitor.h
r405c592 r1a18423 81 81 virtual void visit( ConstructorExpr * ctorExpr ); 82 82 virtual void visit( CompoundLiteralExpr *compLitExpr ); 83 virtual void visit( UntypedValofExpr *valofExpr );84 83 virtual void visit( RangeExpr *rangeExpr ); 85 84 virtual void visit( UntypedTupleExpr *tupleExpr ); … … 163 162 } // if 164 163 } catch( SemanticError &e ) { 165 e.set_location( (*i)->location ); 164 e.set_location( (*i)->location ); 166 165 errors.append( e ); 167 166 } // try
Note:
See TracChangeset
for help on using the changeset viewer.