source: src/SynTree/Constant.h@ b05a4eb

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 b05a4eb was bb9d8e8, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Fix Constant print to use Indenter

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