blob: 8acff0d3901931ff7b5a46c885521661ee7f989d [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Resource.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080018#include "ResourceValues.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070019#include "ValueVisitor.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020
Adam Lesinskie78fd612015-10-22 12:48:43 -070021#include "util/Util.h"
22#include "flatten/ResourceTypeExtensions.h"
23
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080024#include <androidfw/ResourceTypes.h>
25#include <limits>
26
27namespace aapt {
28
Adam Lesinski1ab598f2015-08-14 14:26:04 -070029template <typename Derived>
30void BaseValue<Derived>::accept(RawValueVisitor* visitor) {
31 visitor->visit(static_cast<Derived*>(this));
32}
33
34template <typename Derived>
35void BaseItem<Derived>::accept(RawValueVisitor* visitor) {
36 visitor->visit(static_cast<Derived*>(this));
37}
38
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080039bool Value::isWeak() const {
40 return false;
41}
42
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080043RawString::RawString(const StringPool::Ref& ref) : value(ref) {
44}
45
Adam Lesinski769de982015-04-10 19:43:55 -070046RawString* RawString::clone(StringPool* newPool) const {
Adam Lesinskib274e352015-11-06 15:14:35 -080047 RawString* rs = new RawString(newPool->makeRef(*value));
48 rs->mComment = mComment;
49 rs->mSource = mSource;
50 return rs;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080051}
52
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053bool RawString::flatten(android::Res_value* outValue) const {
54 outValue->dataType = ExtendedTypes::TYPE_RAW_STRING;
55 outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080056 return true;
57}
58
Adam Lesinski1ab598f2015-08-14 14:26:04 -070059void RawString::print(std::ostream* out) const {
60 *out << "(raw string) " << *value;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080061}
62
63Reference::Reference() : referenceType(Reference::Type::kResource) {
64}
65
66Reference::Reference(const ResourceNameRef& n, Type t) :
67 name(n.toResourceName()), referenceType(t) {
68}
69
70Reference::Reference(const ResourceId& i, Type type) : id(i), referenceType(type) {
71}
72
Adam Lesinski1ab598f2015-08-14 14:26:04 -070073bool Reference::flatten(android::Res_value* outValue) const {
74 outValue->dataType = (referenceType == Reference::Type::kResource)
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080075 ? android::Res_value::TYPE_REFERENCE
76 : android::Res_value::TYPE_ATTRIBUTE;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070077 outValue->data = util::hostToDevice32(id ? id.value().id : 0);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078 return true;
79}
80
Adam Lesinski769de982015-04-10 19:43:55 -070081Reference* Reference::clone(StringPool* /*newPool*/) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080082 Reference* ref = new Reference();
Adam Lesinskib274e352015-11-06 15:14:35 -080083 ref->mComment = mComment;
84 ref->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080085 ref->referenceType = referenceType;
86 ref->name = name;
87 ref->id = id;
88 return ref;
89}
90
Adam Lesinski1ab598f2015-08-14 14:26:04 -070091void Reference::print(std::ostream* out) const {
92 *out << "(reference) ";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080093 if (referenceType == Reference::Type::kResource) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070094 *out << "@";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080095 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070096 *out << "?";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080097 }
98
Adam Lesinski1ab598f2015-08-14 14:26:04 -070099 if (name) {
100 *out << name.value();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800101 }
102
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700103 if (id && !Res_INTERNALID(id.value().id)) {
104 *out << " " << id.value();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800105 }
106}
107
108bool Id::isWeak() const {
109 return true;
110}
111
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700112bool Id::flatten(android::Res_value* out) const {
113 out->dataType = android::Res_value::TYPE_INT_BOOLEAN;
114 out->data = util::hostToDevice32(0);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800115 return true;
116}
117
Adam Lesinski769de982015-04-10 19:43:55 -0700118Id* Id::clone(StringPool* /*newPool*/) const {
Adam Lesinskib274e352015-11-06 15:14:35 -0800119 Id* id = new Id();
120 id->mComment = mComment;
121 id->mSource = mSource;
122 return id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800123}
124
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700125void Id::print(std::ostream* out) const {
126 *out << "(id)";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800127}
128
129String::String(const StringPool::Ref& ref) : value(ref) {
130}
131
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700132bool String::flatten(android::Res_value* outValue) const {
133 // Verify that our StringPool index is within encode-able limits.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800134 if (value.getIndex() > std::numeric_limits<uint32_t>::max()) {
135 return false;
136 }
137
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700138 outValue->dataType = android::Res_value::TYPE_STRING;
139 outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800140 return true;
141}
142
Adam Lesinski769de982015-04-10 19:43:55 -0700143String* String::clone(StringPool* newPool) const {
Adam Lesinskib274e352015-11-06 15:14:35 -0800144 String* str = new String(newPool->makeRef(*value));
145 str->mComment = mComment;
146 str->mSource = mSource;
147 return str;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800148}
149
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700150void String::print(std::ostream* out) const {
151 *out << "(string) \"" << *value << "\"";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800152}
153
154StyledString::StyledString(const StringPool::StyleRef& ref) : value(ref) {
155}
156
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700157bool StyledString::flatten(android::Res_value* outValue) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800158 if (value.getIndex() > std::numeric_limits<uint32_t>::max()) {
159 return false;
160 }
161
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700162 outValue->dataType = android::Res_value::TYPE_STRING;
163 outValue->data = util::hostToDevice32(static_cast<uint32_t>(value.getIndex()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800164 return true;
165}
166
Adam Lesinski769de982015-04-10 19:43:55 -0700167StyledString* StyledString::clone(StringPool* newPool) const {
Adam Lesinskib274e352015-11-06 15:14:35 -0800168 StyledString* str = new StyledString(newPool->makeRef(value));
169 str->mComment = mComment;
170 str->mSource = mSource;
171 return str;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800172}
173
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700174void StyledString::print(std::ostream* out) const {
175 *out << "(styled string) \"" << *value->str << "\"";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800176}
177
178FileReference::FileReference(const StringPool::Ref& _path) : path(_path) {
179}
180
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700181bool FileReference::flatten(android::Res_value* outValue) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800182 if (path.getIndex() > std::numeric_limits<uint32_t>::max()) {
183 return false;
184 }
185
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700186 outValue->dataType = android::Res_value::TYPE_STRING;
187 outValue->data = util::hostToDevice32(static_cast<uint32_t>(path.getIndex()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800188 return true;
189}
190
Adam Lesinski769de982015-04-10 19:43:55 -0700191FileReference* FileReference::clone(StringPool* newPool) const {
Adam Lesinskib274e352015-11-06 15:14:35 -0800192 FileReference* fr = new FileReference(newPool->makeRef(*path));
193 fr->mComment = mComment;
194 fr->mSource = mSource;
195 return fr;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800196}
197
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700198void FileReference::print(std::ostream* out) const {
199 *out << "(file) " << *path;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800200}
201
202BinaryPrimitive::BinaryPrimitive(const android::Res_value& val) : value(val) {
203}
204
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700205BinaryPrimitive::BinaryPrimitive(uint8_t dataType, uint32_t data) {
206 value.dataType = dataType;
207 value.data = data;
208}
209
210bool BinaryPrimitive::flatten(android::Res_value* outValue) const {
211 outValue->dataType = value.dataType;
212 outValue->data = util::hostToDevice32(value.data);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800213 return true;
214}
215
Adam Lesinski769de982015-04-10 19:43:55 -0700216BinaryPrimitive* BinaryPrimitive::clone(StringPool* /*newPool*/) const {
Adam Lesinskib274e352015-11-06 15:14:35 -0800217 BinaryPrimitive* bp = new BinaryPrimitive(value);
218 bp->mComment = mComment;
219 bp->mSource = mSource;
220 return bp;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800221}
222
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700223void BinaryPrimitive::print(std::ostream* out) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800224 switch (value.dataType) {
225 case android::Res_value::TYPE_NULL:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700226 *out << "(null)";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800227 break;
228 case android::Res_value::TYPE_INT_DEC:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700229 *out << "(integer) " << value.data;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800230 break;
231 case android::Res_value::TYPE_INT_HEX:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700232 *out << "(integer) " << std::hex << value.data << std::dec;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800233 break;
234 case android::Res_value::TYPE_INT_BOOLEAN:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700235 *out << "(boolean) " << (value.data != 0 ? "true" : "false");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800236 break;
237 case android::Res_value::TYPE_INT_COLOR_ARGB8:
238 case android::Res_value::TYPE_INT_COLOR_RGB8:
239 case android::Res_value::TYPE_INT_COLOR_ARGB4:
240 case android::Res_value::TYPE_INT_COLOR_RGB4:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700241 *out << "(color) #" << std::hex << value.data << std::dec;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800242 break;
243 default:
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700244 *out << "(unknown 0x" << std::hex << (int) value.dataType << ") 0x"
245 << std::hex << value.data << std::dec;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800246 break;
247 }
248}
249
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800250Attribute::Attribute(bool w, uint32_t t) : weak(w), typeMask(t) {
251}
252
253bool Attribute::isWeak() const {
254 return weak;
255}
256
Adam Lesinski769de982015-04-10 19:43:55 -0700257Attribute* Attribute::clone(StringPool* /*newPool*/) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800258 Attribute* attr = new Attribute(weak);
Adam Lesinskib274e352015-11-06 15:14:35 -0800259 attr->mComment = mComment;
260 attr->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800261 attr->typeMask = typeMask;
262 std::copy(symbols.begin(), symbols.end(), std::back_inserter(attr->symbols));
263 return attr;
264}
265
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700266void Attribute::printMask(std::ostream* out) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800267 if (typeMask == android::ResTable_map::TYPE_ANY) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700268 *out << "any";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800269 return;
270 }
271
272 bool set = false;
273 if ((typeMask & android::ResTable_map::TYPE_REFERENCE) != 0) {
274 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800275 set = true;
276 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700277 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800278 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700279 *out << "reference";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800280 }
281
282 if ((typeMask & android::ResTable_map::TYPE_STRING) != 0) {
283 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800284 set = true;
285 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700286 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800287 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700288 *out << "string";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800289 }
290
291 if ((typeMask & android::ResTable_map::TYPE_INTEGER) != 0) {
292 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800293 set = true;
294 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700295 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800296 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700297 *out << "integer";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800298 }
299
300 if ((typeMask & android::ResTable_map::TYPE_BOOLEAN) != 0) {
301 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800302 set = true;
303 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700304 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800305 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700306 *out << "boolean";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800307 }
308
309 if ((typeMask & android::ResTable_map::TYPE_COLOR) != 0) {
310 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800311 set = true;
312 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700313 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800314 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700315 *out << "color";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800316 }
317
318 if ((typeMask & android::ResTable_map::TYPE_FLOAT) != 0) {
319 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800320 set = true;
321 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700322 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800323 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700324 *out << "float";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800325 }
326
327 if ((typeMask & android::ResTable_map::TYPE_DIMENSION) != 0) {
328 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800329 set = true;
330 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700331 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800332 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700333 *out << "dimension";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800334 }
335
336 if ((typeMask & android::ResTable_map::TYPE_FRACTION) != 0) {
337 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800338 set = true;
339 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700340 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800341 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700342 *out << "fraction";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800343 }
344
345 if ((typeMask & android::ResTable_map::TYPE_ENUM) != 0) {
346 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800347 set = true;
348 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700349 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800350 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700351 *out << "enum";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800352 }
353
354 if ((typeMask & android::ResTable_map::TYPE_FLAGS) != 0) {
355 if (!set) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800356 set = true;
357 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700358 *out << "|";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800359 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700360 *out << "flags";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800361 }
Adam Lesinski330edcd2015-05-04 17:40:56 -0700362}
363
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700364void Attribute::print(std::ostream* out) const {
365 *out << "(attr) ";
Adam Lesinski330edcd2015-05-04 17:40:56 -0700366 printMask(out);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800367
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700368 if (!symbols.empty()) {
369 *out << " ["
370 << util::joiner(symbols.begin(), symbols.end(), ", ")
371 << "]";
372 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800373
374 if (weak) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700375 *out << " [weak]";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800376 }
377}
378
Adam Lesinski769de982015-04-10 19:43:55 -0700379Style* Style::clone(StringPool* newPool) const {
Adam Lesinskibdaa0922015-05-08 20:16:23 -0700380 Style* style = new Style();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800381 style->parent = parent;
Adam Lesinskibdaa0922015-05-08 20:16:23 -0700382 style->parentInferred = parentInferred;
Adam Lesinskib274e352015-11-06 15:14:35 -0800383 style->mComment = mComment;
384 style->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800385 for (auto& entry : entries) {
386 style->entries.push_back(Entry{
387 entry.key,
Adam Lesinski769de982015-04-10 19:43:55 -0700388 std::unique_ptr<Item>(entry.value->clone(newPool))
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800389 });
390 }
391 return style;
392}
393
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700394void Style::print(std::ostream* out) const {
395 *out << "(style) ";
396 if (parent && parent.value().name) {
397 *out << parent.value().name.value();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800398 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700399 *out << " ["
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800400 << util::joiner(entries.begin(), entries.end(), ", ")
401 << "]";
402}
403
404static ::std::ostream& operator<<(::std::ostream& out, const Style::Entry& value) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700405 if (value.key.name) {
406 out << value.key.name.value();
407 } else {
408 out << "???";
409 }
410 out << " = ";
411 value.value->print(&out);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800412 return out;
413}
414
Adam Lesinski769de982015-04-10 19:43:55 -0700415Array* Array::clone(StringPool* newPool) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800416 Array* array = new Array();
Adam Lesinskib274e352015-11-06 15:14:35 -0800417 array->mComment = mComment;
418 array->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800419 for (auto& item : items) {
Adam Lesinski769de982015-04-10 19:43:55 -0700420 array->items.emplace_back(std::unique_ptr<Item>(item->clone(newPool)));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800421 }
422 return array;
423}
424
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700425void Array::print(std::ostream* out) const {
426 *out << "(array) ["
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800427 << util::joiner(items.begin(), items.end(), ", ")
428 << "]";
429}
430
Adam Lesinski769de982015-04-10 19:43:55 -0700431Plural* Plural::clone(StringPool* newPool) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800432 Plural* p = new Plural();
Adam Lesinskib274e352015-11-06 15:14:35 -0800433 p->mComment = mComment;
434 p->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800435 const size_t count = values.size();
436 for (size_t i = 0; i < count; i++) {
437 if (values[i]) {
Adam Lesinski769de982015-04-10 19:43:55 -0700438 p->values[i] = std::unique_ptr<Item>(values[i]->clone(newPool));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800439 }
440 }
441 return p;
442}
443
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700444void Plural::print(std::ostream* out) const {
445 *out << "(plural)";
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800446}
447
448static ::std::ostream& operator<<(::std::ostream& out, const std::unique_ptr<Item>& item) {
449 return out << *item;
450}
451
Adam Lesinski769de982015-04-10 19:43:55 -0700452Styleable* Styleable::clone(StringPool* /*newPool*/) const {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800453 Styleable* styleable = new Styleable();
Adam Lesinskib274e352015-11-06 15:14:35 -0800454 styleable->mComment = mComment;
455 styleable->mSource = mSource;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800456 std::copy(entries.begin(), entries.end(), std::back_inserter(styleable->entries));
457 return styleable;
458}
459
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700460void Styleable::print(std::ostream* out) const {
461 *out << "(styleable) " << " ["
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800462 << util::joiner(entries.begin(), entries.end(), ", ")
463 << "]";
464}
465
466} // namespace aapt