aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since d56e5bc was
d56e5bc,
checked in by Peter A. Buhr <pabuhr@…>, 6 years ago
|
add constant value into constants
|
-
Property mode set to
100644
|
File size:
1.6 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 |
---|
[d56e5bc] | 12 | // Last Modified On : Wed Jun 21 16:44:48 2017 |
---|
| 13 | // Update Count : 27 |
---|
[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 | |
---|
[d56e5bc] | 23 | Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {} |
---|
| 24 | Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {} |
---|
[51b7345] | 25 | |
---|
[d56e5bc] | 26 | Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) { |
---|
[7f5566b] | 27 | type = other.type->clone(); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | Constant::~Constant() { delete type; } |
---|
[51b7345] | 31 | |
---|
[cb4c607] | 32 | Constant Constant::from_int( int i ) { |
---|
[d56e5bc] | 33 | return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); |
---|
[9d7b3ea] | 34 | } |
---|
| 35 | |
---|
[cb4c607] | 36 | Constant Constant::from_ulong( unsigned long i ) { |
---|
[d56e5bc] | 37 | return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i ); |
---|
[9d7b3ea] | 38 | } |
---|
| 39 | |
---|
[cb4c607] | 40 | Constant Constant::from_double( double d ) { |
---|
[d56e5bc] | 41 | return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d ); |
---|
[9d7b3ea] | 42 | } |
---|
| 43 | |
---|
[51b7345] | 44 | void Constant::print( std::ostream &os ) const { |
---|
[d56e5bc] | 45 | os << "(" << rep << " " << val.ival; |
---|
[0dd3a2f] | 46 | if ( type ) { |
---|
[ea9b9d3] | 47 | os << ": "; |
---|
[0dd3a2f] | 48 | type->print( os ); |
---|
| 49 | } // if |
---|
[ea9b9d3] | 50 | os << ")"; |
---|
[51b7345] | 51 | } |
---|
| 52 | |
---|
[0dd3a2f] | 53 | // Local Variables: // |
---|
| 54 | // tab-width: 4 // |
---|
| 55 | // mode: c++ // |
---|
| 56 | // compile-command: "make install" // |
---|
| 57 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.