From a109809e4f9d66ad37afebd1eacd247c47e63f2e Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 30 Dec 2015 06:11:17 -0800 Subject: [PATCH] Show more explicit types for Objective-C Instance. --- ObjectiveC/Library.mm | 16 +++++----------- sig/copy.cpp | 35 ++++++++++++++--------------------- sig/types.hpp | 27 +++++++++++++-------------- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index b3dcc0a..a2a3190 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -2545,7 +2545,11 @@ static JSValueRef Selector_getProperty_$cyt(JSContextRef context, JSObjectRef ob } CYCatch(NULL) } static JSValueRef Instance_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - return CYMakeType(context, sig::Object()); + Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); + id self(internal->GetValue()); + if (CYIsClass(self)) + return CYMakeType(context, sig::Meta()); + return CYMakeType(context, sig::Object(class_getName(object_getClass(self)))); } CYCatch(NULL) } static JSValueRef FunctionInstance_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { @@ -2557,10 +2561,6 @@ static JSValueRef FunctionInstance_getProperty_$cyt(JSContextRef context, JSObje return CYMakeType(context, type); } CYCatch(NULL) } -static JSValueRef Class_getProperty_$cyt(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { - return CYMakeType(context, sig::Meta()); -} CYCatch(NULL) } - static JSValueRef Instance_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry { Instance *internal(reinterpret_cast(JSObjectGetPrivate(object))); return CYMakeInstance(context, object_getClass(internal->GetValue()), Instance::Permanent); @@ -2745,11 +2745,6 @@ static JSStaticFunction Class_staticFunctions[2] = { {NULL, NULL, 0} }; -static JSStaticValue Class_staticValues[2] = { - {"$cyt", &Class_getProperty_$cyt, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, - {NULL, NULL, NULL, 0} -}; - static JSStaticFunction Internal_staticFunctions[2] = { {"$cya", &Internal_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete}, {NULL, NULL, 0} @@ -2837,7 +2832,6 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { definition = kJSClassDefinitionEmpty; definition.className = "Class"; definition.staticFunctions = Class_staticFunctions; - definition.staticValues = Class_staticValues; Class_ = JSClassCreate(&definition); definition = kJSClassDefinitionEmpty; diff --git a/sig/copy.cpp b/sig/copy.cpp index 4fb98bd..d00a869 100644 --- a/sig/copy.cpp +++ b/sig/copy.cpp @@ -45,58 +45,55 @@ void Copy(CYPool &pool, Signature &lhs, const Signature &rhs) { Copy(pool, lhs.elements[index], rhs.elements[index]); } -Void *Void::Copy(CYPool &pool, const char *name) const { +Void *Void::Copy(CYPool &pool, const char *rename) const { return new(pool) Void(); } -Unknown *Unknown::Copy(CYPool &pool, const char *name) const { +Unknown *Unknown::Copy(CYPool &pool, const char *rename) const { return new(pool) Unknown(); } -String *String::Copy(CYPool &pool, const char *name) const { +String *String::Copy(CYPool &pool, const char *rename) const { return new(pool) String(); } -Meta *Meta::Copy(CYPool &pool, const char *name) const { +Meta *Meta::Copy(CYPool &pool, const char *rename) const { return new(pool) Meta(); } -Selector *Selector::Copy(CYPool &pool, const char *name) const { +Selector *Selector::Copy(CYPool &pool, const char *rename) const { return new(pool) Selector(); } -Bits *Bits::Copy(CYPool &pool, const char *name) const { +Bits *Bits::Copy(CYPool &pool, const char *rename) const { return new(pool) Bits(size); } -Pointer *Pointer::Copy(CYPool &pool, const char *name) const { +Pointer *Pointer::Copy(CYPool &pool, const char *rename) const { return new(pool) Pointer(*type.Copy(pool)); } -Array *Array::Copy(CYPool &pool, const char *name) const { +Array *Array::Copy(CYPool &pool, const char *rename) const { return new(pool) Array(*type.Copy(pool), size); } -Object *Object::Copy(CYPool &pool, const char *name) const { - Object *copy(new(pool) Object(pool.strdup(name))); - copy->name = name; - return copy; +Object *Object::Copy(CYPool &pool, const char *rename) const { + return new(pool) Object(pool.strdup(name)); } -Aggregate *Aggregate::Copy(CYPool &pool, const char *name) const { - Aggregate *copy(new(pool) Aggregate(overlap, name)); +Aggregate *Aggregate::Copy(CYPool &pool, const char *rename) const { + Aggregate *copy(new(pool) Aggregate(overlap, rename ?: pool.strdup(name))); sig::Copy(pool, copy->signature, signature); - copy->name = name; return copy; } -Function *Function::Copy(CYPool &pool, const char *name) const { +Function *Function::Copy(CYPool &pool, const char *rename) const { Function *copy(new(pool) Function(variadic)); sig::Copy(pool, copy->signature, signature); return copy; } -Block *Block::Copy(CYPool &pool, const char *name) const { +Block *Block::Copy(CYPool &pool, const char *rename) const { Block *copy(new(pool) Block()); sig::Copy(pool, copy->signature, signature); return copy; @@ -129,10 +126,6 @@ const char *Type::GetName() const { return NULL; } -const char *Object::GetName() const { - return name; -} - const char *Aggregate::GetName() const { return name; } diff --git a/sig/types.hpp b/sig/types.hpp index f053046..82ee41e 100644 --- a/sig/types.hpp +++ b/sig/types.hpp @@ -57,7 +57,7 @@ struct Type { { } - virtual Type *Copy(CYPool &pool, const char *name = NULL) const = 0; + virtual Type *Copy(CYPool &pool, const char *rename = NULL) const = 0; virtual const char *GetName() const; virtual const char *Encode(CYPool &pool) const = 0; @@ -98,7 +98,7 @@ struct Signature { struct Void : Type { - Void *Copy(CYPool &pool, const char *name = NULL) const override; + Void *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -111,7 +111,7 @@ struct Void : struct Unknown : Type { - Unknown *Copy(CYPool &pool, const char *name = NULL) const override; + Unknown *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -124,7 +124,7 @@ struct Unknown : struct String : Type { - String *Copy(CYPool &pool, const char *name = NULL) const override; + String *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -137,7 +137,7 @@ struct String : struct Meta : Type { - Meta *Copy(CYPool &pool, const char *name = NULL) const override; + Meta *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -150,7 +150,7 @@ struct Meta : struct Selector : Type { - Selector *Copy(CYPool &pool, const char *name = NULL) const override; + Selector *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -170,7 +170,7 @@ struct Bits : { } - Bits *Copy(CYPool &pool, const char *name = NULL) const override; + Bits *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -190,7 +190,7 @@ struct Pointer : { } - Pointer *Copy(CYPool &pool, const char *name = NULL) const override; + Pointer *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -212,7 +212,7 @@ struct Array : { } - Array *Copy(CYPool &pool, const char *name = NULL) const override; + Array *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -232,8 +232,7 @@ struct Object : { } - Object *Copy(CYPool &pool, const char *name = NULL) const override; - const char *GetName() const override; + Object *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; @@ -256,7 +255,7 @@ struct Aggregate : { } - Aggregate *Copy(CYPool &pool, const char *name = NULL) const override; + Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override; const char *GetName() const override; const char *Encode(CYPool &pool) const override; @@ -286,7 +285,7 @@ struct Function : { } - Function *Copy(CYPool &pool, const char *name = NULL) const override; + Function *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override; @@ -299,7 +298,7 @@ struct Function : struct Block : Callable { - Block *Copy(CYPool &pool, const char *name = NULL) const override; + Block *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; CYTypedIdentifier *Decode(CYPool &pool) const override; -- 2.47.2