Changes in src/SynTree/Constant.cc [c36298d:bb9d8e8]
- File:
-
- 1 edited
-
src/SynTree/Constant.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.cc
rc36298d rbb9d8e8 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 13 18:11:22 201913 // Update Count : 3211 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 14 14:50:00 2017 13 // Update Count : 29 14 14 // 15 15 … … 19 19 20 20 #include "Constant.h" 21 #include "Expression.h" // for ConstantExpr22 21 #include "Type.h" // for BasicType, Type, Type::Qualifiers, PointerType 23 22 24 Constant::Constant( Type * type, std::string rep, std::optional<unsigned long long> ival ) : type( type ), rep( rep ), ival( ival ) {} 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 ) {} 25 25 26 Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), ival( other.ival ) {26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) { 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 36 40 Constant Constant::from_int( int i ) { 37 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); … … 40 44 Constant Constant::from_ulong( unsigned long i ) { 41 45 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 ); 42 50 } 43 51 … … 55 63 unsigned long long Constant::get_ival() const { 56 64 assertf( strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." ); 57 return ival.value(); 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; 58 71 } 59 72 60 73 void Constant::print( std::ostream &os, Indenter ) const { 61 os << "(" << rep << " " << (ival ? toString(ival.value()) : "");74 os << "(" << rep << " " << val.ival; 62 75 if ( type ) { 63 76 os << ": ";
Note:
See TracChangeset
for help on using the changeset viewer.