]>
Commit | Line | Data |
---|---|---|
1 | /* Cycript - The Truly Universal Scripting Language | |
2 | * Copyright (C) 2009-2016 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 | out << *typed_; | |
53 | out.Terminate(); | |
54 | out << '\n'; | |
55 | } | |
56 | ||
57 | void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { | |
58 | out << '#'; | |
59 | number_->Output(out, CYRight(flags)); | |
60 | } | |
61 | ||
62 | void CYMessage::Output(CYOutput &out) const { | |
63 | out << (instance_ ? '-' : '+'); | |
64 | ||
65 | CYForEach (parameter, parameters_) | |
66 | if (parameter->name_ != NULL) { | |
67 | out << ' ' << *parameter->name_; | |
68 | if (parameter->type_ != NULL) | |
69 | out << ':' << *parameter->type_->identifier_; | |
70 | } | |
71 | ||
72 | out << code_; | |
73 | } | |
74 | ||
75 | void CYBox::Output(CYOutput &out, CYFlags flags) const { | |
76 | out << '@'; | |
77 | value_->Output(out, Precedence(), CYRight(flags)); | |
78 | } | |
79 | ||
80 | void CYObjCArray::Output(CYOutput &out, CYFlags flags) const { | |
81 | out << '@' << '[' << elements_ << ']'; | |
82 | } | |
83 | ||
84 | void CYObjCDictionary::Output(CYOutput &out, CYFlags flags) const { | |
85 | out << '@' << '{' << '}'; | |
86 | } | |
87 | ||
88 | void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const { | |
89 | out << '^' << ' ' << *typed_ << ' ' << '('; | |
90 | ||
91 | bool comma(false); | |
92 | CYForEach (parameter, parameters_) { | |
93 | if (comma) | |
94 | out << ',' << ' '; | |
95 | else | |
96 | comma = true; | |
97 | out << *parameter->typed_; | |
98 | } | |
99 | ||
100 | out << ')' << ' ' << '{' << '\n'; | |
101 | ++out.indent_; | |
102 | out << code_; | |
103 | --out.indent_; | |
104 | out << '\n' << '}'; | |
105 | } | |
106 | ||
107 | void CYProtocol::Output(CYOutput &out) const { | |
108 | name_->Output(out, CYAssign::Precedence_, CYNoFlags); | |
109 | if (next_ != NULL) | |
110 | out << ',' << ' ' << *next_; | |
111 | } | |
112 | ||
113 | void CYSelector::Output(CYOutput &out, CYFlags flags) const { | |
114 | out << "@selector" << '(' << parts_ << ')'; | |
115 | } | |
116 | ||
117 | void CYSelectorPart::Output(CYOutput &out) const { | |
118 | out << name_; | |
119 | if (value_) | |
120 | out << ':'; | |
121 | out << next_; | |
122 | } | |
123 | ||
124 | void CYSend::Output(CYOutput &out, CYFlags flags) const { | |
125 | CYForEach (argument, arguments_) | |
126 | if (argument->name_ != NULL) { | |
127 | out << ' ' << *argument->name_; | |
128 | if (argument->value_ != NULL) | |
129 | out << ':' << *argument->value_; | |
130 | } | |
131 | } | |
132 | ||
133 | void CYSendDirect::Output(CYOutput &out, CYFlags flags) const { | |
134 | out << '['; | |
135 | self_->Output(out, CYAssign::Precedence_, CYNoFlags); | |
136 | CYSend::Output(out, flags); | |
137 | out << ']'; | |
138 | } | |
139 | ||
140 | void CYSendSuper::Output(CYOutput &out, CYFlags flags) const { | |
141 | out << '[' << "super"; | |
142 | CYSend::Output(out, flags); | |
143 | out << ']'; | |
144 | } |