]> git.saurik.com Git - cycript.git/blobdiff - ObjectiveC/Output.cpp
Correct prototype hierearchy (simple AND elegant).
[cycript.git] / ObjectiveC / Output.cpp
index a1101ecce77ebafd841eea3c974ecdd63ad328b2..6927938200db773981b2228b892ae4df3b752093 100644 (file)
@@ -1,5 +1,5 @@
-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015  Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016  Jay Freeman (saurik)
 */
 
 /* GNU Affero General Public License, Version 3 {{{ */
@@ -49,6 +49,9 @@ void CYImplementation::Output(CYOutput &out, CYFlags flags) const {
 }
 
 void CYImplementationField::Output(CYOutput &out) const {
+    type_->Output(out, name_);
+    out.Terminate();
+    out << '\n';
 }
 
 void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
@@ -62,8 +65,13 @@ void CYMessage::Output(CYOutput &out) const {
     CYForEach (parameter, parameters_)
         if (parameter->name_ != NULL) {
             out << ' ' << *parameter->name_;
-            if (parameter->type_ != NULL)
-                out << ':' << *parameter->type_->identifier_;
+            // XXX: this is off somehow
+            if (parameter->identifier_ != NULL) {
+                out << ':';
+                if (parameter->type_ != NULL)
+                    out << '(' << *parameter->type_ << ')';
+                out << *parameter->identifier_;
+            }
         }
 
     out << code_;
@@ -74,12 +82,70 @@ void CYBox::Output(CYOutput &out, CYFlags flags) const {
     value_->Output(out, Precedence(), CYRight(flags));
 }
 
+void CYObjCArray::Output(CYOutput &out, CYFlags flags) const {
+    out << '@' << '[' << elements_ << ']';
+}
+
+void CYObjCDictionary::Output(CYOutput &out, CYFlags flags) const {
+    unsigned count(0);
+    CYForEach (pair, pairs_)
+        ++count;
+    bool large(count > 8);
+
+    out << '@' << '{';
+    if (large) {
+        out << '\n';
+        ++out.indent_;
+    }
+
+    bool comma(false);
+    CYForEach (pair, pairs_) {
+        if (!comma)
+            comma = true;
+        else {
+            out << ',';
+            if (large)
+                out << '\n';
+            else
+                out << ' ';
+        }
+
+        if (large)
+            out << '\t';
+
+        pair->key_->Output(out, CYAssign::Precedence_, CYNoFlags);
+        out << ':' << ' ';
+        pair->value_->Output(out, CYAssign::Precedence_, CYNoFlags);
+    }
+
+    if (large && out.pretty_)
+        out << ',';
+
+    if (large) {
+        out << '\n';
+        --out.indent_;
+    }
+
+    out << '\t' << '}';
+}
+
 void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
-    // XXX: this is seriously wrong
-    out << "^(";
-    out << ")";
-    out << "{";
-    out << "}";
+    out << '^' << ' ' << *typed_ << ' ' << '(';
+
+    bool comma(false);
+    CYForEach (parameter, parameters_) {
+        if (comma)
+            out << ',' << ' ';
+        else
+            comma = true;
+        parameter->type_->Output(out, parameter->name_);
+    }
+
+    out << ')' << ' ' << '{' << '\n';
+    ++out.indent_;
+    out << code_;
+    --out.indent_;
+    out << '\t' << '}';
 }
 
 void CYProtocol::Output(CYOutput &out) const {