]> git.saurik.com Git - cycript.git/blobdiff - ObjectiveC/Output.cpp
Add a ?reparse mode to experiment pretty printing.
[cycript.git] / ObjectiveC / Output.cpp
index a1101ecce77ebafd841eea3c974ecdd63ad328b2..e2bb0f8e618c0e8ebdab28c028234fbcad2c8239 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 {
+    out << *typed_;
+    out.Terminate();
+    out << '\n';
 }
 
 void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
@@ -74,12 +77,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;
+        out << *parameter->typed_;
+    }
+
+    out << ')' << ' ' << '{' << '\n';
+    ++out.indent_;
+    out << code_;
+    --out.indent_;
+    out << '\t' << '}';
 }
 
 void CYProtocol::Output(CYOutput &out) const {