Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -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 "type_cpp.h" |
| 18 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 19 | #include <algorithm> |
| 20 | #include <iostream> |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 21 | #include <vector> |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 23 | #include <android-base/stringprintf.h> |
| 24 | #include <android-base/strings.h> |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 25 | |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 26 | #include "logging.h" |
| 27 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 28 | using std::cerr; |
| 29 | using std::endl; |
Christopher Wiley | 8a65797 | 2015-10-28 16:03:45 -0700 | [diff] [blame] | 30 | using std::set; |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 31 | using std::string; |
| 32 | using std::unique_ptr; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 33 | using std::vector; |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 34 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 35 | using android::base::Split; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 36 | using android::base::Join; |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 37 | using android::base::StringPrintf; |
| 38 | |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 39 | namespace android { |
| 40 | namespace aidl { |
| 41 | namespace cpp { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 44 | const char kNoPackage[] = ""; |
| 45 | const char kNoHeader[] = ""; |
| 46 | const char kNoValidMethod[] = ""; |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 47 | Type* const kNoArrayType = nullptr; |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 48 | Type* const kNoNullableType = nullptr; |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 49 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 50 | bool is_cpp_keyword(const std::string& str) { |
| 51 | static const std::vector<std::string> kCppKeywords{ |
| 52 | "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", |
| 53 | "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "class", |
| 54 | "compl", "concept", "const", "constexpr", "const_cast", "continue", |
| 55 | "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", |
| 56 | "enum", "explicit", "export", "extern", "false", "float", "for", "friend", |
| 57 | "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", |
| 58 | "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", |
| 59 | "private", "protected", "public", "register", "reinterpret_cast", |
| 60 | "requires", "return", "short", "signed", "sizeof", "static", |
| 61 | "static_assert", "static_cast", "struct", "switch", "template", "this", |
| 62 | "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", |
| 63 | "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", |
| 64 | "while", "xor", "xor_eq", |
| 65 | }; |
| 66 | return std::find(kCppKeywords.begin(), kCppKeywords.end(), str) != |
| 67 | kCppKeywords.end(); |
| 68 | } |
| 69 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 70 | class VoidType : public Type { |
| 71 | public: |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 72 | VoidType() : Type(ValidatableType::KIND_BUILT_IN, kNoPackage, "void", |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 73 | {}, "void", kNoValidMethod, kNoValidMethod) {} |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 74 | virtual ~VoidType() = default; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 75 | bool CanBeOutParameter() const override { return false; } |
| 76 | bool CanWriteToParcel() const override { return false; } |
| 77 | }; // class VoidType |
| 78 | |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 79 | class CppArrayType : public Type { |
| 80 | public: |
| 81 | CppArrayType(int kind, // from ValidatableType |
| 82 | const std::string& package, |
| 83 | const string& underlying_aidl_type, |
| 84 | const string& cpp_header, |
| 85 | const string& underlying_cpp_type, |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 86 | const string& underlying_cpp_type_nulllable, |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 87 | const string& read_method, |
| 88 | const string& write_method, |
| 89 | bool is_nullable, |
| 90 | const string& src_file_name = "") |
| 91 | : Type(kind, package, |
| 92 | underlying_aidl_type + "[]", |
| 93 | GetHeaders(is_nullable, cpp_header), |
| 94 | GetCppType(is_nullable, underlying_cpp_type), |
| 95 | read_method, write_method, kNoArrayType, |
| 96 | (is_nullable) |
| 97 | ? kNoNullableType |
| 98 | // All arrays are nullable. |
| 99 | : new CppArrayType(kind, package, underlying_aidl_type, |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 100 | cpp_header, underlying_cpp_type_nulllable, |
| 101 | underlying_cpp_type_nulllable, |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 102 | read_method, write_method, true), |
| 103 | src_file_name) {} |
| 104 | |
| 105 | bool CanBeOutParameter() const override { return true; } |
| 106 | |
| 107 | private: |
| 108 | static vector<string> GetHeaders(bool is_nullable, const string& cpp_header) { |
| 109 | vector<string> result = {"vector"}; |
| 110 | if (is_nullable) { |
| 111 | result.push_back("memory"); |
| 112 | } |
| 113 | if (!cpp_header.empty()) { |
| 114 | result.push_back(cpp_header); |
| 115 | } |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | static string GetCppType(bool is_nullable, |
| 120 | const string& underlying_cpp_type) { |
| 121 | if (is_nullable) |
| 122 | return StringPrintf("::std::unique_ptr<::std::vector<%s>>", |
| 123 | underlying_cpp_type.c_str()); |
| 124 | return StringPrintf("::std::vector<%s>", |
| 125 | underlying_cpp_type.c_str()); |
| 126 | } |
| 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(CppArrayType); |
| 129 | }; // class CppArrayType |
| 130 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 131 | class PrimitiveType : public Type { |
| 132 | public: |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 133 | PrimitiveType(const std::string& aidl_type, |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 134 | const std::string& header, |
| 135 | const std::string& cpp_type, |
| 136 | const std::string& read_method, |
| 137 | const std::string& write_method, |
| 138 | const std::string& read_array_method, |
| 139 | const std::string& write_array_method) |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 140 | : Type(ValidatableType::KIND_BUILT_IN, kNoPackage, aidl_type, {header}, |
| 141 | cpp_type, read_method, write_method, |
| 142 | new CppArrayType(ValidatableType::KIND_BUILT_IN, kNoPackage, |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 143 | aidl_type, header, cpp_type, cpp_type, |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 144 | read_array_method, write_array_method, |
| 145 | false)) {} |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 146 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 147 | virtual ~PrimitiveType() = default; |
| 148 | bool IsCppPrimitive() const override { return true; } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 149 | |
| 150 | private: |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 151 | DISALLOW_COPY_AND_ASSIGN(PrimitiveType); |
| 152 | }; // class PrimitiveType |
| 153 | |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 154 | // Unfortunately, bytes in Java are signed. However, most C authors would |
| 155 | // say that a byte is not in fact signed. Compromise: customize this otherwise |
| 156 | // normal primitive to use signed single bytes, but unsigned byte arrays. |
Casey Dahlin | e9e73f1 | 2016-02-09 11:10:17 -0800 | [diff] [blame] | 157 | class ByteType : public Type { |
| 158 | public: |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 159 | ByteType() |
| 160 | : Type(ValidatableType::KIND_BUILT_IN, kNoPackage, "byte", |
| 161 | {"cstdint"}, "int8_t", "readByte", "writeByte", |
| 162 | new CppArrayType(ValidatableType::KIND_BUILT_IN, kNoPackage, |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 163 | "byte", "cstdint", "uint8_t", "uint8_t", |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 164 | "readByteVector", "writeByteVector", |
| 165 | false)) {} |
Casey Dahlin | e9e73f1 | 2016-02-09 11:10:17 -0800 | [diff] [blame] | 166 | |
| 167 | virtual ~ByteType() = default; |
| 168 | bool IsCppPrimitive() const override { return true; } |
Casey Dahlin | e9e73f1 | 2016-02-09 11:10:17 -0800 | [diff] [blame] | 169 | |
| 170 | private: |
Casey Dahlin | e9e73f1 | 2016-02-09 11:10:17 -0800 | [diff] [blame] | 171 | DISALLOW_COPY_AND_ASSIGN(ByteType); |
| 172 | }; // class PrimitiveType |
| 173 | |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 174 | class BinderType : public Type { |
| 175 | public: |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 176 | BinderType(const AidlInterface& interface, const std::string& src_file_name) |
Casey Dahlin | ef88bce | 2016-04-15 11:55:30 -0700 | [diff] [blame] | 177 | : BinderType(interface, src_file_name, |
| 178 | new BinderType(interface, src_file_name, kNoNullableType, |
| 179 | "readNullableStrongBinder"), |
| 180 | "readStrongBinder") {} |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 181 | virtual ~BinderType() = default; |
| 182 | |
| 183 | string WriteCast(const string& val) const override { |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 184 | return write_cast_ + "(" + val + ")"; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | private: |
Casey Dahlin | ef88bce | 2016-04-15 11:55:30 -0700 | [diff] [blame] | 188 | BinderType(const AidlInterface& interface, |
| 189 | const std::string& src_file_name, |
| 190 | Type* nullable_type, const std::string& read) |
| 191 | : Type(ValidatableType::KIND_GENERATED, |
| 192 | interface.GetPackage(), interface.GetName(), |
| 193 | {GetCppHeader(interface)}, GetCppName(interface), |
| 194 | read, "writeStrongBinder", kNoArrayType, nullable_type, |
| 195 | src_file_name, interface.GetLine()), |
| 196 | write_cast_(GetRawCppName(interface) + "::asBinder") {} |
| 197 | |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 198 | static string GetCppName(const AidlInterface& interface) { |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 199 | return "::android::sp<" + GetRawCppName(interface) + ">"; |
| 200 | } |
| 201 | |
| 202 | static string GetRawCppName(const AidlInterface& interface) { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 203 | vector<string> name = interface.GetSplitPackage(); |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 204 | string ret; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 205 | |
| 206 | name.push_back(interface.GetName()); |
| 207 | |
| 208 | for (const auto& term : name) { |
| 209 | ret += "::" + term; |
| 210 | } |
| 211 | |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 212 | return ret; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static string GetCppHeader(const AidlInterface& interface) { |
| 216 | vector<string> name = interface.GetSplitPackage(); |
| 217 | name.push_back(interface.GetName()); |
| 218 | return Join(name, '/') + ".h"; |
| 219 | } |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 220 | |
| 221 | std::string write_cast_; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 224 | class NullableParcelableType : public Type { |
| 225 | public: |
| 226 | NullableParcelableType(const AidlParcelable& parcelable, |
| 227 | const std::string& src_file_name) |
| 228 | : Type(ValidatableType::KIND_PARCELABLE, |
| 229 | parcelable.GetPackage(), parcelable.GetName(), |
| 230 | {parcelable.GetCppHeader()}, GetCppName(parcelable), |
| 231 | "readParcelable", "writeNullableParcelable", |
| 232 | kNoArrayType, kNoNullableType, |
| 233 | src_file_name, parcelable.GetLine()) {} |
| 234 | virtual ~NullableParcelableType() = default; |
| 235 | bool CanBeOutParameter() const override { return true; } |
| 236 | |
| 237 | private: |
| 238 | static string GetCppName(const AidlParcelable& parcelable) { |
| 239 | return "::std::unique_ptr<::" + Join(parcelable.GetSplitPackage(), "::") + |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 240 | "::" + parcelable.GetCppName() + ">"; |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 241 | } |
| 242 | }; |
| 243 | |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 244 | class ParcelableType : public Type { |
| 245 | public: |
| 246 | ParcelableType(const AidlParcelable& parcelable, |
| 247 | const std::string& src_file_name) |
| 248 | : Type(ValidatableType::KIND_PARCELABLE, |
| 249 | parcelable.GetPackage(), parcelable.GetName(), |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 250 | {parcelable.GetCppHeader()}, GetCppName(parcelable), |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 251 | "readParcelable", "writeParcelable", |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 252 | new CppArrayType( |
| 253 | ValidatableType::KIND_PARCELABLE, parcelable.GetPackage(), |
| 254 | parcelable.GetName(), parcelable.GetCppHeader(), |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 255 | GetCppName(parcelable), GetCppName(parcelable), |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 256 | "readParcelableVector", "writeParcelableVector", false, |
| 257 | src_file_name), |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 258 | new NullableParcelableType(parcelable, src_file_name), |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 259 | src_file_name, parcelable.GetLine()) {} |
| 260 | virtual ~ParcelableType() = default; |
| 261 | bool CanBeOutParameter() const override { return true; } |
| 262 | |
| 263 | private: |
| 264 | static string GetCppName(const AidlParcelable& parcelable) { |
Casey Dahlin | 8cfb588 | 2015-12-03 16:15:41 -0800 | [diff] [blame] | 265 | return "::" + Join(parcelable.GetSplitPackage(), "::") + |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 266 | "::" + parcelable.GetCppName(); |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 267 | } |
| 268 | }; |
| 269 | |
Robert Quattlebaum | cd8c135 | 2017-01-04 13:42:51 -0800 | [diff] [blame] | 270 | class NullableMap : public Type { |
| 271 | public: |
| 272 | NullableMap() |
| 273 | : Type(ValidatableType::KIND_BUILT_IN, |
| 274 | "java.util", "Map", |
| 275 | {"binder/Map.h", "binder/Value.h"}, |
| 276 | "::std::unique_ptr<::android::binder::Map>", |
| 277 | "readNullableMap", "writeNullableMap") {} |
| 278 | virtual ~NullableMap() = default; |
| 279 | bool CanBeOutParameter() const override { return true; } |
| 280 | }; |
| 281 | |
| 282 | |
| 283 | class MapType : public Type { |
| 284 | public: |
| 285 | MapType() |
| 286 | : Type(ValidatableType::KIND_BUILT_IN, |
| 287 | "java.util", "Map", |
| 288 | {"binder/Map.h","binder/Value.h"}, |
| 289 | "::android::binder::Map", |
| 290 | "readMap", "writeMap", |
| 291 | kNoArrayType, |
| 292 | new NullableMap() ) {} |
| 293 | virtual ~MapType() = default; |
| 294 | bool CanBeOutParameter() const override { return true; } |
| 295 | |
| 296 | private: |
| 297 | DISALLOW_COPY_AND_ASSIGN(MapType); |
| 298 | }; // class MapType |
| 299 | |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 300 | class NullableStringListType : public Type { |
| 301 | public: |
| 302 | NullableStringListType() |
Christopher Wiley | 5d9bc93 | 2016-02-01 13:23:16 -0800 | [diff] [blame] | 303 | : Type(ValidatableType::KIND_BUILT_IN, |
| 304 | "java.util", "List<" + string(kStringCanonicalName) + ">", |
| 305 | {"utils/String16.h", "memory", "vector"}, |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 306 | "::std::unique_ptr<::std::vector<std::unique_ptr<::android::String16>>>", |
| 307 | "readString16Vector", "writeString16Vector") {} |
| 308 | virtual ~NullableStringListType() = default; |
| 309 | bool CanBeOutParameter() const override { return true; } |
| 310 | |
| 311 | private: |
| 312 | DISALLOW_COPY_AND_ASSIGN(NullableStringListType); |
| 313 | }; // class NullableStringListType |
| 314 | |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 315 | class StringListType : public Type { |
| 316 | public: |
| 317 | StringListType() |
Christopher Wiley | 5d9bc93 | 2016-02-01 13:23:16 -0800 | [diff] [blame] | 318 | : Type(ValidatableType::KIND_BUILT_IN, |
| 319 | "java.util", "List<" + string(kStringCanonicalName) + ">", |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 320 | {"utils/String16.h", "vector"}, |
| 321 | "::std::vector<::android::String16>", |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 322 | "readString16Vector", "writeString16Vector", |
| 323 | kNoArrayType, new NullableStringListType()) {} |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 324 | virtual ~StringListType() = default; |
| 325 | bool CanBeOutParameter() const override { return true; } |
| 326 | |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 327 | private: |
| 328 | DISALLOW_COPY_AND_ASSIGN(StringListType); |
| 329 | }; // class StringListType |
| 330 | |
Christopher Wiley | 5d9bc93 | 2016-02-01 13:23:16 -0800 | [diff] [blame] | 331 | class NullableUtf8InCppStringListType : public Type { |
| 332 | public: |
| 333 | NullableUtf8InCppStringListType() |
| 334 | : Type(ValidatableType::KIND_BUILT_IN, |
| 335 | "java.util", "List<" + string(kUtf8InCppStringCanonicalName) + ">", |
| 336 | {"memory", "string", "vector"}, |
| 337 | "::std::unique_ptr<::std::vector<std::unique_ptr<::std::string>>>", |
| 338 | "readUtf8VectorFromUtf16Vector", "writeUtf8VectorAsUtf16Vector") {} |
| 339 | virtual ~NullableUtf8InCppStringListType() = default; |
| 340 | bool CanBeOutParameter() const override { return true; } |
| 341 | |
| 342 | private: |
| 343 | DISALLOW_COPY_AND_ASSIGN(NullableUtf8InCppStringListType); |
| 344 | }; // class NullableUtf8InCppStringListType |
| 345 | |
| 346 | class Utf8InCppStringListType : public Type { |
| 347 | public: |
| 348 | Utf8InCppStringListType() |
| 349 | : Type(ValidatableType::KIND_BUILT_IN, |
| 350 | "java.util", "List<" + string(kUtf8InCppStringCanonicalName) + ">", |
| 351 | {"string", "vector"}, |
| 352 | "::std::vector<::std::string>", |
| 353 | "readUtf8VectorFromUtf16Vector", "writeUtf8VectorAsUtf16Vector", |
| 354 | kNoArrayType, new NullableUtf8InCppStringListType()) {} |
| 355 | virtual ~Utf8InCppStringListType() = default; |
| 356 | bool CanBeOutParameter() const override { return true; } |
| 357 | |
| 358 | private: |
| 359 | DISALLOW_COPY_AND_ASSIGN(Utf8InCppStringListType); |
| 360 | }; // class Utf8InCppStringListType |
| 361 | |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 362 | class NullableBinderListType : public Type { |
| 363 | public: |
| 364 | NullableBinderListType() |
| 365 | : Type(ValidatableType::KIND_BUILT_IN, "java.util", |
| 366 | "List<android.os.IBinder>", {"binder/IBinder.h", "vector"}, |
| 367 | "::std::unique_ptr<::std::vector<::android::sp<::android::IBinder>>>", |
| 368 | "readStrongBinderVector", "writeStrongBinderVector") {} |
| 369 | virtual ~NullableBinderListType() = default; |
| 370 | bool CanBeOutParameter() const override { return true; } |
| 371 | |
| 372 | private: |
| 373 | DISALLOW_COPY_AND_ASSIGN(NullableBinderListType); |
| 374 | }; // class NullableBinderListType |
| 375 | |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 376 | class BinderListType : public Type { |
| 377 | public: |
| 378 | BinderListType() |
| 379 | : Type(ValidatableType::KIND_BUILT_IN, "java.util", |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 380 | "List<android.os.IBinder>", {"binder/IBinder.h", "vector"}, |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 381 | "::std::vector<::android::sp<::android::IBinder>>", |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 382 | "readStrongBinderVector", "writeStrongBinderVector", |
| 383 | kNoArrayType, new NullableBinderListType()) {} |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 384 | virtual ~BinderListType() = default; |
| 385 | bool CanBeOutParameter() const override { return true; } |
| 386 | |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 387 | private: |
| 388 | DISALLOW_COPY_AND_ASSIGN(BinderListType); |
| 389 | }; // class BinderListType |
| 390 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 391 | } // namespace |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 392 | |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 393 | Type::Type(int kind, |
| 394 | const std::string& package, |
| 395 | const std::string& aidl_type, |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 396 | const vector<string>& headers, |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 397 | const string& cpp_type, |
| 398 | const string& read_method, |
| 399 | const string& write_method, |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 400 | Type* array_type, |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 401 | Type* nullable_type, |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 402 | const string& src_file_name, |
| 403 | int line) |
| 404 | : ValidatableType(kind, package, aidl_type, src_file_name, line), |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 405 | headers_(headers), |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 406 | aidl_type_(aidl_type), |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 407 | cpp_type_(cpp_type), |
| 408 | parcel_read_method_(read_method), |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 409 | parcel_write_method_(write_method), |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 410 | array_type_(array_type), |
| 411 | nullable_type_(nullable_type) {} |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 412 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 413 | bool Type::CanWriteToParcel() const { return true; } |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 414 | |
Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 415 | void TypeNamespace::Init() { |
Casey Dahlin | e9e73f1 | 2016-02-09 11:10:17 -0800 | [diff] [blame] | 416 | Add(new ByteType()); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 417 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 418 | "int", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 419 | "cstdint", "int32_t", "readInt32", "writeInt32", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 420 | "readInt32Vector", "writeInt32Vector")); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 421 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 422 | "long", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 423 | "cstdint", "int64_t", "readInt64", "writeInt64", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 424 | "readInt64Vector", "writeInt64Vector")); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 425 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 426 | "float", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 427 | kNoHeader, "float", "readFloat", "writeFloat", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 428 | "readFloatVector", "writeFloatVector")); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 429 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 430 | "double", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 431 | kNoHeader, "double", "readDouble", "writeDouble", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 432 | "readDoubleVector", "writeDoubleVector")); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 433 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 434 | "boolean", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 435 | kNoHeader, "bool", "readBool", "writeBool", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 436 | "readBoolVector", "writeBoolVector")); |
| 437 | // C++11 defines the char16_t type as a built in for Unicode characters. |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 438 | Add(new PrimitiveType( |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 439 | "char", |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 440 | kNoHeader, "char16_t", "readChar", "writeChar", |
Christopher Wiley | b8e49a4 | 2015-10-27 12:55:18 -0700 | [diff] [blame] | 441 | "readCharVector", "writeCharVector")); |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 442 | |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 443 | Type* string_array_type = new CppArrayType( |
| 444 | ValidatableType::KIND_BUILT_IN, "java.lang", "String", |
| 445 | "utils/String16.h", "::android::String16", |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 446 | "::std::unique_ptr<::android::String16>", "readString16Vector", |
| 447 | "writeString16Vector", false); |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 448 | |
| 449 | Type* nullable_string_type = |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 450 | new Type(ValidatableType::KIND_BUILT_IN, "java.lang", "String", |
Christopher Wiley | e3946d4 | 2016-01-28 15:51:39 -0800 | [diff] [blame] | 451 | {"memory", "utils/String16.h"}, "::std::unique_ptr<::android::String16>", |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 452 | "readString16", "writeString16"); |
| 453 | |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 454 | string_type_ = new Type(ValidatableType::KIND_BUILT_IN, "java.lang", "String", |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 455 | {"utils/String16.h"}, "::android::String16", |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 456 | "readString16", "writeString16", |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 457 | string_array_type, nullable_string_type); |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 458 | Add(string_type_); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 459 | |
Christopher Wiley | b7e0117 | 2016-01-28 16:32:34 -0800 | [diff] [blame] | 460 | using ::android::aidl::kAidlReservedTypePackage; |
| 461 | using ::android::aidl::kUtf8InCppStringClass; |
| 462 | |
| 463 | // This type is a Utf16 string in the parcel, but deserializes to |
| 464 | // a std::string in Utf8 format when we use it in C++. |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 465 | Type* cpp_utf8_string_array = new CppArrayType( |
Christopher Wiley | b7e0117 | 2016-01-28 16:32:34 -0800 | [diff] [blame] | 466 | ValidatableType::KIND_BUILT_IN, |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 467 | kAidlReservedTypePackage, kUtf8InCppStringClass, |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 468 | "string", "::std::string", "::std::unique_ptr<::std::string>", |
Christopher Wiley | b7e0117 | 2016-01-28 16:32:34 -0800 | [diff] [blame] | 469 | "readUtf8VectorFromUtf16Vector", "writeUtf8VectorAsUtf16Vector", |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 470 | false); |
Christopher Wiley | b7e0117 | 2016-01-28 16:32:34 -0800 | [diff] [blame] | 471 | Type* nullable_cpp_utf8_string_type = new Type( |
| 472 | ValidatableType::KIND_BUILT_IN, |
| 473 | kAidlReservedTypePackage, kUtf8InCppStringClass, |
| 474 | {"string", "memory"}, "::std::unique_ptr<::std::string>", |
| 475 | "readUtf8FromUtf16", "writeUtf8AsUtf16"); |
| 476 | Add(new Type( |
| 477 | ValidatableType::KIND_BUILT_IN, |
| 478 | kAidlReservedTypePackage, kUtf8InCppStringClass, |
| 479 | {"string"}, "::std::string", "readUtf8FromUtf16", "writeUtf8AsUtf16", |
| 480 | cpp_utf8_string_array, nullable_cpp_utf8_string_type)); |
| 481 | |
Christopher Wiley | d646e0b | 2016-03-09 09:24:55 -0800 | [diff] [blame] | 482 | Type* nullable_ibinder = new Type( |
| 483 | ValidatableType::KIND_BUILT_IN, "android.os", "IBinder", |
| 484 | {"binder/IBinder.h"}, "::android::sp<::android::IBinder>", |
| 485 | "readNullableStrongBinder", "writeStrongBinder"); |
| 486 | ibinder_type_ = new Type( |
| 487 | ValidatableType::KIND_BUILT_IN, "android.os", "IBinder", |
| 488 | {"binder/IBinder.h"}, "::android::sp<::android::IBinder>", |
| 489 | "readStrongBinder", "writeStrongBinder", |
| 490 | kNoArrayType, nullable_ibinder); |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 491 | Add(ibinder_type_); |
| 492 | |
Robert Quattlebaum | cd8c135 | 2017-01-04 13:42:51 -0800 | [diff] [blame] | 493 | Add(new MapType()); |
| 494 | |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 495 | Add(new BinderListType()); |
| 496 | Add(new StringListType()); |
Christopher Wiley | 5d9bc93 | 2016-02-01 13:23:16 -0800 | [diff] [blame] | 497 | Add(new Utf8InCppStringListType()); |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 498 | |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 499 | Type* fd_vector_type = new CppArrayType( |
| 500 | ValidatableType::KIND_BUILT_IN, kNoPackage, "FileDescriptor", |
| 501 | "android-base/unique_fd.h", |
Casey Dahlin | d2bcf2f | 2017-08-16 14:24:16 -0700 | [diff] [blame] | 502 | "::android::base::unique_fd", "::android::base::unique_fd", |
Christopher Wiley | 041c8d7 | 2016-08-18 13:52:51 -0700 | [diff] [blame] | 503 | "readUniqueFileDescriptorVector", "writeUniqueFileDescriptorVector", |
| 504 | false); |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 505 | |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 506 | Add(new Type( |
| 507 | ValidatableType::KIND_BUILT_IN, kNoPackage, "FileDescriptor", |
Christopher Wiley | 7cb9c25 | 2016-04-11 11:07:33 -0700 | [diff] [blame] | 508 | {"android-base/unique_fd.h"}, "::android::base::unique_fd", |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 509 | "readUniqueFileDescriptor", "writeUniqueFileDescriptor", |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 510 | fd_vector_type)); |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 511 | |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 512 | void_type_ = new class VoidType(); |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 513 | Add(void_type_); |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 516 | bool TypeNamespace::AddParcelableType(const AidlParcelable& p, |
Christopher Wiley | 9078d72 | 2015-11-17 10:23:49 -0800 | [diff] [blame] | 517 | const string& filename) { |
Christopher Wiley | e9351cc | 2016-01-21 15:56:30 -0800 | [diff] [blame] | 518 | if (p.GetCppHeader().empty()) { |
| 519 | LOG(ERROR) << "Parcelable " << p.GetCanonicalName() |
| 520 | << " has no C++ header defined."; |
| 521 | return false; |
| 522 | } |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 523 | Add(new ParcelableType(p, filename)); |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 524 | return true; |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 527 | bool TypeNamespace::AddBinderType(const AidlInterface& b, |
Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 528 | const string& file_name) { |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 529 | Add(new BinderType(b, file_name)); |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 530 | return true; |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 533 | bool TypeNamespace::AddListType(const std::string& type_name) { |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 534 | const Type* contained_type = FindTypeByCanonicalName(type_name); |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 535 | if (!contained_type) { |
| 536 | LOG(ERROR) << "Cannot create List<" << type_name << "> because contained " |
| 537 | "type cannot be found or is invalid."; |
| 538 | return false; |
| 539 | } |
| 540 | if (contained_type->IsCppPrimitive()) { |
| 541 | LOG(ERROR) << "Cannot create List<" << type_name << "> because contained " |
| 542 | "type is a primitive in Java and Java List cannot hold " |
| 543 | "primitives."; |
| 544 | return false; |
| 545 | } |
| 546 | |
Christopher Wiley | 5d9bc93 | 2016-02-01 13:23:16 -0800 | [diff] [blame] | 547 | if (contained_type->CanonicalName() == kStringCanonicalName || |
| 548 | contained_type->CanonicalName() == kUtf8InCppStringCanonicalName || |
| 549 | contained_type == IBinderType()) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 550 | return true; |
| 551 | } |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 552 | |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 553 | // TODO Support lists of parcelables b/23600712 |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 554 | |
| 555 | LOG(ERROR) << "aidl-cpp does not yet support List<" << type_name << ">"; |
Christopher Wiley | cd8e897 | 2015-10-26 10:24:35 -0700 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | |
| 559 | bool TypeNamespace::AddMapType(const std::string& /* key_type_name */, |
| 560 | const std::string& /* value_type_name */) { |
| 561 | // TODO Support list types b/25242025 |
| 562 | LOG(ERROR) << "aidl does not implement support for typed maps!"; |
| 563 | return false; |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 566 | bool TypeNamespace::IsValidPackage(const string& package) const { |
| 567 | if (package.empty()) { |
| 568 | return false; |
| 569 | } |
| 570 | |
| 571 | auto pieces = Split(package, "."); |
| 572 | for (const string& piece : pieces) { |
| 573 | if (is_cpp_keyword(piece)) { |
| 574 | return false; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | return true; |
| 579 | } |
| 580 | |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 581 | const ValidatableType* TypeNamespace::GetArgType(const AidlArgument& a, |
| 582 | int arg_index, |
Casey Dahlin | c5afb40 | 2016-03-01 13:54:05 -0800 | [diff] [blame] | 583 | const std::string& filename, |
| 584 | const AidlInterface& interface) const { |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 585 | const string error_prefix = StringPrintf( |
| 586 | "In file %s line %d parameter %s (%d):\n ", |
| 587 | filename.c_str(), a.GetLine(), a.GetName().c_str(), arg_index); |
| 588 | |
| 589 | // check that the name doesn't match a keyword |
| 590 | if (is_cpp_keyword(a.GetName().c_str())) { |
| 591 | cerr << error_prefix << "Argument name is a C++ keyword" |
| 592 | << endl; |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 593 | return nullptr; |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Casey Dahlin | c5afb40 | 2016-03-01 13:54:05 -0800 | [diff] [blame] | 596 | return ::android::aidl::TypeNamespace::GetArgType(a, arg_index, filename, |
| 597 | interface); |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 600 | } // namespace cpp |
| 601 | } // namespace aidl |
| 602 | } // namespace android |