]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Output.mm
Update the todo list with the new tasks from stash.
[cycript.git] / ObjectiveC / Output.mm
CommitLineData
b3378a02
JF
1/* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
b53b30c1
JF
3*/
4
b3378a02 5/* GNU Lesser General Public License, Version 3 {{{ */
b53b30c1 6/*
b3378a02
JF
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
b53b30c1 11 *
b3378a02
JF
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
b53b30c1 16 *
b3378a02
JF
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
19**/
b53b30c1
JF
20/* }}} */
21
4de0686f 22#include "Replace.hpp"
3c1c3635 23#include "ObjectiveC/Syntax.hpp"
4de0686f 24
aabea98c 25#include <Foundation/Foundation.h>
4de0686f
JF
26#include <sstream>
27
28void CYCategory::Output(CYOutput &out, CYFlags flags) const {
29 out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
30 out << "$cyp=object_getClass($cys);";
31 out << "$cyc=$cys;";
32 if (messages_ != NULL)
33 messages_->Output(out, true);
34 out << "})(";
35 name_->ClassName(out, true);
36 out << ')';
37 out << ';';
38}
39
40void CYClass::Output(CYOutput &out, CYFlags flags) const {
41 // XXX: I don't necc. need the ()s
42 out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
43 out << "$cyp=object_getClass($cys);";
44 out << "$cyc=objc_allocateClassPair($cys,";
45 if (name_ != NULL)
46 name_->ClassName(out, false);
47 else
48 out << "$cyq(\"CY$\")";
49 out << ",0);";
50 out << "$cym=object_getClass($cyc);";
51 if (fields_ != NULL)
52 fields_->Output(out);
53 if (messages_ != NULL)
54 messages_->Output(out, false);
64b8d29f
JF
55 if (protocols_ != NULL) {
56 out << '<';
57 out << *protocols_;
58 out << '>';
59 }
4de0686f
JF
60 out << "objc_registerClassPair($cyc);";
61 out << "return $cyc;";
62 out << "}(";
63 if (super_ != NULL)
8351aa30 64 super_->Output(out, CYAssign::Precedence_, CYNoFlags);
4de0686f
JF
65 else
66 out << "null";
67 out << "))";
68}
69
70void CYClassExpression::Output(CYOutput &out, CYFlags flags) const {
71 CYClass::Output(out, flags);
72}
73
74void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
75 CYClass::Output(out, flags);
76}
77
78void CYField::Output(CYOutput &out) const {
4de0686f
JF
79}
80
1ba6903e
JF
81void CYImport::Output(CYOutput &out, CYFlags flags) const {
82 out << "@import";
83}
84
4de0686f 85void CYMessage::Output(CYOutput &out, bool replace) const {
4644480a
JF
86 out << (instance_ ? '-' : '+');
87
c2c9f509 88 CYForEach (parameter, parameters_)
4de0686f 89 if (parameter->tag_ != NULL) {
4644480a 90 out << ' ' << *parameter->tag_;
4de0686f 91 if (parameter->name_ != NULL)
4644480a 92 out << ':' << *parameter->name_;
4de0686f 93 }
4644480a
JF
94
95 out << code_;
4de0686f
JF
96}
97
f2f0d1d1
JF
98void CYBox::Output(CYOutput &out, CYFlags flags) const {
99 out << '@';
100 value_->Output(out, Precedence(), CYRight(flags));
101}
102
64b8d29f 103void CYProtocol::Output(CYOutput &out) const {
8351aa30 104 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
64b8d29f
JF
105 if (next_ != NULL)
106 out << ',' << ' ' << *next_;
107}
108
4de0686f
JF
109void CYSelector::Output(CYOutput &out, CYFlags flags) const {
110 out << "@selector" << '(' << name_ << ')';
111}
112
113void CYSelectorPart::Output(CYOutput &out) const {
114 out << name_;
115 if (value_)
116 out << ':';
117 out << next_;
118}
119
120void CYSend::Output(CYOutput &out, CYFlags flags) const {
c2c9f509 121 CYForEach (argument, arguments_)
4de0686f 122 if (argument->name_ != NULL) {
4644480a 123 out << ' ' << *argument->name_;
4de0686f 124 if (argument->value_ != NULL)
4644480a 125 out << ':' << *argument->value_;
4de0686f 126 }
cacd1a88
JF
127}
128
129void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
130 out << '[';
8351aa30 131 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
cacd1a88
JF
132 CYSend::Output(out, flags);
133 out << ']';
134}
4de0686f 135
cacd1a88
JF
136void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
137 out << '[' << "super";
138 CYSend::Output(out, flags);
4644480a 139 out << ']';
4de0686f 140}