source: src/SynTree/Constant.h @ 0f2c555

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0f2c555 was 7870799, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Cast cost and conversion cost now take constant parameters.
This required supporting visiting const node.
The PassVisitor? can now visit const nodes but not when using the Indexer

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