From 1e8d80477a3e058a30c477955f1e0c56deb6e956 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 8 Jan 2016 20:32:36 -0800 Subject: [PATCH] Also use CXType walker to for function prototypes. --- Analyze.cpp | 13 ++++++++++--- Decode.cpp | 9 +++++++-- Execute.cpp | 14 ++++++++++++-- Output.cpp | 9 +++++++++ Parser.ypp.in | 7 +++++-- Replace.cpp | 9 +++++++++ Syntax.hpp | 14 ++++++++++++++ sig/ffi_type.cpp | 5 +++++ sig/parse.cpp | 6 ++++++ 9 files changed, 77 insertions(+), 9 deletions(-) diff --git a/Analyze.cpp b/Analyze.cpp index f1ef107..5bf4914 100644 --- a/Analyze.cpp +++ b/Analyze.cpp @@ -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); diff --git a/Decode.cpp b/Decode.cpp index c20fb1c..63bb9ef 100644 --- a/Decode.cpp +++ b/Decode.cpp @@ -38,12 +38,17 @@ CYType *Primitive::Decode(CYPool &pool) const { template <> CYType *Primitive::Decode(CYPool &pool) const { - return $ CYType($ CYTypeVariable("double")); + return $ CYType($ CYTypeFloating(1)); } template <> CYType *Primitive::Decode(CYPool &pool) const { - return $ CYType($ CYTypeVariable("float")); + return $ CYType($ CYTypeFloating(0)); +} + +template <> +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeFloating(2)); } template <> diff --git a/Execute.cpp b/Execute.cpp index 0f27732..48dc478 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -332,6 +332,7 @@ JSValueRef CYCastJSValue(JSContextRef context, double value) { return JSValueMakeNumber(context, static_cast(value)); \ } +CYCastJSValue_(long double) CYCastJSValue_(signed short int) CYCastJSValue_(unsigned short int) CYCastJSValue_(signed int) @@ -716,13 +717,17 @@ void Primitive::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi *reinterpret_cast(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::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()), kJSPropertyAttributeDontEnum); CYSetProperty(context, cache, CYJSString("double"), CYMakeType(context, sig::Primitive()), kJSPropertyAttributeDontEnum); + CYSetProperty(context, cache, CYJSString("longdouble"), CYMakeType(context, sig::Primitive()), kJSPropertyAttributeDontEnum); CYSetProperty(context, global, CYJSString("require"), &require_callAsFunction, kJSPropertyAttributeDontEnum); diff --git a/Output.cpp b/Output.cpp index 3daf4cf..50cc836 100644 --- a/Output.cpp +++ b/Output.cpp @@ -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; diff --git a/Parser.ypp.in b/Parser.ypp.in index 0d8e87d..d608263 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -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 diff --git a/Replace.cpp b/Replace.cpp index bfcacf4..68beb4f 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -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"); } diff --git a/Syntax.hpp b/Syntax.hpp index a3dad90..c710d89 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -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 { diff --git a/sig/ffi_type.cpp b/sig/ffi_type.cpp index e0c4d0f..04c68a1 100644 --- a/sig/ffi_type.cpp +++ b/sig/ffi_type.cpp @@ -48,6 +48,11 @@ ffi_type *Primitive::GetFFI(CYPool &pool) const { return &ffi_type_float; } +template <> +ffi_type *Primitive::GetFFI(CYPool &pool) const { + return &ffi_type_longdouble; +} + template <> ffi_type *Primitive::GetFFI(CYPool &pool) const { return &ffi_type_double; diff --git a/sig/parse.cpp b/sig/parse.cpp index 20fa5a2..7e025f8 100644 --- a/sig/parse.cpp +++ b/sig/parse.cpp @@ -169,6 +169,7 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback break; case 'c': type = new(pool) Primitive(); break; + case 'D': type = new(pool) Primitive(); break; case 'd': type = new(pool) Primitive(); break; case 'f': type = new(pool) Primitive(); break; case 'i': type = new(pool) Primitive(); break; @@ -279,6 +280,11 @@ const char *Primitive::Encode(CYPool &pool) const { return "f"; } +template <> +const char *Primitive::Encode(CYPool &pool) const { + return "D"; +} + template <> const char *Primitive::Encode(CYPool &pool) const { return "c"; -- 2.45.2