source: src/SynTree/Constant.h @ 80ac42d

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 80ac42d was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

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