source: src/SynTree/Constant.h@ 699a97d

ADT ast-experimental
Last change on this file since 699a97d was b91bfde, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added and used some helpers. The widely useful one is a from_string helper for constants.

  • 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 : 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 /// generates a string constant from the given string (char type, unquoted string)
50 static Constant from_string( const std::string & string );
51
52 /// generates a null pointer value for the given type. void * if omitted.
53 static Constant null( Type * ptrtype = nullptr );
54
55 virtual void accept( Visitor & v ) override { v.visit( this ); }
56 virtual void accept( Visitor & v ) const override { v.visit( this ); }
57 virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
58 virtual void print( std::ostream & os, Indenter indent = 0 ) const override;
59
60 Type * type;
61 std::string rep;
62 std::optional<unsigned long long> ival;
63};
64
65// Local Variables: //
66// tab-width: 4 //
67// mode: c++ //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.