Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Constant.h

    r7870799 rbb9d8e8  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 10 15:57:38 2019
    13 // Update Count     : 19
     12// Last Modified On : Sat Jul 22 09:54:46 2017
     13// Update Count     : 17
    1414//
    1515
     
    1818#include <iosfwd>     // for ostream
    1919#include <string>     // for string
    20 #include <optional>   // for optional
    2120
    2221#include "BaseSyntaxNode.h"
     
    2827class Constant : public BaseSyntaxNode {
    2928  public:
    30         Constant( Type * type, std::string rep, std::optional<unsigned long long> i );
     29        Constant( Type * type, std::string rep, unsigned long long val );
     30        Constant( Type * type, std::string rep, double val );
    3131        Constant( const Constant & other );
    32         Constant & operator=( const Constant & ) = default;
    3332        virtual ~Constant();
    3433
    35         virtual Constant * clone() const override { return new Constant( *this ); }
     34        virtual Constant * clone() const { return new Constant( *this ); }
    3635
    3736        Type * get_type() { return type; }
     
    4039        void set_value( std::string newValue ) { rep = newValue; }
    4140        unsigned long long get_ival() const;
     41        double get_dval() const;
    4242
    4343        /// generates a boolean constant of the given bool
    4444        static Constant from_bool( bool b );
     45        /// generates a char constant of the given char
     46        static Constant from_char( char c );
    4547        /// generates an integer constant of the given int
    4648        static Constant from_int( int i );
    4749        /// generates an integer constant of the given unsigned long int
    4850        static Constant from_ulong( unsigned long i );
     51        /// generates a floating point constant of the given double
     52        static Constant from_double( double d );
    4953
    5054        /// generates a null pointer value for the given type. void * if omitted.
    5155        static Constant null( Type * ptrtype = nullptr );
    5256
    53         virtual void accept( Visitor & v ) override { v.visit( this ); }
    54         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    55         virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    56         virtual void print( std::ostream & os, Indenter indent = 0 ) const override;
    57 
     57        virtual void accept( Visitor & v ) { v.visit( this ); }
     58        virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     59        virtual void print( std::ostream & os, Indenter indent = 0 ) const;
     60  private:
    5861        Type * type;
    5962        std::string rep;
    60         std::optional<unsigned long long> ival;
     63        union Val {
     64                unsigned long long ival;
     65                double dval;
     66                Val( unsigned long long ival ) : ival( ival ) {}
     67                Val( double dval ) : dval( dval ) {}
     68        } val;
    6169};
    6270
Note: See TracChangeset for help on using the changeset viewer.