Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Constant.h

    rbb9d8e8 r7870799  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:46 2017
    13 // Update Count     : 17
     12// Last Modified On : Wed Jul 10 15:57:38 2019
     13// Update Count     : 19
    1414//
    1515
     
    1818#include <iosfwd>     // for ostream
    1919#include <string>     // for string
     20#include <optional>   // for optional
    2021
    2122#include "BaseSyntaxNode.h"
     
    2728class Constant : public BaseSyntaxNode {
    2829  public:
    29         Constant( Type * type, std::string rep, unsigned long long val );
    30         Constant( Type * type, std::string rep, double val );
     30        Constant( Type * type, std::string rep, std::optional<unsigned long long> i );
    3131        Constant( const Constant & other );
     32        Constant & operator=( const Constant & ) = default;
    3233        virtual ~Constant();
    3334
    34         virtual Constant * clone() const { return new Constant( *this ); }
     35        virtual Constant * clone() const override { return new Constant( *this ); }
    3536
    3637        Type * get_type() { return type; }
     
    3940        void set_value( std::string newValue ) { rep = newValue; }
    4041        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 );
    4745        /// generates an integer constant of the given int
    4846        static Constant from_int( int i );
    4947        /// generates an integer constant of the given unsigned long int
    5048        static Constant from_ulong( unsigned long i );
    51         /// generates a floating point constant of the given double
    52         static Constant from_double( double d );
    5349
    5450        /// generates a null pointer value for the given type. void * if omitted.
    5551        static Constant null( Type * ptrtype = nullptr );
    5652
    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:
     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
    6158        Type * type;
    6259        std::string rep;
    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;
     60        std::optional<unsigned long long> ival;
    6961};
    7062
Note: See TracChangeset for help on using the changeset viewer.