source: src/SynTree/Constant.cc @ cb4c607

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglergc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since cb4c607 was cb4c607, checked in by Aaron Moss <a3moss@…>, 5 years ago

Refactor Constant::from to disambiguate type

  • Property mode set to 100644
File size: 1.5 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.cc --
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 : Thu Jul 30 15:18:38 2015
13// Update Count     : 12
14//
15
16#include <iostream>
17#include <list>
18#include <string>
19
20#include "Constant.h"
21#include "Type.h"
22
23Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {}
24
25Constant::Constant( const Constant &other ) {
26        type = other.type->clone();
27        value = other.value;
28}
29
30Constant::~Constant() { delete type; }
31
32Constant Constant::from_int( int i ) {
33        return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) );
34}
35
36Constant Constant::from_ulong( unsigned long i ) {
37        return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) );
38}
39
40Constant Constant::from_double( double d ) {
41        return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) );
42}
43
44Constant *Constant::clone() const { assert( false ); return 0; }
45
46void Constant::print( std::ostream &os ) const {
47        os << "(" << value;
48        if ( type ) {
49                os << ": ";
50                type->print( os );
51        } // if
52  os << ")";
53}
54
55// Local Variables: //
56// tab-width: 4 //
57// mode: c++ //
58// compile-command: "make install" //
59// End: //
Note: See TracBrowser for help on using the repository browser.