# source:src/SynTree/Constant.h@6b0b624

Last change on this file since 6b0b624 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
Line
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
13// Update Count     : 17
14//
15
16#pragma once
17
18#include "SynTree.h"
19#include "Visitor.h"
20#include "Mutator.h"
21
22class Constant {
23  public:
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 );
27        virtual ~Constant();
28
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; }
33        unsigned long long get_ival() const;
34        double get_dval() const;
35
36        /// generates a boolean constant of the given bool
37        static Constant from_bool( bool b );
38        /// generates an integer constant of the given int
39        static Constant from_int( int i );
40        /// generates an integer constant of the given unsigned long int
41        static Constant from_ulong( unsigned long i );
42        /// generates a floating point constant of the given double
43        static Constant from_double( double d );
44
45        /// generates a null pointer value for the given type. void * if omitted.
46        static Constant null( Type * ptrtype = nullptr );
47
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;
51  private:
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;
60};
61
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.