| [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 | 
|---|
| [6b0b624] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Sat Jul 22 09:54:46 2017 | 
|---|
|  | 13 | // Update Count     : 17 | 
|---|
| [0dd3a2f] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [6b0b624] | 16 | #pragma once | 
|---|
| [51b73452] | 17 |  | 
|---|
| [ea6332d] | 18 | #include <iosfwd>     // for ostream | 
|---|
|  | 19 | #include <string>     // for string | 
|---|
|  | 20 |  | 
|---|
|  | 21 | #include "Mutator.h"  // for Mutator | 
|---|
|  | 22 | #include "Visitor.h"  // for Visitor | 
|---|
|  | 23 |  | 
|---|
|  | 24 | class Type; | 
|---|
| [51b73452] | 25 |  | 
|---|
| [0dd3a2f] | 26 | class Constant { | 
|---|
|  | 27 | public: | 
|---|
| [d56e5bc] | 28 | Constant( Type * type, std::string rep, unsigned long long val ); | 
|---|
|  | 29 | Constant( Type * type, std::string rep, double val ); | 
|---|
|  | 30 | Constant( const Constant & other ); | 
|---|
| [0dd3a2f] | 31 | virtual ~Constant(); | 
|---|
|  | 32 |  | 
|---|
| [d56e5bc] | 33 | Type * get_type() { return type; } | 
|---|
|  | 34 | void set_type( Type * newValue ) { type = newValue; } | 
|---|
|  | 35 | std::string & get_value() { return rep; } | 
|---|
|  | 36 | void set_value( std::string newValue ) { rep = newValue; } | 
|---|
| [62423350] | 37 | unsigned long long get_ival() const; | 
|---|
|  | 38 | double get_dval() const; | 
|---|
| [0dd3a2f] | 39 |  | 
|---|
| [2c37f34] | 40 | /// generates a boolean constant of the given bool | 
|---|
|  | 41 | static Constant from_bool( bool b ); | 
|---|
| [a2dbad10] | 42 | /// generates a char constant of the given char | 
|---|
|  | 43 | static Constant from_char( char c ); | 
|---|
| [9d7b3ea] | 44 | /// generates an integer constant of the given int | 
|---|
| [cb4c607] | 45 | static Constant from_int( int i ); | 
|---|
| [9d7b3ea] | 46 | /// generates an integer constant of the given unsigned long int | 
|---|
| [cb4c607] | 47 | static Constant from_ulong( unsigned long i ); | 
|---|
| [9d7b3ea] | 48 | /// generates a floating point constant of the given double | 
|---|
| [cb4c607] | 49 | static Constant from_double( double d ); | 
|---|
| [9d7b3ea] | 50 |  | 
|---|
| [6ea87486] | 51 | /// generates a null pointer value for the given type. void * if omitted. | 
|---|
|  | 52 | static Constant null( Type * ptrtype = nullptr ); | 
|---|
|  | 53 |  | 
|---|
| [d56e5bc] | 54 | virtual void accept( Visitor & v ) { v.visit( this ); } | 
|---|
|  | 55 | virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); } | 
|---|
|  | 56 | virtual void print( std::ostream & os ) const; | 
|---|
| [0dd3a2f] | 57 | private: | 
|---|
| [d56e5bc] | 58 | Type * type; | 
|---|
|  | 59 | std::string rep; | 
|---|
|  | 60 | union Val { | 
|---|
|  | 61 | unsigned long long ival; | 
|---|
|  | 62 | double dval; | 
|---|
|  | 63 | Val( unsigned long long ival ) : ival( ival ) {} | 
|---|
|  | 64 | Val( double dval ) : dval( dval ) {} | 
|---|
|  | 65 | } val; | 
|---|
| [51b73452] | 66 | }; | 
|---|
|  | 67 |  | 
|---|
| [0dd3a2f] | 68 | // Local Variables: // | 
|---|
|  | 69 | // tab-width: 4 // | 
|---|
|  | 70 | // mode: c++ // | 
|---|
|  | 71 | // compile-command: "make install" // | 
|---|
|  | 72 | // End: // | 
|---|