source: src/SynTree/Constant.h @ 8217e8f

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8217e8f was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change #ifndef to #pragma once

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[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//
[51b7345]15
[6b0b624]16#pragma once
[51b7345]17
18#include "SynTree.h"
19#include "Visitor.h"
20#include "Mutator.h"
21
[0dd3a2f]22class Constant {
23  public:
[d56e5bc]24        Constant( Type * type, std::string rep, unsigned long long val );
25        Constant( Type * type, std::string rep, double val );
26        Constant( const Constant & other );
[0dd3a2f]27        virtual ~Constant();
28
[d56e5bc]29        Type * get_type() { return type; }
30        void set_type( Type * newValue ) { type = newValue; }
31        std::string & get_value() { return rep; }
32        void set_value( std::string newValue ) { rep = newValue; }
[62423350]33        unsigned long long get_ival() const;
34        double get_dval() const;
[0dd3a2f]35
[2c37f34]36        /// generates a boolean constant of the given bool
37        static Constant from_bool( bool b );
[9d7b3ea]38        /// generates an integer constant of the given int
[cb4c607]39        static Constant from_int( int i );
[9d7b3ea]40        /// generates an integer constant of the given unsigned long int
[cb4c607]41        static Constant from_ulong( unsigned long i );
[9d7b3ea]42        /// generates a floating point constant of the given double
[cb4c607]43        static Constant from_double( double d );
[9d7b3ea]44
[6ea87486]45        /// generates a null pointer value for the given type. void * if omitted.
46        static Constant null( Type * ptrtype = nullptr );
47
[d56e5bc]48        virtual void accept( Visitor & v ) { v.visit( this ); }
49        virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
50        virtual void print( std::ostream & os ) const;
[0dd3a2f]51  private:
[d56e5bc]52        Type * type;
53        std::string rep;
54        union Val {
55                unsigned long long ival;
56                double dval;
57                Val( unsigned long long ival ) : ival( ival ) {}
58                Val( double dval ) : dval( dval ) {}
59        } val;
[51b7345]60};
61
[0dd3a2f]62// Local Variables: //
63// tab-width: 4 //
64// mode: c++ //
65// compile-command: "make install" //
66// End: //
Note: See TracBrowser for help on using the repository browser.