]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Output.cpp
Move TypedIdentifier assertions to separate rules.
[cycript.git] / ObjectiveC / Output.cpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c1d3e52e 2 * Copyright (C) 2009-2015 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 {
4de0686f
JF
52}
53
61769f4f
JF
54void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
55 out << '#';
56 number_->Output(out, CYRight(flags));
57}
58
c5b15840 59void CYMessage::Output(CYOutput &out) const {
4644480a
JF
60 out << (instance_ ? '-' : '+');
61
c2c9f509 62 CYForEach (parameter, parameters_)
09fc3efb
JF
63 if (parameter->name_ != NULL) {
64 out << ' ' << *parameter->name_;
104cc5f5
JF
65 if (parameter->type_ != NULL)
66 out << ':' << *parameter->type_->identifier_;
4de0686f 67 }
4644480a
JF
68
69 out << code_;
4de0686f
JF
70}
71
f2f0d1d1
JF
72void CYBox::Output(CYOutput &out, CYFlags flags) const {
73 out << '@';
74 value_->Output(out, Precedence(), CYRight(flags));
75}
76
56e02e5b
JF
77void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
78 // XXX: this is seriously wrong
79 out << "^(";
80 out << ")";
81 out << "{";
82 out << "}";
83}
84
64b8d29f 85void CYProtocol::Output(CYOutput &out) const {
8351aa30 86 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
64b8d29f
JF
87 if (next_ != NULL)
88 out << ',' << ' ' << *next_;
89}
90
4de0686f 91void CYSelector::Output(CYOutput &out, CYFlags flags) const {
09fc3efb 92 out << "@selector" << '(' << parts_ << ')';
4de0686f
JF
93}
94
95void CYSelectorPart::Output(CYOutput &out) const {
96 out << name_;
97 if (value_)
98 out << ':';
99 out << next_;
100}
101
102void CYSend::Output(CYOutput &out, CYFlags flags) const {
c2c9f509 103 CYForEach (argument, arguments_)
4de0686f 104 if (argument->name_ != NULL) {
4644480a 105 out << ' ' << *argument->name_;
4de0686f 106 if (argument->value_ != NULL)
4644480a 107 out << ':' << *argument->value_;
4de0686f 108 }
cacd1a88
JF
109}
110
111void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
112 out << '[';
8351aa30 113 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
cacd1a88
JF
114 CYSend::Output(out, flags);
115 out << ']';
116}
4de0686f 117
cacd1a88
JF
118void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
119 out << '[' << "super";
120 CYSend::Output(out, flags);
4644480a 121 out << ']';
4de0686f 122}