]> git.saurik.com Git - cycript.git/commitdiff
Reorganize typed identifier storage for other uses.
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 15 Sep 2012 11:34:50 +0000 (04:34 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 15 Sep 2012 11:34:50 +0000 (04:34 -0700)
Cycript.yy.in
ObjectiveC/Output.mm
ObjectiveC/Replace.cpp
ObjectiveC/Syntax.hpp

index b6f355c865f96cb50ab283163d2c67c38f045412..90588f78237c3aa455e1675fb36f747f63973200 100644 (file)
@@ -73,7 +73,6 @@ typedef struct {
         CYMember *member_;
         CYNull *null_;
         CYNumber *number_;
         CYMember *member_;
         CYNull *null_;
         CYNumber *number_;
-        CYEncodedPart *part_;
         CYProgram *program_;
         CYProperty *property_;
         CYPropertyName *propertyName_;
         CYProgram *program_;
         CYProperty *property_;
         CYPropertyName *propertyName_;
@@ -82,7 +81,8 @@ typedef struct {
         CYString *string_;
         CYThis *this_;
         CYTrue *true_;
         CYString *string_;
         CYThis *this_;
         CYTrue *true_;
-        CYEncodedType *type_;
+        CYTypeModifier *type_;
+        CYTypedIdentifier *typed_;
         CYWord *word_;
 
 @begin ObjectiveC
         CYWord *word_;
 
 @begin ObjectiveC
@@ -471,6 +471,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
+%type <expression_> EncodedType
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
@@ -478,8 +479,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <type_> ModifiedType
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <type_> ModifiedType
-%type <part_> NamedTypeOpt
-%type <part_> PrefixedType
+%type <typed_> PrefixedType
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
 %type <selector_> SelectorExpression_
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
 %type <selector_> SelectorExpression_
@@ -487,9 +487,9 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <selector_> SelectorExpressionOpt
 %type <argument_> SelectorList
 %type <word_> SelectorWordOpt
 %type <selector_> SelectorExpressionOpt
 %type <argument_> SelectorList
 %type <word_> SelectorWordOpt
-%type <part_> SuffixedType
+%type <typed_> SuffixedType
 %type <expression_> TypeOpt
 %type <expression_> TypeOpt
-%type <type_> TypedIdentifier
+%type <typed_> TypedIdentifier
 %type <argument_> VariadicCall
 @end
 
 %type <argument_> VariadicCall
 @end
 
@@ -1340,33 +1340,33 @@ ProgramBodyOpt
 
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
 
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
-NamedTypeOpt
-    : Identifier { $$ = CYNew CYEncodedPart(NULL, "withName", CYNew CYArgument(CYNew CYString($1->word_))); }
-    | { $$ = NULL; }
-    ;
-
 SuffixedType
 SuffixedType
-    : NamedTypeOpt { $$ = $1; }
+    : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
     | "(" PrefixedType ")" { $$ = $2; }
     | "(" PrefixedType ")" { $$ = $2; }
-    | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); }
+    | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
     ;
 
 PrefixedType
     : SuffixedType { $$ = $1; }
     ;
 
 PrefixedType
     : SuffixedType { $$ = $1; }
-    | "*" PrefixedType { $$ = CYNew CYEncodedPart($2, "pointerTo"); }
+    | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; }
+    | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
     ;
 
 ModifiedType
     ;
 
 ModifiedType
-    : Variable { $$ = CYNew CYEncodedType($1); }
-    | "const" ModifiedType { $2->base_ = CYNew CYCall(CYNew CYDirectMember($2->base_, CYNew CYString("constant"))); $$ = $2; }
+    : Variable { $$ = CYNew CYTypeVariable($1); }
+    | "const" ModifiedType { $$ = CYNew CYTypeConstant($2); }
     ;
 
 TypedIdentifier
     ;
 
 TypedIdentifier
-    : ModifiedType PrefixedType { $1->parts_ = $2; $$ = $1;}
+    : ModifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+    ;
+
+EncodedType
+    : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
     ;
 
 PrimaryExpression
     ;
 
 PrimaryExpression
-    : AtEncode "(" TypedIdentifier ")" { $$ = $3; }
+    : AtEncode "(" EncodedType ")" { $$ = $3; }
     ;
 /* }}} */
 /* Cycript (Objective-C): @class Declaration {{{ */
     ;
 /* }}} */
 /* Cycript (Objective-C): @class Declaration {{{ */
@@ -1391,7 +1391,7 @@ MessageScope
     ;
 
 TypeOpt
     ;
 
 TypeOpt
-    : "(" TypedIdentifier ")" { $$ = $2; }
+    : "(" EncodedType ")" { $$ = $2; }
     | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
     | { $$ = NULL; }
     ;
     | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
     | { $$ = NULL; }
     ;
index c90418d5a393f82474bd2bb57258703402dcc8b7..ecc8d1a4bdc77fc9f39cfb9d5a940c16d486f446 100644 (file)
@@ -76,7 +76,9 @@ void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
 }
 
 void CYEncodedType::Output(CYOutput &out, CYFlags flags) const {
 }
 
 void CYEncodedType::Output(CYOutput &out, CYFlags flags) const {
+    out << "@encode(";
     // XXX: this is seriously wrong
     // XXX: this is seriously wrong
+    out << ")";
 }
 
 void CYField::Output(CYOutput &out) const {
 }
 
 void CYField::Output(CYOutput &out) const {
index f6e98f1d060b568d060eb1e6d56582c174472f8c..a8515a5ee4555610e35dc11c62add543b45dfb17 100644 (file)
@@ -78,12 +78,24 @@ CYStatement *CYClassStatement::Replace(CYContext &context) {
     return $E(Replace_(context));
 }
 
     return $E(Replace_(context));
 }
 
-CYExpression *CYEncodedPart::Replace(CYContext &context, CYExpression *base) { $T(base)
-    return next_->Replace(context, $ CYCall($ CYDirectMember(base, $ CYString(name_)), arguments_));
+CYExpression *CYTypeArrayOf::Replace(CYContext &context) {
+    return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument($ CYNumber(size_)));
+}
+
+CYExpression *CYTypeConstant::Replace(CYContext &context) {
+    return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("constant")));
+}
+
+CYExpression *CYTypePointerTo::Replace(CYContext &context) {
+    return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("pointerTo")));
+}
+
+CYExpression *CYTypeVariable::Replace(CYContext &context) {
+    return expression_;
 }
 
 CYExpression *CYEncodedType::Replace(CYContext &context) {
 }
 
 CYExpression *CYEncodedType::Replace(CYContext &context) {
-    return parts_->Replace(context, base_);
+    return type_->Replace(context);
 }
 
 CYStatement *CYField::Replace(CYContext &context) const { $T(NULL)
 }
 
 CYStatement *CYField::Replace(CYContext &context) const { $T(NULL)
index 0caaad469544d96d81d18bf5ddb547a8ef9bba84..e9101541f23c5960f05c55be9f96e5f1a8e93fb1 100644 (file)
 
 #include "Parser.hpp"
 
 
 #include "Parser.hpp"
 
-struct CYEncodedPart :
-    CYNext<CYEncodedPart>
+struct CYTypeModifier :
+    CYNext<CYTypeModifier>
 {
 {
-    const char *name_;
-    CYArgument *arguments_;
+    CYTypeModifier(CYTypeModifier *next) :
+        CYNext<CYTypeModifier>(next)
+    {
+    }
 
 
-    CYEncodedPart(CYEncodedPart *next, const char *name, CYArgument *arguments = NULL) :
-        CYNext<CYEncodedPart>(next),
-        name_(name),
-        arguments_(arguments)
+    virtual CYExpression *Replace(CYContext &context) = 0;
+};
+
+struct CYTypeArrayOf :
+    CYTypeModifier
+{
+    size_t size_;
+
+    CYTypeArrayOf(size_t size, CYTypeModifier *next = NULL) :
+        CYTypeModifier(next),
+        size_(size)
+    {
+    }
+
+    CYPrecedence(2)
+
+    virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypeConstant :
+    CYTypeModifier
+{
+    CYTypeConstant(CYTypeModifier *next = NULL) :
+        CYTypeModifier(next)
     {
     }
 
     {
     }
 
-    CYExpression *Replace(CYContext &context, CYExpression *base);
+    CYPrecedence(3)
+
+    virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypePointerTo :
+    CYTypeModifier
+{
+    CYTypePointerTo(CYTypeModifier *next = NULL) :
+        CYTypeModifier(next)
+    {
+    }
+
+    CYPrecedence(3)
+
+    virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypeVariable :
+    CYTypeModifier
+{
+    CYExpression *expression_;
+
+    CYTypeVariable(CYExpression *expression) :
+        CYTypeModifier(NULL),
+        expression_(expression)
+    {
+    }
+
+    CYPrecedence(1)
+
+    virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypedIdentifier :
+    CYNext<CYTypedIdentifier>
+{
+    CYIdentifier *identifier_;
+    CYTypeModifier *type_;
+
+    CYTypedIdentifier(CYIdentifier *identifier) :
+        identifier_(identifier),
+        type_(NULL)
+    {
+    }
 };
 
 struct CYEncodedType :
     CYExpression
 {
 };
 
 struct CYEncodedType :
     CYExpression
 {
-    CYExpression *base_;
-    CYEncodedPart *parts_;
+    CYTypeModifier *type_;
 
 
-    CYEncodedType(CYExpression *base, CYEncodedPart *parts = NULL) :
-        base_(base),
-        parts_(parts)
+    CYEncodedType(CYTypeModifier *type) :
+        type_(type)
     {
     }
 
     {
     }