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