source: src/SynTree/Constant.h @ 68f9c43

new-envwith_gc
Last change on this file since 68f9c43 was 68f9c43, checked in by Aaron Moss <a3moss@…>, 6 years ago

First pass at delete removal

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