#include <value.h>
Collaboration diagram for celx::Value:

Public Member Functions | |
| bool | booleanValue (bool &) const |
| bool | functionValue (Function *&) const |
| Type | getType () const |
| bool | numberValue (double &) const |
| bool | operator!= (const Value &) const |
| Value & | operator= (const Value &) |
| bool | operator== (const Value &) const |
| void | output (std::ostream &) const |
| bool | stringValue (std::string &) const |
| bool | toBoolean () const |
| double | toNumber () const |
| std::string | toString () const |
| Value (Function *) | |
| Value (bool) | |
| Value (const std::string &) | |
| Value (double) | |
| Value (const Value &) | |
| Value () | |
| ~Value () | |
Private Attributes | |
| Type | type |
| union { | |
| bool boolVal | |
| Function * funcVal | |
| double numVal | |
| const std::string * strVal | |
| } | val |
|
|
Definition at line 19 of file value.cpp. References celx::NilType. 00019 : 00020 type(NilType) 00021 { 00022 }
|
|
|
Definition at line 67 of file value.cpp. References celx::NilType.
|
|
|
Definition at line 38 of file value.cpp. References celx::NumberType, and val.
|
|
|
Definition at line 45 of file value.cpp. References celx::StringType, and val.
|
|
|
Definition at line 52 of file value.cpp. References celx::BooleanType, and val.
|
|
|
Definition at line 59 of file value.cpp. References celx::FunctionType, and val.
|
|
|
Definition at line 25 of file value.cpp. References celx::FunctionType, celx::StringType, type, and val. 00026 {
00027 if (type == StringType)
00028 {
00029 delete val.strVal;
00030 }
00031 else if (type == FunctionType)
00032 {
00033 delete val.funcVal;
00034 }
00035 }
|
|
|
Definition at line 69 of file value.h. 00070 {
00071 if (type != BooleanType)
00072 {
00073 return false;
00074 }
00075 else
00076 {
00077 x = val.boolVal;
00078 return true;
00079 }
00080 }
|
|
|
Definition at line 108 of file value.h. References celx::FunctionType. Referenced by celx::FunctionCallExpression::eval(). 00109 {
00110 if (type != FunctionType)
00111 {
00112 return false;
00113 }
00114 else
00115 {
00116 f = val.funcVal;
00117 return true;
00118 }
00119 }
|
|
|
Definition at line 64 of file value.h. 00065 {
00066 return type;
00067 }
|
|
|
Definition at line 82 of file value.h. Referenced by AddFunc(), DivideFunc(), MultiplyFunc(), and SubtractFunc(). 00083 {
00084 if (type != NumberType)
00085 {
00086 return false;
00087 }
00088 else
00089 {
00090 x = val.numVal;
00091 return true;
00092 }
00093 }
|
|
|
Definition at line 141 of file value.cpp. 00142 {
00143 return !(*this == v);
00144 }
|
|
|
Definition at line 74 of file value.cpp. References celx::BooleanType, celx::FunctionType, funcVal, celx::NilType, celx::NumberType, celx::StringType, strVal, type, and val. 00075 {
00076 if (this != &v)
00077 {
00078 // Clean up the current contents first
00079 switch (type)
00080 {
00081 case StringType:
00082 delete val.strVal;
00083 break;
00084 case FunctionType:
00085 delete val.funcVal;
00086 break;
00087 default:
00088 break;
00089 }
00090
00091 type = v.type;
00092 switch (type)
00093 {
00094 case NumberType:
00095 val.numVal = v.val.numVal;
00096 break;
00097 case StringType:
00098 val.strVal = new string(*v.val.strVal);
00099 break;
00100 case BooleanType:
00101 val.boolVal = v.val.boolVal;
00102 break;
00103 case NilType:
00104 break;
00105 case FunctionType:
00106 val.funcVal = new Function(*v.val.funcVal);
00107 break;
00108 default:
00109 assert(0);
00110 break;
00111 }
00112 }
00113
00114 return *this;
00115 }
|
|
|
Definition at line 118 of file value.cpp. References celx::BooleanType, celx::FunctionType, celx::NilType, celx::NumberType, celx::StringType, type, and val. 00119 {
00120 if (v.type != type)
00121 return false;
00122
00123 switch (type)
00124 {
00125 case BooleanType:
00126 return v.val.boolVal == val.boolVal;
00127 case NumberType:
00128 return v.val.numVal == val.numVal;
00129 case StringType:
00130 return *v.val.strVal == *val.strVal;
00131 case FunctionType:
00132 return v.val.funcVal == val.funcVal;
00133 case NilType:
00134 return true;
00135 default:
00136 return false;
00137 }
00138 }
|
|
|
Definition at line 207 of file value.cpp. References celx::BooleanType, celx::FunctionType, celx::NilType, celx::NumberType, celx::StringType, type, and val. 00208 {
00209 switch (type)
00210 {
00211 case NilType:
00212 out << "null";
00213 break;
00214 case BooleanType:
00215 if (val.boolVal)
00216 out << "true";
00217 else
00218 out << "false";
00219 break;
00220 case NumberType:
00221 out << val.numVal;
00222 break;
00223 case StringType:
00224 out << '"' << *val.strVal << '"';
00225 break;
00226 case FunctionType:
00227 out << "[function]";
00228 break;
00229 default:
00230 out << "#unknown";
00231 break;
00232 }
00233 }
|
|
|
Definition at line 95 of file value.h. 00096 {
00097 if (type != StringType)
00098 {
00099 return false;
00100 }
00101 else
00102 {
00103 x = *val.strVal;
00104 return true;
00105 }
00106 }
|
|
|
Definition at line 147 of file value.cpp. References celx::BooleanType, celx::NumberType, celx::StringType, type, and val. Referenced by celx::WhileStatement::execute(), and celx::IfStatement::execute(). 00148 {
00149 switch (type)
00150 {
00151 case BooleanType:
00152 return val.boolVal;
00153 case NumberType:
00154 return val.numVal != 0.0;
00155 case StringType:
00156 return !val.strVal->empty();
00157 default:
00158 return false;
00159 }
00160 }
|
|
|
Definition at line 163 of file value.cpp. References celx::BooleanType, celx::NumberType, celx::StringType, type, and val. 00164 {
00165 switch (type)
00166 {
00167 case BooleanType:
00168 return val.boolVal ? 1.0 : 0.0;
00169 case NumberType:
00170 return val.numVal;
00171 case StringType:
00172 return 0.0; // TODO: attempt conversion to number
00173 default:
00174 return 0.0;
00175 }
00176 }
|
|
|
Definition at line 179 of file value.cpp. References celx::BooleanType, celx::NilType, celx::NumberType, celx::StringType, type, and val. 00180 {
00181 switch (type)
00182 {
00183 case BooleanType:
00184 if (val.boolVal)
00185 return string("true");
00186 else
00187 return string("false");
00188 case NumberType:
00189 {
00190 char buf[256];
00191 sprintf(buf, "%f", val.numVal);
00192 return string(buf);
00193 }
00194
00195 case StringType:
00196 return *val.strVal;
00197
00198 case NilType:
00199 return string("null");
00200
00201 default:
00202 return string("");
00203 }
00204 }
|
|
|
|
|
|
Definition at line 60 of file value.h. Referenced by operator=(). |
|
|
|
|
|
Definition at line 59 of file value.h. Referenced by operator=(). |
|
|
Definition at line 54 of file value.h. Referenced by operator=(), operator==(), output(), toBoolean(), toNumber(), toString(), and ~Value(). |
|
|
Referenced by operator=(), operator==(), output(), toBoolean(), toNumber(), toString(), Value(), and ~Value(). |
1.4.1