blob: 6337f8e7f0fd826335977110ff13432b478662e3 [file] [log] [blame]
Jiyong Park3656c3c2018-08-01 20:02:01 +09001/*
Will McVickerd7d18df2019-09-12 13:40:50 -07002 * Copyright (C) 2018, The Android Open Source Project
3 *
Jiyong Park3656c3c2018-08-01 20:02:01 +09004 * 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 "aidl.h"
18#include "aidl_language.h"
19#include "import_resolver.h"
Jeongik Cha047c5ee2019-08-07 23:16:49 +090020#include "logging.h"
Jiyong Park3656c3c2018-08-01 20:02:01 +090021#include "options.h"
Jiyong Park3656c3c2018-08-01 20:02:01 +090022
23#include <map>
24#include <string>
25#include <vector>
26
Jiyong Park0cf03b12020-07-22 19:36:34 +090027#include <android-base/result.h>
Jiyong Parkf7534672019-08-12 22:06:22 +090028#include <android-base/strings.h>
Jooyung Hanb8a97772021-01-19 01:27:38 +090029#include <gtest/gtest.h>
Jiyong Parkf7534672019-08-12 22:06:22 +090030
Jiyong Park3656c3c2018-08-01 20:02:01 +090031namespace android {
32namespace aidl {
33
Jiyong Park0cf03b12020-07-22 19:36:34 +090034using android::base::Error;
35using android::base::Result;
Jooyung Han00073272020-11-27 14:20:20 +090036using android::base::StartsWith;
Jiyong Park3656c3c2018-08-01 20:02:01 +090037using std::map;
38using std::set;
39using std::string;
40using std::vector;
41
Jooyung Hanb8a97772021-01-19 01:27:38 +090042static std::string Dump(const AidlDefinedType& type) {
43 std::string dump;
44 type.Dump(CodeWriter::ForString(&dump).get());
45 return dump;
46}
47
48// Uses each type's Dump() and GTest utility(EqHelper).
49static bool CheckEquality(const AidlDefinedType& older, const AidlDefinedType& newer) {
50 using testing::internal::EqHelper;
51 auto older_file = older.GetLocation().GetFile();
52 auto newer_file = newer.GetLocation().GetFile();
53 auto result = EqHelper::Compare(older_file.data(), newer_file.data(), Dump(older), Dump(newer));
54 if (!result) {
55 AIDL_ERROR(newer) << result.failure_message();
56 }
57 return result;
58}
59
Jooyung Han69ea4ba2020-10-29 15:33:37 +090060static vector<string> get_strict_annotations(const AidlAnnotatable& node) {
Steven Moreland7b6a7d92020-04-20 22:00:33 -070061 // This must be symmetrical (if you can add something, you must be able to
62 // remove it). The reason is that we have no way of knowing which interface a
63 // server serves and which interface a client serves (e.g. a callback
64 // interface). Note that this is being overly lenient. It makes sense for
65 // newer code to start accepting nullable things. However, here, we don't know
66 // if the client of an interface or the server of an interface is newer.
67 //
68 // Here are two examples to demonstrate this:
69 // - a new implementation might change so that it no longer returns null
70 // values (remove @nullable)
71 // - a new implementation might start accepting null values (add @nullable)
72 static const set<AidlAnnotation::Type> kIgnoreAnnotations{
73 AidlAnnotation::Type::NULLABLE,
Jooyung Han69ea4ba2020-10-29 15:33:37 +090074 // @JavaDerive doesn't affect read/write
Jooyung Han90345002020-10-23 15:28:53 +090075 AidlAnnotation::Type::JAVA_DERIVE,
Jeongik Chad0a10272020-08-06 16:33:36 +090076 AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE,
Jooyung Han69ea4ba2020-10-29 15:33:37 +090077 // @Backing for a enum type is checked by the enum checker
78 AidlAnnotation::Type::BACKING,
79 // @RustDerive doesn't affect read/write
80 AidlAnnotation::Type::RUST_DERIVE,
Jooyung Hanf8dbbcc2020-12-26 03:05:55 +090081 AidlAnnotation::Type::SUPPRESS_WARNINGS,
Steven Moreland7b6a7d92020-04-20 22:00:33 -070082 };
Jooyung Han69ea4ba2020-10-29 15:33:37 +090083 vector<string> annotations;
Steven Moreland7b6a7d92020-04-20 22:00:33 -070084 for (const AidlAnnotation& annotation : node.GetAnnotations()) {
Jooyung Han00073272020-11-27 14:20:20 +090085 if (kIgnoreAnnotations.find(annotation.GetType()) != kIgnoreAnnotations.end()) {
86 continue;
Steven Moreland7b6a7d92020-04-20 22:00:33 -070087 }
Jooyung Han00073272020-11-27 14:20:20 +090088 auto annotation_string = annotation.ToString();
89 // adding @Deprecated (with optional args) is okay
90 if (StartsWith(annotation_string, "@JavaPassthrough(annotation=\"@Deprecated")) {
91 continue;
92 }
93 annotations.push_back(annotation_string);
Steven Moreland7b6a7d92020-04-20 22:00:33 -070094 }
95 return annotations;
96}
97
Jiyong Park3656c3c2018-08-01 20:02:01 +090098static bool have_compatible_annotations(const AidlAnnotatable& older,
99 const AidlAnnotatable& newer) {
Jooyung Han69ea4ba2020-10-29 15:33:37 +0900100 vector<string> olderAnnotations = get_strict_annotations(older);
101 vector<string> newerAnnotations = get_strict_annotations(newer);
102 sort(olderAnnotations.begin(), olderAnnotations.end());
103 sort(newerAnnotations.begin(), newerAnnotations.end());
Jeongik Cha3271ffa2018-12-04 15:19:20 +0900104 if (olderAnnotations != newerAnnotations) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900105 const string from = older.ToString().empty() ? "(empty)" : older.ToString();
106 const string to = newer.ToString().empty() ? "(empty)" : newer.ToString();
107 AIDL_ERROR(newer) << "Changed annotations: " << from << " to " << to;
108 return false;
109 }
110 return true;
111}
112
113static bool are_compatible_types(const AidlTypeSpecifier& older, const AidlTypeSpecifier& newer) {
114 bool compatible = true;
Jooyung Han965e31d2020-11-27 12:30:16 +0900115 if (older.Signature() != newer.Signature()) {
116 AIDL_ERROR(newer) << "Type changed: " << older.Signature() << " to " << newer.Signature()
117 << ".";
Jiyong Park3656c3c2018-08-01 20:02:01 +0900118 compatible = false;
119 }
120 compatible &= have_compatible_annotations(older, newer);
121 return compatible;
122}
123
Jooyung Han829ec7c2020-12-02 12:07:36 +0900124static bool are_compatible_constants(const AidlDefinedType& older, const AidlDefinedType& newer) {
Jooyung Han3f347ca2020-12-01 12:41:50 +0900125 bool compatible = true;
126
127 map<string, AidlConstantDeclaration*> new_constdecls;
128 for (const auto& c : newer.GetConstantDeclarations()) {
129 new_constdecls[c->GetName()] = &*c;
130 }
131
132 for (const auto& old_c : older.GetConstantDeclarations()) {
133 const auto found = new_constdecls.find(old_c->GetName());
134 if (found == new_constdecls.end()) {
135 AIDL_ERROR(old_c) << "Removed constant declaration: " << older.GetCanonicalName() << "."
136 << old_c->GetName();
137 compatible = false;
138 continue;
139 }
140
141 const auto new_c = found->second;
142 compatible &= are_compatible_types(old_c->GetType(), new_c->GetType());
143
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900144 const string old_value = old_c->GetValue().Literal();
145 const string new_value = new_c->GetValue().Literal();
Jooyung Han3f347ca2020-12-01 12:41:50 +0900146 if (old_value != new_value) {
147 AIDL_ERROR(newer) << "Changed constant value: " << older.GetCanonicalName() << "."
148 << old_c->GetName() << " from " << old_value << " to " << new_value << ".";
149 compatible = false;
150 }
151 }
152 return compatible;
153}
154
Jiyong Park3656c3c2018-08-01 20:02:01 +0900155static bool are_compatible_interfaces(const AidlInterface& older, const AidlInterface& newer) {
156 bool compatible = true;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900157
158 map<string, AidlMethod*> new_methods;
159 for (const auto& m : newer.AsInterface()->GetMethods()) {
160 new_methods.emplace(m->Signature(), m.get());
161 }
162
163 for (const auto& old_m : older.AsInterface()->GetMethods()) {
164 const auto found = new_methods.find(old_m->Signature());
165 if (found == new_methods.end()) {
Steven Moreland4ee68632018-12-14 15:52:46 -0800166 AIDL_ERROR(old_m) << "Removed or changed method: " << older.GetCanonicalName() << "."
Jiyong Park3656c3c2018-08-01 20:02:01 +0900167 << old_m->Signature();
168 compatible = false;
169 continue;
170 }
171
172 // Compare IDs to detect method reordering. IDs are assigned by their
173 // textual order, so if there is an ID mismatch, that means reordering
174 // has happened.
175 const auto new_m = found->second;
Steven Moreland4ee68632018-12-14 15:52:46 -0800176
177 if (old_m->IsOneway() != new_m->IsOneway()) {
178 AIDL_ERROR(new_m) << "Oneway attribute " << (old_m->IsOneway() ? "removed" : "added") << ": "
179 << older.GetCanonicalName() << "." << old_m->Signature();
180 compatible = false;
181 }
182
Jiyong Park3656c3c2018-08-01 20:02:01 +0900183 if (old_m->GetId() != new_m->GetId()) {
184 AIDL_ERROR(new_m) << "Transaction ID changed: " << older.GetCanonicalName() << "."
185 << old_m->Signature() << " is changed from " << old_m->GetId() << " to "
186 << new_m->GetId() << ".";
187 compatible = false;
188 }
189
190 compatible &= are_compatible_types(old_m->GetType(), new_m->GetType());
191
192 const auto& old_args = old_m->GetArguments();
193 const auto& new_args = new_m->GetArguments();
194 // this is guaranteed because arguments are part of AidlMethod::Signature()
Steven Moreland21780812020-09-11 01:29:45 +0000195 AIDL_FATAL_IF(old_args.size() != new_args.size(), old_m);
Jiyong Park3656c3c2018-08-01 20:02:01 +0900196 for (size_t i = 0; i < old_args.size(); i++) {
197 const AidlArgument& old_a = *(old_args.at(i));
198 const AidlArgument& new_a = *(new_args.at(i));
199 compatible &= are_compatible_types(old_a.GetType(), new_a.GetType());
200
201 if (old_a.GetDirection() != new_a.GetDirection()) {
202 AIDL_ERROR(new_m) << "Direction changed: " << old_a.GetDirectionSpecifier() << " to "
203 << new_a.GetDirectionSpecifier() << ".";
204 compatible = false;
205 }
206 }
207 }
Jiyong Parka428d212018-08-29 22:26:30 +0900208
Jooyung Han3f347ca2020-12-01 12:41:50 +0900209 compatible = are_compatible_constants(older, newer) && compatible;
Jiyong Parka428d212018-08-29 22:26:30 +0900210
Jiyong Park3656c3c2018-08-01 20:02:01 +0900211 return compatible;
212}
213
Jooyung Han636fd2f2020-10-22 11:33:45 +0900214static bool HasZeroEnumerator(const AidlEnumDeclaration& enum_decl) {
215 return std::any_of(enum_decl.GetEnumerators().begin(), enum_decl.GetEnumerators().end(),
216 [&](const unique_ptr<AidlEnumerator>& enumerator) {
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900217 return enumerator->GetValue()->Literal() == "0";
Jooyung Han636fd2f2020-10-22 11:33:45 +0900218 });
219}
220
Jooyung Han829ec7c2020-12-02 12:07:36 +0900221static bool are_compatible_parcelables(const AidlDefinedType& older, const AidlTypenames&,
222 const AidlDefinedType& newer,
Jooyung Han636fd2f2020-10-22 11:33:45 +0900223 const AidlTypenames& new_types) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900224 const auto& old_fields = older.GetFields();
225 const auto& new_fields = newer.GetFields();
226 if (old_fields.size() > new_fields.size()) {
227 // you can add new fields only at the end
228 AIDL_ERROR(newer) << "Number of fields in " << older.GetCanonicalName() << " is reduced from "
229 << old_fields.size() << " to " << new_fields.size() << ".";
230 return false;
231 }
Devin Moorec7e47a32020-08-07 10:55:25 -0700232 if (newer.IsFixedSize() && old_fields.size() != new_fields.size()) {
233 AIDL_ERROR(newer) << "Number of fields in " << older.GetCanonicalName() << " is changed from "
234 << old_fields.size() << " to " << new_fields.size()
235 << ". This is an incompatible change for FixedSize types.";
236 return false;
237 }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900238
239 bool compatible = true;
240 for (size_t i = 0; i < old_fields.size(); i++) {
Jiyong Parka468e2a2018-08-29 21:25:18 +0900241 const auto& old_field = old_fields.at(i);
242 const auto& new_field = new_fields.at(i);
243 compatible &= are_compatible_types(old_field->GetType(), new_field->GetType());
Jiyong Park3656c3c2018-08-01 20:02:01 +0900244
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900245 string old_value = old_field->GetDefaultValue() ? old_field->GetDefaultValue()->Literal() : "";
246 string new_value = new_field->GetDefaultValue() ? new_field->GetDefaultValue()->Literal() : "";
Jiyong Parka468e2a2018-08-29 21:25:18 +0900247 if (old_value != new_value) {
Steven Moreland370ed342020-04-28 18:14:39 -0700248 AIDL_ERROR(new_field) << "Changed default value: " << old_value << " to " << new_value << ".";
249 compatible = false;
250 }
251 }
252
Jiyong Parkb07d9932020-05-15 12:56:54 +0900253 // Reordering of fields is an incompatible change.
254 for (size_t i = 0; i < new_fields.size(); i++) {
255 const auto& new_field = new_fields.at(i);
256 auto found = std::find_if(old_fields.begin(), old_fields.end(), [&new_field](const auto& f) {
257 return new_field->GetName() == f->GetName();
258 });
259 if (found != old_fields.end()) {
260 size_t old_index = std::distance(old_fields.begin(), found);
261 if (old_index != i) {
262 AIDL_ERROR(new_field) << "Reordered " << new_field->GetName() << " from " << old_index
263 << " to " << i << ".";
264 compatible = false;
265 }
266 }
267 }
268
Steven Moreland370ed342020-04-28 18:14:39 -0700269 for (size_t i = old_fields.size(); i < new_fields.size(); i++) {
270 const auto& new_field = new_fields.at(i);
Jooyung Han53fb4242020-12-17 16:03:49 +0900271 if (new_field->HasUsefulDefaultValue()) {
Jooyung Han636fd2f2020-10-22 11:33:45 +0900272 continue;
273 }
274
275 // enum can't be nullable, but it's okay if it has 0 as a valid enumerator.
276 if (const auto& enum_decl = new_types.GetEnumDeclaration(new_field->GetType());
277 enum_decl != nullptr) {
278 if (HasZeroEnumerator(*enum_decl)) {
279 continue;
280 }
281
282 // TODO(b/142893595): Rephrase the message: "provide a default value or make sure ..."
283 AIDL_ERROR(new_field) << "Field '" << new_field->GetName() << "' of enum '"
284 << enum_decl->GetName()
285 << "' can't be initialized as '0'. Please make sure '"
286 << enum_decl->GetName() << "' has '0' as a valid value.";
287 compatible = false;
288 continue;
289 }
290
291 // Old API versions may suffer from the issue presented here. There is
292 // only a finite number in Android, which we must allow indefinitely.
293 struct HistoricalException {
294 std::string canonical;
295 std::string field;
296 };
297 static std::vector<HistoricalException> exceptions = {
298 {"android.net.DhcpResultsParcelable", "serverHostName"},
299 {"android.net.ResolverParamsParcel", "resolverOptions"},
300 };
301 bool excepted = false;
302 for (const HistoricalException& exception : exceptions) {
303 if (older.GetCanonicalName() == exception.canonical &&
304 new_field->GetName() == exception.field) {
305 excepted = true;
306 break;
307 }
308 }
309 if (excepted) continue;
310
311 AIDL_ERROR(new_field)
312 << "Field '" << new_field->GetName()
313 << "' does not have a useful default in some backends. Please either provide a default "
314 "value for this field or mark the field as @nullable. This value or a null value will "
315 "be used automatically when an old version of this parcelable is sent to a process "
316 "which understands a new version of this parcelable. In order to make sure your code "
317 "continues to be backwards compatible, make sure the default or null value does not "
318 "cause a semantic change to this parcelable.";
319 compatible = false;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900320 }
Jooyung Han3f347ca2020-12-01 12:41:50 +0900321
322 compatible = are_compatible_constants(older, newer) && compatible;
323
Jiyong Park3656c3c2018-08-01 20:02:01 +0900324 return compatible;
325}
326
Daniel Norman85aed542019-08-21 12:01:14 -0700327static bool are_compatible_enums(const AidlEnumDeclaration& older,
328 const AidlEnumDeclaration& newer) {
329 if (!are_compatible_types(older.GetBackingType(), newer.GetBackingType())) {
330 AIDL_ERROR(newer) << "Changed backing types.";
331 return false;
332 }
333
334 std::map<std::string, const AidlConstantValue*> old_enum_map;
335 for (const auto& enumerator : older.GetEnumerators()) {
336 old_enum_map[enumerator->GetName()] = enumerator->GetValue();
337 }
338 std::map<std::string, const AidlConstantValue*> new_enum_map;
339 for (const auto& enumerator : newer.GetEnumerators()) {
340 new_enum_map[enumerator->GetName()] = enumerator->GetValue();
341 }
342
343 bool compatible = true;
344 for (const auto& [name, value] : old_enum_map) {
345 if (new_enum_map.find(name) == new_enum_map.end()) {
346 AIDL_ERROR(newer) << "Removed enumerator from " << older.GetCanonicalName() << ": " << name;
347 compatible = false;
348 continue;
349 }
Jooyung Hanfdaae1d2020-12-14 13:16:15 +0900350 const string old_value = old_enum_map[name]->Literal();
351 const string new_value = new_enum_map[name]->Literal();
Daniel Norman85aed542019-08-21 12:01:14 -0700352 if (old_value != new_value) {
353 AIDL_ERROR(newer) << "Changed enumerator value: " << older.GetCanonicalName() << "::" << name
354 << " from " << old_value << " to " << new_value << ".";
355 compatible = false;
356 }
357 }
358 return compatible;
359}
360
Jiyong Park0cf03b12020-07-22 19:36:34 +0900361static Result<AidlTypenames> load_from_dir(const Options& options, const IoDelegate& io_delegate,
362 const std::string& dir) {
363 AidlTypenames typenames;
364 for (const auto& file : io_delegate.ListFiles(dir)) {
365 if (!android::base::EndsWith(file, ".aidl")) continue;
366 if (internals::load_and_validate_aidl(file, options, io_delegate, &typenames,
367 nullptr /* imported_files */) != AidlError::OK) {
368 AIDL_ERROR(file) << "Failed to read.";
369 return Error();
370 }
371 }
372 return typenames;
373}
374
Jiyong Park3656c3c2018-08-01 20:02:01 +0900375bool check_api(const Options& options, const IoDelegate& io_delegate) {
Steven Moreland21780812020-09-11 01:29:45 +0000376 AIDL_FATAL_IF(!options.IsStructured(), AIDL_LOCATION_HERE);
377 AIDL_FATAL_IF(options.InputFiles().size() != 2, AIDL_LOCATION_HERE)
378 << "--checkapi requires two inputs "
379 << "but got " << options.InputFiles().size();
Jiyong Park0cf03b12020-07-22 19:36:34 +0900380 auto old_tns = load_from_dir(options, io_delegate, options.InputFiles().at(0));
381 if (!old_tns.ok()) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900382 return false;
383 }
Jiyong Park0cf03b12020-07-22 19:36:34 +0900384 auto new_tns = load_from_dir(options, io_delegate, options.InputFiles().at(1));
385 if (!new_tns.ok()) {
Jiyong Park3656c3c2018-08-01 20:02:01 +0900386 return false;
387 }
Jiyong Parkf7534672019-08-12 22:06:22 +0900388
Jooyung Hanb8a97772021-01-19 01:27:38 +0900389 const Options::CheckApiLevel level = options.GetCheckApiLevel();
390
Jiyong Park0cf03b12020-07-22 19:36:34 +0900391 std::vector<AidlDefinedType*> old_types = old_tns->AllDefinedTypes();
392 std::vector<AidlDefinedType*> new_types = new_tns->AllDefinedTypes();
Jiyong Park3656c3c2018-08-01 20:02:01 +0900393
Jooyung Hanb8a97772021-01-19 01:27:38 +0900394 bool compatible = true;
395
396 if (level == Options::CheckApiLevel::EQUAL) {
397 std::set<string> old_type_names;
398 for (const auto t : old_types) {
399 old_type_names.insert(t->GetCanonicalName());
400 }
401 for (const auto new_type : new_types) {
402 const auto found = old_type_names.find(new_type->GetCanonicalName());
403 if (found == old_type_names.end()) {
404 AIDL_ERROR(new_type) << "Added type: " << new_type->GetCanonicalName();
405 compatible = false;
406 continue;
407 }
408 }
409 }
410
Jiyong Park3656c3c2018-08-01 20:02:01 +0900411 map<string, AidlDefinedType*> new_map;
412 for (const auto t : new_types) {
413 new_map.emplace(t->GetCanonicalName(), t);
414 }
415
Jiyong Park3656c3c2018-08-01 20:02:01 +0900416 for (const auto old_type : old_types) {
417 const auto found = new_map.find(old_type->GetCanonicalName());
418 if (found == new_map.end()) {
419 AIDL_ERROR(old_type) << "Removed type: " << old_type->GetCanonicalName();
420 compatible = false;
421 continue;
422 }
423 const auto new_type = found->second;
424
Jooyung Hanb8a97772021-01-19 01:27:38 +0900425 if (level == Options::CheckApiLevel::EQUAL) {
426 if (!CheckEquality(*old_type, *new_type)) {
427 compatible = false;
428 }
429 continue;
430 }
431
Devin Mooredb7ac512020-08-07 11:17:36 -0700432 if (!have_compatible_annotations(*old_type, *new_type)) {
433 compatible = false;
434 }
Daniel Norman85aed542019-08-21 12:01:14 -0700435 if (old_type->AsInterface() != nullptr) {
436 if (new_type->AsInterface() == nullptr) {
437 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
438 << " is changed from " << old_type->GetPreprocessDeclarationName()
439 << " to " << new_type->GetPreprocessDeclarationName();
440 compatible = false;
441 continue;
442 }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900443 compatible &=
444 are_compatible_interfaces(*(old_type->AsInterface()), *(new_type->AsInterface()));
Daniel Norman85aed542019-08-21 12:01:14 -0700445 } else if (old_type->AsStructuredParcelable() != nullptr) {
446 if (new_type->AsStructuredParcelable() == nullptr) {
447 AIDL_ERROR(new_type) << "Parcelable" << new_type->GetCanonicalName()
448 << " is not structured. ";
449 compatible = false;
450 continue;
451 }
Jooyung Han636fd2f2020-10-22 11:33:45 +0900452 compatible &= are_compatible_parcelables(*(old_type->AsStructuredParcelable()), *old_tns,
453 *(new_type->AsStructuredParcelable()), *new_tns);
Jooyung Han2946afc2020-10-05 20:29:16 +0900454 } else if (old_type->AsUnionDeclaration() != nullptr) {
455 if (new_type->AsUnionDeclaration() == nullptr) {
456 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
457 << " is changed from " << old_type->GetPreprocessDeclarationName()
458 << " to " << new_type->GetPreprocessDeclarationName();
459 compatible = false;
460 continue;
461 }
Jooyung Han636fd2f2020-10-22 11:33:45 +0900462 compatible &= are_compatible_parcelables(*(old_type->AsUnionDeclaration()), *old_tns,
463 *(new_type->AsUnionDeclaration()), *new_tns);
Daniel Norman85aed542019-08-21 12:01:14 -0700464 } else if (old_type->AsEnumDeclaration() != nullptr) {
465 if (new_type->AsEnumDeclaration() == nullptr) {
466 AIDL_ERROR(new_type) << "Type mismatch: " << old_type->GetCanonicalName()
467 << " is changed from " << old_type->GetPreprocessDeclarationName()
468 << " to " << new_type->GetPreprocessDeclarationName();
469 compatible = false;
470 continue;
471 }
472 compatible &=
473 are_compatible_enums(*(old_type->AsEnumDeclaration()), *(new_type->AsEnumDeclaration()));
474 } else {
475 AIDL_ERROR(old_type) << "Unsupported type " << old_type->GetPreprocessDeclarationName()
476 << " for " << old_type->GetCanonicalName();
477 compatible = false;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900478 }
479 }
480
481 return compatible;
482}
483
484} // namespace aidl
485} // namespace android