Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

scv_expression.cpp

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   scv_expression.cpp -- The public interface for the expression facility.
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey, Samir Agrawal
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
00037 
00038  *****************************************************************************/
00039 
00040 #include "scv/scv_util.h"
00041 #include "scv/scv_introspection.h"
00042 #include "scv/scv_debug.h"
00043 
00044 int scv_expression::_debug = scv_debug::INITIAL_DEBUG_LEVEL;
00045 
00047 // Class : scv_expression
00048 //   - Implementation of scv_expression interface
00050 
00051 scv_expression::scv_expression(scv_expression_core_base * core) : core_(core) {}
00052 
00053 scv_expression::scv_expression(const scv_expression& rhs) : core_(rhs.core_) {}
00054  
00055 scv_expression::scv_expression(int i) : core_(new scv_expression_core(i) ) {}
00056 
00057 scv_expression::scv_expression(long long i) : core_(new scv_expression_core(i)) {}
00058 
00059 scv_expression::scv_expression(bool b) : core_(new scv_expression_core(b) ) {}
00060 
00061 scv_expression::scv_expression(unsigned u) : core_(new scv_expression_core(u) ) {}
00062 
00063 scv_expression::scv_expression(unsigned long long u) : core_(new scv_expression_core(u)) {}
00064 
00065 scv_expression::scv_expression(double d) : core_(new scv_expression_core(d)) {}
00066 
00067 scv_expression::scv_expression(sc_string s) : core_(new scv_expression_core(s)) {}
00068 
00069 scv_expression::scv_expression(string s) : core_(new scv_expression_core(s)) {}
00070 
00071 scv_expression::~scv_expression() {}
00072 
00073 scv_expression operator==(const scv_expression& a,
00074                          const scv_expression& b) 
00075 {
00076   return scv_expression(new scv_expression_core(scv_expression::EQUAL, a, b)); 
00077 }
00078 
00079 scv_expression operator!=(const scv_expression& a,
00080                          const scv_expression& b) 
00081 {
00082   return scv_expression(new scv_expression_core(scv_expression::NOT_EQUAL, a, b)); 
00083 }
00084 
00085 scv_expression operator>(const scv_expression& a,
00086                         const scv_expression& b) 
00087 {
00088   return scv_expression(new scv_expression_core(scv_expression::GREATER_THAN, a, b)); 
00089 }
00090 
00091 scv_expression operator<(const scv_expression& a,
00092                         const scv_expression& b) 
00093 {
00094   return scv_expression(new scv_expression_core(scv_expression::LESS_THAN, a, b)); 
00095 }
00096 
00097 scv_expression operator>=(const scv_expression& a,
00098                          const scv_expression& b) 
00099 {
00100   return scv_expression(new scv_expression_core(scv_expression::GREATER_OR_EQUAL, a, b)); 
00101 }
00102 
00103 scv_expression operator<=(const scv_expression& a,
00104                          const scv_expression& b) 
00105 {
00106   return scv_expression(new scv_expression_core(scv_expression::LESS_OR_EQUAL, a, b)); 
00107 }
00108 
00109 scv_expression operator&&(const scv_expression& a,
00110                          const scv_expression& b) 
00111 {
00112   return scv_expression(new scv_expression_core(scv_expression::AND, a, b)); 
00113 }
00114 
00115 scv_expression operator||(const scv_expression& a,
00116                          const scv_expression& b) 
00117 {
00118   return scv_expression(new scv_expression_core(scv_expression::OR, a, b)); 
00119 }
00120 
00121 scv_expression operator!(const scv_expression& a)
00122 {
00123   return scv_expression(new scv_expression_core(scv_expression::NOT, a, a)); 
00124 }
00125 
00126 scv_expression operator+(const scv_expression& a,
00127                         const scv_expression& b) 
00128 {
00129   return scv_expression(new scv_expression_core(scv_expression::PLUS, a, b)); 
00130 }
00131 
00132 scv_expression operator-(const scv_expression& a,
00133                         const scv_expression& b) 
00134 {
00135   return scv_expression(new scv_expression_core(scv_expression::MINUS, a, b)); 
00136 }
00137 
00138 scv_expression operator*(const scv_expression& a,
00139                         const scv_expression& b) 
00140 {
00141   return scv_expression(new scv_expression_core(scv_expression::MULTIPLY, a, b)); 
00142 }
00143 
00144 scv_expression& scv_expression::operator=(bool) { static scv_expression e = scv_expression(new scv_expression_core(1));
00145   *this = e; 
00146   return *this;
00147 }
00148 
00149 scv_expression& scv_expression::operator&=(const scv_expression& e) { 
00150   *this = *this && e;
00151   return *this; 
00152 }
00153 
00154 template <typename T>
00155 static T _evaluateOperation(const scv_expression& e, T& left, T& right ); 
00156 static const scv_extensions_if * _evaluateExpression(const scv_expression& e); 
00157 static bool _getBool(const scv_extensions_if * valueP); 
00158 
00159 bool scv_expression::evaluate(void) const {
00160   const scv_extensions_if * valueP = _evaluateExpression(*this);
00161   if (!valueP) return false;
00162   switch (valueP->get_type()) {
00163   case scv_extensions_if::RECORD:
00164   case scv_extensions_if::ARRAY:
00165     assert(0); return false;
00166   case scv_extensions_if::INTEGER:
00167     return valueP->get_integer() > 0; 
00168   case scv_extensions_if::BOOLEAN:
00169     return valueP->get_bool(); 
00170   case scv_extensions_if::UNSIGNED:
00171     return valueP->get_unsigned() > 0; 
00172   case scv_extensions_if::FLOATING_POINT_NUMBER:
00173     return valueP->get_double() > 0; 
00174   default: {
00175     string msg = "Cannot recognize extensions of type " +
00176                  string(valueP->get_type_name()) + "in scv_expression";
00177     _scv_message::message(_scv_message::INTERNAL_ERROR, msg.c_str());
00178     return false;
00179   }
00180   }
00181 }
00182 
00183 long long scv_expression::get_int_value() const 
00184 {
00185   return (core_->get_int_value());
00186 }
00187 
00188 bool scv_expression::get_bool_value() const 
00189 {
00190   return (core_->get_bool_value());
00191 }
00192 
00193 unsigned long long scv_expression::get_unsigned_value() const 
00194 {
00195   return (core_->get_unsigned_value());
00196 }
00197 
00198 double scv_expression::get_double_value() const 
00199 {
00200   return (core_->get_double_value());
00201 }
00202 
00203 int scv_expression::get_bit_width(void) const {
00204   return core_->get_bit_width();
00205 }
00206 
00207 scv_extensions_if* scv_expression::get_extension(void) const 
00208 {
00209   return (core_->get_extension());
00210 }
00211 
00212 sc_interface* scv_expression::get_signal(void) const 
00213 {
00214   return (core_->get_signal());
00215 }
00216 
00217 static void _get_extension_list(const scv_expression& e, 
00218   list<scv_extensions_if*>&ext_list);
00219 
00220 void scv_expression::get_extension_list(list<scv_extensions_if*>& ext_list)
00221 {
00222   ext_list.clear();
00223   _get_extension_list(*this, ext_list);
00224 }
00225 
00226 static void _get_signal_list(const scv_expression& e, 
00227   list<sc_interface*>&sig_list);
00228 
00229 void scv_expression::get_signal_list(list<sc_interface*>& sig_list)
00230 {
00231   sig_list.clear();
00232   _get_signal_list(*this, sig_list);
00233 }
00234 
00235 const scv_expression& scv_expression::get_left(void) const
00236 {
00237   return (core_->get_left());
00238 }
00239 
00240 const scv_expression& scv_expression::get_right(void) const
00241 {
00242   return (core_->get_right());
00243 }
00244 
00245 scv_expression::operatorT scv_expression::get_operator(void) const
00246 {
00247   return (core_->get_operator());
00248 }
00249 
00250 void _scv_update_signal_value(const scv_expression& e)
00251 {
00252   e.update_signal_value();
00253 }
00254 
00255 static string _get_expression_string(const scv_expression& e);
00256 
00257 const char *scv_expression::get_expression_string(void) const 
00258 {
00259   static string text;
00260   text = _get_expression_string(*this);
00261   return text.c_str();
00262 }
00263 
00264 int scv_expression::get_debug()
00265 {
00266   return _debug;
00267 }
00268 
00269 const char *scv_expression::get_name() const
00270 {
00271   return core_->get_name();
00272 }
00273 
00274 const char *scv_expression::kind() const
00275 {
00276   static const char *name = "scv_expression"; 
00277   return name;
00278 }
00279 
00280 void scv_expression::print(ostream& o, int details, int indent) const
00281 {
00282   o << get_expression_string() << endl; 
00283 }
00284 
00285 void scv_expression::set_debug(int debug)
00286 {
00287   if ( _debug == debug ) return;
00288   _debug = debug;
00289   scv_debug::set_facility_level(scv_debug::RANDOMIZATION, debug);
00290 }
00291 
00292 void scv_expression::show(int details, int indent) const
00293 {
00294   print(scv_out, details, indent);
00295 }
00296 
00297 void scv_expression::update_signal_value(void) const
00298 {
00299   core_->update_signal_value();
00300 }
00301 
00302 void scv_expression::get_value(bool& v) const{ 
00303   core_->get_value(v);
00304 }
00305 void scv_expression::get_value(char& v) const{ 
00306   core_->get_value(v);
00307 }
00308 void scv_expression::get_value(short& v) const{ 
00309   core_->get_value(v);
00310 }
00311 void scv_expression::get_value(unsigned short& v) const{ 
00312   core_->get_value(v);
00313 }
00314 void scv_expression::get_value(int& v) const{ 
00315   core_->get_value(v);
00316 }
00317 void scv_expression::get_value(unsigned int& v) const{ 
00318   core_->get_value(v);
00319 }
00320 void scv_expression::get_value(long& v) const{ 
00321   core_->get_value(v);
00322 }
00323 void scv_expression::get_value(unsigned long& v) const{ 
00324   core_->get_value(v);
00325 }
00326 void scv_expression::get_value(long long& v) const{ 
00327   core_->get_value(v);
00328 }
00329 void scv_expression::get_value(unsigned long long& v) const{ 
00330   core_->get_value(v);
00331 }
00332 void scv_expression::get_value(float& v) const{ 
00333   core_->get_value(v);
00334 }
00335 void scv_expression::get_value(double& v) const{ 
00336   core_->get_value(v);
00337 }
00338 void scv_expression::get_value(string& v) const{ 
00339   core_->get_value(v);
00340 }
00341 void scv_expression::get_value(sc_string& v) const{ 
00342   core_->get_value(v);
00343 }
00344 void scv_expression::get_value(sc_bv_base& v) const{ 
00345   core_->get_value(v);
00346 }
00347 void scv_expression::get_value(sc_lv_base& v) const{ 
00348   core_->get_value(v);
00349 }
00350 
00351 static string _get_expression_string(const scv_expression& e) {
00352   char tmpString[1024];
00353   switch (e.get_operator()) {
00354   case scv_expression::EMPTY:
00355     return "(empty)";
00356   case scv_expression::INT_CONSTANT:
00357     sprintf(tmpString,"%lld",e.get_int_value()); return tmpString;
00358   case scv_expression::BOOLEAN_CONSTANT:
00359     if (e.get_bool_value()) {
00360       sprintf(tmpString,"true"); return tmpString;
00361     } else {
00362       sprintf(tmpString,"false"); return tmpString;
00363     }
00364   case scv_expression::UNSIGNED_CONSTANT:
00365     sprintf(tmpString,"%llu",e.get_unsigned_value()); return tmpString;
00366   case scv_expression::SC_BIGINT_CONSTANT:
00367   case scv_expression::SC_BIGUINT_CONSTANT:
00368   case scv_expression::SC_BV_CONSTANT: {
00369     sc_bv_base val(e.get_bit_width());
00370     e.get_value(val);
00371     for (int i=0; i < val.size(); i++) { 
00372       sprintf(tmpString , "%ld%s", val.get_word(i), tmpString) ;
00373     }
00374     return tmpString;
00375   }
00376   case scv_expression::DOUBLE_CONSTANT:
00377     sprintf(tmpString,"%f",e.get_double_value()); return tmpString;
00378   case scv_expression::EXTENSION:
00379     return e.get_name();
00380   case scv_expression::PLUS:
00381     return "(" + _get_expression_string(e.get_left()) + "+" + _get_expression_string(e.get_right()) + ")";
00382   case scv_expression::MINUS:
00383     return "(" + _get_expression_string(e.get_left()) + "-" + _get_expression_string(e.get_right()) + ")";
00384   case scv_expression::MULTIPLY:
00385     return "(" + _get_expression_string(e.get_left()) + "*" + _get_expression_string(e.get_right()) + ")";
00386   case scv_expression::EQUAL:
00387     return "(" + _get_expression_string(e.get_left()) + "==" + _get_expression_string(e.get_right()) + ")";
00388   case scv_expression::NOT_EQUAL:
00389     return "(" + _get_expression_string(e.get_left()) + "!=" + _get_expression_string(e.get_right()) + ")";
00390   case scv_expression::GREATER_THAN:
00391     return "(" + _get_expression_string(e.get_left()) + ">" + _get_expression_string(e.get_right()) + ")";
00392   case scv_expression::LESS_THAN:
00393     return "(" + _get_expression_string(e.get_left()) + "<" + _get_expression_string(e.get_right()) + ")";
00394 
00395   case scv_expression::GREATER_OR_EQUAL:
00396     return "(" + _get_expression_string(e.get_left()) + ">=" + _get_expression_string(e.get_right()) + ")";
00397   case scv_expression::LESS_OR_EQUAL:
00398     return "(" + _get_expression_string(e.get_left()) + "<=" + _get_expression_string(e.get_right()) + ")";
00399   case scv_expression::AND:
00400     return "(" + _get_expression_string(e.get_left()) + "&&" + _get_expression_string(e.get_right()) + ")";
00401   case scv_expression::OR:
00402     return "(" + _get_expression_string(e.get_left()) + "||" + _get_expression_string(e.get_right()) + ")";
00403   case scv_expression::NOT:
00404     return "!" + _get_expression_string(e.get_left());
00405   case scv_expression::SC_SIGNAL:
00406     return e.get_name();
00407   default:
00408     return "<error>";
00409   }
00410 }
00411 
00412 static void _get_extension_list(const scv_expression& e, list<scv_extensions_if*>&ext_list)
00413 {
00414   switch (e.get_operator()) {
00415   case scv_expression::EMPTY:
00416   case scv_expression::INT_CONSTANT:
00417   case scv_expression::BOOLEAN_CONSTANT:
00418   case scv_expression::UNSIGNED_CONSTANT:
00419   case scv_expression::DOUBLE_CONSTANT:
00420   case scv_expression::SC_SIGNAL:
00421     return;
00422   case scv_expression::EXTENSION:
00423     ext_list.push_back(e.get_extension());
00424     return;
00425   case scv_expression::PLUS:
00426   case scv_expression::MINUS:
00427   case scv_expression::MULTIPLY:
00428   case scv_expression::EQUAL:
00429   case scv_expression::NOT_EQUAL:
00430   case scv_expression::GREATER_THAN:
00431   case scv_expression::LESS_THAN:
00432   case scv_expression::GREATER_OR_EQUAL:
00433   case scv_expression::LESS_OR_EQUAL:
00434   case scv_expression::AND:
00435   case scv_expression::OR:
00436     _get_extension_list(e.get_left(),ext_list);
00437     _get_extension_list(e.get_right(),ext_list);
00438     return;
00439   case scv_expression::NOT:
00440     _get_extension_list(e.get_left(),ext_list);
00441     return;
00442   default:
00443     return;
00444   }
00445 }
00446 
00447 static void _get_signal_list(const scv_expression& e, list<sc_interface*>&sig_list)
00448 {
00449   switch (e.get_operator()) {
00450   case scv_expression::EMPTY:
00451   case scv_expression::INT_CONSTANT:
00452   case scv_expression::BOOLEAN_CONSTANT:
00453   case scv_expression::UNSIGNED_CONSTANT:
00454   case scv_expression::DOUBLE_CONSTANT:
00455   case scv_expression::EXTENSION:
00456     return;
00457   case scv_expression::SC_SIGNAL:
00458     sig_list.push_back(e.get_signal());
00459     return;
00460   case scv_expression::PLUS:
00461   case scv_expression::MINUS:
00462   case scv_expression::MULTIPLY:
00463   case scv_expression::EQUAL:
00464   case scv_expression::NOT_EQUAL:
00465   case scv_expression::GREATER_THAN:
00466   case scv_expression::LESS_THAN:
00467   case scv_expression::GREATER_OR_EQUAL:
00468   case scv_expression::LESS_OR_EQUAL:
00469   case scv_expression::AND:
00470   case scv_expression::OR:
00471     _get_signal_list(e.get_left(),sig_list);
00472     _get_signal_list(e.get_right(),sig_list);
00473     return;
00474   case scv_expression::NOT:
00475     _get_signal_list(e.get_left(),sig_list);
00476     return;
00477   default:
00478     return;
00479   }
00480 }
00481 
00482 static bool _getBool(const scv_extensions_if * valueP) {
00483   switch (valueP->get_type()) {
00484   case scv_extensions_if::INTEGER:
00485     return valueP->get_integer() > 0;
00486   case scv_extensions_if::BOOLEAN:
00487     return valueP->get_bool();
00488   case scv_extensions_if::UNSIGNED:
00489     return valueP->get_unsigned() > 0;
00490   case scv_extensions_if::FLOATING_POINT_NUMBER:
00491     return valueP->get_double() > 0;
00492   default:
00493     assert(0); return false;
00494   }
00495 } 
00496 
00497 template <typename T>
00498 static T _evaluateOperation(const scv_expression& e, T& left, T& right ) {
00499   switch (e.get_operator()) {
00500   case scv_expression::PLUS:
00501     return left + right; 
00502   case scv_expression::MINUS:
00503     return left - right; 
00504   case scv_expression::MULTIPLY:
00505     return left * right;
00506   case scv_expression::EQUAL:
00507     return left == right;
00508   case scv_expression::NOT_EQUAL:
00509     return left != right;
00510   case scv_expression::GREATER_THAN:
00511     return left > right;
00512   case scv_expression::LESS_THAN:
00513     return left < right;
00514   case scv_expression::GREATER_OR_EQUAL:
00515     return left >= right;
00516   case scv_expression::LESS_OR_EQUAL:
00517     return left <= right;
00518   default:
00519     assert(0); T val=0; return val;
00520   }
00521 }
00522 
00523 static const scv_extensions_if * 
00524 _evaluateExpression(const scv_expression& e) {
00525   static scv_smart_ptr<long long> s_intValue;
00526   static scv_smart_ptr<unsigned long long> s_unsignedValue;
00527   static scv_smart_ptr<double> s_doubleValue;
00528   static scv_smart_ptr<bool> s_boolValue;
00529 
00530   switch (e.get_operator()) {
00531   case scv_expression::EMPTY:
00532     *s_intValue = 0; return &*s_intValue;
00533   case scv_expression::INT_CONSTANT:
00534     *s_intValue = e.get_int_value(); return &*s_intValue;
00535   case scv_expression::BOOLEAN_CONSTANT:
00536     *s_boolValue = e.get_bool_value(); return &*s_boolValue;
00537   case scv_expression::UNSIGNED_CONSTANT:
00538     *s_unsignedValue = e.get_unsigned_value(); return &*s_unsignedValue;
00539   case scv_expression::DOUBLE_CONSTANT:
00540     *s_doubleValue = e.get_double_value(); return &*s_doubleValue;
00541   case scv_expression::EXTENSION:
00542     return e.get_extension();
00543   case scv_expression::SC_SIGNAL: 
00544     _scv_update_signal_value(e);
00545     return e.get_extension();
00546   case scv_expression::PLUS:
00547   case scv_expression::MINUS:
00548   case scv_expression::MULTIPLY:
00549   case scv_expression::EQUAL:
00550   case scv_expression::NOT_EQUAL:
00551   case scv_expression::GREATER_THAN:
00552   case scv_expression::LESS_THAN:
00553   case scv_expression::GREATER_OR_EQUAL:
00554   case scv_expression::LESS_OR_EQUAL:
00555     {
00556       const scv_extensions_if * valueP;
00557 
00558       valueP = _evaluateExpression(e.get_left());
00559       if (!valueP) return NULL;
00560 
00561       switch(valueP->get_type()) {
00562       case scv_extensions_if::INTEGER: {
00563         int left = (int)valueP->get_integer();
00564         valueP = _evaluateExpression(e.get_right());
00565         if (!valueP) return NULL;
00566         int right = (int)valueP->get_integer();
00567         *s_intValue = _evaluateOperation(e, left, right);
00568         return &*s_intValue;
00569         break;
00570       }
00571       case scv_extensions_if::BOOLEAN: {
00572         bool left = (bool)valueP->get_bool();
00573         valueP = _evaluateExpression(e.get_right());
00574         if (!valueP) return NULL;
00575         bool right = (bool)valueP->get_bool();
00576         *s_boolValue = _evaluateOperation(e, left, right);
00577         return &*s_boolValue;
00578         break;
00579       }
00580       case scv_extensions_if::UNSIGNED: {
00581         unsigned left = (unsigned)valueP->get_unsigned();
00582         valueP = _evaluateExpression(e.get_right());
00583         if (!valueP) return NULL;
00584         unsigned right = (unsigned)valueP->get_unsigned();
00585         *s_unsignedValue = _evaluateOperation(e, left, right);
00586         return &*s_unsignedValue;
00587         break;
00588       }
00589       case scv_extensions_if::FLOATING_POINT_NUMBER: {
00590         double left = valueP->get_double();
00591         valueP = _evaluateExpression(e.get_right());
00592         if (!valueP) return NULL;
00593         double right = valueP->get_double();
00594         *s_doubleValue = _evaluateOperation(e, left, right);
00595         return &*s_doubleValue;
00596         break;
00597       }
00598       default: {
00599         string msg = "Cannot recognize extensions of type " +
00600                  string(valueP->get_type_name()) + "in scv_expression";
00601         _scv_message::message(_scv_message::INTERNAL_ERROR, msg.c_str());
00602   *s_intValue = 0; return &*s_intValue;
00603       }
00604       }
00605     }
00606   case scv_expression::AND:
00607     {
00608       const scv_extensions_if * valueP;
00609 
00610       valueP = _evaluateExpression(e.get_left());
00611       if (!valueP) return NULL;
00612       bool left = _getBool(valueP);
00613 
00614       valueP = _evaluateExpression(e.get_right());
00615       if (!valueP) return NULL;
00616       bool right = _getBool(valueP);
00617 
00618       *s_intValue = left && right;
00619       return &*s_intValue;
00620     }
00621   case scv_expression::OR:
00622     {
00623       const scv_extensions_if * valueP;
00624 
00625       valueP = _evaluateExpression(e.get_left());
00626       if (!valueP) return NULL;
00627       bool left = _getBool(valueP);
00628 
00629       valueP = _evaluateExpression(e.get_right());
00630       if (!valueP) return NULL;
00631       bool right = _getBool(valueP);
00632 
00633       *s_intValue = left || right;
00634       return &*s_intValue;
00635     }
00636   case scv_expression::NOT:
00637     {
00638       const scv_extensions_if * valueP;
00639 
00640       valueP = _evaluateExpression(e.get_left());
00641       if (!valueP) return NULL;
00642       bool left = _getBool(valueP);
00643 
00644       *s_intValue = !left;
00645       return &*s_intValue;
00646     }
00647   default: {
00648     char msg[1024];
00649     sprintf(msg, "Cannot recognize extensions of type %d in scv_expression.",
00650       e.get_operator()); 
00651     _scv_message::message(_scv_message::INTERNAL_ERROR, msg);
00652     return NULL;
00653   }
00654   }
00655 }
00656 
00657 
00658 
00659 scv_expression_core::scv_expression_core(scv_extensions_if * core) : core_(core), _data(NULL) {
00660   _operator = scv_expression::EXTENSION;
00661 }
00662 scv_expression_core::scv_expression_core(int i) : core_(NULL), _data(NULL) {
00663   _value._intValue = i;
00664   _bit_width = sizeof(int) * 8;
00665   _operator = scv_expression::INT_CONSTANT;
00666 } 
00667 scv_expression_core::scv_expression_core(long long i) : core_(NULL), _data(NULL) {
00668   _value._intValue = i; 
00669   _bit_width = sizeof(long long) * 8;
00670   _operator = scv_expression::INT_CONSTANT;
00671 } 
00672 scv_expression_core::scv_expression_core(bool i) : core_(NULL) , _data(NULL){
00673   _value._boolValue = i;
00674   _bit_width = sizeof(bool) * 8;
00675   _operator = scv_expression::BOOLEAN_CONSTANT;
00676 } 
00677 scv_expression_core::scv_expression_core(unsigned u) : core_(NULL) , _data(NULL){
00678   _value._unsignedValue = u;
00679   _bit_width = sizeof(unsigned) * 8;
00680   _operator = scv_expression::UNSIGNED_CONSTANT;
00681 }
00682 scv_expression_core::scv_expression_core(unsigned long long u) : core_(NULL) , _data(NULL){
00683   _value._unsignedValue = u;
00684   _bit_width = sizeof(unsigned long long) * 8;
00685   _operator = scv_expression::UNSIGNED_CONSTANT;
00686 }
00687 scv_expression_core::scv_expression_core(double d) : core_(NULL) , _data(NULL){
00688   _value._doubleValue = d;
00689   _bit_width = sizeof(double) * 8;
00690   _operator = scv_expression::DOUBLE_CONSTANT;
00691 }
00692 scv_expression_core::scv_expression_core(string s) : core_(NULL) , _data(NULL){
00693   _value._str = new string;
00694   _bit_width = s.length();
00695   *(_value._str) = s;
00696   _operator = scv_expression::STRING_CONSTANT;
00697 }
00698 scv_expression_core::scv_expression_core(sc_string s) : core_(NULL) , _data(NULL){
00699   _value._sc_str = new sc_string;
00700   _bit_width = s.length();
00701   *(_value._sc_str) = s;
00702   _operator = scv_expression::SC_STRING_CONSTANT;
00703 }
00704 scv_expression_core::~scv_expression_core() {
00705   if (_operator == scv_expression::SC_BIGINT_CONSTANT ||
00706     _operator == scv_expression::SC_BIGUINT_CONSTANT ||       
00707     _operator == scv_expression::SC_BV_CONSTANT ) {          
00708     if (_data) delete _data;
00709   } else if (_operator == scv_expression::STRING_CONSTANT) {
00710     if (_value._str) delete _value._str;
00711   } else if (_operator == scv_expression::SC_STRING_CONSTANT) {
00712     if (_value._str) delete _value._sc_str;
00713   }
00714 }
00715 const char *scv_expression_core::get_name(void) const {
00716   const static char *def_name = "";
00717   const static char *def_signal_name = "signal";
00718   const static char *def_ext_name = "default";
00719 
00720   if (_operator == scv_expression::EXTENSION) {
00721     if ( ! strcmp(core_->get_name(),"") ) {
00722       return def_ext_name;
00723     } else {
00724       return core_->get_name();
00725     }
00726   } else if (_operator == scv_expression::SC_SIGNAL) {
00727       return def_signal_name;
00728   } else {
00729     _scv_expression_error::illegalAccess("get_name");
00730     return def_name;
00731   }
00732 }
00733 void scv_expression_core::update_signal_value(void) const {
00734     assert(0);
00735 }
00736 long long scv_expression_core::get_int_value(void) const {
00737   if (_operator == scv_expression::INT_CONSTANT) {
00738     return _value._intValue;
00739   } else {
00740     _scv_expression_error::illegalAccess("get_int_value");
00741     return 0;
00742   }
00743 }
00744 bool scv_expression_core::get_bool_value(void) const {
00745   if (_operator == scv_expression::BOOLEAN_CONSTANT) {
00746     return _value._boolValue;
00747   } else {
00748     _scv_expression_error::illegalAccess("get_bool_value");
00749     return 0;
00750   }
00751 }
00752 unsigned long long scv_expression_core::get_unsigned_value(void) const {
00753   if (_operator == scv_expression::UNSIGNED_CONSTANT) {
00754     return _value._unsignedValue;
00755   } else {
00756     _scv_expression_error::illegalAccess("get_unsigned_value");
00757     return 0;
00758   }
00759 }
00760 double scv_expression_core::get_double_value(void) const {
00761   if (_operator == scv_expression::DOUBLE_CONSTANT) {
00762     return _value._doubleValue;
00763   } else {
00764     _scv_expression_error::illegalAccess("get_double_value");
00765     return 0.0;
00766   }
00767 }
00768 scv_extensions_if * scv_expression_core::get_extension(void) const {
00769   if (_operator == scv_expression::EXTENSION ||
00770       _operator == scv_expression::SC_SIGNAL ) {
00771     return core_;
00772   } else {
00773     _scv_expression_error::illegalAccess("get_extension");
00774     return NULL;
00775   }
00776 }
00777 sc_interface * scv_expression_core::get_signal(void) const {
00778     _scv_expression_error::illegalAccess("get_signal");
00779     return NULL;
00780 }
00781 
00782 void scv_expression_core::get_value(char& val) const {
00783   _SCV_GET_SC_VAL(char, to_int);
00784 }
00785 
00786 void scv_expression_core::get_value(short& val) const {
00787  _SCV_GET_SC_VAL(short, to_int);
00788 }
00789 
00790 void scv_expression_core::get_value(unsigned short& val) const {
00791   _SCV_GET_SC_VAL(int, to_uint);
00792 }
00793 
00794 void scv_expression_core::get_value(int& val) const {
00795   _SCV_GET_SC_VAL(int, to_int);
00796 }
00797 
00798 void scv_expression_core::get_value(unsigned int& val) const {
00799   _SCV_GET_SC_VAL(int, to_uint);
00800 }
00801 
00802 void scv_expression_core::get_value(long& val) const {
00803   _SCV_GET_SC_VAL(long, to_long);
00804 }
00805 
00806 void scv_expression_core::get_value(unsigned long& val) const {
00807   _SCV_GET_SC_VAL(unsigned long, to_ulong);
00808 }
00809 
00810 void scv_expression_core::get_value(long long& val) const {
00811   _SCV_GET_SC_VAL(long long, to_int64);
00812 }
00813 
00814 void scv_expression_core::get_value(unsigned long long& val) const {
00815   _SCV_GET_SC_VAL(unsigned long long, to_uint64);
00816 }
00817 
00818 void scv_expression_core::get_value(float& val) const {
00819   _SCV_GET_SC_VAL(float, to_double);
00820 }
00821 
00822 void scv_expression_core::get_value(double& val) const {
00823   _SCV_GET_SC_VAL(double, to_double);
00824 }
00825 
00826 void scv_expression_core::get_value(string& val) const {
00827   if (_operator == scv_expression::STRING_CONSTANT) { 
00828     val = *(_value._str);
00829   } else if (_operator == scv_expression::SC_STRING_CONSTANT) {
00830     val = (_value._sc_str)->c_str();
00831   } else {
00832     _scv_expression_error::illegalAccess("get_value(string&)");
00833     return ;                                               
00834   }
00835 }
00836 
00837 void scv_expression_core::get_value(sc_string& val) const {
00838   if (_operator == scv_expression::SC_STRING_CONSTANT) {
00839     val = *(_value._sc_str);
00840   } else if (_operator == scv_expression::STRING_CONSTANT) {
00841     val = (_value._str)->c_str();
00842   } else {
00843     _scv_expression_error::illegalAccess("get_value(sc_string&)");
00844     return ;                                                  
00845   }
00846 }
00847 
00848 void scv_expression_core::get_value(sc_bv_base& val) const {
00849   _SCV_GET_CONSTANT_VALUE();                                        
00850   val = value;
00851   _SCV_GET_CONSTANT_ERROR(sc_bv_base);                         
00852 }
00853 
00854 void scv_expression_core::get_value(sc_lv_base& val) const {
00855   _SCV_GET_CONSTANT_VALUE();                                        
00856   val = value;
00857   _SCV_GET_CONSTANT_ERROR(sc_lv_base);                         
00858 }
00859 
00860 void scv_expression_core::get_value(bool& val) const {
00861   if (_operator == scv_expression::BOOLEAN_CONSTANT) {  
00862     val =  _value._boolValue;                          
00863   } else if (_operator == scv_expression::INT_CONSTANT) { 
00864     val = (_value._intValue != 0);                              
00865   } else if (_operator == scv_expression::UNSIGNED_CONSTANT) {
00866     val = (_value._unsignedValue != 0);                             
00867   } else if (_operator == scv_expression::SC_BIGINT_CONSTANT ||
00868     _operator == scv_expression::SC_BIGUINT_CONSTANT ||       
00869     _operator == scv_expression::SC_BV_CONSTANT ) {          
00870     val = ((*_data) != 0);
00871   } else {
00872     _scv_expression_error::illegalAccess("get_value(bool&)");
00873     return ;                                                  
00874   }
00875 }

Generated on Fri Jan 14 08:29:10 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18