]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Output.cpp
Move TypedIdentifier assertions to separate rules.
[cycript.git] / ObjectiveC / Output.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
19 **/
20 /* }}} */
21
22 #include <sstream>
23
24 #include "Replace.hpp"
25
26 #include "ObjectiveC/Syntax.hpp"
27
28 void CYCategory::Output(CYOutput &out, CYFlags flags) const {
29 out << "@implementation" << ' ' << *name_ << ' ' << '(' << ')' << '\n';
30 ++out.indent_;
31
32 CYForEach (message, messages_) {
33 message->Output(out);
34 out << '\n';
35 }
36
37 --out.indent_;
38 out << "@end";
39 }
40
41 void 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";
49 }
50
51 void CYImplementationField::Output(CYOutput &out) const {
52 }
53
54 void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
55 out << '#';
56 number_->Output(out, CYRight(flags));
57 }
58
59 void CYMessage::Output(CYOutput &out) const {
60 out << (instance_ ? '-' : '+');
61
62 CYForEach (parameter, parameters_)
63 if (parameter->name_ != NULL) {
64 out << ' ' << *parameter->name_;
65 if (parameter->type_ != NULL)
66 out << ':' << *parameter->type_->identifier_;
67 }
68
69 out << code_;
70 }
71
72 void CYBox::Output(CYOutput &out, CYFlags flags) const {
73 out << '@';
74 value_->Output(out, Precedence(), CYRight(flags));
75 }
76
77 void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
78 // XXX: this is seriously wrong
79 out << "^(";
80 out << ")";
81 out << "{";
82 out << "}";
83 }
84
85 void CYProtocol::Output(CYOutput &out) const {
86 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
87 if (next_ != NULL)
88 out << ',' << ' ' << *next_;
89 }
90
91 void CYSelector::Output(CYOutput &out, CYFlags flags) const {
92 out << "@selector" << '(' << parts_ << ')';
93 }
94
95 void CYSelectorPart::Output(CYOutput &out) const {
96 out << name_;
97 if (value_)
98 out << ':';
99 out << next_;
100 }
101
102 void CYSend::Output(CYOutput &out, CYFlags flags) const {
103 CYForEach (argument, arguments_)
104 if (argument->name_ != NULL) {
105 out << ' ' << *argument->name_;
106 if (argument->value_ != NULL)
107 out << ':' << *argument->value_;
108 }
109 }
110
111 void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
112 out << '[';
113 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
114 CYSend::Output(out, flags);
115 out << ']';
116 }
117
118 void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
119 out << '[' << "super";
120 CYSend::Output(out, flags);
121 out << ']';
122 }