| 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 | //
 | 
|---|
| 7 | // Constant.h --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| 11 | // Last Modified By : Andrew Beach
 | 
|---|
| 12 | // Last Modified On : Fri Spt 28 14:48:00 2018
 | 
|---|
| 13 | // Update Count     : 18
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #pragma once
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <iosfwd>     // for ostream
 | 
|---|
| 19 | #include <string>     // for string
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "BaseSyntaxNode.h"
 | 
|---|
| 22 | #include "Mutator.h"  // for Mutator
 | 
|---|
| 23 | #include "Visitor.h"  // for Visitor
 | 
|---|
| 24 | 
 | 
|---|
| 25 | class Type;
 | 
|---|
| 26 | 
 | 
|---|
| 27 | class Constant : public BaseSyntaxNode {
 | 
|---|
| 28 |   public:
 | 
|---|
| 29 |         Constant( Type * type, std::string rep, unsigned long long val );
 | 
|---|
| 30 |         Constant( Type * type, std::string rep, double val );
 | 
|---|
| 31 |         Constant( const Constant & other );
 | 
|---|
| 32 |         virtual ~Constant();
 | 
|---|
| 33 | 
 | 
|---|
| 34 |         virtual Constant * clone() const { return new Constant( *this ); }
 | 
|---|
| 35 | 
 | 
|---|
| 36 |         Type * get_type() { return type; }
 | 
|---|
| 37 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 38 |         std::string & get_value() { return rep; }
 | 
|---|
| 39 |         void set_value( std::string newValue ) { rep = newValue; }
 | 
|---|
| 40 |         unsigned long long get_ival() const;
 | 
|---|
| 41 |         double get_dval() const;
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         /// generates a boolean constant of the given bool
 | 
|---|
| 44 |         static Constant from_bool( bool b );
 | 
|---|
| 45 |         /// generates a char constant of the given char
 | 
|---|
| 46 |         static Constant from_char( char c );
 | 
|---|
| 47 |         /// generates an integer constant of the given int
 | 
|---|
| 48 |         static Constant from_int( int i );
 | 
|---|
| 49 |         /// generates an integer constant of the given unsigned long int
 | 
|---|
| 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 );
 | 
|---|
| 53 |         /// generates an array of chars constant of the given string
 | 
|---|
| 54 |         static Constant from_string( std::string const & s );
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         /// generates a null pointer value for the given type. void * if omitted.
 | 
|---|
| 57 |         static Constant null( Type * ptrtype = nullptr );
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 60 |         virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 61 |         virtual void print( std::ostream & os, Indenter indent = 0 ) const;
 | 
|---|
| 62 |   private:
 | 
|---|
| 63 |         Type * type;
 | 
|---|
| 64 |         std::string rep;
 | 
|---|
| 65 |         union Val {
 | 
|---|
| 66 |                 unsigned long long ival;
 | 
|---|
| 67 |                 double dval;
 | 
|---|
| 68 |                 Val( unsigned long long ival ) : ival( ival ) {}
 | 
|---|
| 69 |                 Val( double dval ) : dval( dval ) {}
 | 
|---|
| 70 |         } val;
 | 
|---|
| 71 | };
 | 
|---|
| 72 | 
 | 
|---|
| 73 | // Local Variables: //
 | 
|---|
| 74 | // tab-width: 4 //
 | 
|---|
| 75 | // mode: c++ //
 | 
|---|
| 76 | // compile-command: "make install" //
 | 
|---|
| 77 | // End: //
 | 
|---|