source: src/SynTree/Constant.h@ 948b0c8

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 948b0c8 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 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//
[51b73452]15
[6b0b624]16#pragma once
[51b73452]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;
[51b73452]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.