source: src/SynTree/Constant.h @ 08065aa4

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 08065aa4 was c36298d, checked in by Michael Brooks <mlbrooks@…>, 5 years ago

Fixed handling of "literals.cfa" string-detail test cases by simplifying constant analysis. Now a ConstantExpr? is a minial passthrough from parser to code generator, with special-case analysis only for integer values. Awareness of how to build a string-constant type is back in ExpressionNode?.cc; now, this knowlede is only needed there. AST conversion no longer specializes string-int-float constants; it just converts types and passes values through. Unused constant API features are removed, notably from-to-float and from-string.

  • Property mode set to 100644
File size: 2.0 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 : Andrew Beach
12// Last Modified On : Fri Spt 28 14:48:00 2018
13// Update Count     : 18
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        virtual ~Constant();
33
34        virtual Constant * clone() const { return new Constant( *this ); }
35
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; }
40        unsigned long long get_ival() const;
41
42        /// generates a boolean constant of the given bool
43        static Constant from_bool( bool b );
44        /// generates an integer constant of the given int
45        static Constant from_int( int i );
46        /// generates an integer constant of the given unsigned long int
47        static Constant from_ulong( unsigned long i );
48
49        /// generates a null pointer value for the given type. void * if omitted.
50        static Constant null( Type * ptrtype = nullptr );
51
52        virtual void accept( Visitor & v ) { v.visit( this ); }
53        virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
54        virtual void print( std::ostream & os, Indenter indent = 0 ) const;
55  private:
56        Type * type;
57        std::string rep;
58        std::optional<unsigned long long> ival;
59
60        friend class ConverterOldToNew;
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.