| [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
 | 
|---|
| [39156ed] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
 | 12 | // Last Modified On : Wed Jul 10 15:57:38 2019
 | 
|---|
 | 13 | // Update Count     : 19
 | 
|---|
| [0dd3a2f] | 14 | //
 | 
|---|
| [51b73452] | 15 | 
 | 
|---|
| [6b0b624] | 16 | #pragma once
 | 
|---|
| [51b73452] | 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;
 | 
|---|
| [51b73452] | 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 );
 | 
|---|
| [39156ed] | 32 |         Constant & operator=( const Constant & ) = default;
 | 
|---|
| [0dd3a2f] | 33 |         virtual ~Constant();
 | 
|---|
 | 34 | 
 | 
|---|
| [7870799] | 35 |         virtual Constant * clone() const override { return new Constant( *this ); }
 | 
|---|
| [3c398b6] | 36 | 
 | 
|---|
| [d56e5bc] | 37 |         Type * get_type() { return type; }
 | 
|---|
 | 38 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
 | 39 |         std::string & get_value() { return rep; }
 | 
|---|
 | 40 |         void set_value( std::string newValue ) { rep = newValue; }
 | 
|---|
| [62423350] | 41 |         unsigned long long get_ival() const;
 | 
|---|
| [0dd3a2f] | 42 | 
 | 
|---|
| [2c37f34] | 43 |         /// generates a boolean constant of the given bool
 | 
|---|
 | 44 |         static Constant from_bool( bool b );
 | 
|---|
| [9d7b3ea] | 45 |         /// generates an integer constant of the given int
 | 
|---|
| [cb4c607] | 46 |         static Constant from_int( int i );
 | 
|---|
| [9d7b3ea] | 47 |         /// generates an integer constant of the given unsigned long int
 | 
|---|
| [cb4c607] | 48 |         static Constant from_ulong( unsigned long i );
 | 
|---|
| [b91bfde] | 49 |         /// generates a string constant from the given string (char type, unquoted string)
 | 
|---|
 | 50 |         static Constant from_string( const std::string & string );
 | 
|---|
| [9d7b3ea] | 51 | 
 | 
|---|
| [6ea87486] | 52 |         /// generates a null pointer value for the given type. void * if omitted.
 | 
|---|
 | 53 |         static Constant null( Type * ptrtype = nullptr );
 | 
|---|
 | 54 | 
 | 
|---|
| [7870799] | 55 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
 | 56 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
 | 57 |         virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
 | 
|---|
 | 58 |         virtual void print( std::ostream & os, Indenter indent = 0 ) const override;
 | 
|---|
 | 59 | 
 | 
|---|
| [d56e5bc] | 60 |         Type * type;
 | 
|---|
 | 61 |         std::string rep;
 | 
|---|
| [c36298d] | 62 |         std::optional<unsigned long long> ival;
 | 
|---|
| [51b73452] | 63 | };
 | 
|---|
 | 64 | 
 | 
|---|
| [0dd3a2f] | 65 | // Local Variables: //
 | 
|---|
 | 66 | // tab-width: 4 //
 | 
|---|
 | 67 | // mode: c++ //
 | 
|---|
 | 68 | // compile-command: "make install" //
 | 
|---|
 | 69 | // End: //
 | 
|---|