]> git.saurik.com Git - cycript.git/commitdiff
Implemented CYSelector::Output, split CYSelectorPart, and further enforced CYNext.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 1 Oct 2009 22:07:04 +0000 (22:07 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 1 Oct 2009 22:07:04 +0000 (22:07 +0000)
Cycript.y
Output.cpp
Parser.hpp

index 46e81a4a25e0123f6c1d9cfcce37c847261d7f8e..31fd1bc9d49bbfde70725c235b1e5cc5b3c519be 100644 (file)
--- a/Cycript.y
+++ b/Cycript.y
@@ -29,7 +29,7 @@ typedef struct {
         CYNumber *number_;
         CYParameter *parameter_;
         CYProperty *property_;
-        CYSelector *selector_;
+        CYSelectorPart *selector_;
         CYSource *source_;
         CYStatement *statement_;
         CYString *string_;
@@ -1076,17 +1076,17 @@ SelectorExpressionOpt
     ;
 
 SelectorExpression_
-    : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelector($1, true, $3); }
+    : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
     ;
 
 SelectorExpression
     : SelectorExpression_ { $$ = $1; }
-    | Word { $$ = new(driver.pool_) CYSelector($1, false, NULL); }
+    | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
     ;
 
 PrimaryExpression_
     : MessageExpression { $$ = $1; }
-    | "@selector" "(" SelectorExpression ")" { $$ = $3; }
+    | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); }
     ;
 /* }}} */
 
index edd262fdd819dc5b87f9b1a53128ce157e2a369c..ecd39bbb993787fa1f076b08dc559c602d247277 100644 (file)
@@ -288,10 +288,20 @@ void CYReturn::Output(std::ostream &out) const {
 
 void CYSelector::Output(std::ostream &out) const {
     out << '"';
-    out << "<unimplemented>";
+    if (name_ != NULL)
+        name_->Output(out);
     out << '"';
 }
 
+void CYSelectorPart::Output(std::ostream &out) const {
+    if (name_ != NULL)
+        out << *name_;
+    if (value_)
+        out << ':';
+    if (next_ != NULL)
+        next_->Output(out);
+}
+
 void CYSource::Show(std::ostream &out) const {
     for (const CYSource *next(this); next != NULL; next = next->next_)
         next->Output(out, false);
index 2663eb85dc71c48fc5bde633314e8074be38a550..b848c7b5d576d10ed857a3ccd95170934b7b1927 100644 (file)
@@ -17,6 +17,11 @@ struct CYNext {
     {
     }
 
+    CYNext(Type_ *next) :
+        next_(next)
+    {
+    }
+
     void SetNext(Type_ *next) {
         next_ = next;
     }
@@ -79,13 +84,14 @@ struct CYIdentifier :
     }
 };
 
-struct CYLabel {
+struct CYLabel :
+    CYNext<CYLabel>
+{
     CYIdentifier *identifier_;
-    CYLabel *next_;
 
     CYLabel(CYIdentifier *identifier, CYLabel *next) :
-        identifier_(identifier),
-        next_(next)
+        CYNext<CYLabel>(next),
+        identifier_(identifier)
     {
     }
 };
@@ -167,17 +173,29 @@ struct CYLiteral :
 {
 };
 
-struct CYSelector :
-    CYLiteral
+struct CYSelectorPart :
+    CYNext<CYSelectorPart>
 {
     CYWord *name_;
     bool value_;
-    CYSelector *after_;
 
-    CYSelector(CYWord *name, bool value, CYSelector *after) :
+    CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
+        CYNext<CYSelectorPart>(next),
         name_(name),
-        value_(value),
-        after_(after)
+        value_(value)
+    {
+    }
+
+    virtual void Output(std::ostream &out) const;
+};
+
+struct CYSelector :
+    CYLiteral
+{
+    CYSelectorPart *name_;
+
+    CYSelector(CYSelectorPart *name) :
+        name_(name)
     {
     }
 
@@ -366,15 +384,16 @@ struct CYAssignment :
     virtual const char *Operator() const = 0;
 };
 
-struct CYArgument {
+struct CYArgument :
+    CYNext<CYArgument>
+{
     CYWord *name_;
     CYExpression *value_;
-    CYArgument *next_;
 
     CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
+        CYNext<CYArgument>(next),
         name_(name),
-        value_(value),
-        next_(next)
+        value_(value)
     {
     }
 
@@ -406,13 +425,14 @@ struct CYClause :
     virtual void Output(std::ostream &out) const;
 };
 
-struct CYElement {
+struct CYElement :
+    CYNext<CYElement>
+{
     CYExpression *value_;
-    CYElement *next_;
 
     CYElement(CYExpression *value, CYElement *next) :
-        value_(value),
-        next_(next)
+        CYNext<CYElement>(next),
+        value_(value)
     {
     }
 
@@ -467,14 +487,14 @@ struct CYDeclarations :
 };
 
 struct CYParameter :
+    CYNext<CYParameter>,
     CYThing
 {
     CYIdentifier *name_;
-    CYParameter *next_;
 
     CYParameter(CYIdentifier *name, CYParameter *next) :
-        name_(name),
-        next_(next)
+        CYNext<CYParameter>(next),
+        name_(name)
     {
     }
 
@@ -517,15 +537,16 @@ struct CYForIn :
     virtual void Output(std::ostream &out) const;
 };
 
-struct CYProperty {
+struct CYProperty :
+    CYNext<CYProperty>
+{
     CYName *name_;
     CYExpression *value_;
-    CYProperty *next_;
 
     CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
+        CYNext<CYProperty>(next),
         name_(name),
-        value_(value),
-        next_(next)
+        value_(value)
     {
     }