[0dd3a2f] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
[62423350] | 7 | // Constant.h --
|
---|
[0dd3a2f] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[2c37f34] | 11 | // Last Modified By : Andrew Beach
|
---|
| 12 | // Last Modified On : Thr Jun 22 10:13:00 2017
|
---|
| 13 | // Update Count : 15
|
---|
[0dd3a2f] | 14 | //
|
---|
[51b73452] | 15 |
|
---|
| 16 | #ifndef CONSTANT_H
|
---|
| 17 | #define CONSTANT_H
|
---|
| 18 |
|
---|
| 19 | #include "SynTree.h"
|
---|
| 20 | #include "Visitor.h"
|
---|
| 21 | #include "Mutator.h"
|
---|
| 22 |
|
---|
[0dd3a2f] | 23 | class Constant {
|
---|
| 24 | public:
|
---|
[d56e5bc] | 25 | Constant( Type * type, std::string rep, unsigned long long val );
|
---|
| 26 | Constant( Type * type, std::string rep, double val );
|
---|
| 27 | Constant( const Constant & other );
|
---|
[0dd3a2f] | 28 | virtual ~Constant();
|
---|
| 29 |
|
---|
[d56e5bc] | 30 | Type * get_type() { return type; }
|
---|
| 31 | void set_type( Type * newValue ) { type = newValue; }
|
---|
| 32 | std::string & get_value() { return rep; }
|
---|
| 33 | void set_value( std::string newValue ) { rep = newValue; }
|
---|
[62423350] | 34 | unsigned long long get_ival() const;
|
---|
| 35 | double get_dval() const;
|
---|
[0dd3a2f] | 36 |
|
---|
[2c37f34] | 37 | /// generates a boolean constant of the given bool
|
---|
| 38 | static Constant from_bool( bool b );
|
---|
[9d7b3ea] | 39 | /// generates an integer constant of the given int
|
---|
[cb4c607] | 40 | static Constant from_int( int i );
|
---|
[9d7b3ea] | 41 | /// generates an integer constant of the given unsigned long int
|
---|
[cb4c607] | 42 | static Constant from_ulong( unsigned long i );
|
---|
[9d7b3ea] | 43 | /// generates a floating point constant of the given double
|
---|
[cb4c607] | 44 | static Constant from_double( double d );
|
---|
[9d7b3ea] | 45 |
|
---|
[d56e5bc] | 46 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 47 | virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
| 48 | virtual void print( std::ostream & os ) const;
|
---|
[0dd3a2f] | 49 | private:
|
---|
[d56e5bc] | 50 | Type * type;
|
---|
| 51 | std::string rep;
|
---|
| 52 | union Val {
|
---|
| 53 | unsigned long long ival;
|
---|
| 54 | double dval;
|
---|
| 55 | Val( unsigned long long ival ) : ival( ival ) {}
|
---|
| 56 | Val( double dval ) : dval( dval ) {}
|
---|
| 57 | } val;
|
---|
[51b73452] | 58 | };
|
---|
| 59 |
|
---|
[0dd3a2f] | 60 | #endif // CONSTANT_H
|
---|
[51b73452] | 61 |
|
---|
[0dd3a2f] | 62 | // Local Variables: //
|
---|
| 63 | // tab-width: 4 //
|
---|
| 64 | // mode: c++ //
|
---|
| 65 | // compile-command: "make install" //
|
---|
| 66 | // End: //
|
---|