Changes in src/SynTree/Constant.cc [bb9d8e8:c36298d]
- File:
-
- 1 edited
-
src/SynTree/Constant.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.cc
rbb9d8e8 rc36298d 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 : Fri Jul 14 14:50:00 201713 // Update Count : 2911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:11:22 2019 13 // Update Count : 32 14 14 // 15 15 … … 19 19 20 20 #include "Constant.h" 21 #include "Expression.h" // for ConstantExpr 21 22 #include "Type.h" // for BasicType, Type, Type::Qualifiers, PointerType 22 23 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 Constant::Constant( Type * type, std::string rep, std::optional<unsigned long long> ival ) : type( type ), rep( rep ), ival( ival ) {} 25 25 26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {26 Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), ival( other.ival ) { 27 27 type = other.type->clone(); 28 28 } … … 34 34 } 35 35 36 Constant Constant::from_char( char c ) {37 return Constant( new BasicType( Type::Qualifiers(), BasicType::Char ), std::to_string( c ), (unsigned long long int)c );38 }39 40 36 Constant Constant::from_int( int i ) { 41 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); … … 44 40 Constant Constant::from_ulong( unsigned long i ) { 45 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i ); 46 }47 48 Constant Constant::from_double( double d ) {49 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );50 42 } 51 43 … … 63 55 unsigned long long Constant::get_ival() const { 64 56 assertf( strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." ); 65 return val.ival; 66 } 67 68 double Constant::get_dval() const { 69 assertf( ! strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." ); 70 return val.dval; 57 return ival.value(); 71 58 } 72 59 73 60 void Constant::print( std::ostream &os, Indenter ) const { 74 os << "(" << rep << " " << val.ival;61 os << "(" << rep << " " << (ival ? toString(ival.value()) : "") ; 75 62 if ( type ) { 76 63 os << ": ";
Note:
See TracChangeset
for help on using the changeset viewer.