X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/7cf0481b5ad2ae2b3b17fbc475bacae5c1a4ddd4..HEAD:/ObjectiveC/Output.cpp diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index 7d21d6f..6927938 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -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,7 +49,7 @@ void CYImplementation::Output(CYOutput &out, CYFlags flags) const { } void CYImplementationField::Output(CYOutput &out) const { - out << *typed_; + type_->Output(out, name_); out.Terminate(); out << '\n'; } @@ -65,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_; @@ -77,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 {