]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Output.cpp
Fix build of cycript when using g++-fsf from Fink.
[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
4de0686f 22#include "Replace.hpp"
3c1c3635 23#include "ObjectiveC/Syntax.hpp"
4de0686f 24
4de0686f
JF
25#include <sstream>
26
27void CYCategory::Output(CYOutput &out, CYFlags flags) const {
28 out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
29 out << "$cyp=object_getClass($cys);";
30 out << "$cyc=$cys;";
31 if (messages_ != NULL)
32 messages_->Output(out, true);
33 out << "})(";
34 name_->ClassName(out, true);
35 out << ')';
36 out << ';';
37}
38
39void CYClass::Output(CYOutput &out, CYFlags flags) const {
40 // XXX: I don't necc. need the ()s
41 out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
42 out << "$cyp=object_getClass($cys);";
43 out << "$cyc=objc_allocateClassPair($cys,";
44 if (name_ != NULL)
45 name_->ClassName(out, false);
46 else
47 out << "$cyq(\"CY$\")";
48 out << ",0);";
49 out << "$cym=object_getClass($cyc);";
50 if (fields_ != NULL)
51 fields_->Output(out);
52 if (messages_ != NULL)
53 messages_->Output(out, false);
64b8d29f
JF
54 if (protocols_ != NULL) {
55 out << '<';
56 out << *protocols_;
57 out << '>';
58 }
4de0686f
JF
59 out << "objc_registerClassPair($cyc);";
60 out << "return $cyc;";
61 out << "}(";
62 if (super_ != NULL)
8351aa30 63 super_->Output(out, CYAssign::Precedence_, CYNoFlags);
4de0686f
JF
64 else
65 out << "null";
66 out << "))";
67}
68
69void CYClassExpression::Output(CYOutput &out, CYFlags flags) const {
70 CYClass::Output(out, flags);
71}
72
73void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
74 CYClass::Output(out, flags);
75}
76
77void CYField::Output(CYOutput &out) const {
4de0686f
JF
78}
79
61769f4f
JF
80void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
81 out << '#';
82 number_->Output(out, CYRight(flags));
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
56e02e5b
JF
103void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
104 // XXX: this is seriously wrong
105 out << "^(";
106 out << ")";
107 out << "{";
108 out << "}";
109}
110
64b8d29f 111void CYProtocol::Output(CYOutput &out) const {
8351aa30 112 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
64b8d29f
JF
113 if (next_ != NULL)
114 out << ',' << ' ' << *next_;
115}
116
4de0686f
JF
117void CYSelector::Output(CYOutput &out, CYFlags flags) const {
118 out << "@selector" << '(' << name_ << ')';
119}
120
121void CYSelectorPart::Output(CYOutput &out) const {
122 out << name_;
123 if (value_)
124 out << ':';
125 out << next_;
126}
127
128void CYSend::Output(CYOutput &out, CYFlags flags) const {
c2c9f509 129 CYForEach (argument, arguments_)
4de0686f 130 if (argument->name_ != NULL) {
4644480a 131 out << ' ' << *argument->name_;
4de0686f 132 if (argument->value_ != NULL)
4644480a 133 out << ':' << *argument->value_;
4de0686f 134 }
cacd1a88
JF
135}
136
137void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
138 out << '[';
8351aa30 139 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
cacd1a88
JF
140 CYSend::Output(out, flags);
141 out << ']';
142}
4de0686f 143
cacd1a88
JF
144void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
145 out << '[' << "super";
146 CYSend::Output(out, flags);
4644480a 147 out << ']';
4de0686f 148}