source: src/SynTree/Constant.h @ f9723e8

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f9723e8 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
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
[39156ed]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Jul 10 15:57:38 2019
13// Update Count     : 19
[0dd3a2f]14//
[51b7345]15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <iosfwd>     // for ostream
19#include <string>     // for string
[c36298d]20#include <optional>   // for optional
[ea6332d]21
[3c398b6]22#include "BaseSyntaxNode.h"
[ea6332d]23#include "Mutator.h"  // for Mutator
24#include "Visitor.h"  // for Visitor
25
26class Type;
[51b7345]27
[3c398b6]28class Constant : public BaseSyntaxNode {
[0dd3a2f]29  public:
[c36298d]30        Constant( Type * type, std::string rep, std::optional<unsigned long long> i );
[d56e5bc]31        Constant( const Constant & other );
[39156ed]32        Constant & operator=( const Constant & ) = default;
[0dd3a2f]33        virtual ~Constant();
34
[7870799]35        virtual Constant * clone() const override { return new Constant( *this ); }
[3c398b6]36
[d56e5bc]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; }
[62423350]41        unsigned long long get_ival() const;
[0dd3a2f]42
[2c37f34]43        /// generates a boolean constant of the given bool
44        static Constant from_bool( bool b );
[9d7b3ea]45        /// generates an integer constant of the given int
[cb4c607]46        static Constant from_int( int i );
[9d7b3ea]47        /// generates an integer constant of the given unsigned long int
[cb4c607]48        static Constant from_ulong( unsigned long i );
[9d7b3ea]49
[6ea87486]50        /// generates a null pointer value for the given type. void * if omitted.
51        static Constant null( Type * ptrtype = nullptr );
52
[7870799]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
[d56e5bc]58        Type * type;
59        std::string rep;
[c36298d]60        std::optional<unsigned long long> ival;
[51b7345]61};
62
[0dd3a2f]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.