]> git.saurik.com Git - cycript.git/blobdiff - Syntax.hpp
Use variadic templates to better organize Classes.
[cycript.git] / Syntax.hpp
index a82ded1d271a3de5b8ab96a60859be7195e00441..a3f03fab47eaca021196368cdc7cd29e965986ed 100644 (file)
@@ -150,6 +150,7 @@ enum CYFlags {
     CYNoRightHand =  (1 << 5),
     CYNoDangle =     (1 << 6),
     CYNoInteger =    (1 << 7),
+    CYNoColon =      (1 << 8),
     CYNoBFC =        (CYNoBrace | CYNoFunction | CYNoClass),
 };
 
@@ -962,6 +963,22 @@ struct CYVariable :
     virtual CYFunctionParameter *Parameter() const;
 };
 
+struct CYSymbol :
+    CYTarget
+{
+    const char *name_;
+
+    CYSymbol(const char *name) :
+        name_(name)
+    {
+    }
+
+    CYPrecedence(0)
+
+    virtual CYTarget *Replace(CYContext &context);
+    virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
 struct CYPrefix :
     CYExpression
 {
@@ -1089,21 +1106,26 @@ struct CYClause :
 };
 
 struct CYElement :
+    CYNext<CYElement>,
     CYThing
 {
+    CYElement(CYElement *next) :
+        CYNext<CYElement>(next)
+    {
+    }
+
     virtual bool Elision() const = 0;
 
     virtual void Replace(CYContext &context) = 0;
 };
 
 struct CYElementValue :
-    CYNext<CYElement>,
     CYElement
 {
     CYExpression *value_;
 
     CYElementValue(CYExpression *value, CYElement *next = NULL) :
-        CYNext<CYElement>(next),
+        CYElement(next),
         value_(value)
     {
     }
@@ -1121,7 +1143,8 @@ struct CYElementSpread :
 {
     CYExpression *value_;
 
-    CYElementSpread(CYExpression *value) :
+    CYElementSpread(CYExpression *value, CYElement *next = NULL) :
+        CYElement(next),
         value_(value)
     {
     }
@@ -1442,6 +1465,20 @@ struct CYIndirectMember :
     virtual void Output(CYOutput &out, CYFlags flags) const;
 };
 
+struct CYResolveMember :
+    CYMember
+{
+    CYResolveMember(CYExpression *object, CYExpression *property) :
+        CYMember(object, property)
+    {
+    }
+
+    CYPrecedence(1)
+
+    virtual CYTarget *Replace(CYContext &context);
+    virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
 namespace cy {
 namespace Syntax {
 
@@ -1963,23 +2000,19 @@ struct CYTypeError :
     virtual void Output(CYOutput &out) const;
 };
 
-struct CYTypeVoid :
-    CYTypeSpecifier
-{
-    CYTypeVoid() {
-    }
-
-    virtual CYTarget *Replace(CYContext &context);
-    virtual void Output(CYOutput &out) const;
+enum CYTypeSigning {
+    CYTypeNeutral,
+    CYTypeSigned,
+    CYTypeUnsigned,
 };
 
-struct CYTypeReference :
+struct CYTypeCharacter :
     CYTypeSpecifier
 {
-    CYIdentifier *name_;
+    CYTypeSigning signing_;
 
-    CYTypeReference(CYIdentifier *name) :
-        name_(name)
+    CYTypeCharacter(CYTypeSigning signing) :
+        signing_(signing)
     {
     }
 
@@ -1987,60 +2020,67 @@ struct CYTypeReference :
     virtual void Output(CYOutput &out) const;
 };
 
-struct CYTypeVariable :
+struct CYTypeIntegral :
     CYTypeSpecifier
 {
-    CYIdentifier *name_;
+    CYTypeSigning signing_;
+    int length_;
 
-    CYTypeVariable(CYIdentifier *name) :
-        name_(name)
+    CYTypeIntegral(CYTypeSigning signing, int length = 1) :
+        signing_(signing),
+        length_(length)
     {
     }
 
-    CYTypeVariable(const char *name) :
-        name_(new($pool) CYIdentifier(name))
-    {
+    CYTypeIntegral *Long() {
+        if (length_ != 1 && length_ != 2)
+            return NULL;
+        ++length_;
+        return this;
     }
 
-    virtual CYTarget *Replace(CYContext &context);
-    virtual void Output(CYOutput &out) const;
-};
+    CYTypeIntegral *Short() {
+        if (length_ != 1)
+            return NULL;
+        --length_;
+        return this;
+    }
 
-struct CYTypeUnsigned :
-    CYTypeSpecifier
-{
-    CYTypeSpecifier *specifier_;
+    CYTypeIntegral *Signed() {
+        if (signing_ != CYTypeNeutral)
+            return NULL;
+        signing_ = CYTypeSigned;
+        return this;
+    }
 
-    CYTypeUnsigned(CYTypeSpecifier *specifier) :
-        specifier_(specifier)
-    {
+    CYTypeIntegral *Unsigned() {
+        if (signing_ != CYTypeNeutral)
+            return NULL;
+        signing_ = CYTypeUnsigned;
+        return this;
     }
 
     virtual CYTarget *Replace(CYContext &context);
     virtual void Output(CYOutput &out) const;
 };
 
-struct CYTypeSigned :
+struct CYTypeVoid :
     CYTypeSpecifier
 {
-    CYTypeSpecifier *specifier_;
-
-    CYTypeSigned(CYTypeSpecifier *specifier) :
-        specifier_(specifier)
-    {
+    CYTypeVoid() {
     }
 
     virtual CYTarget *Replace(CYContext &context);
     virtual void Output(CYOutput &out) const;
 };
 
-struct CYTypeLong :
+struct CYTypeReference :
     CYTypeSpecifier
 {
-    CYTypeSpecifier *specifier_;
+    CYIdentifier *name_;
 
-    CYTypeLong(CYTypeSpecifier *specifier) :
-        specifier_(specifier)
+    CYTypeReference(CYIdentifier *name) :
+        name_(name)
     {
     }
 
@@ -2048,13 +2088,18 @@ struct CYTypeLong :
     virtual void Output(CYOutput &out) const;
 };
 
-struct CYTypeShort :
+struct CYTypeVariable :
     CYTypeSpecifier
 {
-    CYTypeSpecifier *specifier_;
+    CYIdentifier *name_;
+
+    CYTypeVariable(CYIdentifier *name) :
+        name_(name)
+    {
+    }
 
-    CYTypeShort(CYTypeSpecifier *specifier) :
-        specifier_(specifier)
+    CYTypeVariable(const char *name) :
+        name_(new($pool) CYIdentifier(name))
     {
     }
 
@@ -2212,6 +2257,17 @@ struct CYTypedParameter :
     virtual void Output(CYOutput &out) const;
 };
 
+struct CYTypedFormal {
+    bool variadic_;
+    CYTypedParameter *parameters_;
+
+    CYTypedFormal(bool variadic) :
+        variadic_(variadic),
+        parameters_(NULL)
+    {
+    }
+};
+
 struct CYLambda :
     CYTarget
 {
@@ -2367,10 +2423,12 @@ struct CYTypeBlockWith :
 struct CYTypeFunctionWith :
     CYTypeModifier
 {
+    bool variadic_;
     CYTypedParameter *parameters_;
 
-    CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
+    CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
         CYTypeModifier(next),
+        variadic_(variadic),
         parameters_(parameters)
     {
     }