source: src/SynTree/Constant.h@ ac10576

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since ac10576 was 6ea87486, checked in by Andrew Beach <ajbeach@…>, 8 years ago

That should be all the base code for 'tree structures' to work.

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