//
// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
//
// The contents of this file are covered under the licence agreement in the
// file "LICENCE" distributed with Cforall.
//
// Constant.h --
//
// Author           : Richard C. Bilson
// Created On       : Mon May 18 07:44:20 2015
// Last Modified By : Andrew Beach
// Last Modified On : Fri Spt 28 14:48:00 2018
// Update Count     : 18
//

#pragma once

#include <iosfwd>     // for ostream
#include <string>     // for string

#include "BaseSyntaxNode.h"
#include "Mutator.h"  // for Mutator
#include "Visitor.h"  // for Visitor

class Type;

class Constant : public BaseSyntaxNode {
  public:
	Constant( Type * type, std::string rep, unsigned long long val );
	Constant( Type * type, std::string rep, double val );
	Constant( const Constant & other );
	virtual ~Constant();

	virtual Constant * clone() const { return new Constant( *this ); }

	Type * get_type() { return type; }
	void set_type( Type * newValue ) { type = newValue; }
	std::string & get_value() { return rep; }
	void set_value( std::string newValue ) { rep = newValue; }
	unsigned long long get_ival() const;
	double get_dval() const;

	/// generates a boolean constant of the given bool
	static Constant from_bool( bool b );
	/// generates a char constant of the given char
	static Constant from_char( char c );
	/// generates an integer constant of the given int
	static Constant from_int( int i );
	/// generates an integer constant of the given unsigned long int
	static Constant from_ulong( unsigned long i );
	/// generates a floating point constant of the given double
	static Constant from_double( double d );
	/// generates an array of chars constant of the given string
	static Constant from_string( std::string const & s );

	/// generates a null pointer value for the given type. void * if omitted.
	static Constant null( Type * ptrtype = nullptr );

	virtual void accept( Visitor & v ) { v.visit( this ); }
	virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
	virtual void print( std::ostream & os, Indenter indent = 0 ) const;
  private:
	Type * type;
	std::string rep;
	union Val {
		unsigned long long ival;
		double dval;
		Val( unsigned long long ival ) : ival( ival ) {}
		Val( double dval ) : dval( dval ) {}
	} val;
};

// Local Variables: //
// tab-width: 4 //
// mode: c++ //
// compile-command: "make install" //
// End: //
