]> git.saurik.com Git - cycript.git/commitdiff
Allow Type objects to have associated identifiers.
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 15 Sep 2012 08:38:22 +0000 (01:38 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 15 Sep 2012 08:38:22 +0000 (01:38 -0700)
Cycript.yy.in
Execute.cpp
sig/types.hpp
todo.txt

index 92d57f68bdfc733727ca99cf000e23778b03d8ea..b6f355c865f96cb50ab283163d2c67c38f045412 100644 (file)
@@ -478,6 +478,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <type_> ModifiedType
+%type <part_> NamedTypeOpt
 %type <part_> PrefixedType
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
@@ -1339,8 +1340,13 @@ ProgramBodyOpt
 
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
+NamedTypeOpt
+    : Identifier { $$ = CYNew CYEncodedPart(NULL, "withName", CYNew CYArgument(CYNew CYString($1->word_))); }
+    | { $$ = NULL; }
+    ;
+
 SuffixedType
-    : { $$ = NULL; }
+    : NamedTypeOpt { $$ = $1; }
     | "(" PrefixedType ")" { $$ = $2; }
     | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); }
     ;
index 601ed9f3fe05762a8611d7d4956f33aacda53075..70cceaeaf1c939ecfde411abe140fd3efba34941 100644 (file)
@@ -1097,6 +1097,19 @@ static JSValueRef Type_callAsFunction_pointerTo(JSContextRef context, JSObjectRe
     return CYMakeType(context, &type);
 } CYCatch }
 
+static JSValueRef Type_callAsFunction_withName(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+    if (count != 1)
+        throw CYJSError(context, "incorrect number of arguments to Type.withName");
+    Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(_this)));
+
+    CYPool pool;
+    const char *name(CYPoolCString(pool, context, arguments[0]));
+
+    sig::Type type(*internal->type_);
+    type.name = name;
+    return CYMakeType(context, &type);
+} CYCatch }
+
 static JSValueRef Type_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
     if (count != 1)
         throw CYJSError(context, "incorrect number of arguments to type cast function");
@@ -1172,6 +1185,11 @@ static JSValueRef Type_getProperty_alignment(JSContextRef context, JSObjectRef o
     return CYCastJSValue(context, internal->GetFFI()->alignment);
 }
 
+static JSValueRef Type_getProperty_name(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
+    Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
+    return CYCastJSValue(context, internal->type_->name);
+}
+
 static JSValueRef Type_getProperty_size(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
     Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
     return CYCastJSValue(context, internal->GetFFI()->size);
@@ -1225,16 +1243,18 @@ namespace cy {
     JSStaticFunction const * const Functor::StaticFunctions = Functor_staticFunctions;
 }
 
-static JSStaticValue Type_staticValues[3] = {
+static JSStaticValue Type_staticValues[4] = {
     {"alignment", &Type_getProperty_alignment, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"name", &Type_getProperty_name, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"size", &Type_getProperty_size, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {NULL, NULL, NULL, 0}
 };
 
-static JSStaticFunction Type_staticFunctions[7] = {
+static JSStaticFunction Type_staticFunctions[8] = {
     {"arrayOf", &Type_callAsFunction_arrayOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"constant", &Type_callAsFunction_constant, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"pointerTo", &Type_callAsFunction_pointerTo, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"withName", &Type_callAsFunction_withName, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toCYON", &Type_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toJSON", &Type_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toString", &Type_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
index e6240a11b5f8d888f2001b0660af724f0ae94336..54da645e76a11cc1d7fe16e19feab6d6c4d4e1bb 100644 (file)
@@ -74,7 +74,7 @@ struct Signature {
 
 struct Type {
     enum Primitive primitive;
-    char *name;
+    const char *name;
     uint8_t flags;
 
     union {
index 626b4b5526863c8fc653f7a24cbe1b4a838db2c7..4df4d2d28078432522abf51fddf90fded6851c1e 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -111,3 +111,5 @@ constant flags on types are encoded using something horribly wrong
 http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
 http://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html
 http://gcc.gnu.org/onlinedocs/gcc/Legacy-type-encoding.html
+
+using .withName from the grammar is a horrible hack that makes other uses impossible