]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Output.cpp
Do not use corrupt struct to store type reference.
[cycript.git] / ObjectiveC / Output.cpp
CommitLineData
7341eedb
JF
1/* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
b53b30c1
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
b53b30c1 6/*
f95d2598
JF
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c15969fd 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b3378a02 19**/
b53b30c1
JF
20/* }}} */
21
20052ff7
JF
22#include <sstream>
23
4de0686f 24#include "Replace.hpp"
4de0686f 25
20052ff7 26#include "ObjectiveC/Syntax.hpp"
4de0686f
JF
27
28void CYCategory::Output(CYOutput &out, CYFlags flags) const {
c5b15840
JF
29 out << "@implementation" << ' ' << *name_ << ' ' << '(' << ')' << '\n';
30 ++out.indent_;
4de0686f 31
c5b15840
JF
32 CYForEach (message, messages_) {
33 message->Output(out);
34 out << '\n';
64b8d29f 35 }
c5b15840
JF
36
37 --out.indent_;
38 out << "@end";
39}
40
41void CYImplementation::Output(CYOutput &out, CYFlags flags) const {
42 out << "@implementation" << ' ' << *name_ << '\n';
43 ++out.indent_;
44
45 // XXX: implement
46
47 --out.indent_;
48 out << "@end";
4de0686f
JF
49}
50
c5b15840 51void CYImplementationField::Output(CYOutput &out) const {
7cf0481b
JF
52 out << *typed_;
53 out.Terminate();
54 out << '\n';
4de0686f
JF
55}
56
61769f4f
JF
57void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
58 out << '#';
59 number_->Output(out, CYRight(flags));
60}
61
c5b15840 62void CYMessage::Output(CYOutput &out) const {
4644480a
JF
63 out << (instance_ ? '-' : '+');
64
c2c9f509 65 CYForEach (parameter, parameters_)
09fc3efb
JF
66 if (parameter->name_ != NULL) {
67 out << ' ' << *parameter->name_;
104cc5f5
JF
68 if (parameter->type_ != NULL)
69 out << ':' << *parameter->type_->identifier_;
4de0686f 70 }
4644480a
JF
71
72 out << code_;
4de0686f
JF
73}
74
f2f0d1d1
JF
75void CYBox::Output(CYOutput &out, CYFlags flags) const {
76 out << '@';
77 value_->Output(out, Precedence(), CYRight(flags));
78}
79
5a6c975a
JF
80void CYObjCArray::Output(CYOutput &out, CYFlags flags) const {
81 out << '@' << '[' << elements_ << ']';
82}
83
84void CYObjCDictionary::Output(CYOutput &out, CYFlags flags) const {
a4d849b7
JF
85 unsigned count(0);
86 CYForEach (pair, pairs_)
87 ++count;
88 bool large(count > 8);
89
90 out << '@' << '{';
91 if (large) {
92 out << '\n';
93 ++out.indent_;
94 }
95
96 bool comma(false);
97 CYForEach (pair, pairs_) {
98 if (!comma)
99 comma = true;
100 else {
101 out << ',';
102 if (large)
103 out << '\n';
104 else
105 out << ' ';
106 }
107
108 if (large)
109 out << '\t';
110
111 pair->key_->Output(out, CYAssign::Precedence_, CYNoFlags);
112 out << ':' << ' ';
113 pair->value_->Output(out, CYAssign::Precedence_, CYNoFlags);
114 }
115
116 if (large && out.pretty_)
117 out << ',';
118
119 if (large) {
120 out << '\n';
121 --out.indent_;
122 }
123
124 out << '\t' << '}';
5a6c975a
JF
125}
126
56e02e5b 127void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
4d3ff062
JF
128 out << '^' << ' ' << *typed_ << ' ' << '(';
129
130 bool comma(false);
131 CYForEach (parameter, parameters_) {
132 if (comma)
133 out << ',' << ' ';
134 else
135 comma = true;
136 out << *parameter->typed_;
137 }
138
139 out << ')' << ' ' << '{' << '\n';
140 ++out.indent_;
141 out << code_;
142 --out.indent_;
a4d849b7 143 out << '\t' << '}';
56e02e5b
JF
144}
145
64b8d29f 146void CYProtocol::Output(CYOutput &out) const {
8351aa30 147 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
64b8d29f
JF
148 if (next_ != NULL)
149 out << ',' << ' ' << *next_;
150}
151
4de0686f 152void CYSelector::Output(CYOutput &out, CYFlags flags) const {
09fc3efb 153 out << "@selector" << '(' << parts_ << ')';
4de0686f
JF
154}
155
156void CYSelectorPart::Output(CYOutput &out) const {
157 out << name_;
158 if (value_)
159 out << ':';
160 out << next_;
161}
162
163void CYSend::Output(CYOutput &out, CYFlags flags) const {
c2c9f509 164 CYForEach (argument, arguments_)
4de0686f 165 if (argument->name_ != NULL) {
4644480a 166 out << ' ' << *argument->name_;
4de0686f 167 if (argument->value_ != NULL)
4644480a 168 out << ':' << *argument->value_;
4de0686f 169 }
cacd1a88
JF
170}
171
172void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
173 out << '[';
8351aa30 174 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
cacd1a88
JF
175 CYSend::Output(out, flags);
176 out << ']';
177}
4de0686f 178
cacd1a88
JF
179void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
180 out << '[' << "super";
181 CYSend::Output(out, flags);
4644480a 182 out << ']';
4de0686f 183}