Changeset d56e5bc for src/SynTree
- Timestamp:
- Jun 21, 2017, 5:47:44 PM (7 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:
- e9a3b20b
- Parents:
- da24468
- Location:
- src/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.cc
rda24468 rd56e5bc 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
rda24468 rd56e5bc 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
Note: See TracChangeset
for help on using the changeset viewer.