ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since c13b2b8 was
cb4c607,
checked in by Aaron Moss <a3moss@…>, 9 years ago
|
Refactor Constant::from to disambiguate type
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[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 | // |
---|
| 7 | // Constant.cc -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[7f5566b] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Thu Jul 30 15:18:38 2015 |
---|
| 13 | // Update Count : 12 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include <iostream> |
---|
| 17 | #include <list> |
---|
[9d7b3ea] | 18 | #include <string> |
---|
[51b7345] | 19 | |
---|
| 20 | #include "Constant.h" |
---|
| 21 | #include "Type.h" |
---|
| 22 | |
---|
[59db689] | 23 | Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {} |
---|
[51b7345] | 24 | |
---|
[7f5566b] | 25 | Constant::Constant( const Constant &other ) { |
---|
| 26 | type = other.type->clone(); |
---|
| 27 | value = other.value; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | Constant::~Constant() { delete type; } |
---|
[51b7345] | 31 | |
---|
[cb4c607] | 32 | Constant Constant::from_int( int i ) { |
---|
[9d7b3ea] | 33 | return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) ); |
---|
| 34 | } |
---|
| 35 | |
---|
[cb4c607] | 36 | Constant Constant::from_ulong( unsigned long i ) { |
---|
[9d7b3ea] | 37 | return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) ); |
---|
| 38 | } |
---|
| 39 | |
---|
[cb4c607] | 40 | Constant Constant::from_double( double d ) { |
---|
[9d7b3ea] | 41 | return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) ); |
---|
| 42 | } |
---|
| 43 | |
---|
[7f5566b] | 44 | Constant *Constant::clone() const { assert( false ); return 0; } |
---|
[51b7345] | 45 | |
---|
| 46 | void Constant::print( std::ostream &os ) const { |
---|
[ea9b9d3] | 47 | os << "(" << value; |
---|
[0dd3a2f] | 48 | if ( type ) { |
---|
[ea9b9d3] | 49 | os << ": "; |
---|
[0dd3a2f] | 50 | type->print( os ); |
---|
| 51 | } // if |
---|
[ea9b9d3] | 52 | os << ")"; |
---|
[51b7345] | 53 | } |
---|
| 54 | |
---|
[0dd3a2f] | 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.