| 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 : Andrew Beach
|
|---|
| 12 | // Last Modified On : Thr Jun 22 10:11:00 2017
|
|---|
| 13 | // Update Count : 28
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include <iostream>
|
|---|
| 17 | #include <list>
|
|---|
| 18 | #include <string>
|
|---|
| 19 |
|
|---|
| 20 | #include "Constant.h"
|
|---|
| 21 | #include "Type.h"
|
|---|
| 22 |
|
|---|
| 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 ) {}
|
|---|
| 25 |
|
|---|
| 26 | Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {
|
|---|
| 27 | type = other.type->clone();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | Constant::~Constant() { delete type; }
|
|---|
| 31 |
|
|---|
| 32 | Constant Constant::from_bool( bool b ) {
|
|---|
| 33 | return Constant( new BasicType( Type::Qualifiers(), BasicType::Bool ), b ? "1" : "0" , (unsigned long long int)b );
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | Constant Constant::from_int( int i ) {
|
|---|
| 37 | return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i );
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | Constant Constant::from_ulong( unsigned long i ) {
|
|---|
| 41 | return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i );
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | Constant Constant::from_double( double d ) {
|
|---|
| 45 | return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void Constant::print( std::ostream &os ) const {
|
|---|
| 49 | os << "(" << rep << " " << val.ival;
|
|---|
| 50 | if ( type ) {
|
|---|
| 51 | os << ": ";
|
|---|
| 52 | type->print( os );
|
|---|
| 53 | } // if
|
|---|
| 54 | os << ")";
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | // Local Variables: //
|
|---|
| 58 | // tab-width: 4 //
|
|---|
| 59 | // mode: c++ //
|
|---|
| 60 | // compile-command: "make install" //
|
|---|
| 61 | // End: //
|
|---|