]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Output.mm
Remove --with-frameworks (it didn't work anyway).
[cycript.git] / ObjectiveC / Output.mm
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c15969fd 2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
b53b30c1
JF
3*/
4
c15969fd 5/* GNU General Public License, Version 3 {{{ */
b53b30c1 6/*
c15969fd
JF
7 * Cycript is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
b53b30c1 11 *
c15969fd
JF
12 * Cycript is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
b53b30c1 16 *
c15969fd 17 * You should have received a copy of the GNU General Public License
b3378a02
JF
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
46f4f308 78void CYEncodedType::Output(CYOutput &out, CYFlags flags) const {
561e7f1c 79 out << "@encode(";
46f4f308 80 // XXX: this is seriously wrong
561e7f1c 81 out << ")";
46f4f308
JF
82}
83
4de0686f 84void CYField::Output(CYOutput &out) const {
4de0686f
JF
85}
86
1ba6903e
JF
87void CYImport::Output(CYOutput &out, CYFlags flags) const {
88 out << "@import";
89}
90
4de0686f 91void CYMessage::Output(CYOutput &out, bool replace) const {
4644480a
JF
92 out << (instance_ ? '-' : '+');
93
c2c9f509 94 CYForEach (parameter, parameters_)
4de0686f 95 if (parameter->tag_ != NULL) {
4644480a 96 out << ' ' << *parameter->tag_;
4de0686f 97 if (parameter->name_ != NULL)
4644480a 98 out << ':' << *parameter->name_;
4de0686f 99 }
4644480a
JF
100
101 out << code_;
4de0686f
JF
102}
103
f2f0d1d1
JF
104void CYBox::Output(CYOutput &out, CYFlags flags) const {
105 out << '@';
106 value_->Output(out, Precedence(), CYRight(flags));
107}
108
56e02e5b
JF
109void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
110 // XXX: this is seriously wrong
111 out << "^(";
112 out << ")";
113 out << "{";
114 out << "}";
115}
116
64b8d29f 117void CYProtocol::Output(CYOutput &out) const {
8351aa30 118 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
64b8d29f
JF
119 if (next_ != NULL)
120 out << ',' << ' ' << *next_;
121}
122
4de0686f
JF
123void CYSelector::Output(CYOutput &out, CYFlags flags) const {
124 out << "@selector" << '(' << name_ << ')';
125}
126
127void CYSelectorPart::Output(CYOutput &out) const {
128 out << name_;
129 if (value_)
130 out << ':';
131 out << next_;
132}
133
134void CYSend::Output(CYOutput &out, CYFlags flags) const {
c2c9f509 135 CYForEach (argument, arguments_)
4de0686f 136 if (argument->name_ != NULL) {
4644480a 137 out << ' ' << *argument->name_;
4de0686f 138 if (argument->value_ != NULL)
4644480a 139 out << ':' << *argument->value_;
4de0686f 140 }
cacd1a88
JF
141}
142
143void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
144 out << '[';
8351aa30 145 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
cacd1a88
JF
146 CYSend::Output(out, flags);
147 out << ']';
148}
4de0686f 149
cacd1a88
JF
150void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
151 out << '[' << "super";
152 CYSend::Output(out, flags);
4644480a 153 out << ']';
4de0686f 154}