Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Constant.cc

    rc36298d rbb9d8e8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:11:22 2019
    13 // Update Count     : 32
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jul 14 14:50:00 2017
     13// Update Count     : 29
    1414//
    1515
     
    1919
    2020#include "Constant.h"
    21 #include "Expression.h" // for ConstantExpr
    2221#include "Type.h"    // for BasicType, Type, Type::Qualifiers, PointerType
    2322
    24 Constant::Constant( Type * type, std::string rep, std::optional<unsigned long long> ival ) : type( type ), rep( rep ), ival( ival ) {}
     23Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {}
     24Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {}
    2525
    26 Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), ival( other.ival ) {
     26Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {
    2727        type = other.type->clone();
    2828}
     
    3434}
    3535
     36Constant 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
    3640Constant Constant::from_int( int i ) {
    3741        return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i );
     
    4044Constant Constant::from_ulong( unsigned long i ) {
    4145        return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i );
     46}
     47
     48Constant Constant::from_double( double d ) {
     49        return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );
    4250}
    4351
     
    5563unsigned long long Constant::get_ival() const {
    5664        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
     68double Constant::get_dval() const {
     69        assertf( ! strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." );
     70        return val.dval;
    5871}
    5972
    6073void Constant::print( std::ostream &os, Indenter ) const {
    61         os << "(" << rep << " " << (ival ? toString(ival.value()) : "") ;
     74        os << "(" << rep << " " << val.ival;
    6275        if ( type ) {
    6376                os << ": ";
Note: See TracChangeset for help on using the changeset viewer.