Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -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 | */ |
| 16 | |
| 17 | #include "generate_cpp.h" |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 18 | |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 19 | #include <cctype> |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 20 | #include <cstring> |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 21 | #include <memory> |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 22 | #include <random> |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 23 | #include <set> |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 24 | #include <string> |
| 25 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 26 | #include <android-base/stringprintf.h> |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 27 | |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 28 | #include "aidl_language.h" |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 29 | #include "ast_cpp.h" |
| 30 | #include "code_writer.h" |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 31 | #include "logging.h" |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 32 | #include "os.h" |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 33 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 34 | using android::base::Join; |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 35 | using android::base::StringPrintf; |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 36 | using std::set; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 37 | using std::string; |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 38 | using std::unique_ptr; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 39 | using std::vector; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 40 | |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace aidl { |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 43 | namespace cpp { |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 44 | namespace internals { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 45 | namespace { |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 46 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 47 | const char kAndroidStatusVarName[] = "_aidl_ret_status"; |
| 48 | const char kCodeVarName[] = "_aidl_code"; |
| 49 | const char kFlagsVarName[] = "_aidl_flags"; |
| 50 | const char kDataVarName[] = "_aidl_data"; |
| 51 | const char kErrorLabel[] = "_aidl_error"; |
| 52 | const char kImplVarName[] = "_aidl_impl"; |
| 53 | const char kReplyVarName[] = "_aidl_reply"; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 54 | const char kReturnVarName[] = "_aidl_return"; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 55 | const char kStatusVarName[] = "_aidl_status"; |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 56 | const char kTraceVarName[] = "_aidl_trace"; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 57 | const char kAndroidParcelLiteral[] = "::android::Parcel"; |
| 58 | const char kAndroidStatusLiteral[] = "::android::status_t"; |
| 59 | const char kAndroidStatusOk[] = "::android::OK"; |
| 60 | const char kBinderStatusLiteral[] = "::android::binder::Status"; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 61 | const char kIBinderHeader[] = "binder/IBinder.h"; |
| 62 | const char kIInterfaceHeader[] = "binder/IInterface.h"; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 63 | const char kParcelHeader[] = "binder/Parcel.h"; |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 64 | const char kStatusHeader[] = "binder/Status.h"; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 65 | const char kString16Header[] = "utils/String16.h"; |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 66 | const char kTraceHeader[] = "utils/Trace.h"; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 67 | const char kStrongPointerHeader[] = "utils/StrongPointer.h"; |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 68 | const char kAndroidBaseMacrosHeader[] = "android-base/macros.h"; |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 69 | |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 70 | unique_ptr<AstNode> BreakOnStatusNotOk() { |
| 71 | IfStatement* ret = new IfStatement(new Comparison( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 72 | new LiteralExpression(kAndroidStatusVarName), "!=", |
| 73 | new LiteralExpression(kAndroidStatusOk))); |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 74 | ret->OnTrue()->AddLiteral("break"); |
| 75 | return unique_ptr<AstNode>(ret); |
| 76 | } |
| 77 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 78 | unique_ptr<AstNode> GotoErrorOnBadStatus() { |
| 79 | IfStatement* ret = new IfStatement(new Comparison( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 80 | new LiteralExpression(kAndroidStatusVarName), "!=", |
| 81 | new LiteralExpression(kAndroidStatusOk))); |
| 82 | ret->OnTrue()->AddLiteral(StringPrintf("goto %s", kErrorLabel)); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 83 | return unique_ptr<AstNode>(ret); |
| 84 | } |
| 85 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 86 | unique_ptr<AstNode> ReturnOnStatusNotOk() { |
| 87 | IfStatement* ret = new IfStatement(new Comparison(new LiteralExpression(kAndroidStatusVarName), |
| 88 | "!=", new LiteralExpression(kAndroidStatusOk))); |
| 89 | ret->OnTrue()->AddLiteral(StringPrintf("return %s", kAndroidStatusVarName)); |
| 90 | return unique_ptr<AstNode>(ret); |
| 91 | } |
| 92 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 93 | string UpperCase(const std::string& s) { |
| 94 | string result = s; |
| 95 | for (char& c : result) |
| 96 | c = toupper(c); |
| 97 | return result; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 98 | } |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 99 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 100 | string BuildVarName(const AidlArgument& a) { |
| 101 | string prefix = "out_"; |
| 102 | if (a.GetDirection() & AidlArgument::IN_DIR) { |
| 103 | prefix = "in_"; |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 104 | } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 105 | return prefix + a.GetName(); |
| 106 | } |
| 107 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 108 | ArgList BuildArgList(const TypeNamespace& types, const AidlMethod& method, bool for_declaration, |
| 109 | bool type_name_only = false) { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 110 | // Build up the argument list for the server method call. |
| 111 | vector<string> method_arguments; |
| 112 | for (const unique_ptr<AidlArgument>& a : method.GetArguments()) { |
| 113 | string literal; |
| 114 | if (for_declaration) { |
| 115 | // Method declarations need types, pointers to out params, and variable |
| 116 | // names that match the .aidl specification. |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 117 | const Type* type = a->GetType().GetLanguageType<Type>(); |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 118 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 119 | literal = type->CppType(); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 120 | |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 121 | if (a->IsOut()) { |
| 122 | literal = literal + "*"; |
| 123 | } else { |
| 124 | // We pass in parameters that are not primitives by const reference. |
| 125 | // Arrays of primitives are not primitives. |
| 126 | if (!type->IsCppPrimitive() || a->GetType().IsArray()) { |
| 127 | literal = "const " + literal + "&"; |
| 128 | } |
| 129 | } |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 130 | if (!type_name_only) { |
| 131 | literal += " " + a->GetName(); |
| 132 | } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 133 | } else { |
| 134 | if (a->IsOut()) { literal = "&"; } |
| 135 | literal += BuildVarName(*a); |
| 136 | } |
| 137 | method_arguments.push_back(literal); |
| 138 | } |
| 139 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 140 | const Type* return_type = method.GetType().GetLanguageType<Type>(); |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 141 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 142 | if (return_type != types.VoidType()) { |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 143 | string literal; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 144 | if (for_declaration) { |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 145 | literal = StringPrintf("%s* %s", return_type->CppType().c_str(), |
| 146 | type_name_only ? "" : kReturnVarName); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 147 | } else { |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 148 | literal = string{"&"} + kReturnVarName; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 149 | } |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 150 | method_arguments.push_back(literal); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 153 | return ArgList(method_arguments); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 156 | unique_ptr<Declaration> BuildMethodDecl(const AidlMethod& method, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 157 | const TypeNamespace& types, |
| 158 | bool for_interface) { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 159 | uint32_t modifiers = 0; |
| 160 | if (for_interface) { |
| 161 | modifiers |= MethodDecl::IS_VIRTUAL; |
| 162 | modifiers |= MethodDecl::IS_PURE_VIRTUAL; |
| 163 | } else { |
| 164 | modifiers |= MethodDecl::IS_OVERRIDE; |
| 165 | } |
| 166 | |
| 167 | return unique_ptr<Declaration>{ |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 168 | new MethodDecl{kBinderStatusLiteral, |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 169 | method.GetName(), |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 170 | BuildArgList(types, method, true /* for method decl */), |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 171 | modifiers}}; |
| 172 | } |
| 173 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 174 | unique_ptr<CppNamespace> NestInNamespaces( |
| 175 | vector<unique_ptr<Declaration>> decls, |
| 176 | const vector<string>& package) { |
| 177 | if (package.empty()) { |
| 178 | // We should also be checking this before we get this far, but do it again |
| 179 | // for the sake of unit tests and meaningful errors. |
| 180 | LOG(FATAL) << "C++ generation requires a package declaration " |
| 181 | "for namespacing"; |
| 182 | } |
| 183 | auto it = package.crbegin(); // Iterate over the namespaces inner to outer |
| 184 | unique_ptr<CppNamespace> inner{new CppNamespace{*it, std::move(decls)}}; |
| 185 | ++it; |
| 186 | for (; it != package.crend(); ++it) { |
| 187 | inner.reset(new CppNamespace{*it, std::move(inner)}); |
| 188 | } |
| 189 | return inner; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 192 | unique_ptr<CppNamespace> NestInNamespaces(unique_ptr<Declaration> decl, |
| 193 | const vector<string>& package) { |
| 194 | vector<unique_ptr<Declaration>> decls; |
| 195 | decls.push_back(std::move(decl)); |
| 196 | return NestInNamespaces(std::move(decls), package); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Steven Moreland | 1c41e97 | 2018-07-09 16:07:00 -0700 | [diff] [blame] | 199 | bool DeclareLocalVariable(const AidlArgument& a, StatementBlock* b) { |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 200 | const Type* cpp_type = a.GetType().GetLanguageType<Type>(); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 201 | if (!cpp_type) { return false; } |
| 202 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 203 | string type = cpp_type->CppType(); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 204 | |
| 205 | b->AddLiteral(type + " " + BuildVarName(a)); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 206 | return true; |
| 207 | } |
| 208 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 209 | string ClassName(const AidlDefinedType& defined_type, ClassNames type) { |
| 210 | string c_name = defined_type.GetName(); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 211 | |
| 212 | if (c_name.length() >= 2 && c_name[0] == 'I' && isupper(c_name[1])) |
| 213 | c_name = c_name.substr(1); |
| 214 | |
| 215 | switch (type) { |
| 216 | case ClassNames::CLIENT: |
| 217 | c_name = "Bp" + c_name; |
| 218 | break; |
| 219 | case ClassNames::SERVER: |
| 220 | c_name = "Bn" + c_name; |
| 221 | break; |
| 222 | case ClassNames::INTERFACE: |
| 223 | c_name = "I" + c_name; |
| 224 | break; |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 225 | case ClassNames::DEFAULT_IMPL: |
| 226 | c_name = "I" + c_name + "Default"; |
| 227 | break; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 228 | case ClassNames::BASE: |
| 229 | break; |
| 230 | } |
| 231 | return c_name; |
| 232 | } |
| 233 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 234 | string BuildHeaderGuard(const AidlDefinedType& defined_type, ClassNames header_type) { |
| 235 | string class_name = ClassName(defined_type, header_type); |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 236 | for (size_t i = 1; i < class_name.size(); ++i) { |
| 237 | if (isupper(class_name[i])) { |
| 238 | class_name.insert(i, "_"); |
| 239 | ++i; |
| 240 | } |
| 241 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 242 | string ret = StringPrintf("AIDL_GENERATED_%s_%s_H_", defined_type.GetPackage().c_str(), |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 243 | class_name.c_str()); |
| 244 | for (char& c : ret) { |
| 245 | if (c == '.') { |
| 246 | c = '_'; |
| 247 | } |
| 248 | c = toupper(c); |
| 249 | } |
| 250 | return ret; |
| 251 | } |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 252 | |
| 253 | unique_ptr<Declaration> DefineClientTransaction(const TypeNamespace& types, |
| 254 | const AidlInterface& interface, |
| 255 | const AidlMethod& method) { |
| 256 | const string i_name = ClassName(interface, ClassNames::INTERFACE); |
| 257 | const string bp_name = ClassName(interface, ClassNames::CLIENT); |
| 258 | unique_ptr<MethodImpl> ret{new MethodImpl{ |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 259 | kBinderStatusLiteral, bp_name, method.GetName(), |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 260 | ArgList{BuildArgList(types, method, true /* for method decl */)}}}; |
| 261 | StatementBlock* b = ret->GetStatementBlock(); |
| 262 | |
| 263 | // Declare parcels to hold our query and the response. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 264 | b->AddLiteral(StringPrintf("%s %s", kAndroidParcelLiteral, kDataVarName)); |
Christopher Wiley | 1227d61 | 2015-10-26 16:59:20 -0700 | [diff] [blame] | 265 | // Even if we're oneway, the transact method still takes a parcel. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 266 | b->AddLiteral(StringPrintf("%s %s", kAndroidParcelLiteral, kReplyVarName)); |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 267 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 268 | // Declare the status_t variable we need for error handling. |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 269 | b->AddLiteral(StringPrintf("%s %s = %s", kAndroidStatusLiteral, |
| 270 | kAndroidStatusVarName, |
| 271 | kAndroidStatusOk)); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 272 | // We unconditionally return a Status object. |
| 273 | b->AddLiteral(StringPrintf("%s %s", kBinderStatusLiteral, kStatusVarName)); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 274 | |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 275 | if (interface.ShouldGenerateTraces()) { |
| 276 | b->AddLiteral( |
| 277 | StringPrintf("ScopedTrace %s(ATRACE_TAG_AIDL, \"%s::%s::cppClient\")", |
| 278 | kTraceVarName, interface.GetName().c_str(), method.GetName().c_str())); |
| 279 | } |
| 280 | |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 281 | // Add the name of the interface we're hoping to call. |
| 282 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 283 | kAndroidStatusVarName, |
| 284 | new MethodCall(StringPrintf("%s.writeInterfaceToken", |
| 285 | kDataVarName), |
| 286 | "getInterfaceDescriptor()"))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 287 | b->AddStatement(GotoErrorOnBadStatus()); |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 288 | |
Christopher Wiley | 74b7bf1 | 2016-08-19 11:06:32 -0700 | [diff] [blame] | 289 | for (const auto& a: method.GetArguments()) { |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 290 | const Type* type = a->GetType().GetLanguageType<Type>(); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 291 | string var_name = ((a->IsOut()) ? "*" : "") + a->GetName(); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 292 | var_name = type->WriteCast(var_name); |
Christopher Wiley | 74b7bf1 | 2016-08-19 11:06:32 -0700 | [diff] [blame] | 293 | |
| 294 | if (a->IsIn()) { |
| 295 | // Serialization looks roughly like: |
| 296 | // _aidl_ret_status = _aidl_data.WriteInt32(in_param_name); |
| 297 | // if (_aidl_ret_status != ::android::OK) { goto error; } |
| 298 | const string& method = type->WriteToParcelMethod(); |
| 299 | b->AddStatement(new Assignment( |
| 300 | kAndroidStatusVarName, |
| 301 | new MethodCall(StringPrintf("%s.%s", kDataVarName, method.c_str()), |
| 302 | ArgList(var_name)))); |
| 303 | b->AddStatement(GotoErrorOnBadStatus()); |
| 304 | } else if (a->IsOut() && a->GetType().IsArray()) { |
| 305 | // Special case, the length of the out array is written into the parcel. |
| 306 | // _aidl_ret_status = _aidl_data.writeVectorSize(&out_param_name); |
| 307 | // if (_aidl_ret_status != ::android::OK) { goto error; } |
| 308 | b->AddStatement(new Assignment( |
| 309 | kAndroidStatusVarName, |
| 310 | new MethodCall(StringPrintf("%s.writeVectorSize", kDataVarName), |
| 311 | ArgList(var_name)))); |
| 312 | b->AddStatement(GotoErrorOnBadStatus()); |
| 313 | } |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // Invoke the transaction on the remote binder and confirm status. |
| 317 | string transaction_code = StringPrintf( |
| 318 | "%s::%s", i_name.c_str(), UpperCase(method.GetName()).c_str()); |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 319 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 320 | vector<string> args = {transaction_code, kDataVarName, |
| 321 | StringPrintf("&%s", kReplyVarName)}; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 322 | |
| 323 | if (interface.IsOneway() || method.IsOneway()) { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 324 | args.push_back("::android::IBinder::FLAG_ONEWAY"); |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 327 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 328 | kAndroidStatusVarName, |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 329 | new MethodCall("remote()->transact", |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 330 | ArgList(args)))); |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 331 | |
| 332 | // If the method is not implemented in the remote side, try to call the |
| 333 | // default implementation, if provided. |
| 334 | vector<string> arg_names; |
| 335 | for (const auto& a : method.GetArguments()) { |
| 336 | arg_names.emplace_back(a->GetName()); |
| 337 | } |
| 338 | if (method.GetType().GetLanguageType<Type>() != types.VoidType()) { |
| 339 | arg_names.emplace_back(kReturnVarName); |
| 340 | } |
| 341 | b->AddLiteral(StringPrintf("if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && " |
| 342 | "%s::getDefaultImpl())) {\n" |
| 343 | " return %s::getDefaultImpl()->%s(%s);\n" |
| 344 | "}\n", |
| 345 | i_name.c_str(), i_name.c_str(), method.GetName().c_str(), |
| 346 | Join(arg_names, ", ").c_str()), |
| 347 | false /* no semicolon */); |
| 348 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 349 | b->AddStatement(GotoErrorOnBadStatus()); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 350 | |
Christopher Wiley | 1227d61 | 2015-10-26 16:59:20 -0700 | [diff] [blame] | 351 | if (!interface.IsOneway() && !method.IsOneway()) { |
| 352 | // Strip off the exception header and fail if we see a remote exception. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 353 | // _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 354 | // if (_aidl_ret_status != ::android::OK) { goto error; } |
| 355 | // if (!_aidl_status.isOk()) { return _aidl_ret_status; } |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 356 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 357 | kAndroidStatusVarName, |
| 358 | StringPrintf("%s.readFromParcel(%s)", kStatusVarName, kReplyVarName))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 359 | b->AddStatement(GotoErrorOnBadStatus()); |
Christopher Wiley | 1227d61 | 2015-10-26 16:59:20 -0700 | [diff] [blame] | 360 | IfStatement* exception_check = new IfStatement( |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 361 | new LiteralExpression(StringPrintf("!%s.isOk()", kStatusVarName))); |
Christopher Wiley | 1227d61 | 2015-10-26 16:59:20 -0700 | [diff] [blame] | 362 | b->AddStatement(exception_check); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 363 | exception_check->OnTrue()->AddLiteral( |
| 364 | StringPrintf("return %s", kStatusVarName)); |
Christopher Wiley | 1227d61 | 2015-10-26 16:59:20 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // Type checking should guarantee that nothing below emits code until "return |
| 368 | // status" if we are a oneway method, so no more fear of accessing reply. |
Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 369 | |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 370 | // If the method is expected to return something, read it first by convention. |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 371 | const Type* return_type = method.GetType().GetLanguageType<Type>(); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 372 | if (return_type != types.VoidType()) { |
Chih-Hung Hsieh | f05cc26 | 2016-07-27 11:42:51 -0700 | [diff] [blame] | 373 | const string& method_call = return_type->ReadFromParcelMethod(); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 374 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 375 | kAndroidStatusVarName, |
| 376 | new MethodCall(StringPrintf("%s.%s", kReplyVarName, |
| 377 | method_call.c_str()), |
| 378 | ArgList(kReturnVarName)))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 379 | b->AddStatement(GotoErrorOnBadStatus()); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | for (const AidlArgument* a : method.GetOutArguments()) { |
| 383 | // Deserialization looks roughly like: |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 384 | // _aidl_ret_status = _aidl_reply.ReadInt32(out_param_name); |
| 385 | // if (_aidl_status != ::android::OK) { goto _aidl_error; } |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 386 | string method = |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 387 | a->GetType().GetLanguageType<Type>()->ReadFromParcelMethod(); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 388 | |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 389 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 390 | kAndroidStatusVarName, |
| 391 | new MethodCall(StringPrintf("%s.%s", kReplyVarName, |
| 392 | method.c_str()), |
| 393 | ArgList(a->GetName())))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 394 | b->AddStatement(GotoErrorOnBadStatus()); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 397 | // If we've gotten to here, one of two things is true: |
| 398 | // 1) We've read some bad status_t |
| 399 | // 2) We've only read status_t == OK and there was no exception in the |
| 400 | // response. |
| 401 | // In both cases, we're free to set Status from the status_t and return. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 402 | b->AddLiteral(StringPrintf("%s:\n", kErrorLabel), false /* no semicolon */); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 403 | b->AddLiteral( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 404 | StringPrintf("%s.setFromStatusT(%s)", kStatusVarName, |
| 405 | kAndroidStatusVarName)); |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 406 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 407 | b->AddLiteral(StringPrintf("return %s", kStatusVarName)); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 408 | |
| 409 | return unique_ptr<Declaration>(ret.release()); |
| 410 | } |
| 411 | |
| 412 | } // namespace |
| 413 | |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 414 | unique_ptr<Document> BuildClientSource(const TypeNamespace& types, |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 415 | const AidlInterface& interface) { |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 416 | vector<string> include_list = { |
| 417 | HeaderFile(interface, ClassNames::CLIENT, false), |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 418 | kParcelHeader, |
| 419 | kAndroidBaseMacrosHeader |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 420 | }; |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 421 | vector<unique_ptr<Declaration>> file_decls; |
| 422 | |
| 423 | // The constructor just passes the IBinder instance up to the super |
| 424 | // class. |
Christopher Wiley | 1db0348 | 2015-10-22 11:42:02 -0700 | [diff] [blame] | 425 | const string i_name = ClassName(interface, ClassNames::INTERFACE); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 426 | file_decls.push_back(unique_ptr<Declaration>{new ConstructorImpl{ |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 427 | ClassName(interface, ClassNames::CLIENT), |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 428 | ArgList{StringPrintf("const ::android::sp<::android::IBinder>& %s", |
| 429 | kImplVarName)}, |
| 430 | { "BpInterface<" + i_name + ">(" + kImplVarName + ")" }}}); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 431 | |
| 432 | // Clients define a method per transaction. |
| 433 | for (const auto& method : interface.GetMethods()) { |
| 434 | unique_ptr<Declaration> m = DefineClientTransaction( |
| 435 | types, interface, *method); |
| 436 | if (!m) { return nullptr; } |
| 437 | file_decls.push_back(std::move(m)); |
| 438 | } |
| 439 | return unique_ptr<Document>{new CppSource{ |
| 440 | include_list, |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 441 | NestInNamespaces(std::move(file_decls), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 444 | namespace { |
| 445 | |
| 446 | bool HandleServerTransaction(const TypeNamespace& types, |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 447 | const AidlInterface& interface, |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 448 | const AidlMethod& method, |
| 449 | StatementBlock* b) { |
| 450 | // Declare all the parameters now. In the common case, we expect no errors |
| 451 | // in serialization. |
| 452 | for (const unique_ptr<AidlArgument>& a : method.GetArguments()) { |
Steven Moreland | 1c41e97 | 2018-07-09 16:07:00 -0700 | [diff] [blame] | 453 | if (!DeclareLocalVariable(*a, b)) { |
| 454 | return false; |
| 455 | } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // Declare a variable to hold the return value. |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 459 | const Type* return_type = method.GetType().GetLanguageType<Type>(); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 460 | if (return_type != types.VoidType()) { |
| 461 | b->AddLiteral(StringPrintf( |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 462 | "%s %s", return_type->CppType().c_str(), |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 463 | kReturnVarName)); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 466 | // Check that the client is calling the correct interface. |
| 467 | IfStatement* interface_check = new IfStatement( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 468 | new MethodCall(StringPrintf("%s.checkInterface", |
| 469 | kDataVarName), "this"), |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 470 | true /* invert the check */); |
| 471 | b->AddStatement(interface_check); |
| 472 | interface_check->OnTrue()->AddStatement( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 473 | new Assignment(kAndroidStatusVarName, "::android::BAD_TYPE")); |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 474 | interface_check->OnTrue()->AddLiteral("break"); |
| 475 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 476 | // Deserialize each "in" parameter to the transaction. |
Christopher Wiley | 74b7bf1 | 2016-08-19 11:06:32 -0700 | [diff] [blame] | 477 | for (const auto& a: method.GetArguments()) { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 478 | // Deserialization looks roughly like: |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 479 | // _aidl_ret_status = _aidl_data.ReadInt32(&in_param_name); |
| 480 | // if (_aidl_ret_status != ::android::OK) { break; } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 481 | const Type* type = a->GetType().GetLanguageType<Type>(); |
Chih-Hung Hsieh | f05cc26 | 2016-07-27 11:42:51 -0700 | [diff] [blame] | 482 | const string& readMethod = type->ReadFromParcelMethod(); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 483 | |
Christopher Wiley | 74b7bf1 | 2016-08-19 11:06:32 -0700 | [diff] [blame] | 484 | if (a->IsIn()) { |
| 485 | b->AddStatement(new Assignment{ |
| 486 | kAndroidStatusVarName, |
| 487 | new MethodCall{string(kDataVarName) + "." + readMethod, |
| 488 | "&" + BuildVarName(*a)}}); |
| 489 | b->AddStatement(BreakOnStatusNotOk()); |
| 490 | } else if (a->IsOut() && a->GetType().IsArray()) { |
| 491 | // Special case, the length of the out array is written into the parcel. |
| 492 | // _aidl_ret_status = _aidl_data.resizeOutVector(&out_param_name); |
| 493 | // if (_aidl_ret_status != ::android::OK) { break; } |
| 494 | b->AddStatement(new Assignment{ |
| 495 | kAndroidStatusVarName, |
| 496 | new MethodCall{string(kDataVarName) + ".resizeOutVector", |
| 497 | "&" + BuildVarName(*a)}}); |
| 498 | b->AddStatement(BreakOnStatusNotOk()); |
| 499 | } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 502 | if (interface.ShouldGenerateTraces()) { |
| 503 | b->AddStatement(new Statement(new MethodCall("atrace_begin", |
| 504 | ArgList{{"ATRACE_TAG_AIDL", |
| 505 | StringPrintf("\"%s::%s::cppServer\"", |
| 506 | interface.GetName().c_str(), |
| 507 | method.GetName().c_str())}}))); |
| 508 | } |
| 509 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 510 | // Call the actual method. This is implemented by the subclass. |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 511 | vector<unique_ptr<AstNode>> status_args; |
| 512 | status_args.emplace_back(new MethodCall( |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 513 | method.GetName(), |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 514 | BuildArgList(types, method, false /* not for method decl */))); |
| 515 | b->AddStatement(new Statement(new MethodCall( |
| 516 | StringPrintf("%s %s", kBinderStatusLiteral, kStatusVarName), |
| 517 | ArgList(std::move(status_args))))); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 518 | |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 519 | if (interface.ShouldGenerateTraces()) { |
| 520 | b->AddStatement(new Statement(new MethodCall("atrace_end", |
| 521 | "ATRACE_TAG_AIDL"))); |
| 522 | } |
| 523 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 524 | // Write exceptions during transaction handling to parcel. |
| 525 | if (!method.IsOneway()) { |
| 526 | b->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 527 | kAndroidStatusVarName, |
| 528 | StringPrintf("%s.writeToParcel(%s)", kStatusVarName, kReplyVarName))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 529 | b->AddStatement(BreakOnStatusNotOk()); |
| 530 | IfStatement* exception_check = new IfStatement( |
| 531 | new LiteralExpression(StringPrintf("!%s.isOk()", kStatusVarName))); |
| 532 | b->AddStatement(exception_check); |
| 533 | exception_check->OnTrue()->AddLiteral("break"); |
| 534 | } |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 535 | |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 536 | // If we have a return value, write it first. |
| 537 | if (return_type != types.VoidType()) { |
Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 538 | string writeMethod = |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 539 | string(kReplyVarName) + "->" + |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 540 | return_type->WriteToParcelMethod(); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 541 | b->AddStatement(new Assignment{ |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 542 | kAndroidStatusVarName, new MethodCall{writeMethod, |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 543 | ArgList{return_type->WriteCast(kReturnVarName)}}}); |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 544 | b->AddStatement(BreakOnStatusNotOk()); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 547 | // Write each out parameter to the reply parcel. |
| 548 | for (const AidlArgument* a : method.GetOutArguments()) { |
| 549 | // Serialization looks roughly like: |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 550 | // _aidl_ret_status = data.WriteInt32(out_param_name); |
| 551 | // if (_aidl_ret_status != ::android::OK) { break; } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 552 | const Type* type = a->GetType().GetLanguageType<Type>(); |
Chih-Hung Hsieh | f05cc26 | 2016-07-27 11:42:51 -0700 | [diff] [blame] | 553 | const string& writeMethod = type->WriteToParcelMethod(); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 554 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 555 | b->AddStatement(new Assignment{ |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 556 | kAndroidStatusVarName, |
| 557 | new MethodCall{string(kReplyVarName) + "->" + writeMethod, |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 558 | type->WriteCast(BuildVarName(*a))}}); |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 559 | b->AddStatement(BreakOnStatusNotOk()); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | } // namespace |
| 566 | |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 567 | unique_ptr<Document> BuildServerSource(const TypeNamespace& types, |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 568 | const AidlInterface& interface) { |
| 569 | const string bn_name = ClassName(interface, ClassNames::SERVER); |
| 570 | vector<string> include_list{ |
| 571 | HeaderFile(interface, ClassNames::SERVER, false), |
| 572 | kParcelHeader |
| 573 | }; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 574 | unique_ptr<MethodImpl> on_transact{new MethodImpl{ |
| 575 | kAndroidStatusLiteral, bn_name, "onTransact", |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 576 | ArgList{{StringPrintf("uint32_t %s", kCodeVarName), |
| 577 | StringPrintf("const %s& %s", kAndroidParcelLiteral, |
| 578 | kDataVarName), |
| 579 | StringPrintf("%s* %s", kAndroidParcelLiteral, kReplyVarName), |
| 580 | StringPrintf("uint32_t %s", kFlagsVarName)}} |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 581 | }}; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 582 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 583 | // Declare the status_t variable |
Christopher Wiley | 05f4f89 | 2015-10-14 13:30:43 -0700 | [diff] [blame] | 584 | on_transact->GetStatementBlock()->AddLiteral( |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 585 | StringPrintf("%s %s = %s", kAndroidStatusLiteral, kAndroidStatusVarName, |
| 586 | kAndroidStatusOk)); |
Christopher Wiley | 05f4f89 | 2015-10-14 13:30:43 -0700 | [diff] [blame] | 587 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 588 | // Add the all important switch statement, but retain a pointer to it. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 589 | SwitchStatement* s = new SwitchStatement{kCodeVarName}; |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 590 | on_transact->GetStatementBlock()->AddStatement(s); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 591 | |
| 592 | // The switch statement has a case statement for each transaction code. |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 593 | for (const auto& method : interface.GetMethods()) { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 594 | StatementBlock* b = s->AddCase("Call::" + UpperCase(method->GetName())); |
| 595 | if (!b) { return nullptr; } |
| 596 | |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 597 | if (!HandleServerTransaction(types, interface, *method, b)) { return nullptr; } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | // The switch statement has a default case which defers to the super class. |
| 601 | // The superclass handles a few pre-defined transactions. |
| 602 | StatementBlock* b = s->AddCase(""); |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 603 | b->AddLiteral(StringPrintf( |
| 604 | "%s = ::android::BBinder::onTransact(%s, %s, " |
| 605 | "%s, %s)", kAndroidStatusVarName, kCodeVarName, |
| 606 | kDataVarName, kReplyVarName, kFlagsVarName)); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 607 | |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 608 | // If we saw a null reference, we can map that to an appropriate exception. |
| 609 | IfStatement* null_check = new IfStatement( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 610 | new LiteralExpression(string(kAndroidStatusVarName) + |
| 611 | " == ::android::UNEXPECTED_NULL")); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 612 | on_transact->GetStatementBlock()->AddStatement(null_check); |
| 613 | null_check->OnTrue()->AddStatement(new Assignment( |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 614 | kAndroidStatusVarName, |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 615 | StringPrintf("%s::fromExceptionCode(%s::EX_NULL_POINTER)" |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 616 | ".writeToParcel(%s)", |
| 617 | kBinderStatusLiteral, kBinderStatusLiteral, |
| 618 | kReplyVarName))); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 619 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 620 | // Finally, the server's onTransact method just returns a status code. |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 621 | on_transact->GetStatementBlock()->AddLiteral( |
| 622 | StringPrintf("return %s", kAndroidStatusVarName)); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 623 | |
| 624 | return unique_ptr<Document>{new CppSource{ |
| 625 | include_list, |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 626 | NestInNamespaces(std::move(on_transact), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 629 | unique_ptr<Document> BuildInterfaceSource(const TypeNamespace& types, |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 630 | const AidlInterface& interface) { |
| 631 | vector<string> include_list{ |
| 632 | HeaderFile(interface, ClassNames::INTERFACE, false), |
| 633 | HeaderFile(interface, ClassNames::CLIENT, false), |
| 634 | }; |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 635 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 636 | string fq_name = ClassName(interface, ClassNames::INTERFACE); |
| 637 | if (!interface.GetPackage().empty()) { |
| 638 | fq_name = interface.GetPackage() + "." + fq_name; |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 641 | vector<unique_ptr<Declaration>> decls; |
| 642 | |
Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame] | 643 | unique_ptr<MacroDecl> meta_if{new MacroDecl{ |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 644 | "IMPLEMENT_META_INTERFACE", |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 645 | ArgList{vector<string>{ClassName(interface, ClassNames::BASE), |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 646 | '"' + fq_name + '"'}}}}; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 647 | decls.push_back(std::move(meta_if)); |
| 648 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 649 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 650 | const AidlConstantValue& value = constant->GetValue(); |
| 651 | if (value.GetType() != AidlConstantValue::Type::STRING) continue; |
| 652 | |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 653 | unique_ptr<MethodImpl> getter(new MethodImpl( |
| 654 | "const ::android::String16&", |
| 655 | ClassName(interface, ClassNames::INTERFACE), |
| 656 | constant->GetName(), |
| 657 | {})); |
| 658 | getter->GetStatementBlock()->AddLiteral( |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 659 | StringPrintf("static const ::android::String16 value(%s)", value.ToString().c_str())); |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 660 | getter->GetStatementBlock()->AddLiteral("return value"); |
| 661 | decls.push_back(std::move(getter)); |
| 662 | } |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 663 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 664 | // Implement the default impl class. |
| 665 | // onAsBinder returns nullptr as this interface is not associated with a |
| 666 | // real binder. |
| 667 | const string default_impl(ClassName(interface, ClassNames::DEFAULT_IMPL)); |
| 668 | decls.emplace_back( |
| 669 | new LiteralDecl(StringPrintf("::android::IBinder* %s::onAsBinder() {\n" |
| 670 | " return nullptr;\n" |
| 671 | "}\n", |
| 672 | default_impl.c_str()))); |
| 673 | // Each interface method by default returns UNKNOWN_TRANSACTION with is |
| 674 | // the same status that is returned by transact() when the method is |
| 675 | // not implemented in the server side. In other words, these default |
| 676 | // methods do nothing; they only exist to aid making a real default |
| 677 | // impl class without having to override all methods in an interface. |
| 678 | for (const auto& method : interface.GetMethods()) { |
| 679 | decls.emplace_back(new LiteralDecl(StringPrintf( |
| 680 | "::android::binder::Status %s::%s%s {\n" |
| 681 | " return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);\n" |
| 682 | "}\n", |
| 683 | default_impl.c_str(), method->GetName().c_str(), |
| 684 | BuildArgList(types, *method, true, true).ToString().c_str()))); |
| 685 | } |
| 686 | |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 687 | return unique_ptr<Document>{new CppSource{ |
| 688 | include_list, |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 689 | NestInNamespaces(std::move(decls), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 692 | unique_ptr<Document> BuildClientHeader(const TypeNamespace& types, |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 693 | const AidlInterface& interface) { |
| 694 | const string i_name = ClassName(interface, ClassNames::INTERFACE); |
| 695 | const string bp_name = ClassName(interface, ClassNames::CLIENT); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 696 | |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 697 | unique_ptr<ConstructorDecl> constructor{new ConstructorDecl{ |
| 698 | bp_name, |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 699 | ArgList{StringPrintf("const ::android::sp<::android::IBinder>& %s", |
| 700 | kImplVarName)}, |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 701 | ConstructorDecl::IS_EXPLICIT |
| 702 | }}; |
| 703 | unique_ptr<ConstructorDecl> destructor{new ConstructorDecl{ |
| 704 | "~" + bp_name, |
| 705 | ArgList{}, |
| 706 | ConstructorDecl::IS_VIRTUAL | ConstructorDecl::IS_DEFAULT}}; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 707 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 708 | vector<unique_ptr<Declaration>> publics; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 709 | publics.push_back(std::move(constructor)); |
| 710 | publics.push_back(std::move(destructor)); |
| 711 | |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 712 | for (const auto& method: interface.GetMethods()) { |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 713 | publics.push_back(BuildMethodDecl(*method, types, false)); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 716 | unique_ptr<ClassDecl> bp_class{ |
| 717 | new ClassDecl{bp_name, |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 718 | "::android::BpInterface<" + i_name + ">", |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 719 | std::move(publics), |
| 720 | {} |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 721 | }}; |
| 722 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 723 | return unique_ptr<Document>{new CppHeader{ |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 724 | BuildHeaderGuard(interface, ClassNames::CLIENT), |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 725 | {kIBinderHeader, |
| 726 | kIInterfaceHeader, |
| 727 | "utils/Errors.h", |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 728 | HeaderFile(interface, ClassNames::INTERFACE, false)}, |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 729 | NestInNamespaces(std::move(bp_class), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Christopher Wiley | f59c499 | 2015-10-08 13:12:44 -0700 | [diff] [blame] | 732 | unique_ptr<Document> BuildServerHeader(const TypeNamespace& /* types */, |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 733 | const AidlInterface& interface) { |
| 734 | const string i_name = ClassName(interface, ClassNames::INTERFACE); |
| 735 | const string bn_name = ClassName(interface, ClassNames::SERVER); |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 736 | |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 737 | unique_ptr<Declaration> on_transact{new MethodDecl{ |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 738 | kAndroidStatusLiteral, "onTransact", |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 739 | ArgList{{StringPrintf("uint32_t %s", kCodeVarName), |
| 740 | StringPrintf("const %s& %s", kAndroidParcelLiteral, |
| 741 | kDataVarName), |
| 742 | StringPrintf("%s* %s", kAndroidParcelLiteral, kReplyVarName), |
| 743 | StringPrintf("uint32_t %s = 0", kFlagsVarName)}}, |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 744 | MethodDecl::IS_OVERRIDE |
| 745 | }}; |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 746 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 747 | std::vector<unique_ptr<Declaration>> publics; |
Casey Dahlin | b7d0f7f | 2015-09-22 17:21:08 -0700 | [diff] [blame] | 748 | publics.push_back(std::move(on_transact)); |
| 749 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 750 | unique_ptr<ClassDecl> bn_class{ |
| 751 | new ClassDecl{bn_name, |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 752 | "::android::BnInterface<" + i_name + ">", |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 753 | std::move(publics), |
| 754 | {} |
Casey Dahlin | b7d0f7f | 2015-09-22 17:21:08 -0700 | [diff] [blame] | 755 | }}; |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 756 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 757 | return unique_ptr<Document>{new CppHeader{ |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 758 | BuildHeaderGuard(interface, ClassNames::SERVER), |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 759 | {"binder/IInterface.h", |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 760 | HeaderFile(interface, ClassNames::INTERFACE, false)}, |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 761 | NestInNamespaces(std::move(bn_class), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 764 | unique_ptr<Document> BuildInterfaceHeader(const TypeNamespace& types, |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 765 | const AidlInterface& interface) { |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 766 | set<string> includes = {kIBinderHeader, kIInterfaceHeader, kStatusHeader, kStrongPointerHeader}; |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 767 | |
| 768 | for (const auto& method : interface.GetMethods()) { |
| 769 | for (const auto& argument : method->GetArguments()) { |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 770 | const Type* type = argument->GetType().GetLanguageType<Type>(); |
| 771 | type->GetHeaders(&includes); |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 774 | const Type* return_type = method->GetType().GetLanguageType<Type>(); |
| 775 | return_type->GetHeaders(&includes); |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 778 | const string i_name = ClassName(interface, ClassNames::INTERFACE); |
| 779 | unique_ptr<ClassDecl> if_class{new ClassDecl{i_name, "::android::IInterface"}}; |
Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame] | 780 | if_class->AddPublic(unique_ptr<Declaration>{new MacroDecl{ |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 781 | "DECLARE_META_INTERFACE", |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 782 | ArgList{vector<string>{ClassName(interface, ClassNames::BASE)}}}}); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 783 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 784 | std::vector<std::unique_ptr<Declaration>> string_constants; |
| 785 | unique_ptr<Enum> int_constant_enum{new Enum{"", "int32_t"}}; |
| 786 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 787 | const AidlConstantValue& value = constant->GetValue(); |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 788 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 789 | switch (value.GetType()) { |
| 790 | case AidlConstantValue::Type::STRING: { |
| 791 | unique_ptr<Declaration> getter(new MethodDecl( |
| 792 | "const ::android::String16&", constant->GetName(), {}, MethodDecl::IS_STATIC)); |
| 793 | string_constants.push_back(std::move(getter)); |
| 794 | break; |
| 795 | } |
| 796 | case AidlConstantValue::Type::INTEGER: { |
| 797 | int_constant_enum->AddValue(constant->GetName(), value.ToString()); |
| 798 | break; |
| 799 | } |
| 800 | default: { |
| 801 | LOG(FATAL) << "Unrecognized constant type: " << static_cast<int>(value.GetType()); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | if (int_constant_enum->HasValues()) { |
| 806 | if_class->AddPublic(std::move(int_constant_enum)); |
| 807 | } |
| 808 | if (!string_constants.empty()) { |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 809 | includes.insert(kString16Header); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 810 | |
| 811 | for (auto& string_constant : string_constants) { |
| 812 | if_class->AddPublic(std::move(string_constant)); |
| 813 | } |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 814 | } |
Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 815 | |
| 816 | if (interface.ShouldGenerateTraces()) { |
| 817 | includes.insert(kTraceHeader); |
| 818 | } |
| 819 | |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 820 | if (!interface.GetMethods().empty()) { |
| 821 | unique_ptr<Enum> call_enum{new Enum{"Call"}}; |
| 822 | for (const auto& method : interface.GetMethods()) { |
| 823 | // Each method gets an enum entry and pure virtual declaration. |
| 824 | if_class->AddPublic(BuildMethodDecl(*method, types, true)); |
| 825 | call_enum->AddValue( |
| 826 | UpperCase(method->GetName()), |
| 827 | StringPrintf("::android::IBinder::FIRST_CALL_TRANSACTION + %d", |
| 828 | method->GetId())); |
| 829 | } |
| 830 | if_class->AddPublic(std::move(call_enum)); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 831 | } |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 832 | |
Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 833 | vector<unique_ptr<Declaration>> decls; |
| 834 | decls.emplace_back(std::move(if_class)); |
| 835 | |
| 836 | // Base class for the default implementation. |
| 837 | vector<string> method_decls; |
| 838 | for (const auto& method : interface.GetMethods()) { |
| 839 | method_decls.emplace_back(BuildMethodDecl(*method, types, false)->ToString()); |
| 840 | } |
| 841 | decls.emplace_back(new LiteralDecl( |
| 842 | android::base::StringPrintf("class %s : public %s {\n" |
| 843 | "public:\n" |
| 844 | " ::android::IBinder* onAsBinder() override;\n" |
| 845 | " %s\n" |
| 846 | "};\n", |
| 847 | ClassName(interface, ClassNames::DEFAULT_IMPL).c_str(), |
| 848 | i_name.c_str(), Join(method_decls, " ").c_str()))); |
| 849 | |
| 850 | return unique_ptr<Document>{ |
| 851 | new CppHeader{BuildHeaderGuard(interface, ClassNames::INTERFACE), |
| 852 | vector<string>(includes.begin(), includes.end()), |
| 853 | NestInNamespaces(std::move(decls), interface.GetSplitPackage())}}; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 856 | std::unique_ptr<Document> BuildParcelHeader(const TypeNamespace& /*types*/, |
| 857 | const AidlStructuredParcelable& parcel) { |
| 858 | unique_ptr<ClassDecl> parcel_class{new ClassDecl{parcel.GetName(), "::android::Parcelable"}}; |
| 859 | |
| 860 | set<string> includes = {kStatusHeader, kParcelHeader}; |
| 861 | for (const auto& variable : parcel.GetFields()) { |
| 862 | const Type* type = variable->GetType().GetLanguageType<Type>(); |
| 863 | type->GetHeaders(&includes); |
| 864 | } |
| 865 | |
| 866 | for (const auto& variable : parcel.GetFields()) { |
| 867 | const Type* type = variable->GetType().GetLanguageType<Type>(); |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame^] | 868 | const AidlConstantValue* default_value = variable->GetDefaultValue(); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 869 | |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame^] | 870 | std::ostringstream out; |
| 871 | out << type->CppType().c_str() << " " << variable->GetName().c_str(); |
| 872 | if (default_value) { |
| 873 | out << " = " << type->CppType().c_str() << "(" << default_value->ToString() << ")"; |
| 874 | } |
| 875 | out << ";\n"; |
| 876 | |
| 877 | parcel_class->AddPublic(std::unique_ptr<LiteralDecl>(new LiteralDecl(out.str()))); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | unique_ptr<MethodDecl> read(new MethodDecl(kAndroidStatusLiteral, "readFromParcel", |
Steven Moreland | ce39c53 | 2018-07-11 16:59:50 -0700 | [diff] [blame] | 881 | ArgList("const ::android::Parcel* _aidl_parcel"), |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 882 | MethodDecl::IS_OVERRIDE)); |
| 883 | parcel_class->AddPublic(std::move(read)); |
| 884 | unique_ptr<MethodDecl> write(new MethodDecl(kAndroidStatusLiteral, "writeToParcel", |
Steven Moreland | ce39c53 | 2018-07-11 16:59:50 -0700 | [diff] [blame] | 885 | ArgList("::android::Parcel* _aidl_parcel"), |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 886 | MethodDecl::IS_OVERRIDE | MethodDecl::IS_CONST)); |
| 887 | parcel_class->AddPublic(std::move(write)); |
| 888 | |
| 889 | return unique_ptr<Document>{new CppHeader{ |
| 890 | BuildHeaderGuard(parcel, ClassNames::BASE), vector<string>(includes.begin(), includes.end()), |
| 891 | NestInNamespaces(std::move(parcel_class), parcel.GetSplitPackage())}}; |
| 892 | } |
Steven Moreland | 1c41e97 | 2018-07-09 16:07:00 -0700 | [diff] [blame] | 893 | std::unique_ptr<Document> BuildParcelSource(const TypeNamespace& /*types*/, |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 894 | const AidlStructuredParcelable& parcel) { |
| 895 | unique_ptr<MethodImpl> read{new MethodImpl{kAndroidStatusLiteral, parcel.GetName(), |
| 896 | "readFromParcel", |
Steven Moreland | ce39c53 | 2018-07-11 16:59:50 -0700 | [diff] [blame] | 897 | ArgList("const ::android::Parcel* _aidl_parcel")}}; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 898 | StatementBlock* read_block = read->GetStatementBlock(); |
| 899 | read_block->AddLiteral( |
| 900 | StringPrintf("%s %s = %s", kAndroidStatusLiteral, kAndroidStatusVarName, kAndroidStatusOk)); |
| 901 | for (const auto& variable : parcel.GetFields()) { |
| 902 | string method = variable->GetType().GetLanguageType<Type>()->ReadFromParcelMethod(); |
| 903 | |
| 904 | read_block->AddStatement(new Assignment( |
| 905 | kAndroidStatusVarName, new MethodCall(StringPrintf("_aidl_parcel->%s", method.c_str()), |
| 906 | ArgList("&" + variable->GetName())))); |
| 907 | read_block->AddStatement(ReturnOnStatusNotOk()); |
| 908 | } |
| 909 | read_block->AddLiteral(StringPrintf("return %s", kAndroidStatusVarName)); |
| 910 | |
Steven Moreland | ce39c53 | 2018-07-11 16:59:50 -0700 | [diff] [blame] | 911 | unique_ptr<MethodImpl> write{ |
| 912 | new MethodImpl{kAndroidStatusLiteral, parcel.GetName(), "writeToParcel", |
| 913 | ArgList("::android::Parcel* _aidl_parcel"), true /*const*/}}; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 914 | StatementBlock* write_block = write->GetStatementBlock(); |
| 915 | write_block->AddLiteral( |
| 916 | StringPrintf("%s %s = %s", kAndroidStatusLiteral, kAndroidStatusVarName, kAndroidStatusOk)); |
| 917 | for (const auto& variable : parcel.GetFields()) { |
| 918 | string method = variable->GetType().GetLanguageType<Type>()->WriteToParcelMethod(); |
| 919 | |
| 920 | write_block->AddStatement(new Assignment( |
| 921 | kAndroidStatusVarName, new MethodCall(StringPrintf("_aidl_parcel->%s", method.c_str()), |
| 922 | ArgList(variable->GetName())))); |
| 923 | write_block->AddStatement(ReturnOnStatusNotOk()); |
| 924 | } |
| 925 | write_block->AddLiteral(StringPrintf("return %s", kAndroidStatusVarName)); |
| 926 | |
| 927 | vector<unique_ptr<Declaration>> file_decls; |
| 928 | file_decls.push_back(std::move(read)); |
| 929 | file_decls.push_back(std::move(write)); |
| 930 | |
| 931 | set<string> includes = {}; |
| 932 | parcel.GetLanguageType<Type>()->GetHeaders(&includes); |
| 933 | |
| 934 | return unique_ptr<Document>{ |
| 935 | new CppSource{vector<string>(includes.begin(), includes.end()), |
| 936 | NestInNamespaces(std::move(file_decls), parcel.GetSplitPackage())}}; |
| 937 | } |
| 938 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 939 | bool WriteHeader(const CppOptions& options, |
| 940 | const TypeNamespace& types, |
| 941 | const AidlInterface& interface, |
| 942 | const IoDelegate& io_delegate, |
| 943 | ClassNames header_type) { |
| 944 | unique_ptr<Document> header; |
| 945 | switch (header_type) { |
| 946 | case ClassNames::INTERFACE: |
| 947 | header = BuildInterfaceHeader(types, interface); |
| 948 | break; |
| 949 | case ClassNames::CLIENT: |
| 950 | header = BuildClientHeader(types, interface); |
| 951 | break; |
| 952 | case ClassNames::SERVER: |
| 953 | header = BuildServerHeader(types, interface); |
| 954 | break; |
| 955 | default: |
| 956 | LOG(FATAL) << "aidl internal error"; |
| 957 | } |
| 958 | if (!header) { |
| 959 | LOG(ERROR) << "aidl internal error: Failed to generate header."; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 960 | return false; |
| 961 | } |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 962 | |
Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 963 | const string header_path = options.OutputHeaderDir() + OS_PATH_SEPARATOR + |
| 964 | HeaderFile(interface, header_type); |
| 965 | unique_ptr<CodeWriter> code_writer(io_delegate.GetCodeWriter(header_path)); |
| 966 | header->Write(code_writer.get()); |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 967 | |
Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 968 | const bool success = code_writer->Close(); |
| 969 | if (!success) { |
| 970 | io_delegate.RemovePath(header_path); |
| 971 | } |
| 972 | |
| 973 | return success; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 976 | } // namespace internals |
| 977 | |
| 978 | using namespace internals; |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 979 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 980 | string HeaderFile(const AidlDefinedType& defined_type, ClassNames class_type, bool use_os_sep) { |
| 981 | string file_path = defined_type.GetPackage(); |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 982 | for (char& c: file_path) { |
| 983 | if (c == '.') { |
| 984 | c = (use_os_sep) ? OS_PATH_SEPARATOR : '/'; |
| 985 | } |
| 986 | } |
| 987 | if (!file_path.empty()) { |
| 988 | file_path += (use_os_sep) ? OS_PATH_SEPARATOR : '/'; |
| 989 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 990 | file_path += ClassName(defined_type, class_type); |
Christopher Wiley | 3a9911c | 2016-01-19 12:59:09 -0800 | [diff] [blame] | 991 | file_path += ".h"; |
| 992 | |
| 993 | return file_path; |
| 994 | } |
| 995 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 996 | bool GenerateCppInterface(const CppOptions& options, const TypeNamespace& types, |
| 997 | const AidlInterface& interface, const IoDelegate& io_delegate) { |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 998 | auto interface_src = BuildInterfaceSource(types, interface); |
| 999 | auto client_src = BuildClientSource(types, interface); |
| 1000 | auto server_src = BuildServerSource(types, interface); |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 1001 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 1002 | if (!interface_src || !client_src || !server_src) { |
| 1003 | return false; |
| 1004 | } |
Christopher Wiley | 9a8e1d9 | 2015-09-19 10:34:33 -0700 | [diff] [blame] | 1005 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 1006 | if (!io_delegate.CreatedNestedDirs(options.OutputHeaderDir(), |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 1007 | interface.GetSplitPackage())) { |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 1008 | LOG(ERROR) << "Failed to create directory structure for headers."; |
| 1009 | return false; |
| 1010 | } |
| 1011 | |
| 1012 | if (!WriteHeader(options, types, interface, io_delegate, |
| 1013 | ClassNames::INTERFACE) || |
| 1014 | !WriteHeader(options, types, interface, io_delegate, |
| 1015 | ClassNames::CLIENT) || |
| 1016 | !WriteHeader(options, types, interface, io_delegate, |
| 1017 | ClassNames::SERVER)) { |
| 1018 | return false; |
| 1019 | } |
| 1020 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 1021 | unique_ptr<CodeWriter> writer = io_delegate.GetCodeWriter( |
| 1022 | options.OutputCppFilePath()); |
| 1023 | interface_src->Write(writer.get()); |
| 1024 | client_src->Write(writer.get()); |
| 1025 | server_src->Write(writer.get()); |
| 1026 | |
Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 1027 | const bool success = writer->Close(); |
| 1028 | if (!success) { |
| 1029 | io_delegate.RemovePath(options.OutputCppFilePath()); |
| 1030 | } |
| 1031 | |
| 1032 | return success; |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 1035 | bool GenerateCppParcel(const CppOptions& options, const cpp::TypeNamespace& types, |
| 1036 | const AidlStructuredParcelable& parcelable, const IoDelegate& io_delegate) { |
| 1037 | auto header = BuildParcelHeader(types, parcelable); |
| 1038 | auto source = BuildParcelSource(types, parcelable); |
| 1039 | |
| 1040 | if (!header || !source) { |
| 1041 | return false; |
| 1042 | } |
| 1043 | |
| 1044 | if (!io_delegate.CreatedNestedDirs(options.OutputHeaderDir(), parcelable.GetSplitPackage())) { |
| 1045 | LOG(ERROR) << "Failed to create directory structure for headers."; |
| 1046 | } |
| 1047 | |
| 1048 | const string header_path = |
| 1049 | options.OutputHeaderDir() + OS_PATH_SEPARATOR + HeaderFile(parcelable, ClassNames::BASE); |
| 1050 | unique_ptr<CodeWriter> header_writer(io_delegate.GetCodeWriter(header_path)); |
| 1051 | header->Write(header_writer.get()); |
| 1052 | CHECK(header_writer->Close()); |
| 1053 | |
Steven Moreland | 81079f9 | 2018-07-06 16:15:53 -0700 | [diff] [blame] | 1054 | // TODO(b/111362593): no unecessary files just to have consistent output with interfaces |
| 1055 | const string bp_header = |
| 1056 | options.OutputHeaderDir() + OS_PATH_SEPARATOR + HeaderFile(parcelable, ClassNames::CLIENT); |
| 1057 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 1058 | bp_writer->Write("#error TODO(b/111362593) parcelables do not have bp classes"); |
| 1059 | CHECK(bp_writer->Close()); |
| 1060 | const string bn_header = |
| 1061 | options.OutputHeaderDir() + OS_PATH_SEPARATOR + HeaderFile(parcelable, ClassNames::SERVER); |
| 1062 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 1063 | bn_writer->Write("#error TODO(b/111362593) parcelables do not have bn classes"); |
| 1064 | CHECK(bn_writer->Close()); |
| 1065 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 1066 | unique_ptr<CodeWriter> source_writer = io_delegate.GetCodeWriter(options.OutputCppFilePath()); |
| 1067 | source->Write(source_writer.get()); |
| 1068 | CHECK(source_writer->Close()); |
| 1069 | |
| 1070 | return true; |
| 1071 | } |
| 1072 | |
| 1073 | bool GenerateCpp(const CppOptions& options, const TypeNamespace& types, |
| 1074 | const AidlDefinedType& defined_type, const IoDelegate& io_delegate) { |
| 1075 | const AidlStructuredParcelable* parcelable = defined_type.AsStructuredParcelable(); |
| 1076 | if (parcelable != nullptr) { |
| 1077 | return GenerateCppParcel(options, types, *parcelable, io_delegate); |
| 1078 | } |
| 1079 | |
| 1080 | const AidlInterface* interface = defined_type.AsInterface(); |
| 1081 | if (interface != nullptr) { |
| 1082 | return GenerateCppInterface(options, types, *interface, io_delegate); |
| 1083 | } |
| 1084 | |
| 1085 | CHECK(false) << "Unrecognized type sent for cpp generation."; |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 1089 | } // namespace cpp |
Christopher Wiley | eb1acc1 | 2015-09-16 11:25:13 -0700 | [diff] [blame] | 1090 | } // namespace aidl |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 1091 | } // namespace android |