Changeset 641
- Timestamp:
- 08/28/08 12:41:13 (3 months ago)
- Files:
-
- trunk/rphp/runtime/CMakeLists.txt (modified) (1 diff)
- trunk/rphp/runtime/include/pFunctionManager.h (modified) (1 diff)
- trunk/rphp/runtime/include/pRuntime.h (modified) (1 diff)
- trunk/rphp/runtime/include/pTypeOperators.h (added)
- trunk/rphp/runtime/include/pTypes.h (modified) (3 diffs)
- trunk/rphp/runtime/include/pVar.h (modified) (1 diff)
- trunk/rphp/runtime/include/pVarOperators.h (added)
- trunk/rphp/runtime/pTypeOperators.cpp (added)
- trunk/rphp/runtime/pTypes.cpp (deleted)
- trunk/rphp/runtime/pVarOperators.cpp (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/CMakeLists.txt
r631 r641 9 9 pHash.cpp 10 10 pObject.cpp 11 pTypes.cpp 11 pVarOperators.cpp 12 pTypeOperators.cpp 12 13 pRuntime.cpp 13 14 pOutputBuffer.cpp trunk/rphp/runtime/include/pFunctionManager.h
r621 r641 25 25 #include <boost/multi_index/member.hpp> 26 26 #include <ext/hash_map> 27 #include "pTypeOperators.h" 27 28 #include "pFunctionSig.h" 28 29 trunk/rphp/runtime/include/pRuntime.h
r630 r641 21 21 22 22 #include "pTypes.h" 23 #include "pTypeOperators.h" 24 #include "pVarOperators.h" 23 25 24 26 namespace rphp { trunk/rphp/runtime/include/pTypes.h
r631 r641 20 20 #define RPHP_PTYPES_H_ 21 21 22 #include <boost/lexical_cast.hpp>23 22 #include <boost/tuple/tuple.hpp> 24 23 24 // including this file includes all rphp base types 25 25 #include "pVar.h" 26 26 #include "pHash.h" … … 28 28 #include "pResource.h" 29 29 30 U_NAMESPACE_BEGIN31 // boost hash function for pUString32 std::size_t hash_value(rphp::pUString const& k);33 U_NAMESPACE_END34 35 30 namespace rphp { 36 37 // types used in the runtime which aren't related to pVar (i.e. that aren't builtin php types)38 31 39 32 // note, pUInt is not a base PHP type (all PHP numbers are signed) … … 46 39 typedef boost::tuple<const pUString, const pUInt, const pUInt> pSourceStartEndLocation; 47 40 48 // a visitor for determining type of pVar49 class pVarTypeChecker : public boost::static_visitor<pVarType> {50 51 public:52 53 pVarType operator()(const pTriState &h) const {54 return (pNull(h)) ? pVarNullType : pVarBoolType;55 }56 57 pVarType operator()(const pInt &i) const {58 return pVarIntType;59 }60 61 pVarType operator()(const pFloat &i) const {62 return pVarFloatType;63 }64 65 pVarType operator()(const pBString &str) const {66 return pVarBStringType;67 }68 69 pVarType operator()(const pUStringP &str) const {70 return pVarUStringType;71 }72 73 pVarType operator()(const pHashP &h) const {74 return pVarHashType;75 }76 77 pVarType operator()(const pObjectP &h) const {78 return pVarObjectType;79 }80 81 pVarType operator()(const pResourceP &h) const {82 return pVarResourceType;83 }84 85 pVarType operator()(const pVarRef &p) const {86 return pVarRefType;87 }88 89 };90 91 92 // a visitor for converting to a number (long or float)93 class convertToNumber : public boost::static_visitor<void> {94 protected:95 pVar &var;96 97 public:98 convertToNumber(pVar &v) : var(v) { }99 100 void operator()(pTriState &h) const {101 (h) ? var = 1l : var = 0l;102 }103 104 void operator()(pInt &a) const {105 // nothing, already numeric106 }107 108 void operator()(pFloat &i) const {109 // nothing, already numeric110 }111 112 void operator()(pBString &a) const {113 // TODO: handle floats114 try {115 var = boost::lexical_cast<long>(a);116 } catch(boost::bad_lexical_cast &) {117 var = 0l;118 }119 }120 121 void operator()(pUStringP &a) const {122 // TODO: do a real conversion here123 // should handle both integers and floats124 var = 0l;125 }126 127 void operator()(pHashP &h) const {128 var = (pInt)h->getSize();129 }130 131 void operator()(pObjectP &h) const {132 var = (pInt)h->getNumProperties();133 }134 135 void operator()(pResourceP &h) const {136 // TODO: return static resource count137 var = 0l;138 }139 140 void operator()(pVarRef &r) const {141 // unbox142 //boost::apply_visitor(convertToNumber(*r), *r);143 }144 145 };146 147 // a visitor for converting to a string148 class convertToBString : public boost::static_visitor<void> {149 protected:150 pVar &var;151 152 public:153 convertToBString(pVar &v) : var(v) { }154 155 void operator()(pTriState &h) const {156 (h) ? var = pBString("1") : var = pBString("0");157 }158 159 void operator()(pInt &a) const {160 // TODO: real conversion161 var = pBString("some pInt");162 }163 164 void operator()(pFloat &i) const {165 // TODO: real conversion166 var = pBString("some pFloat");167 }168 169 void operator()(pBString &a) const {170 // nothing171 }172 173 void operator()(pUStringP &a) const {174 // TODO175 }176 177 void operator()(pHashP &h) const {178 var = pBString("array");179 }180 181 void operator()(pObjectP &h) const {182 // TODO: toString183 var = pBString("object");184 }185 186 void operator()(pResourceP &h) const {187 var = pBString("resource");188 }189 190 void operator()(pVarRef &r) const {191 // TODO192 // unbox193 //boost::apply_visitor(convertToNumber(*r), *r);194 }195 196 };197 198 /*199 * convenience accessors200 *201 */202 203 // convert to number (in place)204 inline pVarType pVar_getType(const pVar &p) {205 return boost::apply_visitor(pVarTypeChecker(), p);206 }207 208 // convert to number (in place)209 inline void pVar_convertToNumber(pVar &p) {210 boost::apply_visitor(convertToNumber(p), p);211 }212 213 // get the boolean value of a pVar. does NOT convert so pVar214 // must already be a pTriState215 inline pTriState pVar_getVal_pBool(const pVar &p) {216 return boost::get<rphp::pTriState>(p);217 }218 219 inline pInt pVar_getVal_pInt(const pVar &p) {220 return boost::get<pInt>(p);221 }222 223 inline pBString pVar_getVal_pBString(const pVar &p) {224 return boost::get<pBString>(p);225 }226 227 inline pUStringP pVar_getVal_pUString(const pVar &p) {228 return boost::get<pUStringP>(p);229 }230 231 inline pVarRef pVar_getVal_pRef(const pVar &p) {232 return boost::get<pVarRef>(p);233 }234 235 /*236 * type conversions237 *238 */239 pVar pVar_castToNumber(const pVar p);240 pVar pVar_castToBString(const pVar p);241 242 pVar pVar_add(const pVar lhs, const pVar rhs);243 244 41 } /* namespace rphp */ 245 42 trunk/rphp/runtime/include/pVar.h
r631 r641 25 25 #include <boost/shared_ptr.hpp> 26 26 #include <unicode/unistr.h> 27 #include <iostream>28 27 29 28 namespace rphp { 30 29 31 /* 32 * Definition of the main pVar variant 33 */ 30 /* 31 * Definition of the main pVar variant, which represents 32 * a PHP value in the runtime 33 */ 34 34 35 // a boost::tribool represents php true, false and null values36 // pTrue, pFalse and pNull are defined37 typedef boost::logic::tribool pTriState;38 // convenience accesors39 BOOST_TRIBOOL_THIRD_STATE(pNull)40 #define pTrue pTriState(true)41 #define pFalse pTriState(false)35 // a boost::tribool represents php true, false and null values 36 // pTrue, pFalse and pNull are defined 37 typedef boost::logic::tribool pTriState; 38 // convenience accesors 39 BOOST_TRIBOOL_THIRD_STATE(pNull) 40 #define pTrue pTriState(true) 41 #define pFalse pTriState(false) 42 42 43 // numeric types44 typedef longpInt;45 typedef double pFloat;43 // numeric types 44 typedef signed long pInt; 45 typedef double pFloat; 46 46 47 // string types: binary and unicode flavor48 // "binary" strings49 typedef std::string pBString;47 // string types: binary and unicode flavor 48 // "binary" strings 49 typedef std::string pBString; 50 50 51 // unicode strings, using the ICU library52 typedef UnicodeString pUString;53 typedef boost::shared_ptr<pUString> pUStringP;51 // unicode strings, using the ICU library 52 typedef UnicodeString pUString; 53 typedef boost::shared_ptr<pUString> pUStringP; 54 54 55 // php hash tables56 class pHash;57 typedef boost::shared_ptr<pHash> pHashP;55 // php hash tables 56 class pHash; 57 typedef boost::shared_ptr<pHash> pHashP; 58 58 59 // php objects60 class pObject;61 typedef boost::shared_ptr<pObject> pObjectP;59 // php objects 60 class pObject; 61 typedef boost::shared_ptr<pObject> pObjectP; 62 62 63 // php resources64 class pResource;65 typedef boost::shared_ptr<pResource> pResourceP;63 // php resources 64 class pResource; 65 typedef boost::shared_ptr<pResource> pResourceP; 66 66 67 // base variant that represents a php variable68 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP, pResourceP > pVarBase;67 // base variant that represents a php variable 68 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP, pResourceP > pVarBase; 69 69 70 // reference to a pvarBase, i.e. a container for pvar variables71 typedef boost::shared_ptr<pVarBase> pVarRef;70 // reference to a pvarBase, i.e. a container for pvar variables 71 typedef boost::shared_ptr<pVarBase> pVarRef; 72 72 73 // full pvar definition: a variant that can hold a base type or a reference74 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP, pResourceP, pVarRef > pVar;75 typedef boost::shared_ptr<pVar> pVarP;73 // full pvar definition: a variant that can hold a base type or a reference 74 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP, pResourceP, pVarRef > pVar; 75 typedef boost::shared_ptr<pVar> pVarP; 76 76 77 // associated enum for checking type78 typedef enum {79 pVarNullType,80 pVarBoolType,81 pVarIntType,82 pVarFloatType,83 pVarBStringType,84 pVarUStringType,85 pVarHashType,86 pVarObjectType,87 pVarResourceType,88 pVarRefType89 } pVarType;77 // associated enum for checking type 78 typedef enum { 79 pVarNullType, 80 pVarBoolType, 81 pVarIntType, 82 pVarFloatType, 83 pVarBStringType, 84 pVarUStringType, 85 pVarHashType, 86 pVarObjectType, 87 pVarResourceType, 88 pVarRefType 89 } pVarType; 90 90 91 91 } /* namespace rphp */
