From 8e216accc5c795e2cf42f89276841b175ed33f58 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 20 Dec 2015 03:33:36 -0800 Subject: [PATCH] Support cast and call of pointer-to-function type. --- Execute.cpp | 13 +++++++++++-- Parser.ypp.in | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index 1a3a2df..1cb8373 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1093,6 +1093,14 @@ static JSValueRef Functor_callAsFunction(JSContextRef context, JSObjectRef objec return CYCallFunction(pool, context, 0, NULL, count, arguments, false, &internal->signature_, &internal->cif_, internal->GetValue()); } CYCatch(NULL) } +static JSValueRef Pointer_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { + Pointer *internal(reinterpret_cast(JSObjectGetPrivate(object))); + if (internal->type_->type_->primitive != sig::function_P) + throw CYJSError(context, "cannot call a pointer to non-function"); + JSObjectRef functor(CYCastJSObject(context, CYGetProperty(context, object, cyi_s))); + return CYCallAsFunction(context, functor, _this, count, arguments); +} CYCatch(NULL) } + JSObjectRef CYMakeType(JSContextRef context, const char *encoding) { Type_privateData *internal(new Type_privateData(encoding)); return JSObjectMake(context, Type_privateData::Class_, internal); @@ -1511,7 +1519,7 @@ static JSValueRef CString_callAsFunction_toPointer(JSContextRef context, JSObjec return CYMakePointer(context, internal->value_, _not(size_t), &type, NULL, NULL); } CYCatch(NULL) } -static JSValueRef Functor_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { +static JSValueRef Functor_callAsFunction_$cya(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { CYPool pool; cy::Functor *internal(reinterpret_cast(JSObjectGetPrivate(_this))); @@ -1697,9 +1705,9 @@ static JSStaticFunction Struct_staticFunctions[2] = { }; static JSStaticFunction Functor_staticFunctions[5] = { + {"$cya", &Functor_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toCYON", &CYValue_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"toJSON", &CYValue_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - {"toPointer", &Functor_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {"valueOf", &CYValue_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, 0} }; @@ -1872,6 +1880,7 @@ void CYInitializeDynamic() { definition.className = "Pointer"; definition.staticFunctions = Pointer_staticFunctions; definition.staticValues = Pointer_staticValues; + definition.callAsFunction = &Pointer_callAsFunction; definition.getProperty = &Pointer_getProperty; definition.setProperty = &Pointer_setProperty; definition.finalize = &CYFinalize; diff --git a/Parser.ypp.in b/Parser.ypp.in index d53d442..88c01bf 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -1947,7 +1947,7 @@ ExportSpecifier /* Cycript (C): Type Encoding {{{ */ TypeSignifier : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); } - | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; } + | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; TypeSignifierOpt -- 2.47.2