]> git.saurik.com Git - cycript.git/commitdiff
Also use CXType walker to for function prototypes.
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 9 Jan 2016 04:32:36 +0000 (20:32 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 9 Jan 2016 04:32:36 +0000 (20:32 -0800)
Analyze.cpp
Decode.cpp
Execute.cpp
Output.cpp
Parser.ypp.in
Replace.cpp
Syntax.hpp
sig/ffi_type.cpp
sig/parse.cpp

index f1ef1073652197e10ebad5b610b8d713ca96f610..5bf49148fcb0c6f4504fe95483c1f078a3144c15 100644 (file)
@@ -367,8 +367,10 @@ static void CYParseType(CXType type, CYType *typed) {
         } break;
 
         case CXType_Bool: typed->specifier_ = $ CYTypeVariable("bool"); break;
-        case CXType_Float: typed->specifier_ = $ CYTypeVariable("float"); break;
-        case CXType_Double: typed->specifier_ = $ CYTypeVariable("double"); break;
+        case CXType_WChar: typed->specifier_ = $ CYTypeVariable("wchar_t"); break;
+        case CXType_Float: typed->specifier_ = $ CYTypeFloating(0); break;
+        case CXType_Double: typed->specifier_ = $ CYTypeFloating(1); break;
+        case CXType_LongDouble: typed->specifier_ = $ CYTypeFloating(2); break;
 
         case CXType_Char_U: typed->specifier_ = $ CYTypeCharacter(CYTypeNeutral); break;
         case CXType_Char_S: typed->specifier_ = $ CYTypeCharacter(CYTypeNeutral); break;
@@ -654,8 +656,13 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
                 goto skip;
 
             if (code == NULL) {
+                value << "*";
                 CXType type(clang_getCursorType(cursor));
-                value << "*(typedef " << CYCXString(clang_getTypeSpelling(type)) << ").pointerTo()(dlsym(RTLD_DEFAULT,'" << label.substr(1) << "'))";
+                CYType *typed(CYDecodeType(type));
+                CYOptions options;
+                CYOutput out(*value.rdbuf(), options);
+                CYTypeExpression(typed).Output(out, CYNoBFC);
+                value << ".pointerTo()(dlsym(RTLD_DEFAULT,'" << label.substr(1) << "'))";
             } else {
                 CYOptions options;
                 CYOutput out(*value.rdbuf(), options);
index c20fb1cd1aa3d18edcabac3f9b15583c2cbf987b..63bb9efe040e43284308107178ca4a25845dcd4e 100644 (file)
@@ -38,12 +38,17 @@ CYType *Primitive<char>::Decode(CYPool &pool) const {
 
 template <>
 CYType *Primitive<double>::Decode(CYPool &pool) const {
-    return $ CYType($ CYTypeVariable("double"));
+    return $ CYType($ CYTypeFloating(1));
 }
 
 template <>
 CYType *Primitive<float>::Decode(CYPool &pool) const {
-    return $ CYType($ CYTypeVariable("float"));
+    return $ CYType($ CYTypeFloating(0));
+}
+
+template <>
+CYType *Primitive<long double>::Decode(CYPool &pool) const {
+    return $ CYType($ CYTypeFloating(2));
 }
 
 template <>
index 0f27732ce57d36bb12392bb0b89f34c363751389..48dc4780d8924538f8ac01af90bef4ac5647a57b 100644 (file)
@@ -332,6 +332,7 @@ JSValueRef CYCastJSValue(JSContextRef context, double value) {
         return JSValueMakeNumber(context, static_cast<double>(value)); \
     }
 
+CYCastJSValue_(long double)
 CYCastJSValue_(signed short int)
 CYCastJSValue_(unsigned short int)
 CYCastJSValue_(signed int)
@@ -716,13 +717,17 @@ void Primitive<Type_>::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi
     *reinterpret_cast<Type_ *>(data) = CYCastDouble(context, value); \
 }
 
-CYPoolFFI_(double)
+CYPoolFFI_(wchar_t)
 CYPoolFFI_(float)
+CYPoolFFI_(double)
+CYPoolFFI_(long double)
+
 CYPoolFFI_(signed char)
 CYPoolFFI_(signed int)
 CYPoolFFI_(signed long int)
 CYPoolFFI_(signed long long int)
 CYPoolFFI_(signed short int)
+
 CYPoolFFI_(unsigned char)
 CYPoolFFI_(unsigned int)
 CYPoolFFI_(unsigned long int)
@@ -852,13 +857,17 @@ JSValueRef Primitive<Type_>::FromFFI(JSContextRef context, ffi_type *ffi, void *
 }
 
 CYFromFFI_(bool)
-CYFromFFI_(double)
+CYFromFFI_(wchar_t)
 CYFromFFI_(float)
+CYFromFFI_(double)
+CYFromFFI_(long double)
+
 CYFromFFI_(signed char)
 CYFromFFI_(signed int)
 CYFromFFI_(signed long int)
 CYFromFFI_(signed long long int)
 CYFromFFI_(signed short int)
+
 CYFromFFI_(unsigned char)
 CYFromFFI_(unsigned int)
 CYFromFFI_(unsigned long int)
@@ -2563,6 +2572,7 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) {
 
     CYSetProperty(context, cache, CYJSString("float"), CYMakeType(context, sig::Primitive<float>()), kJSPropertyAttributeDontEnum);
     CYSetProperty(context, cache, CYJSString("double"), CYMakeType(context, sig::Primitive<double>()), kJSPropertyAttributeDontEnum);
+    CYSetProperty(context, cache, CYJSString("longdouble"), CYMakeType(context, sig::Primitive<long double>()), kJSPropertyAttributeDontEnum);
 
     CYSetProperty(context, global, CYJSString("require"), &require_callAsFunction, kJSPropertyAttributeDontEnum);
 
index 3daf4cfa66c6218943ea7890f63e4a7caf53e4e0..50cc836c822ef5b5ff26a74a687d72f598c0783f 100644 (file)
@@ -1185,6 +1185,15 @@ void CYTypeError::Output(CYOutput &out) const {
     out << "@error";
 }
 
+void CYTypeFloating::Output(CYOutput &out) const {
+    switch (length_) {
+        case 0: out << "float"; break;
+        case 1: out << "double"; break;
+        case 2: out << "long" << ' ' << "double"; break;
+        default: _assert(false);
+    }
+}
+
 void CYTypeInt128::Output(CYOutput &out) const {
     switch (signing_) {
         case CYTypeNeutral: break;
index 0d8e87d50109910107dd4d3b02bff9953f3e0516..d60826315de8a1609a62bc22ea40355ae98441dd 100644 (file)
@@ -981,11 +981,9 @@ IdentifierTypeNoOf
     | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
     | "byte" { $$ = CYNew CYIdentifier("byte"); }
     | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
-    | "double" { $$ = CYNew CYIdentifier("double"); }
     | "each" { $$ = CYNew CYIdentifier("each"); }
     | "eval" { $$ = CYNew CYIdentifier("eval"); }
     | "final" { $$ = CYNew CYIdentifier("final"); }
-    | "float" { $$ = CYNew CYIdentifier("float"); }
     | "from" { $$ = CYNew CYIdentifier("from"); }
     | "get" { $$ = CYNew CYIdentifier("get"); }
     | "goto" { $$ = CYNew CYIdentifier("goto"); }
@@ -1029,6 +1027,8 @@ IdentifierTypeOpt
 IdentifierNoOf
     : IdentifierTypeNoOf
     | "char" { $$ = CYNew CYIdentifier("char"); }
+    | "double" { $$ = CYNew CYIdentifier("double"); }
+    | "float" { $$ = CYNew CYIdentifier("float"); }
     | "int" { $$ = CYNew CYIdentifier("int"); }
     | "__int128" { $$ = CYNew CYIdentifier("__int128"); }
     | "long" { $$ = CYNew CYIdentifier("long"); }
@@ -2150,6 +2150,9 @@ PrimitiveType
     | IntegerType[pass] { $$ = $pass; }
     | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); }
     | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); }
+    | "float" { $$ = CYNew CYTypeFloating(0); }
+    | "double" { $$ = CYNew CYTypeFloating(1); }
+    | "long" "double" { $$ = CYNew CYTypeFloating(2); }
     ;
 
 PrimitiveReference
index bfcacf48676732d07d2bb3e986ae36c9101a3572..68beb4f47b3ad1127ba94aabb0338c714434b159 100644 (file)
@@ -1269,6 +1269,15 @@ CYTarget *CYTypeExpression::Replace(CYContext &context) {
     return typed_->Replace(context);
 }
 
+CYTarget *CYTypeFloating::Replace(CYContext &context) {
+    switch (length_) {
+        case 0: return $V("float");
+        case 1: return $V("double");
+        case 2: return $V("longdouble");
+        default: _assert(false);
+    }
+}
+
 CYTarget *CYTypeInt128::Replace(CYContext &context) {
     return $V(signing_ == CYTypeUnsigned ? "uint128" : "int128");
 }
index a3dad90021400de93df1b69430a257eee6ffbf70..c710d8971b2962317d4e735df3122429921a5e50 100644 (file)
@@ -2154,6 +2154,20 @@ struct CYTypeIntegral :
     virtual void Output(CYOutput &out) const;
 };
 
+struct CYTypeFloating :
+    CYTypeSpecifier
+{
+    int length_;
+
+    CYTypeFloating(int length) :
+        length_(length)
+    {
+    }
+
+    virtual CYTarget *Replace(CYContext &context);
+    virtual void Output(CYOutput &out) const;
+};
+
 struct CYTypeVoid :
     CYTypeSpecifier
 {
index e0c4d0f900bd41e73a873563c266ac02cb98540c..04c68a135b5c40bc6a48d0af5b027a3a29825462 100644 (file)
@@ -48,6 +48,11 @@ ffi_type *Primitive<float>::GetFFI(CYPool &pool) const {
     return &ffi_type_float;
 }
 
+template <>
+ffi_type *Primitive<long double>::GetFFI(CYPool &pool) const {
+    return &ffi_type_longdouble;
+}
+
 template <>
 ffi_type *Primitive<double>::GetFFI(CYPool &pool) const {
     return &ffi_type_double;
index 20fa5a2474536ca4d0a3af83c29a8169e64e395d..7e025f8a1a3f363a0c98aa8c9bca52f641feb1ce 100644 (file)
@@ -169,6 +169,7 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback
         break;
 
         case 'c': type = new(pool) Primitive<signed char>(); break;
+        case 'D': type = new(pool) Primitive<long double>(); break;
         case 'd': type = new(pool) Primitive<double>(); break;
         case 'f': type = new(pool) Primitive<float>(); break;
         case 'i': type = new(pool) Primitive<signed int>(); break;
@@ -279,6 +280,11 @@ const char *Primitive<float>::Encode(CYPool &pool) const {
     return "f";
 }
 
+template <>
+const char *Primitive<long double>::Encode(CYPool &pool) const {
+    return "D";
+}
+
 template <>
 const char *Primitive<signed char>::Encode(CYPool &pool) const {
     return "c";