Changes in src/SynTree/Constant.h [7870799:bb9d8e8]
- File:
-
- 1 edited
-
src/SynTree/Constant.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Constant.h
r7870799 rbb9d8e8 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 10 15:57:38 201913 // Update Count : 1 912 // Last Modified On : Sat Jul 22 09:54:46 2017 13 // Update Count : 17 14 14 // 15 15 … … 18 18 #include <iosfwd> // for ostream 19 19 #include <string> // for string 20 #include <optional> // for optional21 20 22 21 #include "BaseSyntaxNode.h" … … 28 27 class Constant : public BaseSyntaxNode { 29 28 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 ); 31 31 Constant( const Constant & other ); 32 Constant & operator=( const Constant & ) = default;33 32 virtual ~Constant(); 34 33 35 virtual Constant * clone() const override{ return new Constant( *this ); }34 virtual Constant * clone() const { return new Constant( *this ); } 36 35 37 36 Type * get_type() { return type; } … … 40 39 void set_value( std::string newValue ) { rep = newValue; } 41 40 unsigned long long get_ival() const; 41 double get_dval() const; 42 42 43 43 /// generates a boolean constant of the given bool 44 44 static Constant from_bool( bool b ); 45 /// generates a char constant of the given char 46 static Constant from_char( char c ); 45 47 /// generates an integer constant of the given int 46 48 static Constant from_int( int i ); 47 49 /// generates an integer constant of the given unsigned long int 48 50 static Constant from_ulong( unsigned long i ); 51 /// generates a floating point constant of the given double 52 static Constant from_double( double d ); 49 53 50 54 /// generates a null pointer value for the given type. void * if omitted. 51 55 static Constant null( Type * ptrtype = nullptr ); 52 56 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: 58 61 Type * type; 59 62 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; 61 69 }; 62 70
Note:
See TracChangeset
for help on using the changeset viewer.