[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 |
---|
[6c89ecc] | 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Fri Spt 28 14:48:00 2018 |
---|
| 13 | // Update Count : 18 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[ea6332d] | 18 | #include <iosfwd> // for ostream |
---|
| 19 | #include <string> // for string |
---|
[c36298d] | 20 | #include <optional> // for optional |
---|
[ea6332d] | 21 | |
---|
[3c398b6] | 22 | #include "BaseSyntaxNode.h" |
---|
[ea6332d] | 23 | #include "Mutator.h" // for Mutator |
---|
| 24 | #include "Visitor.h" // for Visitor |
---|
| 25 | |
---|
| 26 | class Type; |
---|
[51b7345] | 27 | |
---|
[3c398b6] | 28 | class Constant : public BaseSyntaxNode { |
---|
[0dd3a2f] | 29 | public: |
---|
[c36298d] | 30 | Constant( Type * type, std::string rep, std::optional<unsigned long long> i ); |
---|
[d56e5bc] | 31 | Constant( const Constant & other ); |
---|
[0dd3a2f] | 32 | virtual ~Constant(); |
---|
| 33 | |
---|
[3c398b6] | 34 | virtual Constant * clone() const { return new Constant( *this ); } |
---|
| 35 | |
---|
[d56e5bc] | 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; } |
---|
[62423350] | 40 | unsigned long long get_ival() const; |
---|
[0dd3a2f] | 41 | |
---|
[2c37f34] | 42 | /// generates a boolean constant of the given bool |
---|
| 43 | static Constant from_bool( bool b ); |
---|
[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 | |
---|
[6ea87486] | 49 | /// generates a null pointer value for the given type. void * if omitted. |
---|
| 50 | static Constant null( Type * ptrtype = nullptr ); |
---|
| 51 | |
---|
[d56e5bc] | 52 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 53 | virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
[bb9d8e8] | 54 | virtual void print( std::ostream & os, Indenter indent = 0 ) const; |
---|
[0dd3a2f] | 55 | private: |
---|
[d56e5bc] | 56 | Type * type; |
---|
| 57 | std::string rep; |
---|
[c36298d] | 58 | std::optional<unsigned long long> ival; |
---|
| 59 | |
---|
| 60 | friend class ConverterOldToNew; |
---|
[51b7345] | 61 | }; |
---|
| 62 | |
---|
[0dd3a2f] | 63 | // Local Variables: // |
---|
| 64 | // tab-width: 4 // |
---|
| 65 | // mode: c++ // |
---|
| 66 | // compile-command: "make install" // |
---|
| 67 | // End: // |
---|