Christopher Wiley | 89eaab5 | 2015-09-15 14:46:46 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 16 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 17 | #include "aidl.h" |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 18 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 23 | #include <sys/param.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <unistd.h> |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 26 | #include <algorithm> |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 27 | #include <iostream> |
| 28 | #include <map> |
| 29 | #include <memory> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | 549b6e2 | 2015-08-17 12:41:46 -0700 | [diff] [blame] | 31 | #ifdef _WIN32 |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 32 | #include <io.h> |
Andrew Hsieh | 15ce994 | 2014-05-07 20:14:30 +0800 | [diff] [blame] | 33 | #include <direct.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 34 | #include <sys/stat.h> |
| 35 | #endif |
| 36 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 37 | #include <android-base/strings.h> |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 38 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 39 | #include "aidl_language.h" |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 40 | #include "aidl_typenames.h" |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 41 | #include "generate_aidl_mappings.h" |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 42 | #include "generate_cpp.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 43 | #include "generate_java.h" |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 44 | #include "generate_ndk.h" |
Christopher Wiley | 72877ac | 2015-10-06 14:41:42 -0700 | [diff] [blame] | 45 | #include "import_resolver.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 46 | #include "logging.h" |
| 47 | #include "options.h" |
| 48 | #include "os.h" |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 49 | #include "type_cpp.h" |
Christopher Wiley | 775fa1f | 2015-09-22 15:00:12 -0700 | [diff] [blame] | 50 | #include "type_java.h" |
Christopher Wiley | 84c1eac | 2015-09-23 13:29:28 -0700 | [diff] [blame] | 51 | #include "type_namespace.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 52 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 53 | #ifndef O_BINARY |
| 54 | # define O_BINARY 0 |
| 55 | #endif |
| 56 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 57 | using android::base::Join; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 58 | using android::base::Split; |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 59 | using std::cerr; |
| 60 | using std::endl; |
Christopher Wiley | 9f4c7ae | 2015-08-24 14:07:32 -0700 | [diff] [blame] | 61 | using std::set; |
| 62 | using std::string; |
Christopher Wiley | 84c1eac | 2015-09-23 13:29:28 -0700 | [diff] [blame] | 63 | using std::unique_ptr; |
Christopher Wiley | 9f4c7ae | 2015-08-24 14:07:32 -0700 | [diff] [blame] | 64 | using std::vector; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 65 | |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 66 | namespace android { |
| 67 | namespace aidl { |
| 68 | namespace { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 69 | |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 70 | // Copied from android.is.IBinder.[FIRST|LAST]_CALL_TRANSACTION |
| 71 | const int kFirstCallTransaction = 1; |
| 72 | const int kLastCallTransaction = 0x00ffffff; |
| 73 | |
| 74 | // Following IDs are all offsets from kFirstCallTransaction |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 75 | |
| 76 | // IDs for meta transactions. Most of the meta transactions are implemented in |
| 77 | // the framework side (Binder.java or Binder.cpp). But these are the ones that |
| 78 | // are auto-implemented by the AIDL compiler. |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 79 | const int kFirstMetaMethodId = kLastCallTransaction - kFirstCallTransaction; |
| 80 | const int kGetInterfaceVersionId = kFirstMetaMethodId; |
| 81 | // Additional meta transactions implemented by AIDL should use |
| 82 | // kFirstMetaMethodId -1, -2, ...and so on. |
| 83 | |
| 84 | // Reserve 100 IDs for meta methods, which is more than enough. If we don't reserve, |
| 85 | // in the future, a newly added meta transaction ID will have a chance to |
| 86 | // collide with the user-defined methods that were added in the past. So, |
| 87 | // let's prevent users from using IDs in this range from the beginning. |
| 88 | const int kLastMetaMethodId = kFirstMetaMethodId - 99; |
| 89 | |
| 90 | // Range of IDs that is allowed for user-defined methods. |
| 91 | const int kMinUserSetMethodId = 0; |
| 92 | const int kMaxUserSetMethodId = kLastMetaMethodId - 1; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 93 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 94 | bool check_filename(const std::string& filename, const AidlDefinedType& defined_type) { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 95 | const char* p; |
| 96 | string expected; |
| 97 | string fn; |
| 98 | size_t len; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 99 | bool valid = false; |
| 100 | |
Christopher Wiley | bc2df69 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 101 | if (!IoDelegate::GetAbsolutePath(filename, &fn)) { |
| 102 | return false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 105 | const std::string package = defined_type.GetPackage(); |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 106 | if (!package.empty()) { |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 107 | expected = package; |
| 108 | expected += '.'; |
| 109 | } |
| 110 | |
| 111 | len = expected.length(); |
| 112 | for (size_t i=0; i<len; i++) { |
| 113 | if (expected[i] == '.') { |
| 114 | expected[i] = OS_PATH_SEPARATOR; |
| 115 | } |
| 116 | } |
| 117 | |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 118 | const std::string name = defined_type.GetName(); |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 119 | expected.append(name, 0, name.find('.')); |
Christopher Wiley | 8f8cc9b | 2015-09-14 13:47:40 -0700 | [diff] [blame] | 120 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 121 | expected += ".aidl"; |
| 122 | |
| 123 | len = fn.length(); |
| 124 | valid = (len >= expected.length()); |
| 125 | |
| 126 | if (valid) { |
| 127 | p = fn.c_str() + (len - expected.length()); |
| 128 | |
Elliott Hughes | ce310da | 2015-07-29 08:44:17 -0700 | [diff] [blame] | 129 | #ifdef _WIN32 |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 130 | if (OS_PATH_SEPARATOR != '/') { |
| 131 | // Input filename under cygwin most likely has / separators |
| 132 | // whereas the expected string uses \\ separators. Adjust |
| 133 | // them accordingly. |
| 134 | for (char *c = const_cast<char *>(p); *c; ++c) { |
| 135 | if (*c == '/') *c = OS_PATH_SEPARATOR; |
| 136 | } |
| 137 | } |
| 138 | #endif |
| 139 | |
Yabin Cui | 482eefb | 2014-11-10 15:01:43 -0800 | [diff] [blame] | 140 | // aidl assumes case-insensitivity on Mac Os and Windows. |
| 141 | #if defined(__linux__) |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 142 | valid = (expected == p); |
| 143 | #else |
| 144 | valid = !strcasecmp(expected.c_str(), p); |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | if (!valid) { |
Steven Moreland | 92c55f1 | 2018-07-31 14:08:37 -0700 | [diff] [blame] | 149 | AIDL_ERROR(defined_type) << name << " should be declared in a file called " << expected; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Casey Dahlin | 42727f8 | 2015-10-12 19:23:40 -0700 | [diff] [blame] | 152 | return valid; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 155 | bool register_types(const AidlStructuredParcelable* parcel, TypeNamespace* types) { |
Jeongik Cha | 17f7fd4 | 2018-10-31 11:27:59 +0900 | [diff] [blame] | 156 | for (const auto& v : parcel->GetFields()) { |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 157 | if (!types->MaybeAddContainerType(v->GetType())) { |
| 158 | return false; |
| 159 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 160 | |
| 161 | const ValidatableType* type = types->GetReturnType(v->GetType(), *parcel); |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 162 | if (type == nullptr) { |
| 163 | return false; |
| 164 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 165 | v->GetMutableType()->SetLanguageType(type); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 166 | } |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 167 | return true; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 170 | bool register_types(const AidlInterface* c, TypeNamespace* types) { |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 171 | for (const auto& m : c->GetMethods()) { |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 172 | if (!types->MaybeAddContainerType(m->GetType())) { |
| 173 | return false; |
| 174 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 175 | |
| 176 | const ValidatableType* return_type = types->GetReturnType(m->GetType(), *c); |
| 177 | |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 178 | if (return_type == nullptr) { |
| 179 | return false; |
| 180 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 181 | m->GetMutableType()->SetLanguageType(return_type); |
| 182 | |
Steven Moreland | b3cd3c7 | 2018-10-11 12:37:45 -0700 | [diff] [blame] | 183 | set<string> argument_names; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 184 | |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 185 | int index = 1; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 186 | for (const auto& arg : m->GetArguments()) { |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 187 | if (!types->MaybeAddContainerType(arg->GetType())) { |
| 188 | return false; |
| 189 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 190 | |
| 191 | const ValidatableType* arg_type = types->GetArgType(*arg, index, *c); |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 192 | if (arg_type == nullptr) { |
| 193 | return false; |
| 194 | } |
Jeongik Cha | e51a5ea | 2018-11-01 06:36:09 +0000 | [diff] [blame] | 195 | arg->GetMutableType()->SetLanguageType(arg_type); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 196 | } |
Christopher Wiley | fb4b22d | 2015-09-25 15:16:13 -0700 | [diff] [blame] | 197 | } |
Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 198 | |
| 199 | for (const std::unique_ptr<AidlConstantDeclaration>& constant : c->GetConstantDeclarations()) { |
| 200 | AidlTypeSpecifier* specifier = constant->GetMutableType(); |
| 201 | const ValidatableType* return_type = types->GetReturnType(*specifier, *c); |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 202 | if (return_type == nullptr) { |
| 203 | return false; |
| 204 | } |
Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 205 | specifier->SetLanguageType(return_type); |
| 206 | } |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 207 | |
| 208 | return true; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 211 | bool write_dep_file(const Options& options, const AidlDefinedType& defined_type, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 212 | const vector<string>& imports, const IoDelegate& io_delegate, |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 213 | const string& input_file, const string& output_file) { |
| 214 | string dep_file_name = options.DependencyFile(); |
| 215 | if (dep_file_name.empty() && options.AutoDepFile()) { |
| 216 | dep_file_name = output_file + ".d"; |
| 217 | } |
| 218 | |
| 219 | if (dep_file_name.empty()) { |
| 220 | return true; // nothing to do |
| 221 | } |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 222 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 223 | CodeWriterPtr writer = io_delegate.GetCodeWriter(dep_file_name); |
| 224 | if (!writer) { |
| 225 | LOG(ERROR) << "Could not open dependency file: " << dep_file_name; |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | vector<string> source_aidl = {input_file}; |
| 230 | for (const auto& import : imports) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 231 | source_aidl.push_back(import); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 234 | // Encode that the output file depends on aidl input files. |
| 235 | writer->Write("%s : \\\n", output_file.c_str()); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 236 | writer->Write(" %s", Join(source_aidl, " \\\n ").c_str()); |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 237 | writer->Write("\n"); |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 238 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 239 | if (!options.DependencyFileNinja()) { |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 240 | writer->Write("\n"); |
| 241 | // Output "<input_aidl_file>: " so make won't fail if the input .aidl file |
| 242 | // has been deleted, moved or renamed in incremental build. |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 243 | for (const auto& src : source_aidl) { |
Dan Willemsen | 93298ee | 2016-11-10 23:55:55 -0800 | [diff] [blame] | 244 | writer->Write("%s :\n", src.c_str()); |
| 245 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 246 | } |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 247 | |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 248 | if (options.IsCppOutput()) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 249 | if (!options.DependencyFileNinja()) { |
| 250 | using ::android::aidl::cpp::ClassNames; |
| 251 | using ::android::aidl::cpp::HeaderFile; |
| 252 | vector<string> headers; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 253 | for (ClassNames c : {ClassNames::CLIENT, ClassNames::SERVER, ClassNames::RAW}) { |
Jiyong Park | 0546373 | 2018-08-09 16:03:02 +0900 | [diff] [blame] | 254 | headers.push_back(options.OutputHeaderDir() + |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 255 | HeaderFile(defined_type, c, false /* use_os_sep */)); |
| 256 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 257 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 258 | writer->Write("\n"); |
| 259 | |
| 260 | // Generated headers also depend on the source aidl files. |
| 261 | writer->Write("%s : \\\n %s\n", Join(headers, " \\\n ").c_str(), |
| 262 | Join(source_aidl, " \\\n ").c_str()); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 263 | } |
Christopher Wiley | a30a45e | 2015-10-17 10:56:59 -0700 | [diff] [blame] | 264 | } |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 265 | |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 266 | return true; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 269 | string generate_outputFileName(const Options& options, const AidlDefinedType& defined_type) { |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 270 | // create the path to the destination folder based on the |
| 271 | // defined_type package name |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 272 | string result = options.OutputDir(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 273 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 274 | string package = defined_type.GetPackage(); |
| 275 | size_t len = package.length(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 276 | for (size_t i = 0; i < len; i++) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 277 | if (package[i] == '.') { |
| 278 | package[i] = OS_PATH_SEPARATOR; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 279 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 280 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 281 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 282 | result += package; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 283 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 284 | // add the filename by replacing the .aidl extension to .java |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 285 | const string& name = defined_type.GetName(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 286 | result += OS_PATH_SEPARATOR; |
| 287 | result.append(name, 0, name.find('.')); |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 288 | if (options.TargetLanguage() == Options::Language::JAVA) { |
| 289 | result += ".java"; |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 290 | } else if (options.IsCppOutput()) { |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 291 | result += ".cpp"; |
| 292 | } else { |
| 293 | LOG(FATAL) << "Should not reach here" << endl; |
| 294 | return ""; |
| 295 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 296 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 297 | return result; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 300 | bool check_and_assign_method_ids(const std::vector<std::unique_ptr<AidlMethod>>& items) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 301 | // Check whether there are any methods with manually assigned id's and any |
| 302 | // that are not. Either all method id's must be manually assigned or all of |
| 303 | // them must not. Also, check for uplicates of user set ID's and that the |
| 304 | // ID's are within the proper bounds. |
| 305 | set<int> usedIds; |
| 306 | bool hasUnassignedIds = false; |
| 307 | bool hasAssignedIds = false; |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame^] | 308 | int newId = kMinUserSetMethodId; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 309 | for (const auto& item : items) { |
| 310 | // However, meta transactions that are added by the AIDL compiler are |
| 311 | // exceptions. They have fixed IDs but allowed to be with user-defined |
| 312 | // methods having auto-assigned IDs. This is because the Ids of the meta |
| 313 | // transactions must be stable during the entire lifetime of an interface. |
| 314 | // In other words, their IDs must be the same even when new user-defined |
| 315 | // methods are added. |
Jiyong Park | 3633b72 | 2019-04-11 15:38:26 +0900 | [diff] [blame] | 316 | if (!item->IsUserDefined()) { |
| 317 | continue; |
| 318 | } |
| 319 | if (item->HasId()) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 320 | hasAssignedIds = true; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 321 | } else { |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame^] | 322 | item->SetId(newId++); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 323 | hasUnassignedIds = true; |
| 324 | } |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame^] | 325 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 326 | if (hasAssignedIds && hasUnassignedIds) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 327 | AIDL_ERROR(item) << "You must either assign id's to all methods or to none of them."; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 328 | return false; |
| 329 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 330 | |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame^] | 331 | // Ensure that the user set id is not duplicated. |
| 332 | if (usedIds.find(item->GetId()) != usedIds.end()) { |
| 333 | // We found a duplicate id, so throw an error. |
| 334 | AIDL_ERROR(item) << "Found duplicate method id (" << item->GetId() << ") for method " |
| 335 | << item->GetName(); |
| 336 | return false; |
| 337 | } |
| 338 | usedIds.insert(item->GetId()); |
| 339 | |
| 340 | // Ensure that the user set id is within the appropriate limits |
| 341 | if (item->GetId() < kMinUserSetMethodId || item->GetId() > kMaxUserSetMethodId) { |
| 342 | AIDL_ERROR(item) << "Found out of bounds id (" << item->GetId() << ") for method " |
| 343 | << item->GetName() << ". Value for id must be between " |
| 344 | << kMinUserSetMethodId << " and " << kMaxUserSetMethodId << " inclusive."; |
| 345 | return false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 346 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 347 | } |
Steven Moreland | ec6f469 | 2019-08-13 10:03:24 -0700 | [diff] [blame^] | 348 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 349 | return true; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 352 | // TODO: Remove this in favor of using the YACC parser b/25479378 |
| 353 | bool ParsePreprocessedLine(const string& line, string* decl, |
| 354 | vector<string>* package, string* class_name) { |
| 355 | // erase all trailing whitespace and semicolons |
| 356 | const size_t end = line.find_last_not_of(" ;\t"); |
| 357 | if (end == string::npos) { |
| 358 | return false; |
| 359 | } |
| 360 | if (line.rfind(';', end) != string::npos) { |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | decl->clear(); |
| 365 | string type; |
| 366 | vector<string> pieces = Split(line.substr(0, end + 1), " \t"); |
| 367 | for (const string& piece : pieces) { |
| 368 | if (piece.empty()) { |
| 369 | continue; |
| 370 | } |
| 371 | if (decl->empty()) { |
| 372 | *decl = std::move(piece); |
| 373 | } else if (type.empty()) { |
| 374 | type = std::move(piece); |
| 375 | } else { |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | // Note that this logic is absolutely wrong. Given a parcelable |
| 381 | // org.some.Foo.Bar, the class name is Foo.Bar, but this code will claim that |
| 382 | // the class is just Bar. However, this was the way it was done in the past. |
| 383 | // |
| 384 | // See b/17415692 |
| 385 | size_t dot_pos = type.rfind('.'); |
| 386 | if (dot_pos != string::npos) { |
| 387 | *class_name = type.substr(dot_pos + 1); |
| 388 | *package = Split(type.substr(0, dot_pos), "."); |
| 389 | } else { |
| 390 | *class_name = type; |
| 391 | package->clear(); |
| 392 | } |
| 393 | |
| 394 | return true; |
| 395 | } |
| 396 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 397 | } // namespace |
| 398 | |
| 399 | namespace internals { |
| 400 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 401 | bool parse_preprocessed_file(const IoDelegate& io_delegate, const string& filename, |
| 402 | TypeNamespace* types, AidlTypenames& typenames) { |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 403 | bool success = true; |
| 404 | unique_ptr<LineReader> line_reader = io_delegate.GetLineReader(filename); |
| 405 | if (!line_reader) { |
| 406 | LOG(ERROR) << "cannot open preprocessed file: " << filename; |
| 407 | success = false; |
| 408 | return success; |
| 409 | } |
| 410 | |
| 411 | string line; |
| 412 | unsigned lineno = 1; |
| 413 | for ( ; line_reader->ReadLine(&line); ++lineno) { |
| 414 | if (line.empty() || line.compare(0, 2, "//") == 0) { |
| 415 | // skip comments and empty lines |
| 416 | continue; |
| 417 | } |
| 418 | |
| 419 | string decl; |
| 420 | vector<string> package; |
| 421 | string class_name; |
| 422 | if (!ParsePreprocessedLine(line, &decl, &package, &class_name)) { |
| 423 | success = false; |
| 424 | break; |
| 425 | } |
| 426 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 427 | AidlLocation::Point point = {.line = lineno, .column = 0 /*column*/}; |
| 428 | AidlLocation location = AidlLocation(filename, point, point); |
| 429 | |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 430 | if (decl == "parcelable") { |
Jeongik Cha | ce58bc6 | 2019-04-22 13:30:39 +0900 | [diff] [blame] | 431 | // ParcelFileDescriptor is treated as a built-in type, but it's also in the framework.aidl. |
| 432 | // So aidl should ignore built-in types in framework.aidl to prevent duplication. |
| 433 | // (b/130899491) |
| 434 | if (AidlTypenames::IsBuiltinTypename(class_name)) { |
| 435 | continue; |
| 436 | } |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 437 | AidlParcelable* doc = new AidlParcelable( |
| 438 | location, new AidlQualifiedName(location, class_name, ""), package, "" /* comments */); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 439 | types->AddParcelableType(*doc, filename); |
| 440 | typenames.AddPreprocessedType(unique_ptr<AidlParcelable>(doc)); |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 441 | } else if (decl == "structured_parcelable") { |
| 442 | auto temp = new std::vector<std::unique_ptr<AidlVariableDeclaration>>(); |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 443 | AidlStructuredParcelable* doc = |
| 444 | new AidlStructuredParcelable(location, new AidlQualifiedName(location, class_name, ""), |
| 445 | package, "" /* comments */, temp); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 446 | types->AddParcelableType(*doc, filename); |
| 447 | typenames.AddPreprocessedType(unique_ptr<AidlStructuredParcelable>(doc)); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 448 | } else if (decl == "interface") { |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 449 | auto temp = new std::vector<std::unique_ptr<AidlMember>>(); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 450 | AidlInterface* doc = new AidlInterface(location, class_name, "", false, temp, package); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 451 | types->AddBinderType(*doc, filename); |
| 452 | typenames.AddPreprocessedType(unique_ptr<AidlInterface>(doc)); |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 453 | } else { |
| 454 | success = false; |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | if (!success) { |
| 459 | LOG(ERROR) << filename << ':' << lineno |
| 460 | << " malformed preprocessed file line: '" << line << "'"; |
| 461 | } |
| 462 | |
| 463 | return success; |
| 464 | } |
| 465 | |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 466 | AidlError load_and_validate_aidl(const std::string& input_file_name, const Options& options, |
| 467 | const IoDelegate& io_delegate, TypeNamespace* types, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 468 | vector<AidlDefinedType*>* defined_types, |
| 469 | vector<string>* imported_files) { |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 470 | AidlError err = AidlError::OK; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 471 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 472 | ////////////////////////////////////////////////////////////////////////// |
| 473 | // Loading phase |
| 474 | ////////////////////////////////////////////////////////////////////////// |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 475 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 476 | // Parse the main input file |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 477 | std::unique_ptr<Parser> main_parser = |
| 478 | Parser::Parse(input_file_name, io_delegate, types->typenames_); |
| 479 | if (main_parser == nullptr) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 480 | return AidlError::PARSE_ERROR; |
| 481 | } |
Jeongik Cha | 0e42601 | 2019-07-29 15:57:02 +0900 | [diff] [blame] | 482 | if (main_parser->GetDefinedTypes().size() != 1) { |
| 483 | AIDL_ERROR(input_file_name) << "You must declare only one type per a file."; |
| 484 | return AidlError::BAD_TYPE; |
| 485 | } |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 486 | if (!types->AddDefinedTypes(main_parser->GetDefinedTypes(), input_file_name)) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 487 | return AidlError::BAD_TYPE; |
| 488 | } |
| 489 | |
| 490 | // Import the preprocessed file |
Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 491 | for (const string& s : options.PreprocessedFiles()) { |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 492 | if (!parse_preprocessed_file(io_delegate, s, types, types->typenames_)) { |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 493 | err = AidlError::BAD_PRE_PROCESSED_FILE; |
Christopher Wiley | ef14093 | 2015-11-03 09:29:19 -0800 | [diff] [blame] | 494 | } |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 495 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 496 | if (err != AidlError::OK) { |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 497 | return err; |
| 498 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 499 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 500 | // Find files to import and parse them |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 501 | vector<string> import_paths; |
Jiyong Park | 8c38053 | 2018-08-30 14:55:26 +0900 | [diff] [blame] | 502 | ImportResolver import_resolver{io_delegate, input_file_name, options.ImportDirs(), |
| 503 | options.InputFiles()}; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 504 | |
| 505 | set<string> type_from_import_statements; |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 506 | for (const auto& import : main_parser->GetImports()) { |
Jiyong Park | e05195e | 2018-10-08 18:24:23 +0900 | [diff] [blame] | 507 | if (!AidlTypenames::IsBuiltinTypename(import->GetNeededClass())) { |
| 508 | type_from_import_statements.emplace(import->GetNeededClass()); |
| 509 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | // When referencing a type using fully qualified name it should be imported |
| 513 | // without the import statement. To support that, add all unresolved |
| 514 | // typespecs encountered during the parsing to the import_candidates list. |
| 515 | // Note that there is no guarantee that the typespecs are all fully qualified. |
| 516 | // It will be determined by calling FindImportFile(). |
| 517 | set<string> unresolved_types; |
| 518 | for (const auto type : main_parser->GetUnresolvedTypespecs()) { |
| 519 | if (!AidlTypenames::IsBuiltinTypename(type->GetName())) { |
| 520 | unresolved_types.emplace(type->GetName()); |
| 521 | } |
| 522 | } |
| 523 | set<string> import_candidates(type_from_import_statements); |
| 524 | import_candidates.insert(unresolved_types.begin(), unresolved_types.end()); |
| 525 | for (const auto& import : import_candidates) { |
| 526 | if (types->HasImportType(import)) { |
Christopher Wiley | fb4b22d | 2015-09-25 15:16:13 -0700 | [diff] [blame] | 527 | // There are places in the Android tree where an import doesn't resolve, |
| 528 | // but we'll pick the type up through the preprocessed types. |
| 529 | // This seems like an error, but legacy support demands we support it... |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 530 | continue; |
| 531 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 532 | string import_path = import_resolver.FindImportFile(import); |
Christopher Wiley | 72877ac | 2015-10-06 14:41:42 -0700 | [diff] [blame] | 533 | if (import_path.empty()) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 534 | if (type_from_import_statements.find(import) != type_from_import_statements.end()) { |
| 535 | // Complain only when the import from the import statement has failed. |
| 536 | AIDL_ERROR(import) << "couldn't find import for class " << import; |
| 537 | err = AidlError::BAD_IMPORT; |
| 538 | } |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 539 | continue; |
| 540 | } |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 541 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 542 | import_paths.emplace_back(import_path); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 543 | |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 544 | std::unique_ptr<Parser> import_parser = |
| 545 | Parser::Parse(import_path, io_delegate, types->typenames_); |
| 546 | if (import_parser == nullptr) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 547 | cerr << "error while importing " << import_path << " for " << import << endl; |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 548 | err = AidlError::BAD_IMPORT; |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 549 | continue; |
| 550 | } |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 551 | if (!types->AddDefinedTypes(import_parser->GetDefinedTypes(), import_path)) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 552 | return AidlError::BAD_TYPE; |
| 553 | } |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 554 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 555 | if (err != AidlError::OK) { |
Christopher Wiley | c16e5e7 | 2015-09-16 10:49:40 -0700 | [diff] [blame] | 556 | return err; |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 557 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 558 | |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 559 | for (const auto& imported_file : options.ImportFiles()) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 560 | import_paths.emplace_back(imported_file); |
Jiyong Park | 3c35e39 | 2018-08-30 13:10:30 +0900 | [diff] [blame] | 561 | |
| 562 | std::unique_ptr<Parser> import_parser = |
| 563 | Parser::Parse(imported_file, io_delegate, types->typenames_); |
| 564 | if (import_parser == nullptr) { |
| 565 | AIDL_ERROR(imported_file) << "error while importing " << imported_file; |
| 566 | err = AidlError::BAD_IMPORT; |
| 567 | continue; |
| 568 | } |
| 569 | if (!types->AddDefinedTypes(import_parser->GetDefinedTypes(), imported_file)) { |
| 570 | return AidlError::BAD_TYPE; |
| 571 | } |
| 572 | } |
| 573 | if (err != AidlError::OK) { |
| 574 | return err; |
| 575 | } |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 576 | const bool is_check_api = options.GetTask() == Options::Task::CHECK_API; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 577 | |
| 578 | // Resolve the unresolved type references found from the input file |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 579 | if (!is_check_api && !main_parser->Resolve()) { |
| 580 | // Resolution is not need for check api because all typespecs are |
| 581 | // using fully qualified names. |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 582 | return AidlError::BAD_TYPE; |
| 583 | } |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 584 | if (!is_check_api) { |
| 585 | for (const auto defined_type : main_parser->GetDefinedTypes()) { |
| 586 | AidlInterface* interface = defined_type->AsInterface(); |
| 587 | AidlStructuredParcelable* parcelable = defined_type->AsStructuredParcelable(); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 588 | |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 589 | // Link the AIDL type with the type of the target language. This will |
| 590 | // be removed when the migration to AidlTypenames is done. |
| 591 | defined_type->SetLanguageType(types->GetDefinedType(*defined_type)); |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 592 | |
Jeongik Cha | 3717958 | 2018-11-13 14:30:52 +0900 | [diff] [blame] | 593 | if (interface != nullptr) { |
| 594 | if (!register_types(interface, types)) { |
| 595 | return AidlError::BAD_TYPE; |
| 596 | } |
| 597 | } |
| 598 | if (parcelable != nullptr) { |
| 599 | if (!register_types(parcelable, types)) { |
| 600 | return AidlError::BAD_TYPE; |
| 601 | } |
| 602 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | ////////////////////////////////////////////////////////////////////////// |
| 607 | // Validation phase |
| 608 | ////////////////////////////////////////////////////////////////////////// |
| 609 | |
| 610 | AidlTypenames& typenames = types->typenames_; |
| 611 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 612 | // For legacy reasons, by default, compiling an unstructured parcelable (which contains no output) |
| 613 | // is allowed. This must not be returned as an error until the very end of this procedure since |
| 614 | // this may be considered a success, and we should first check that there are not other, more |
| 615 | // serious failures. |
| 616 | bool contains_unstructured_parcelable = false; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 617 | |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 618 | const int num_defined_types = main_parser->GetDefinedTypes().size(); |
| 619 | for (const auto defined_type : main_parser->GetDefinedTypes()) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 620 | CHECK(defined_type != nullptr); |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 621 | AidlParcelable* unstructuredParcelable = defined_type->AsUnstructuredParcelable(); |
| 622 | if (unstructuredParcelable != nullptr) { |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 623 | if (!unstructuredParcelable->CheckValid(typenames)) { |
| 624 | return AidlError::BAD_TYPE; |
| 625 | } |
| 626 | bool isStable = unstructuredParcelable->IsStableParcelable(); |
| 627 | if (options.IsStructured() && !isStable) { |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 628 | AIDL_ERROR(unstructuredParcelable) |
| 629 | << "Cannot declared parcelable in a --structured interface. Parcelable must be defined " |
| 630 | "in AIDL directly."; |
| 631 | return AidlError::NOT_STRUCTURED; |
| 632 | } |
| 633 | if (options.FailOnParcelable()) { |
| 634 | AIDL_ERROR(unstructuredParcelable) |
| 635 | << "Refusing to generate code with unstructured parcelables. Declared parcelables " |
| 636 | "should be in their own file and/or cannot be used with --structured interfaces."; |
| 637 | // Continue parsing for more errors |
| 638 | } |
| 639 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 640 | contains_unstructured_parcelable = true; |
| 641 | continue; |
| 642 | } |
| 643 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 644 | if (defined_type->IsVintfStability() && |
| 645 | (options.GetStability() != Options::Stability::VINTF || !options.IsStructured())) { |
| 646 | AIDL_ERROR(defined_type) |
| 647 | << "Must compile @VintfStability type w/ aidl_interface 'stability: \"vintf\"'"; |
| 648 | return AidlError::NOT_STRUCTURED; |
| 649 | } |
| 650 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 651 | // Ensure that a type is either an interface or a structured parcelable |
| 652 | AidlInterface* interface = defined_type->AsInterface(); |
| 653 | AidlStructuredParcelable* parcelable = defined_type->AsStructuredParcelable(); |
| 654 | CHECK(interface != nullptr || parcelable != nullptr); |
| 655 | |
| 656 | // Ensure that foo.bar.IFoo is defined in <some_path>/foo/bar/IFoo.aidl |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 657 | if (num_defined_types == 1 && !check_filename(input_file_name, *defined_type)) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 658 | return AidlError::BAD_PACKAGE; |
| 659 | } |
| 660 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 661 | // Check the referenced types in parsed_doc to make sure we've imported them |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 662 | if (!is_check_api) { |
| 663 | // No need to do this for check api because all typespecs are already |
| 664 | // using fully qualified name and we don't import in AIDL files. |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 665 | if (!defined_type->CheckValid(typenames)) { |
Jiyong Park | 96c16a9 | 2018-08-16 16:37:09 +0900 | [diff] [blame] | 666 | return AidlError::BAD_TYPE; |
| 667 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | if (interface != nullptr) { |
| 671 | // add the meta-method 'int getInterfaceVersion()' if version is specified. |
| 672 | if (options.Version() > 0) { |
| 673 | AidlTypeSpecifier* ret = |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 674 | new AidlTypeSpecifier(AIDL_LOCATION_HERE, "int", false, nullptr, ""); |
Jiyong Park | 640981b | 2018-11-19 19:54:58 +0900 | [diff] [blame] | 675 | ret->Resolve(typenames); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 676 | vector<unique_ptr<AidlArgument>>* args = new vector<unique_ptr<AidlArgument>>(); |
| 677 | AidlMethod* method = |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 678 | new AidlMethod(AIDL_LOCATION_HERE, false, ret, "getInterfaceVersion", args, "", |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 679 | kGetInterfaceVersionId, false /* is_user_defined */); |
| 680 | interface->GetMutableMethods().emplace_back(method); |
| 681 | } |
| 682 | if (!check_and_assign_method_ids(interface->GetMethods())) { |
| 683 | return AidlError::BAD_METHOD_ID; |
| 684 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 685 | } |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 686 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 687 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 688 | typenames.IterateTypes([&](const AidlDefinedType& type) { |
| 689 | if (options.IsStructured() && type.AsUnstructuredParcelable() != nullptr && |
| 690 | !type.AsUnstructuredParcelable()->IsStableParcelable()) { |
| 691 | err = AidlError::NOT_STRUCTURED; |
| 692 | LOG(ERROR) << type.GetCanonicalName() |
| 693 | << " is not structured, but this is a structured interface."; |
| 694 | } |
| 695 | if (options.GetStability() == Options::Stability::VINTF && !type.IsVintfStability()) { |
| 696 | err = AidlError::NOT_STRUCTURED; |
| 697 | LOG(ERROR) << type.GetCanonicalName() |
| 698 | << " does not have VINTF level stability, but this interface requires it."; |
| 699 | } |
| 700 | }); |
| 701 | |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 702 | if (err != AidlError::OK) { |
| 703 | return err; |
| 704 | } |
| 705 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 706 | if (defined_types != nullptr) { |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 707 | *defined_types = main_parser->GetDefinedTypes(); |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 708 | } |
| 709 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 710 | if (imported_files != nullptr) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 711 | *imported_files = import_paths; |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 712 | } |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 713 | |
Steven Moreland | e2c64b4 | 2018-09-18 15:06:37 -0700 | [diff] [blame] | 714 | if (contains_unstructured_parcelable) { |
| 715 | // Considered a success for the legacy case, so this must be returned last. |
| 716 | return AidlError::FOUND_PARCELABLE; |
| 717 | } |
| 718 | |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 719 | return AidlError::OK; |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 722 | } // namespace internals |
| 723 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 724 | int compile_aidl(const Options& options, const IoDelegate& io_delegate) { |
| 725 | const Options::Language lang = options.TargetLanguage(); |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 726 | for (const string& input_file : options.InputFiles()) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 727 | // Create type namespace that will hold the types identified by the parser. |
| 728 | // This two namespaces that are specific to the target language will be |
| 729 | // unified to AidlTypenames which is agnostic to the target language. |
| 730 | cpp::TypeNamespace cpp_types; |
| 731 | cpp_types.Init(); |
| 732 | |
| 733 | java::JavaTypeNamespace java_types; |
| 734 | java_types.Init(); |
| 735 | |
| 736 | TypeNamespace* types; |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 737 | if (options.IsCppOutput()) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 738 | types = &cpp_types; |
| 739 | } else if (lang == Options::Language::JAVA) { |
| 740 | types = &java_types; |
| 741 | } else { |
| 742 | LOG(FATAL) << "Unsupported target language." << endl; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 743 | return 1; |
| 744 | } |
| 745 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 746 | vector<AidlDefinedType*> defined_types; |
| 747 | vector<string> imported_files; |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 748 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 749 | AidlError aidl_err = internals::load_and_validate_aidl(input_file, options, io_delegate, types, |
| 750 | &defined_types, &imported_files); |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 751 | bool allowError = aidl_err == AidlError::FOUND_PARCELABLE && !options.FailOnParcelable(); |
| 752 | if (aidl_err != AidlError::OK && !allowError) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 753 | return 1; |
| 754 | } |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 755 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 756 | for (const auto defined_type : defined_types) { |
| 757 | CHECK(defined_type != nullptr); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 758 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 759 | string output_file_name = options.OutputFile(); |
| 760 | // if needed, generate the output file name from the base folder |
| 761 | if (output_file_name.empty() && !options.OutputDir().empty()) { |
Jiyong Park | b03551f | 2018-08-06 19:20:51 +0900 | [diff] [blame] | 762 | output_file_name = generate_outputFileName(options, *defined_type); |
| 763 | if (output_file_name.empty()) { |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 764 | return 1; |
| 765 | } |
| 766 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 767 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 768 | if (!write_dep_file(options, *defined_type, imported_files, io_delegate, input_file, |
| 769 | output_file_name)) { |
| 770 | return 1; |
| 771 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 772 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 773 | bool success = false; |
| 774 | if (lang == Options::Language::CPP) { |
Jeongik Cha | 1a7ab64 | 2019-07-29 17:31:02 +0900 | [diff] [blame] | 775 | success = cpp::GenerateCpp(output_file_name, options, cpp_types.typenames_, *defined_type, |
| 776 | io_delegate); |
Steven Moreland | c26d814 | 2018-09-17 14:25:33 -0700 | [diff] [blame] | 777 | } else if (lang == Options::Language::NDK) { |
| 778 | ndk::GenerateNdk(output_file_name, options, cpp_types.typenames_, *defined_type, |
| 779 | io_delegate); |
| 780 | success = true; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 781 | } else if (lang == Options::Language::JAVA) { |
Jeongik Cha | a2080bf | 2019-06-18 16:44:29 +0900 | [diff] [blame] | 782 | success = java::generate_java(output_file_name, defined_type, java_types.typenames_, |
| 783 | io_delegate, options); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 784 | } else { |
| 785 | LOG(FATAL) << "Should not reach here" << endl; |
| 786 | return 1; |
| 787 | } |
| 788 | if (!success) { |
| 789 | return 1; |
| 790 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 791 | } |
Christopher Wiley | 3a9d158 | 2015-09-16 12:42:14 -0700 | [diff] [blame] | 792 | } |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 793 | return 0; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 796 | bool dump_mappings(const Options& options, const IoDelegate& io_delegate) { |
| 797 | android::aidl::mappings::SignatureMap all_mappings; |
| 798 | for (const string& input_file : options.InputFiles()) { |
| 799 | java::JavaTypeNamespace java_types; |
| 800 | java_types.Init(); |
| 801 | vector<AidlDefinedType*> defined_types; |
| 802 | vector<string> imported_files; |
| 803 | |
| 804 | AidlError aidl_err = internals::load_and_validate_aidl( |
| 805 | input_file, options, io_delegate, &java_types, &defined_types, &imported_files); |
| 806 | if (aidl_err != AidlError::OK) { |
| 807 | LOG(WARNING) << "AIDL file is invalid.\n"; |
| 808 | continue; |
| 809 | } |
| 810 | for (const auto defined_type : defined_types) { |
| 811 | auto mappings = mappings::generate_mappings(defined_type); |
| 812 | all_mappings.insert(mappings.begin(), mappings.end()); |
| 813 | } |
| 814 | } |
| 815 | std::stringstream mappings_str; |
| 816 | for (const auto& mapping : all_mappings) { |
| 817 | mappings_str << mapping.first << "\n" << mapping.second << "\n"; |
| 818 | } |
| 819 | auto code_writer = io_delegate.GetCodeWriter(options.OutputFile()); |
| 820 | code_writer->Write("%s", mappings_str.str().c_str()); |
| 821 | return true; |
| 822 | } |
| 823 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 824 | bool preprocess_aidl(const Options& options, const IoDelegate& io_delegate) { |
| 825 | unique_ptr<CodeWriter> writer = io_delegate.GetCodeWriter(options.OutputFile()); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 826 | |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 827 | for (const auto& file : options.InputFiles()) { |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 828 | AidlTypenames typenames; |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 829 | std::unique_ptr<Parser> p = Parser::Parse(file, io_delegate, typenames); |
| 830 | if (p == nullptr) return false; |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 831 | |
Steven Moreland | 64e29be | 2018-08-08 18:52:19 -0700 | [diff] [blame] | 832 | for (const auto& defined_type : p->GetDefinedTypes()) { |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 833 | if (!writer->Write("%s %s;\n", defined_type->GetPreprocessDeclarationName().c_str(), |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 834 | defined_type->GetCanonicalName().c_str())) { |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 835 | return false; |
| 836 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 837 | } |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 838 | } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 839 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 840 | return writer->Close(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 841 | } |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 842 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 843 | static string GetApiDumpPathFor(const AidlDefinedType& defined_type, const Options& options) { |
| 844 | string package_as_path = Join(Split(defined_type.GetPackage(), "."), OS_PATH_SEPARATOR); |
| 845 | CHECK(!options.OutputDir().empty() && options.OutputDir().back() == '/'); |
| 846 | return options.OutputDir() + package_as_path + OS_PATH_SEPARATOR + defined_type.GetName() + |
| 847 | ".aidl"; |
| 848 | } |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 849 | |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 850 | bool dump_api(const Options& options, const IoDelegate& io_delegate) { |
Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 851 | for (const auto& file : options.InputFiles()) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 852 | java::JavaTypeNamespace ns; |
| 853 | ns.Init(); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 854 | vector<AidlDefinedType*> defined_types; |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 855 | if (internals::load_and_validate_aidl(file, options, io_delegate, &ns, &defined_types, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 856 | nullptr) == AidlError::OK) { |
| 857 | for (const auto type : defined_types) { |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 858 | unique_ptr<CodeWriter> writer = |
| 859 | io_delegate.GetCodeWriter(GetApiDumpPathFor(*type, options)); |
Steven Moreland | ec0531d | 2018-09-20 11:11:20 -0700 | [diff] [blame] | 860 | if (!type->GetPackage().empty()) { |
| 861 | (*writer) << "package " << type->GetPackage() << ";\n"; |
| 862 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 863 | type->Write(writer.get()); |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 864 | } |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 865 | } else { |
| 866 | return false; |
| 867 | } |
| 868 | } |
Jiyong Park | e59c368 | 2018-09-11 23:10:25 +0900 | [diff] [blame] | 869 | return true; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 870 | } |
| 871 | |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 872 | } // namespace aidl |
Steven Moreland | f4c64df | 2019-07-29 19:54:04 -0700 | [diff] [blame] | 873 | } // namespace android |