Changes in src/SynTree/Constant.cc [62423350:cb4c607]
- File:
-
- 1 edited
-
src/SynTree/Constant.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.cc
r62423350 rcb4c607 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Constant.cc -- 7 // Constant.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Jun 22 10:11:00 201713 // Update Count : 2811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 30 15:18:38 2015 13 // Update Count : 12 14 14 // 15 15 … … 21 21 #include "Type.h" 22 22 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 ) {} 23 Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {} 25 24 26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ){25 Constant::Constant( const Constant &other ) { 27 26 type = other.type->clone(); 27 value = other.value; 28 28 } 29 29 30 30 Constant::~Constant() { delete type; } 31 31 32 Constant Constant::from_bool( bool b ) {33 return Constant( new BasicType( Type::Qualifiers(), BasicType::Bool ), b ? "1" : "0" , (unsigned long long int)b );34 }35 36 32 Constant Constant::from_int( int i ) { 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) , (unsigned long long int)i);33 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) ); 38 34 } 39 35 40 36 Constant Constant::from_ulong( unsigned long i ) { 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) , (unsigned long long int)i);37 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) ); 42 38 } 43 39 44 40 Constant Constant::from_double( double d ) { 45 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) , d);41 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) ); 46 42 } 47 43 48 unsigned long long Constant::get_ival() const { 49 assertf( safe_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." ); 50 return val.ival; 51 } 52 53 double Constant::get_dval() const { 54 assertf( ! safe_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." ); 55 return val.dval; 56 } 44 Constant *Constant::clone() const { assert( false ); return 0; } 57 45 58 46 void Constant::print( std::ostream &os ) const { 59 os << "(" << rep << " " << val.ival;47 os << "(" << value; 60 48 if ( type ) { 61 49 os << ": ";
Note:
See TracChangeset
for help on using the changeset viewer.