Will McVicker | efd970d | 2019-09-25 15:28:30 -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 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 17 | #include "aidl_language.h" |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 18 | #include "aidl_typenames.h" |
Jiyong Park | e5c4529 | 2020-05-26 19:06:24 +0900 | [diff] [blame] | 19 | #include "parser.h" |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 20 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 21 | #include <stdio.h> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 22 | #include <stdlib.h> |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 23 | #include <string.h> |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 24 | #include <algorithm> |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 25 | #include <iostream> |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 26 | #include <set> |
| 27 | #include <sstream> |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 28 | #include <string> |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 29 | #include <utility> |
Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 30 | |
Steven Moreland | 1c4ba20 | 2018-08-09 10:49:54 -0700 | [diff] [blame] | 31 | #include <android-base/parsedouble.h> |
Roshan Pius | 9d7810a | 2016-07-28 08:57:50 -0700 | [diff] [blame] | 32 | #include <android-base/parseint.h> |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 33 | #include <android-base/strings.h> |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 34 | |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 35 | #include "aidl_language_y.h" |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 36 | #include "logging.h" |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 37 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 38 | #include "aidl.h" |
| 39 | |
Casey Dahlin | 07b9dde | 2015-09-10 19:13:49 -0700 | [diff] [blame] | 40 | #ifdef _WIN32 |
| 41 | int isatty(int fd) |
| 42 | { |
| 43 | return (fd == 0); |
| 44 | } |
| 45 | #endif |
| 46 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 47 | using android::aidl::IoDelegate; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 48 | using android::base::Join; |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 49 | using android::base::Split; |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 50 | using std::cerr; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 51 | using std::pair; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 52 | using std::set; |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 53 | using std::string; |
| 54 | using std::unique_ptr; |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 55 | using std::vector; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 56 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 57 | namespace { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 58 | bool IsJavaKeyword(const char* str) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 59 | static const std::vector<std::string> kJavaKeywords{ |
| 60 | "abstract", "assert", "boolean", "break", "byte", "case", "catch", |
| 61 | "char", "class", "const", "continue", "default", "do", "double", |
| 62 | "else", "enum", "extends", "final", "finally", "float", "for", |
| 63 | "goto", "if", "implements", "import", "instanceof", "int", "interface", |
| 64 | "long", "native", "new", "package", "private", "protected", "public", |
| 65 | "return", "short", "static", "strictfp", "super", "switch", "synchronized", |
| 66 | "this", "throw", "throws", "transient", "try", "void", "volatile", |
| 67 | "while", "true", "false", "null", |
| 68 | }; |
| 69 | return std::find(kJavaKeywords.begin(), kJavaKeywords.end(), str) != kJavaKeywords.end(); |
| 70 | } |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 71 | |
| 72 | void AddHideComment(CodeWriter* writer) { |
| 73 | writer->Write("/* @hide */\n"); |
| 74 | } |
| 75 | |
| 76 | inline bool HasHideComment(const std::string& comment) { |
| 77 | return std::regex_search(comment, std::regex("@hide\\b")); |
| 78 | } |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 79 | } // namespace |
| 80 | |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 81 | AidlLocation::AidlLocation(const std::string& file, Point begin, Point end, Source source) |
| 82 | : file_(file), begin_(begin), end_(end), source_(source) {} |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 83 | |
| 84 | std::ostream& operator<<(std::ostream& os, const AidlLocation& l) { |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 85 | os << l.file_; |
| 86 | if (l.LocationKnown()) { |
| 87 | os << ":" << l.begin_.line << "." << l.begin_.column << "-"; |
| 88 | if (l.begin_.line != l.end_.line) { |
| 89 | os << l.end_.line << "."; |
| 90 | } |
| 91 | os << l.end_.column; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 92 | } |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 93 | return os; |
| 94 | } |
| 95 | |
| 96 | AidlNode::AidlNode(const AidlLocation& location) : location_(location) {} |
| 97 | |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 98 | std::string AidlNode::PrintLine() const { |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 99 | std::stringstream ss; |
| 100 | ss << location_.file_ << ":" << location_.begin_.line; |
| 101 | return ss.str(); |
| 102 | } |
| 103 | |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 104 | std::string AidlNode::PrintLocation() const { |
| 105 | std::stringstream ss; |
| 106 | ss << location_.file_ << ":" << location_.begin_.line << ":" << location_.begin_.column << ":" |
| 107 | << location_.end_.line << ":" << location_.end_.column; |
| 108 | return ss.str(); |
| 109 | } |
| 110 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 111 | const std::vector<AidlAnnotation::Schema>& AidlAnnotation::AllSchemas() { |
| 112 | static const std::vector<Schema> kSchemas{ |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 113 | {AidlAnnotation::Type::NULLABLE, "nullable", {}, false}, |
| 114 | {AidlAnnotation::Type::UTF8_IN_CPP, "utf8InCpp", {}, false}, |
| 115 | {AidlAnnotation::Type::VINTF_STABILITY, "VintfStability", {}, false}, |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 116 | {AidlAnnotation::Type::UNSUPPORTED_APP_USAGE, |
| 117 | "UnsupportedAppUsage", |
| 118 | {{"expectedSignature", "String"}, |
| 119 | {"implicitMember", "String"}, |
| 120 | {"maxTargetSdk", "int"}, |
| 121 | {"publicAlternatives", "String"}, |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 122 | {"trackingBug", "long"}}, |
| 123 | false}, |
| 124 | {AidlAnnotation::Type::JAVA_STABLE_PARCELABLE, "JavaOnlyStableParcelable", {}, false}, |
| 125 | {AidlAnnotation::Type::HIDE, "Hide", {}, false}, |
| 126 | {AidlAnnotation::Type::BACKING, "Backing", {{"type", "String"}}, false}, |
| 127 | {AidlAnnotation::Type::JAVA_PASSTHROUGH, "JavaPassthrough", {{"annotation", "String"}}, true}, |
Jooyung Han | 9034500 | 2020-10-23 15:28:53 +0900 | [diff] [blame] | 128 | {AidlAnnotation::Type::JAVA_DERIVE, "JavaDerive", {{"toString", "boolean"}}, false}, |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 129 | {AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, "JavaOnlyImmutable", {}, false}, |
| 130 | {AidlAnnotation::Type::FIXED_SIZE, "FixedSize", {}, false}, |
| 131 | {AidlAnnotation::Type::DESCRIPTOR, "Descriptor", {{"value", "String"}}, false}, |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 132 | {AidlAnnotation::Type::RUST_DERIVE, |
| 133 | "RustDerive", |
| 134 | {{"Copy", "boolean"}, |
| 135 | {"Clone", "boolean"}, |
| 136 | {"PartialOrd", "boolean"}, |
| 137 | {"Ord", "boolean"}, |
| 138 | {"PartialEq", "boolean"}, |
| 139 | {"Eq", "boolean"}, |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 140 | {"Hash", "boolean"}}, |
| 141 | false}, |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 142 | }; |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 143 | return kSchemas; |
| 144 | } |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 145 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 146 | std::string AidlAnnotation::TypeToString(Type type) { |
| 147 | for (const Schema& schema : AllSchemas()) { |
| 148 | if (type == schema.type) return schema.name; |
| 149 | } |
| 150 | AIDL_FATAL(AIDL_LOCATION_HERE) << "Unrecognized type: " << static_cast<size_t>(type); |
| 151 | __builtin_unreachable(); |
| 152 | } |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 153 | |
| 154 | AidlAnnotation* AidlAnnotation::Parse( |
| 155 | const AidlLocation& location, const string& name, |
| 156 | std::map<std::string, std::shared_ptr<AidlConstantValue>>* parameter_list) { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 157 | const Schema* schema = nullptr; |
| 158 | for (const Schema& a_schema : AllSchemas()) { |
| 159 | if (a_schema.name == name) { |
| 160 | schema = &a_schema; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | if (schema == nullptr) { |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 165 | std::ostringstream stream; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 166 | stream << "'" << name << "' is not a recognized annotation. "; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 167 | stream << "It must be one of:"; |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 168 | for (const Schema& s : AllSchemas()) { |
| 169 | stream << " " << s.name; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 170 | } |
| 171 | stream << "."; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 172 | AIDL_ERROR(location) << stream.str(); |
| 173 | return nullptr; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 174 | } |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 175 | if (parameter_list == nullptr) { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 176 | return new AidlAnnotation(location, *schema, {}); |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 179 | return new AidlAnnotation(location, *schema, std::move(*parameter_list)); |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 180 | } |
| 181 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 182 | AidlAnnotation::AidlAnnotation( |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 183 | const AidlLocation& location, const Schema& schema, |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 184 | std::map<std::string, std::shared_ptr<AidlConstantValue>>&& parameters) |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 185 | : AidlNode(location), schema_(schema), parameters_(std::move(parameters)) {} |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 186 | |
| 187 | bool AidlAnnotation::CheckValid() const { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 188 | for (const auto& name_and_param : parameters_) { |
| 189 | const std::string& param_name = name_and_param.first; |
| 190 | const std::shared_ptr<AidlConstantValue>& param = name_and_param.second; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 191 | if (!param->CheckValid()) { |
| 192 | AIDL_ERROR(this) << "Invalid value for parameter " << param_name << " on annotation " |
| 193 | << GetName() << "."; |
| 194 | return false; |
| 195 | } |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 196 | auto parameter_mapping_it = schema_.supported_parameters.find(param_name); |
| 197 | if (parameter_mapping_it == schema_.supported_parameters.end()) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 198 | std::ostringstream stream; |
| 199 | stream << "Parameter " << param_name << " not supported "; |
Devin Moore | decaf29 | 2020-04-30 09:16:40 -0700 | [diff] [blame] | 200 | stream << "for annotation " << GetName() << ". "; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 201 | stream << "It must be one of:"; |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 202 | for (const auto& kv : schema_.supported_parameters) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 203 | stream << " " << kv.first; |
| 204 | } |
| 205 | AIDL_ERROR(this) << stream.str(); |
| 206 | return false; |
| 207 | } |
| 208 | AidlTypeSpecifier type{AIDL_LOCATION_HERE, parameter_mapping_it->second, false, nullptr, ""}; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 209 | const std::string param_value = param->ValueString(type, AidlConstantValueDecorator); |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 210 | // Assume error on empty string. |
| 211 | if (param_value == "") { |
| 212 | AIDL_ERROR(this) << "Invalid value for parameter " << param_name << " on annotation " |
| 213 | << GetName() << "."; |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | std::map<std::string, std::string> AidlAnnotation::AnnotationParams( |
| 221 | const ConstantValueDecorator& decorator) const { |
| 222 | std::map<std::string, std::string> raw_params; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 223 | for (const auto& name_and_param : parameters_) { |
| 224 | const std::string& param_name = name_and_param.first; |
| 225 | const std::shared_ptr<AidlConstantValue>& param = name_and_param.second; |
Devin Moore | decaf29 | 2020-04-30 09:16:40 -0700 | [diff] [blame] | 226 | if (schema_.supported_parameters.find(param_name) == schema_.supported_parameters.end()) { |
| 227 | std::ostringstream stream; |
| 228 | stream << "Parameter " << param_name << " not supported "; |
| 229 | stream << "for annotation " << GetName() << ". "; |
| 230 | stream << "It must be one of:"; |
| 231 | for (const auto& kv : schema_.supported_parameters) { |
| 232 | stream << " " << kv.first; |
| 233 | } |
| 234 | AIDL_ERROR(this) << stream.str(); |
| 235 | continue; |
| 236 | } |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 237 | AidlTypeSpecifier type{AIDL_LOCATION_HERE, schema_.supported_parameters.at(param_name), false, |
| 238 | nullptr, ""}; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 239 | if (!param->CheckValid()) { |
| 240 | AIDL_ERROR(this) << "Invalid value for parameter " << param_name << " on annotation " |
| 241 | << GetName() << "."; |
Devin Moore | decaf29 | 2020-04-30 09:16:40 -0700 | [diff] [blame] | 242 | continue; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | raw_params.emplace(param_name, param->ValueString(type, decorator)); |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 246 | } |
| 247 | return raw_params; |
| 248 | } |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 249 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 250 | std::string AidlAnnotation::ToString(const ConstantValueDecorator& decorator) const { |
| 251 | if (parameters_.empty()) { |
| 252 | return "@" + GetName(); |
| 253 | } else { |
| 254 | vector<string> param_strings; |
| 255 | for (const auto& [name, value] : AnnotationParams(decorator)) { |
| 256 | param_strings.emplace_back(name + "=" + value); |
| 257 | } |
| 258 | return "@" + GetName() + "(" + Join(param_strings, ", ") + ")"; |
| 259 | } |
| 260 | } |
| 261 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 262 | static const AidlAnnotation* GetAnnotation(const vector<AidlAnnotation>& annotations, |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 263 | AidlAnnotation::Type type) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 264 | for (const auto& a : annotations) { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 265 | if (a.GetType() == type) { |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 266 | AIDL_FATAL_IF(a.Repeatable(), a) |
| 267 | << "Trying to get a single annotation when it is repeatable."; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 268 | return &a; |
| 269 | } |
| 270 | } |
| 271 | return nullptr; |
| 272 | } |
| 273 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 274 | AidlAnnotatable::AidlAnnotatable(const AidlLocation& location) : AidlNode(location) {} |
| 275 | |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 276 | bool AidlAnnotatable::IsNullable() const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 277 | return GetAnnotation(annotations_, AidlAnnotation::Type::NULLABLE); |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 278 | } |
| 279 | |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 280 | bool AidlAnnotatable::IsUtf8InCpp() const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 281 | return GetAnnotation(annotations_, AidlAnnotation::Type::UTF8_IN_CPP); |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 282 | } |
| 283 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 284 | bool AidlAnnotatable::IsVintfStability() const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 285 | return GetAnnotation(annotations_, AidlAnnotation::Type::VINTF_STABILITY); |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 288 | bool AidlAnnotatable::IsJavaOnlyImmutable() const { |
| 289 | return GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE); |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 290 | } |
| 291 | |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 292 | bool AidlAnnotatable::IsFixedSize() const { |
| 293 | return GetAnnotation(annotations_, AidlAnnotation::Type::FIXED_SIZE); |
| 294 | } |
| 295 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 296 | const AidlAnnotation* AidlAnnotatable::UnsupportedAppUsage() const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 297 | return GetAnnotation(annotations_, AidlAnnotation::Type::UNSUPPORTED_APP_USAGE); |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 298 | } |
| 299 | |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 300 | const AidlAnnotation* AidlAnnotatable::RustDerive() const { |
| 301 | return GetAnnotation(annotations_, AidlAnnotation::Type::RUST_DERIVE); |
| 302 | } |
| 303 | |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 304 | const AidlTypeSpecifier* AidlAnnotatable::BackingType(const AidlTypenames& typenames) const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 305 | auto annotation = GetAnnotation(annotations_, AidlAnnotation::Type::BACKING); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 306 | if (annotation != nullptr) { |
| 307 | auto annotation_params = annotation->AnnotationParams(AidlConstantValueDecorator); |
| 308 | if (auto it = annotation_params.find("type"); it != annotation_params.end()) { |
| 309 | const string& type = it->second; |
Steven Moreland | e7d5d08 | 2020-05-21 20:29:02 +0000 | [diff] [blame] | 310 | |
| 311 | AIDL_FATAL_IF(type.size() < 2, this) << type; |
| 312 | AIDL_FATAL_IF(type[0] != '"', this) << type; |
| 313 | AIDL_FATAL_IF(type[type.length() - 1] != '"', this) << type; |
| 314 | string unquoted_type = type.substr(1, type.length() - 2); |
| 315 | |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 316 | AidlTypeSpecifier* type_specifier = |
Steven Moreland | e7d5d08 | 2020-05-21 20:29:02 +0000 | [diff] [blame] | 317 | new AidlTypeSpecifier(AIDL_LOCATION_HERE, unquoted_type, false, nullptr, ""); |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 318 | type_specifier->Resolve(typenames); |
| 319 | return type_specifier; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | return nullptr; |
| 323 | } |
| 324 | |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 325 | bool AidlAnnotatable::IsStableApiParcelable(Options::Language lang) const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 326 | return lang == Options::Language::JAVA && |
| 327 | GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_STABLE_PARCELABLE); |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 328 | } |
| 329 | |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 330 | bool AidlAnnotatable::IsHide() const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 331 | return GetAnnotation(annotations_, AidlAnnotation::Type::HIDE); |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Jooyung Han | 9034500 | 2020-10-23 15:28:53 +0900 | [diff] [blame] | 334 | const AidlAnnotation* AidlAnnotatable::JavaDerive() const { |
| 335 | return GetAnnotation(annotations_, AidlAnnotation::Type::JAVA_DERIVE); |
Jiyong Park | 43113fb | 2020-07-20 16:26:19 +0900 | [diff] [blame] | 336 | } |
| 337 | |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 338 | std::string AidlAnnotatable::GetDescriptor() const { |
| 339 | auto annotation = GetAnnotation(annotations_, AidlAnnotation::Type::DESCRIPTOR); |
| 340 | if (annotation != nullptr) { |
| 341 | auto params = annotation->AnnotationParams(AidlConstantValueDecorator); |
| 342 | if (auto it = params.find("value"); it != params.end()) { |
| 343 | const string& value = it->second; |
| 344 | |
| 345 | AIDL_FATAL_IF(value.size() < 2, this) << value; |
| 346 | AIDL_FATAL_IF(value[0] != '"', this) << value; |
| 347 | AIDL_FATAL_IF(value[value.length() - 1] != '"', this) << value; |
| 348 | std::string unquoted_value = value.substr(1, value.length() - 2); |
| 349 | return unquoted_value; |
| 350 | } |
| 351 | } |
| 352 | return ""; |
| 353 | } |
| 354 | |
Steven Moreland | 7e4b950 | 2020-02-20 18:10:42 -0800 | [diff] [blame] | 355 | void AidlAnnotatable::DumpAnnotations(CodeWriter* writer) const { |
| 356 | if (annotations_.empty()) return; |
| 357 | |
| 358 | writer->Write("%s\n", AidlAnnotatable::ToString().c_str()); |
| 359 | } |
| 360 | |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 361 | bool AidlAnnotatable::CheckValid(const AidlTypenames&) const { |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 362 | std::set<AidlAnnotation::Type> supported_annotations = GetSupportedAnnotations(); |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 363 | for (const auto& annotation : GetAnnotations()) { |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 364 | // check if it is allowed for this node |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 365 | if (supported_annotations.find(annotation.GetType()) == supported_annotations.end()) { |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 366 | std::vector<std::string> supported_annot_strings; |
| 367 | for (AidlAnnotation::Type type : supported_annotations) { |
| 368 | supported_annot_strings.push_back(AidlAnnotation::TypeToString(type)); |
| 369 | } |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 370 | AIDL_ERROR(this) << "'" << annotation.GetName() |
| 371 | << "' is not a supported annotation for this node. " |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 372 | << "It must be one of: " |
| 373 | << android::base::Join(supported_annot_strings, ", "); |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 374 | return false; |
| 375 | } |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 376 | // CheckValid() only if it is okay to be here |
| 377 | if (!annotation.CheckValid()) { |
| 378 | return false; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | std::map<AidlAnnotation::Type, AidlLocation> declared; |
| 383 | for (const auto& annotation : GetAnnotations()) { |
| 384 | const auto& [iter, inserted] = declared.emplace(annotation.GetType(), annotation.GetLocation()); |
| 385 | if (!inserted && !annotation.Repeatable()) { |
| 386 | AIDL_ERROR(this) << "'" << annotation.GetName() |
| 387 | << "' is repeated, but not allowed. Previous location: " << iter->second; |
| 388 | return false; |
| 389 | } |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 390 | } |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 391 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 395 | string AidlAnnotatable::ToString() const { |
| 396 | vector<string> ret; |
| 397 | for (const auto& a : annotations_) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 398 | ret.emplace_back(a.ToString(AidlConstantValueDecorator)); |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 399 | } |
| 400 | std::sort(ret.begin(), ret.end()); |
| 401 | return Join(ret, " "); |
| 402 | } |
| 403 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 404 | AidlTypeSpecifier::AidlTypeSpecifier(const AidlLocation& location, const string& unresolved_name, |
| 405 | bool is_array, |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 406 | vector<unique_ptr<AidlTypeSpecifier>>* type_params, |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 407 | const string& comments) |
| 408 | : AidlAnnotatable(location), |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 409 | AidlParameterizable<unique_ptr<AidlTypeSpecifier>>(type_params), |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 410 | unresolved_name_(unresolved_name), |
Casey Dahlin | f7a421c | 2015-10-05 17:24:28 -0700 | [diff] [blame] | 411 | is_array_(is_array), |
Jeongik Cha | 1a7ab64 | 2019-07-29 17:31:02 +0900 | [diff] [blame] | 412 | comments_(comments), |
| 413 | split_name_(Split(unresolved_name, ".")) {} |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 414 | |
Jooyung Han | d2fa023 | 2020-10-19 02:51:41 +0900 | [diff] [blame] | 415 | const AidlTypeSpecifier& AidlTypeSpecifier::ArrayBase() const { |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 416 | AIDL_FATAL_IF(!is_array_, this); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 417 | // Declaring array of generic type cannot happen, it is grammar error. |
| 418 | AIDL_FATAL_IF(IsGeneric(), this); |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 419 | |
Jooyung Han | d2fa023 | 2020-10-19 02:51:41 +0900 | [diff] [blame] | 420 | if (!array_base_) { |
| 421 | array_base_.reset(new AidlTypeSpecifier(*this)); |
| 422 | array_base_->is_array_ = false; |
| 423 | } |
| 424 | return *array_base_; |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 427 | bool AidlTypeSpecifier::IsHidden() const { |
| 428 | return HasHideComment(GetComments()); |
| 429 | } |
| 430 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 431 | string AidlTypeSpecifier::ToString() const { |
| 432 | string ret = GetName(); |
| 433 | if (IsGeneric()) { |
| 434 | vector<string> arg_names; |
| 435 | for (const auto& ta : GetTypeParameters()) { |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 436 | arg_names.emplace_back(ta->ToString()); |
| 437 | } |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 438 | ret += "<" + Join(arg_names, ",") + ">"; |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 439 | } |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 440 | if (IsArray()) { |
| 441 | ret += "[]"; |
| 442 | } |
| 443 | return ret; |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 444 | } |
| 445 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 446 | string AidlTypeSpecifier::Signature() const { |
| 447 | string ret = ToString(); |
| 448 | string annotations = AidlAnnotatable::ToString(); |
| 449 | if (annotations != "") { |
| 450 | ret = annotations + " " + ret; |
| 451 | } |
| 452 | return ret; |
| 453 | } |
| 454 | |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 455 | bool AidlTypeSpecifier::Resolve(const AidlTypenames& typenames) { |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 456 | AIDL_FATAL_IF(IsResolved(), this); |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 457 | AidlTypenames::ResolvedTypename result = typenames.ResolveTypename(unresolved_name_); |
| 458 | if (result.is_resolved) { |
| 459 | fully_qualified_name_ = result.canonical_name; |
Jeongik Cha | 1a7ab64 | 2019-07-29 17:31:02 +0900 | [diff] [blame] | 460 | split_name_ = Split(fully_qualified_name_, "."); |
Jiyong Park | ccf00f8 | 2018-07-17 01:39:23 +0900 | [diff] [blame] | 461 | } |
Steven Moreland | cb1bcd7 | 2020-04-29 16:30:35 -0700 | [diff] [blame] | 462 | return result.is_resolved; |
Casey Dahlin | 70078e6 | 2015-09-30 17:01:30 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 465 | std::set<AidlAnnotation::Type> AidlTypeSpecifier::GetSupportedAnnotations() const { |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 466 | // kHide and kUnsupportedAppUsage are both method return annotations |
| 467 | // which we don't distinguish from other type specifiers. |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 468 | return {AidlAnnotation::Type::NULLABLE, AidlAnnotation::Type::UTF8_IN_CPP, |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 469 | AidlAnnotation::Type::UNSUPPORTED_APP_USAGE, AidlAnnotation::Type::HIDE, |
| 470 | AidlAnnotation::Type::JAVA_PASSTHROUGH}; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 473 | bool AidlTypeSpecifier::CheckValid(const AidlTypenames& typenames) const { |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 474 | if (!AidlAnnotatable::CheckValid(typenames)) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 475 | return false; |
| 476 | } |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 477 | if (IsGeneric()) { |
| 478 | const string& type_name = GetName(); |
Jeongik Cha | e74c86d | 2019-12-12 16:54:03 +0900 | [diff] [blame] | 479 | |
| 480 | auto& types = GetTypeParameters(); |
| 481 | // TODO(b/136048684) Disallow to use primitive types only if it is List or Map. |
| 482 | if (type_name == "List" || type_name == "Map") { |
| 483 | if (std::any_of(types.begin(), types.end(), [](auto& type_ptr) { |
| 484 | return AidlTypenames::IsPrimitiveTypename(type_ptr->GetName()); |
| 485 | })) { |
Devin Moore | 7b8d5c9 | 2020-03-17 14:14:08 -0700 | [diff] [blame] | 486 | AIDL_ERROR(this) << "A generic type cannot have any primitive type parameters."; |
Jeongik Cha | e74c86d | 2019-12-12 16:54:03 +0900 | [diff] [blame] | 487 | return false; |
| 488 | } |
| 489 | } |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 490 | const auto defined_type = typenames.TryGetDefinedType(type_name); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 491 | const auto parameterizable = |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 492 | defined_type != nullptr ? defined_type->AsParameterizable() : nullptr; |
| 493 | const bool is_user_defined_generic_type = |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 494 | parameterizable != nullptr && parameterizable->IsGeneric(); |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 495 | const size_t num_params = GetTypeParameters().size(); |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 496 | if (type_name == "List") { |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 497 | if (num_params > 1) { |
Steven Moreland | ebc3c5d | 2020-09-30 23:40:33 +0000 | [diff] [blame] | 498 | AIDL_ERROR(this) << "List can only have one type parameter, but got: '" << ToString() |
| 499 | << "'"; |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 500 | return false; |
| 501 | } |
| 502 | } else if (type_name == "Map") { |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 503 | if (num_params != 0 && num_params != 2) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 504 | AIDL_ERROR(this) << "Map must have 0 or 2 type parameters, but got " |
| 505 | << "'" << ToString() << "'"; |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 506 | return false; |
| 507 | } |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 508 | if (num_params == 2) { |
Jeongik Cha | e48d994 | 2020-01-02 17:39:00 +0900 | [diff] [blame] | 509 | const string& key_type = GetTypeParameters()[0]->GetName(); |
| 510 | if (key_type != "String") { |
| 511 | AIDL_ERROR(this) << "The type of key in map must be String, but it is " |
| 512 | << "'" << key_type << "'"; |
| 513 | return false; |
| 514 | } |
| 515 | } |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 516 | } else if (is_user_defined_generic_type) { |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 517 | const size_t allowed = parameterizable->GetTypeParameters().size(); |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 518 | if (num_params != allowed) { |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 519 | AIDL_ERROR(this) << type_name << " must have " << allowed << " type parameters, but got " |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 520 | << num_params; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 521 | return false; |
| 522 | } |
| 523 | } else { |
| 524 | AIDL_ERROR(this) << type_name << " is not a generic type."; |
| 525 | return false; |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 526 | } |
| 527 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 528 | |
Steven Moreland | 11cb945 | 2020-01-21 16:56:58 -0800 | [diff] [blame] | 529 | const bool is_generic_string_list = GetName() == "List" && IsGeneric() && |
| 530 | GetTypeParameters().size() == 1 && |
| 531 | GetTypeParameters()[0]->GetName() == "String"; |
| 532 | if (IsUtf8InCpp() && (GetName() != "String" && !is_generic_string_list)) { |
| 533 | AIDL_ERROR(this) << "@utf8InCpp can only be used on String, String[], and List<String>."; |
| 534 | return false; |
| 535 | } |
| 536 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 537 | if (GetName() == "void") { |
| 538 | if (IsArray() || IsNullable() || IsUtf8InCpp()) { |
| 539 | AIDL_ERROR(this) << "void type cannot be an array or nullable or utf8 string"; |
| 540 | return false; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if (IsArray()) { |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 545 | const auto defined_type = typenames.TryGetDefinedType(GetName()); |
| 546 | if (defined_type != nullptr && defined_type->AsInterface() != nullptr) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 547 | AIDL_ERROR(this) << "Binder type cannot be an array"; |
| 548 | return false; |
| 549 | } |
Steven Moreland | 8042d2d | 2020-09-30 23:31:32 +0000 | [diff] [blame] | 550 | if (GetName() == "ParcelableHolder") { |
| 551 | AIDL_ERROR(this) << "Arrays of ParcelableHolder are not supported."; |
| 552 | return false; |
| 553 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | if (IsNullable()) { |
| 557 | if (AidlTypenames::IsPrimitiveTypename(GetName()) && !IsArray()) { |
| 558 | AIDL_ERROR(this) << "Primitive type cannot get nullable annotation"; |
| 559 | return false; |
| 560 | } |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 561 | const auto defined_type = typenames.TryGetDefinedType(GetName()); |
| 562 | if (defined_type != nullptr && defined_type->AsEnumDeclaration() != nullptr && !IsArray()) { |
Daniel Norman | ee8674f | 2019-09-20 16:07:00 -0700 | [diff] [blame] | 563 | AIDL_ERROR(this) << "Enum type cannot get nullable annotation"; |
| 564 | return false; |
| 565 | } |
Jeongik Cha | f6ec898 | 2020-10-15 00:10:30 +0900 | [diff] [blame] | 566 | if (GetName() == "ParcelableHolder") { |
| 567 | AIDL_ERROR(this) << "ParcelableHolder cannot be nullable."; |
| 568 | return false; |
| 569 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 570 | } |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 571 | return true; |
| 572 | } |
| 573 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 574 | std::string AidlConstantValueDecorator(const AidlTypeSpecifier& /*type*/, |
| 575 | const std::string& raw_value) { |
| 576 | return raw_value; |
| 577 | } |
| 578 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 579 | AidlVariableDeclaration::AidlVariableDeclaration(const AidlLocation& location, |
| 580 | AidlTypeSpecifier* type, const std::string& name) |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 581 | : AidlVariableDeclaration(location, type, name, AidlConstantValue::Default(*type)) { |
| 582 | default_user_specified_ = false; |
| 583 | } |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 584 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 585 | AidlVariableDeclaration::AidlVariableDeclaration(const AidlLocation& location, |
| 586 | AidlTypeSpecifier* type, const std::string& name, |
| 587 | AidlConstantValue* default_value) |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 588 | : AidlNode(location), |
| 589 | type_(type), |
| 590 | name_(name), |
| 591 | default_user_specified_(true), |
| 592 | default_value_(default_value) {} |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 593 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 594 | bool AidlVariableDeclaration::CheckValid(const AidlTypenames& typenames) const { |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 595 | bool valid = true; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 596 | valid &= type_->CheckValid(typenames); |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 597 | |
Steven Moreland | 54be7bd | 2019-12-05 11:17:53 -0800 | [diff] [blame] | 598 | if (type_->GetName() == "void") { |
| 599 | AIDL_ERROR(this) << "Declaration " << name_ |
| 600 | << " is void, but declarations cannot be of void type."; |
| 601 | valid = false; |
| 602 | } |
| 603 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 604 | if (default_value_ == nullptr) return valid; |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 605 | valid &= default_value_->CheckValid(); |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 606 | |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 607 | if (!valid) return false; |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 608 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 609 | return !ValueString(AidlConstantValueDecorator).empty(); |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 610 | } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 611 | |
Jooyung Han | acae85d | 2020-10-28 16:39:09 +0900 | [diff] [blame^] | 612 | string AidlVariableDeclaration::GetCapitalizedName() const { |
| 613 | AIDL_FATAL_IF(name_.size() <= 0, *this) << "Name can't be empty."; |
| 614 | string str = name_; |
| 615 | str[0] = static_cast<char>(toupper(str[0])); |
| 616 | return str; |
| 617 | } |
| 618 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 619 | string AidlVariableDeclaration::ToString() const { |
Jeongik Cha | 3271ffa | 2018-12-04 15:19:20 +0900 | [diff] [blame] | 620 | string ret = type_->Signature() + " " + name_; |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 621 | if (default_value_ != nullptr && default_user_specified_) { |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 622 | ret += " = " + ValueString(AidlConstantValueDecorator); |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 623 | } |
| 624 | return ret; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 627 | string AidlVariableDeclaration::Signature() const { |
| 628 | return type_->Signature() + " " + name_; |
| 629 | } |
| 630 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 631 | std::string AidlVariableDeclaration::ValueString(const ConstantValueDecorator& decorator) const { |
Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 632 | if (default_value_ != nullptr) { |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 633 | return default_value_->ValueString(GetType(), decorator); |
Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 634 | } else { |
| 635 | return ""; |
| 636 | } |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 639 | AidlArgument::AidlArgument(const AidlLocation& location, AidlArgument::Direction direction, |
| 640 | AidlTypeSpecifier* type, const std::string& name) |
| 641 | : AidlVariableDeclaration(location, type, name), |
Casey Dahlin | fd6fb48 | 2015-09-30 14:48:18 -0700 | [diff] [blame] | 642 | direction_(direction), |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 643 | direction_specified_(true) {} |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 644 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 645 | AidlArgument::AidlArgument(const AidlLocation& location, AidlTypeSpecifier* type, |
| 646 | const std::string& name) |
| 647 | : AidlVariableDeclaration(location, type, name), |
Casey Dahlin | fd6fb48 | 2015-09-30 14:48:18 -0700 | [diff] [blame] | 648 | direction_(AidlArgument::IN_DIR), |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 649 | direction_specified_(false) {} |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 650 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 651 | string AidlArgument::GetDirectionSpecifier() const { |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 652 | string ret; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 653 | if (direction_specified_) { |
| 654 | switch(direction_) { |
| 655 | case AidlArgument::IN_DIR: |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 656 | ret += "in"; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 657 | break; |
| 658 | case AidlArgument::OUT_DIR: |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 659 | ret += "out"; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 660 | break; |
| 661 | case AidlArgument::INOUT_DIR: |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 662 | ret += "inout"; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 663 | break; |
| 664 | } |
| 665 | } |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 666 | return ret; |
| 667 | } |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 668 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 669 | string AidlArgument::ToString() const { |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 670 | if (direction_specified_) { |
| 671 | return GetDirectionSpecifier() + " " + AidlVariableDeclaration::ToString(); |
| 672 | } else { |
| 673 | return AidlVariableDeclaration::ToString(); |
| 674 | } |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | std::string AidlArgument::Signature() const { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 678 | class AidlInterface; |
| 679 | class AidlInterface; |
| 680 | class AidlParcelable; |
| 681 | class AidlStructuredParcelable; |
| 682 | class AidlParcelable; |
| 683 | class AidlStructuredParcelable; |
Devin Moore | eccdb90 | 2020-03-24 16:22:40 -0700 | [diff] [blame] | 684 | if (direction_specified_) { |
| 685 | return GetDirectionSpecifier() + " " + AidlVariableDeclaration::Signature(); |
| 686 | } else { |
| 687 | return AidlVariableDeclaration::Signature(); |
| 688 | } |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 689 | } |
| 690 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 691 | AidlMember::AidlMember(const AidlLocation& location) : AidlNode(location) {} |
| 692 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 693 | AidlConstantDeclaration::AidlConstantDeclaration(const AidlLocation& location, |
| 694 | AidlTypeSpecifier* type, const std::string& name, |
| 695 | AidlConstantValue* value) |
| 696 | : AidlMember(location), type_(type), name_(name), value_(value) {} |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 697 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 698 | bool AidlConstantDeclaration::CheckValid(const AidlTypenames& typenames) const { |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 699 | bool valid = true; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 700 | valid &= type_->CheckValid(typenames); |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 701 | valid &= value_->CheckValid(); |
| 702 | if (!valid) return false; |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 703 | |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 704 | const static set<string> kSupportedConstTypes = {"String", "int"}; |
| 705 | if (kSupportedConstTypes.find(type_->ToString()) == kSupportedConstTypes.end()) { |
| 706 | AIDL_ERROR(this) << "Constant of type " << type_->ToString() << " is not supported."; |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 707 | return false; |
| 708 | } |
| 709 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 710 | return true; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 713 | string AidlConstantDeclaration::ToString() const { |
| 714 | return "const " + type_->ToString() + " " + name_ + " = " + |
| 715 | ValueString(AidlConstantValueDecorator); |
| 716 | } |
| 717 | |
| 718 | string AidlConstantDeclaration::Signature() const { |
| 719 | return type_->Signature() + " " + name_; |
| 720 | } |
| 721 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 722 | AidlMethod::AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, |
| 723 | const std::string& name, std::vector<std::unique_ptr<AidlArgument>>* args, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 724 | const std::string& comments) |
| 725 | : AidlMethod(location, oneway, type, name, args, comments, 0, true) { |
| 726 | has_id_ = false; |
| 727 | } |
| 728 | |
| 729 | AidlMethod::AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, |
| 730 | const std::string& name, std::vector<std::unique_ptr<AidlArgument>>* args, |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 731 | const std::string& comments, int id, bool is_user_defined) |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 732 | : AidlMember(location), |
| 733 | oneway_(oneway), |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 734 | comments_(comments), |
| 735 | type_(type), |
| 736 | name_(name), |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 737 | arguments_(std::move(*args)), |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 738 | id_(id), |
| 739 | is_user_defined_(is_user_defined) { |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 740 | has_id_ = true; |
| 741 | delete args; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 742 | for (const unique_ptr<AidlArgument>& a : arguments_) { |
| 743 | if (a->IsIn()) { in_arguments_.push_back(a.get()); } |
| 744 | if (a->IsOut()) { out_arguments_.push_back(a.get()); } |
| 745 | } |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 748 | bool AidlMethod::IsHidden() const { |
| 749 | return HasHideComment(GetComments()); |
| 750 | } |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 751 | |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 752 | string AidlMethod::Signature() const { |
| 753 | vector<string> arg_signatures; |
| 754 | for (const auto& arg : GetArguments()) { |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 755 | arg_signatures.emplace_back(arg->GetType().ToString()); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 756 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 757 | return GetName() + "(" + Join(arg_signatures, ", ") + ")"; |
| 758 | } |
| 759 | |
| 760 | string AidlMethod::ToString() const { |
| 761 | vector<string> arg_strings; |
| 762 | for (const auto& arg : GetArguments()) { |
| 763 | arg_strings.emplace_back(arg->Signature()); |
| 764 | } |
Steven Moreland | 4ee6863 | 2018-12-14 15:52:46 -0800 | [diff] [blame] | 765 | string ret = (IsOneway() ? "oneway " : "") + GetType().Signature() + " " + GetName() + "(" + |
| 766 | Join(arg_strings, ", ") + ")"; |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 767 | if (HasId()) { |
| 768 | ret += " = " + std::to_string(GetId()); |
| 769 | } |
| 770 | return ret; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 771 | } |
| 772 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 773 | AidlDefinedType::AidlDefinedType(const AidlLocation& location, const std::string& name, |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 774 | const std::string& comments, const std::string& package) |
| 775 | : AidlAnnotatable(location), |
| 776 | name_(name), |
| 777 | comments_(comments), |
| 778 | package_(package), |
| 779 | split_package_(package.empty() ? std::vector<std::string>() |
| 780 | : android::base::Split(package, ".")) {} |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 781 | |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 782 | bool AidlDefinedType::CheckValid(const AidlTypenames& typenames) const { |
| 783 | if (!AidlAnnotatable::CheckValid(typenames)) { |
| 784 | return false; |
| 785 | } |
| 786 | |
| 787 | return true; |
| 788 | } |
| 789 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 790 | bool AidlDefinedType::IsHidden() const { |
| 791 | return HasHideComment(GetComments()); |
| 792 | } |
| 793 | |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 794 | std::string AidlDefinedType::GetCanonicalName() const { |
| 795 | if (package_.empty()) { |
| 796 | return GetName(); |
| 797 | } |
| 798 | return GetPackage() + "." + GetName(); |
| 799 | } |
| 800 | |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 801 | void AidlDefinedType::DumpHeader(CodeWriter* writer) const { |
| 802 | if (this->IsHidden()) { |
| 803 | AddHideComment(writer); |
| 804 | } |
| 805 | DumpAnnotations(writer); |
| 806 | } |
| 807 | |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 808 | AidlParcelable::AidlParcelable(const AidlLocation& location, const std::string& name, |
| 809 | const std::string& package, const std::string& comments, |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 810 | const std::string& cpp_header, std::vector<std::string>* type_params) |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 811 | : AidlDefinedType(location, name, comments, package), |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 812 | AidlParameterizable<std::string>(type_params), |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 813 | cpp_header_(cpp_header) { |
| 814 | // Strip off quotation marks if we actually have a cpp header. |
| 815 | if (cpp_header_.length() >= 2) { |
| 816 | cpp_header_ = cpp_header_.substr(1, cpp_header_.length() - 2); |
| 817 | } |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 818 | } |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 819 | template <typename T> |
| 820 | AidlParameterizable<T>::AidlParameterizable(const AidlParameterizable& other) { |
| 821 | // Copying is not supported if it has type parameters. |
| 822 | // It doesn't make a problem because only ArrayBase() makes a copy, |
| 823 | // and it can be called only if a type is not generic. |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 824 | AIDL_FATAL_IF(other.IsGeneric(), AIDL_LOCATION_HERE); |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | template <typename T> |
| 828 | bool AidlParameterizable<T>::CheckValid() const { |
| 829 | return true; |
| 830 | }; |
| 831 | |
| 832 | template <> |
| 833 | bool AidlParameterizable<std::string>::CheckValid() const { |
| 834 | if (!IsGeneric()) { |
| 835 | return true; |
| 836 | } |
| 837 | std::unordered_set<std::string> set(GetTypeParameters().begin(), GetTypeParameters().end()); |
| 838 | if (set.size() != GetTypeParameters().size()) { |
| 839 | AIDL_ERROR(this->AsAidlNode()) << "Every type parameter should be unique."; |
| 840 | return false; |
| 841 | } |
| 842 | return true; |
| 843 | } |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 844 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 845 | std::set<AidlAnnotation::Type> AidlParcelable::GetSupportedAnnotations() const { |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 846 | return {AidlAnnotation::Type::VINTF_STABILITY, AidlAnnotation::Type::UNSUPPORTED_APP_USAGE, |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 847 | AidlAnnotation::Type::JAVA_STABLE_PARCELABLE, AidlAnnotation::Type::HIDE, |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 848 | AidlAnnotation::Type::JAVA_PASSTHROUGH, AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE}; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | bool AidlParcelable::CheckValid(const AidlTypenames& typenames) const { |
| 852 | if (!AidlDefinedType::CheckValid(typenames)) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 853 | return false; |
| 854 | } |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 855 | if (!AidlParameterizable<std::string>::CheckValid()) { |
| 856 | return false; |
| 857 | } |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 858 | |
| 859 | return true; |
| 860 | } |
| 861 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 862 | void AidlParcelable::Dump(CodeWriter* writer) const { |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 863 | DumpHeader(writer); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 864 | writer->Write("parcelable %s ;\n", GetName().c_str()); |
| 865 | } |
| 866 | |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 867 | bool AidlWithFields::CheckValid(const AidlParcelable& parcel, |
| 868 | const AidlTypenames& typenames) const { |
| 869 | bool success = true; |
| 870 | |
| 871 | for (const auto& v : GetFields()) { |
| 872 | const bool field_valid = v->CheckValid(typenames); |
| 873 | success = success && field_valid; |
| 874 | } |
| 875 | |
| 876 | // field names should be unique |
| 877 | std::set<std::string> fieldnames; |
| 878 | for (const auto& v : GetFields()) { |
| 879 | bool duplicated = !fieldnames.emplace(v->GetName()).second; |
| 880 | if (duplicated) { |
| 881 | AIDL_ERROR(v) << "'" << parcel.GetName() << "' has duplicate field name '" << v->GetName() |
| 882 | << "'"; |
| 883 | success = false; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | // immutable parcelables should have immutable fields. |
| 888 | if (parcel.IsJavaOnlyImmutable()) { |
| 889 | for (const auto& v : GetFields()) { |
| 890 | if (!typenames.CanBeJavaOnlyImmutable(v->GetType())) { |
| 891 | AIDL_ERROR(v) << "The @JavaOnlyImmutable '" << parcel.GetName() << "' has a " |
| 892 | << "non-immutable field named '" << v->GetName() << "'."; |
| 893 | success = false; |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | return success; |
| 899 | } |
| 900 | |
| 901 | bool AidlWithFields::CheckValidForGetterNames(const AidlParcelable& parcel) const { |
| 902 | bool success = true; |
| 903 | std::set<std::string> getters; |
| 904 | for (const auto& v : GetFields()) { |
Jooyung Han | acae85d | 2020-10-28 16:39:09 +0900 | [diff] [blame^] | 905 | bool duplicated = !getters.emplace(v->GetCapitalizedName()).second; |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 906 | if (duplicated) { |
| 907 | AIDL_ERROR(v) << "'" << parcel.GetName() << "' has duplicate field name '" << v->GetName() |
| 908 | << "' after capitalizing the first letter"; |
| 909 | success = false; |
| 910 | } |
| 911 | } |
| 912 | return success; |
| 913 | } |
| 914 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 915 | AidlStructuredParcelable::AidlStructuredParcelable( |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 916 | const AidlLocation& location, const std::string& name, const std::string& package, |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 917 | const std::string& comments, std::vector<std::unique_ptr<AidlVariableDeclaration>>* variables, |
| 918 | std::vector<std::string>* type_params) |
| 919 | : AidlParcelable(location, name, package, comments, "" /*cpp_header*/, type_params), |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 920 | AidlWithFields(variables) {} |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 921 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 922 | void AidlStructuredParcelable::Dump(CodeWriter* writer) const { |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 923 | DumpHeader(writer); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 924 | writer->Write("parcelable %s {\n", GetName().c_str()); |
| 925 | writer->Indent(); |
| 926 | for (const auto& field : GetFields()) { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 927 | if (field->GetType().IsHidden()) { |
| 928 | AddHideComment(writer); |
| 929 | } |
Jiyong Park | a468e2a | 2018-08-29 21:25:18 +0900 | [diff] [blame] | 930 | writer->Write("%s;\n", field->ToString().c_str()); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 931 | } |
| 932 | writer->Dedent(); |
| 933 | writer->Write("}\n"); |
| 934 | } |
| 935 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 936 | std::set<AidlAnnotation::Type> AidlStructuredParcelable::GetSupportedAnnotations() const { |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 937 | return {AidlAnnotation::Type::VINTF_STABILITY, |
| 938 | AidlAnnotation::Type::UNSUPPORTED_APP_USAGE, |
| 939 | AidlAnnotation::Type::HIDE, |
| 940 | AidlAnnotation::Type::JAVA_PASSTHROUGH, |
Jooyung Han | 9034500 | 2020-10-23 15:28:53 +0900 | [diff] [blame] | 941 | AidlAnnotation::Type::JAVA_DERIVE, |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 942 | AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE, |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 943 | AidlAnnotation::Type::FIXED_SIZE, |
| 944 | AidlAnnotation::Type::RUST_DERIVE}; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 947 | bool AidlStructuredParcelable::CheckValid(const AidlTypenames& typenames) const { |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 948 | if (!AidlParcelable::CheckValid(typenames)) { |
| 949 | return false; |
| 950 | } |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 951 | if (!AidlWithFields::CheckValid(*this, typenames)) { |
| 952 | return false; |
Jooyung Han | d4057c4 | 2020-10-23 13:28:22 +0900 | [diff] [blame] | 953 | } |
Jeongik Cha | 13066da | 2020-08-06 15:43:19 +0900 | [diff] [blame] | 954 | |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 955 | bool success = true; |
Jeongik Cha | 36f76c3 | 2020-07-28 00:25:52 +0900 | [diff] [blame] | 956 | |
Jooyung Han | d4057c4 | 2020-10-23 13:28:22 +0900 | [diff] [blame] | 957 | if (IsFixedSize()) { |
| 958 | for (const auto& v : GetFields()) { |
| 959 | if (!typenames.CanBeFixedSize(v->GetType())) { |
| 960 | AIDL_ERROR(v) << "The @FixedSize parcelable '" << this->GetName() << "' has a " |
| 961 | << "non-fixed size field named " << v->GetName() << "."; |
| 962 | success = false; |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | if (IsJavaOnlyImmutable()) { |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 968 | // Immutable parcelables provide getters |
| 969 | if (!CheckValidForGetterNames(*this)) { |
| 970 | success = false; |
Jooyung Han | d4057c4 | 2020-10-23 13:28:22 +0900 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 974 | return success; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 975 | } |
| 976 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 977 | // TODO: we should treat every backend all the same in future. |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 978 | bool AidlTypeSpecifier::LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 979 | Options::Language lang) const { |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 980 | if ((lang == Options::Language::NDK || lang == Options::Language::RUST) && IsArray() && |
| 981 | GetName() == "IBinder") { |
| 982 | AIDL_ERROR(this) << "The " << Options::LanguageToString(lang) |
| 983 | << " backend does not support array of IBinder"; |
Steven Moreland | 0185d9b | 2020-05-15 23:21:22 +0000 | [diff] [blame] | 984 | return false; |
| 985 | } |
Jeongik Cha | 8f02a53 | 2020-10-14 00:16:28 +0900 | [diff] [blame] | 986 | if (lang == Options::Language::RUST && GetName() == "ParcelableHolder") { |
| 987 | // TODO(b/146611855): Remove it when Rust backend supports ParcelableHolder |
| 988 | AIDL_ERROR(this) << "The Rust backend does not support ParcelableHolder yet."; |
Jeongik Cha | 225519b | 2020-08-29 01:55:32 +0900 | [diff] [blame] | 989 | return false; |
| 990 | } |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 991 | if ((lang == Options::Language::NDK || lang == Options::Language::RUST) && IsArray() && |
| 992 | IsNullable()) { |
Steven Moreland | 0185d9b | 2020-05-15 23:21:22 +0000 | [diff] [blame] | 993 | if (GetName() == "ParcelFileDescriptor") { |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 994 | AIDL_ERROR(this) << "The " << Options::LanguageToString(lang) |
| 995 | << " backend does not support nullable array of ParcelFileDescriptor"; |
Steven Moreland | 0185d9b | 2020-05-15 23:21:22 +0000 | [diff] [blame] | 996 | return false; |
| 997 | } |
| 998 | |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 999 | const auto defined_type = typenames.TryGetDefinedType(GetName()); |
| 1000 | if (defined_type != nullptr && defined_type->AsParcelable() != nullptr) { |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1001 | AIDL_ERROR(this) << "The " << Options::LanguageToString(lang) |
| 1002 | << " backend does not support nullable array of parcelable"; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1003 | return false; |
| 1004 | } |
| 1005 | } |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1006 | if (this->GetName() == "FileDescriptor" && |
| 1007 | (lang == Options::Language::NDK || lang == Options::Language::RUST)) { |
| 1008 | AIDL_ERROR(this) << "FileDescriptor isn't supported by the " << Options::LanguageToString(lang) |
| 1009 | << " backend."; |
Steven Moreland | c8a4ca8 | 2020-01-21 17:50:08 -0800 | [diff] [blame] | 1010 | return false; |
| 1011 | } |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1012 | if (this->IsGeneric()) { |
| 1013 | if (this->GetName() == "List") { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1014 | if (lang == Options::Language::CPP) { |
Devin Moore | 2ac52f9 | 2020-03-23 15:39:36 -0700 | [diff] [blame] | 1015 | const string& contained_type = this->GetTypeParameters()[0]->GetName(); |
| 1016 | if (!(contained_type == "String" || contained_type == "IBinder")) { |
| 1017 | AIDL_ERROR(this) << "List<" << contained_type |
| 1018 | << "> is not supported. List in cpp supports only String and IBinder."; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1019 | return false; |
| 1020 | } |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1021 | } else if (lang == Options::Language::JAVA) { |
| 1022 | const string& contained_type = this->GetTypeParameters()[0]->GetName(); |
| 1023 | if (AidlTypenames::IsBuiltinTypename(contained_type)) { |
| 1024 | if (contained_type != "String" && contained_type != "IBinder" && |
| 1025 | contained_type != "ParcelFileDescriptor") { |
Devin Moore | 2ac52f9 | 2020-03-23 15:39:36 -0700 | [diff] [blame] | 1026 | AIDL_ERROR(this) << "List<" << contained_type |
| 1027 | << "> is not supported. List in Java supports only String, IBinder, " |
| 1028 | "and ParcelFileDescriptor."; |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1029 | return false; |
| 1030 | } |
| 1031 | } |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1032 | } |
Jeongik Cha | bb55b5e | 2020-01-07 23:11:26 +0900 | [diff] [blame] | 1033 | } |
| 1034 | } |
Devin Moore | 6a01ca1 | 2020-08-28 10:24:19 -0700 | [diff] [blame] | 1035 | |
| 1036 | if (this->IsArray()) { |
| 1037 | if (this->GetName() == "List" || this->GetName() == "Map" || |
| 1038 | this->GetName() == "CharSequence") { |
| 1039 | AIDL_ERROR(this) << this->GetName() << "[] is not supported."; |
Jeongik Cha | bb55b5e | 2020-01-07 23:11:26 +0900 | [diff] [blame] | 1040 | return false; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1041 | } |
| 1042 | } |
Devin Moore | 6a01ca1 | 2020-08-28 10:24:19 -0700 | [diff] [blame] | 1043 | |
| 1044 | if (lang != Options::Language::JAVA) { |
| 1045 | if (this->GetName() == "List" && !this->IsGeneric()) { |
| 1046 | AIDL_ERROR(this) << "Currently, only the Java backend supports non-generic List."; |
| 1047 | return false; |
| 1048 | } |
| 1049 | if (this->GetName() == "Map" || this->GetName() == "CharSequence") { |
| 1050 | AIDL_ERROR(this) << "Currently, only Java backend supports " << this->GetName() << "."; |
| 1051 | return false; |
Jeongik Cha | 08ca218 | 2019-11-21 14:01:13 +0900 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1055 | return true; |
| 1056 | } |
| 1057 | |
| 1058 | // TODO: we should treat every backend all the same in future. |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1059 | bool AidlParcelable::LanguageSpecificCheckValid(const AidlTypenames& /*typenames*/, |
| 1060 | Options::Language lang) const { |
Andrei Homescu | b62afd9 | 2020-05-11 19:24:59 -0700 | [diff] [blame] | 1061 | if (lang == Options::Language::CPP || lang == Options::Language::NDK) { |
Steven Moreland | 0d9c26e | 2020-01-22 08:52:08 -0800 | [diff] [blame] | 1062 | const AidlParcelable* unstructured_parcelable = this->AsUnstructuredParcelable(); |
| 1063 | if (unstructured_parcelable != nullptr) { |
| 1064 | if (unstructured_parcelable->GetCppHeader().empty()) { |
| 1065 | AIDL_ERROR(unstructured_parcelable) |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1066 | << "Unstructured parcelable must have C++ header defined."; |
| 1067 | return false; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | return true; |
| 1072 | } |
| 1073 | |
| 1074 | // TODO: we should treat every backend all the same in future. |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1075 | bool AidlStructuredParcelable::LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 1076 | Options::Language lang) const { |
| 1077 | if (!AidlParcelable::LanguageSpecificCheckValid(typenames, lang)) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1078 | return false; |
| 1079 | } |
| 1080 | for (const auto& v : this->GetFields()) { |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1081 | if (!v->GetType().LanguageSpecificCheckValid(typenames, lang)) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1082 | return false; |
| 1083 | } |
| 1084 | } |
| 1085 | return true; |
| 1086 | } |
| 1087 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1088 | AidlEnumerator::AidlEnumerator(const AidlLocation& location, const std::string& name, |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 1089 | AidlConstantValue* value, const std::string& comments) |
| 1090 | : AidlNode(location), name_(name), value_(value), comments_(comments) {} |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1091 | |
| 1092 | bool AidlEnumerator::CheckValid(const AidlTypeSpecifier& enum_backing_type) const { |
| 1093 | if (GetValue() == nullptr) { |
| 1094 | return false; |
| 1095 | } |
| 1096 | if (!GetValue()->CheckValid()) { |
| 1097 | return false; |
| 1098 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 1099 | if (GetValue()->ValueString(enum_backing_type, AidlConstantValueDecorator).empty()) { |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1100 | AIDL_ERROR(this) << "Enumerator type differs from enum backing type."; |
| 1101 | return false; |
| 1102 | } |
| 1103 | return true; |
| 1104 | } |
| 1105 | |
| 1106 | string AidlEnumerator::ValueString(const AidlTypeSpecifier& backing_type, |
| 1107 | const ConstantValueDecorator& decorator) const { |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 1108 | return GetValue()->ValueString(backing_type, decorator); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | AidlEnumDeclaration::AidlEnumDeclaration(const AidlLocation& location, const std::string& name, |
| 1112 | std::vector<std::unique_ptr<AidlEnumerator>>* enumerators, |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 1113 | const std::string& package, const std::string& comments) |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 1114 | : AidlDefinedType(location, name, comments, package), enumerators_(std::move(*enumerators)) {} |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1115 | |
| 1116 | void AidlEnumDeclaration::SetBackingType(std::unique_ptr<const AidlTypeSpecifier> type) { |
| 1117 | backing_type_ = std::move(type); |
| 1118 | } |
| 1119 | |
Steven Moreland | 59e53e4 | 2019-11-26 20:38:08 -0800 | [diff] [blame] | 1120 | bool AidlEnumDeclaration::Autofill() { |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 1121 | const AidlEnumerator* previous = nullptr; |
| 1122 | for (const auto& enumerator : enumerators_) { |
| 1123 | if (enumerator->GetValue() == nullptr) { |
| 1124 | if (previous == nullptr) { |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 1125 | enumerator->SetValue( |
| 1126 | std::unique_ptr<AidlConstantValue>(AidlConstantValue::Integral(GetLocation(), "0"))); |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 1127 | } else { |
Steven Moreland | 59e53e4 | 2019-11-26 20:38:08 -0800 | [diff] [blame] | 1128 | auto prev_value = std::unique_ptr<AidlConstantValue>( |
| 1129 | AidlConstantValue::ShallowIntegralCopy(*previous->GetValue())); |
| 1130 | if (prev_value == nullptr) { |
| 1131 | return false; |
| 1132 | } |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 1133 | enumerator->SetValue(std::make_unique<AidlBinaryConstExpression>( |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 1134 | GetLocation(), std::move(prev_value), "+", |
| 1135 | std::unique_ptr<AidlConstantValue>(AidlConstantValue::Integral(GetLocation(), "1")))); |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | previous = enumerator.get(); |
| 1139 | } |
Steven Moreland | 59e53e4 | 2019-11-26 20:38:08 -0800 | [diff] [blame] | 1140 | return true; |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 1143 | std::set<AidlAnnotation::Type> AidlEnumDeclaration::GetSupportedAnnotations() const { |
| 1144 | return {AidlAnnotation::Type::VINTF_STABILITY, AidlAnnotation::Type::BACKING, |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 1145 | AidlAnnotation::Type::HIDE, AidlAnnotation::Type::JAVA_PASSTHROUGH}; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | bool AidlEnumDeclaration::CheckValid(const AidlTypenames& typenames) const { |
| 1149 | if (!AidlDefinedType::CheckValid(typenames)) { |
| 1150 | return false; |
| 1151 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1152 | if (backing_type_ == nullptr) { |
| 1153 | AIDL_ERROR(this) << "Enum declaration missing backing type."; |
| 1154 | return false; |
| 1155 | } |
| 1156 | bool success = true; |
| 1157 | for (const auto& enumerator : enumerators_) { |
| 1158 | success = success && enumerator->CheckValid(GetBackingType()); |
| 1159 | } |
| 1160 | return success; |
| 1161 | } |
| 1162 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1163 | void AidlEnumDeclaration::Dump(CodeWriter* writer) const { |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 1164 | DumpHeader(writer); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1165 | writer->Write("enum %s {\n", GetName().c_str()); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1166 | writer->Indent(); |
| 1167 | for (const auto& enumerator : GetEnumerators()) { |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1168 | writer->Write("%s = %s,\n", enumerator->GetName().c_str(), |
| 1169 | enumerator->ValueString(GetBackingType(), AidlConstantValueDecorator).c_str()); |
| 1170 | } |
| 1171 | writer->Dedent(); |
| 1172 | writer->Write("}\n"); |
| 1173 | } |
| 1174 | |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1175 | AidlUnionDecl::AidlUnionDecl(const AidlLocation& location, const std::string& name, |
| 1176 | const std::string& package, const std::string& comments, |
| 1177 | std::vector<std::unique_ptr<AidlVariableDeclaration>>* variables, |
| 1178 | std::vector<std::string>* type_params) |
| 1179 | : AidlParcelable(location, name, package, comments, "" /*cpp_header*/, type_params), |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 1180 | AidlWithFields(variables) {} |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1181 | |
| 1182 | std::set<AidlAnnotation::Type> AidlUnionDecl::GetSupportedAnnotations() const { |
| 1183 | return {AidlAnnotation::Type::VINTF_STABILITY, AidlAnnotation::Type::HIDE, |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 1184 | AidlAnnotation::Type::JAVA_PASSTHROUGH, AidlAnnotation::Type::JAVA_DERIVE, |
| 1185 | AidlAnnotation::Type::JAVA_ONLY_IMMUTABLE}; |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | void AidlUnionDecl::Dump(CodeWriter* writer) const { |
| 1189 | DumpHeader(writer); |
| 1190 | writer->Write("union %s {\n", GetName().c_str()); |
| 1191 | writer->Indent(); |
| 1192 | for (const auto& field : GetFields()) { |
| 1193 | if (field->GetType().IsHidden()) { |
| 1194 | AddHideComment(writer); |
| 1195 | } |
| 1196 | writer->Write("%s;\n", field->ToString().c_str()); |
| 1197 | } |
| 1198 | writer->Dedent(); |
| 1199 | writer->Write("}\n"); |
| 1200 | } |
| 1201 | |
Jooyung Han | fe89f12 | 2020-10-14 03:49:18 +0900 | [diff] [blame] | 1202 | bool AidlUnionDecl::CheckValid(const AidlTypenames& typenames) const { |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 1203 | // visit parents |
Jooyung Han | fe89f12 | 2020-10-14 03:49:18 +0900 | [diff] [blame] | 1204 | if (!AidlParcelable::CheckValid(typenames)) { |
| 1205 | return false; |
| 1206 | } |
Jooyung Han | 59af9cc | 2020-10-25 21:44:14 +0900 | [diff] [blame] | 1207 | if (!AidlWithFields::CheckValid(*this, typenames)) { |
| 1208 | return false; |
| 1209 | } |
| 1210 | |
| 1211 | // unions provide getters always |
| 1212 | if (!CheckValidForGetterNames(*this)) { |
| 1213 | return false; |
Jooyung Han | fe89f12 | 2020-10-14 03:49:18 +0900 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | // now, visit self! |
| 1217 | bool success = true; |
| 1218 | |
| 1219 | // TODO(b/170807936) do we need to allow ParcelableHolder in union? |
| 1220 | for (const auto& v : GetFields()) { |
| 1221 | if (v->GetType().GetName() == "ParcelableHolder") { |
| 1222 | AIDL_ERROR(*v) << "A union can't have a member of ParcelableHolder '" << v->GetName() << "'"; |
| 1223 | success = false; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | // first member should have default value (implicit or explicit) |
| 1228 | if (GetFields().empty()) { |
| 1229 | AIDL_ERROR(*this) << "The union '" << this->GetName() << "' has no fields."; |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
| 1233 | return success; |
| 1234 | } |
| 1235 | |
| 1236 | // TODO: we should treat every backend all the same in future. |
| 1237 | bool AidlUnionDecl::LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 1238 | Options::Language lang) const { |
| 1239 | if (!AidlParcelable::LanguageSpecificCheckValid(typenames, lang)) { |
| 1240 | return false; |
| 1241 | } |
| 1242 | for (const auto& v : this->GetFields()) { |
| 1243 | if (!v->GetType().LanguageSpecificCheckValid(typenames, lang)) { |
| 1244 | return false; |
| 1245 | } |
| 1246 | } |
| 1247 | return true; |
| 1248 | } |
| 1249 | |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1250 | // TODO: we should treat every backend all the same in future. |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1251 | bool AidlInterface::LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 1252 | Options::Language lang) const { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1253 | for (const auto& m : this->GetMethods()) { |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1254 | if (!m->GetType().LanguageSpecificCheckValid(typenames, lang)) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1255 | return false; |
| 1256 | } |
| 1257 | for (const auto& arg : m->GetArguments()) { |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1258 | if (!arg->GetType().LanguageSpecificCheckValid(typenames, lang)) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1259 | return false; |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 1266 | AidlInterface::AidlInterface(const AidlLocation& location, const std::string& name, |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 1267 | const std::string& comments, bool oneway, |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1268 | std::vector<std::unique_ptr<AidlMember>>* members, |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 1269 | const std::string& package) |
Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 1270 | : AidlDefinedType(location, name, comments, package) { |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1271 | for (auto& member : *members) { |
| 1272 | AidlMember* local = member.release(); |
| 1273 | AidlMethod* method = local->AsMethod(); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 1274 | AidlConstantDeclaration* constant = local->AsConstantDeclaration(); |
| 1275 | |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 1276 | AIDL_FATAL_IF(method != nullptr && constant != nullptr, member); |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1277 | |
| 1278 | if (method) { |
Steven Moreland | 8c70ba9 | 2018-12-17 10:20:31 -0800 | [diff] [blame] | 1279 | method->ApplyInterfaceOneway(oneway); |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1280 | methods_.emplace_back(method); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 1281 | } else if (constant) { |
| 1282 | constants_.emplace_back(constant); |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1283 | } else { |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 1284 | AIDL_FATAL(this) << "Member is neither method nor constant!"; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | delete members; |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1291 | void AidlInterface::Dump(CodeWriter* writer) const { |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 1292 | DumpHeader(writer); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1293 | writer->Write("interface %s {\n", GetName().c_str()); |
| 1294 | writer->Indent(); |
| 1295 | for (const auto& method : GetMethods()) { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1296 | if (method->IsHidden()) { |
| 1297 | AddHideComment(writer); |
| 1298 | } |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1299 | writer->Write("%s;\n", method->ToString().c_str()); |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1300 | } |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1301 | for (const auto& constdecl : GetConstantDeclarations()) { |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1302 | if (constdecl->GetType().IsHidden()) { |
| 1303 | AddHideComment(writer); |
| 1304 | } |
Jiyong Park | a428d21 | 2018-08-29 22:26:30 +0900 | [diff] [blame] | 1305 | writer->Write("%s;\n", constdecl->ToString().c_str()); |
| 1306 | } |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1307 | writer->Dedent(); |
| 1308 | writer->Write("}\n"); |
| 1309 | } |
| 1310 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 1311 | std::set<AidlAnnotation::Type> AidlInterface::GetSupportedAnnotations() const { |
| 1312 | return {AidlAnnotation::Type::VINTF_STABILITY, AidlAnnotation::Type::UNSUPPORTED_APP_USAGE, |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 1313 | AidlAnnotation::Type::HIDE, AidlAnnotation::Type::JAVA_PASSTHROUGH, |
| 1314 | AidlAnnotation::Type::DESCRIPTOR}; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 1315 | } |
| 1316 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1317 | bool AidlInterface::CheckValid(const AidlTypenames& typenames) const { |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 1318 | if (!AidlDefinedType::CheckValid(typenames)) { |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 1319 | return false; |
| 1320 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1321 | // Has to be a pointer due to deleting copy constructor. No idea why. |
| 1322 | map<string, const AidlMethod*> method_names; |
| 1323 | for (const auto& m : GetMethods()) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1324 | if (!m->GetType().CheckValid(typenames)) { |
| 1325 | return false; |
| 1326 | } |
| 1327 | |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1328 | // TODO(b/156872582): Support it when ParcelableHolder supports every backend. |
| 1329 | if (m->GetType().GetName() == "ParcelableHolder") { |
| 1330 | AIDL_ERROR(m) << "ParcelableHolder cannot be a return type"; |
| 1331 | return false; |
| 1332 | } |
Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 1333 | if (m->IsOneway() && m->GetType().GetName() != "void") { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1334 | AIDL_ERROR(m) << "oneway method '" << m->GetName() << "' cannot return a value"; |
| 1335 | return false; |
| 1336 | } |
| 1337 | |
| 1338 | set<string> argument_names; |
| 1339 | for (const auto& arg : m->GetArguments()) { |
| 1340 | auto it = argument_names.find(arg->GetName()); |
| 1341 | if (it != argument_names.end()) { |
| 1342 | AIDL_ERROR(m) << "method '" << m->GetName() << "' has duplicate argument name '" |
| 1343 | << arg->GetName() << "'"; |
| 1344 | return false; |
| 1345 | } |
| 1346 | argument_names.insert(arg->GetName()); |
| 1347 | |
| 1348 | if (!arg->GetType().CheckValid(typenames)) { |
| 1349 | return false; |
| 1350 | } |
| 1351 | |
Jeongik Cha | 649e8a7 | 2020-03-27 17:47:40 +0900 | [diff] [blame] | 1352 | // TODO(b/156872582): Support it when ParcelableHolder supports every backend. |
| 1353 | if (arg->GetType().GetName() == "ParcelableHolder") { |
| 1354 | AIDL_ERROR(arg) << "ParcelableHolder cannot be an argument type"; |
| 1355 | return false; |
| 1356 | } |
Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 1357 | if (m->IsOneway() && arg->IsOut()) { |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1358 | AIDL_ERROR(m) << "oneway method '" << m->GetName() << "' cannot have out parameters"; |
| 1359 | return false; |
| 1360 | } |
Jooyung Han | 15fd6c6 | 2020-10-23 13:54:46 +0900 | [diff] [blame] | 1361 | |
| 1362 | const auto [can_be_out, type_aspect] = typenames.CanBeOutParameter(arg->GetType()); |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1363 | if (!arg->DirectionWasSpecified() && can_be_out) { |
| 1364 | AIDL_ERROR(arg) << "'" << arg->GetType().ToString() |
| 1365 | << "' can be an out type, so you must declare it as in, out, or inout."; |
| 1366 | return false; |
| 1367 | } |
| 1368 | |
| 1369 | if (arg->GetDirection() != AidlArgument::IN_DIR && !can_be_out) { |
Jooyung Han | 15fd6c6 | 2020-10-23 13:54:46 +0900 | [diff] [blame] | 1370 | AIDL_ERROR(arg) << "'" << arg->GetName() << "' can't be an " << arg->GetDirectionSpecifier() |
| 1371 | << " parameter because " << type_aspect << " can only be an in parameter."; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1372 | return false; |
| 1373 | } |
| 1374 | |
| 1375 | // check that the name doesn't match a keyword |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1376 | if (IsJavaKeyword(arg->GetName().c_str())) { |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 1377 | AIDL_ERROR(arg) << "Argument name is a Java or aidl keyword"; |
| 1378 | return false; |
| 1379 | } |
| 1380 | |
| 1381 | // Reserve a namespace for internal use |
| 1382 | if (android::base::StartsWith(arg->GetName(), "_aidl")) { |
| 1383 | AIDL_ERROR(arg) << "Argument name cannot begin with '_aidl'"; |
| 1384 | return false; |
| 1385 | } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | auto it = method_names.find(m->GetName()); |
| 1389 | // prevent duplicate methods |
| 1390 | if (it == method_names.end()) { |
| 1391 | method_names[m->GetName()] = m.get(); |
| 1392 | } else { |
| 1393 | AIDL_ERROR(m) << "attempt to redefine method " << m->GetName() << ":"; |
| 1394 | AIDL_ERROR(it->second) << "previously defined here."; |
| 1395 | return false; |
| 1396 | } |
| 1397 | |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 1398 | static set<string> reserved_methods{"asBinder()", "getInterfaceHash()", "getInterfaceVersion()", |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1399 | "getTransactionName(int)"}; |
| 1400 | |
| 1401 | if (reserved_methods.find(m->Signature()) != reserved_methods.end()) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1402 | AIDL_ERROR(m) << " method " << m->Signature() << " is reserved for internal use."; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1403 | return false; |
| 1404 | } |
| 1405 | } |
Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 1406 | |
| 1407 | bool success = true; |
| 1408 | set<string> constant_names; |
| 1409 | for (const std::unique_ptr<AidlConstantDeclaration>& constant : GetConstantDeclarations()) { |
| 1410 | if (constant_names.count(constant->GetName()) > 0) { |
Devin Moore | 097a3ab | 2020-03-11 16:08:44 -0700 | [diff] [blame] | 1411 | AIDL_ERROR(constant) << "Found duplicate constant name '" << constant->GetName() << "'"; |
Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 1412 | success = false; |
| 1413 | } |
| 1414 | constant_names.insert(constant->GetName()); |
| 1415 | success = success && constant->CheckValid(typenames); |
| 1416 | } |
| 1417 | |
| 1418 | return success; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1419 | } |
| 1420 | |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 1421 | std::string AidlInterface::GetDescriptor() const { |
| 1422 | std::string annotatedDescriptor = AidlAnnotatable::GetDescriptor(); |
| 1423 | if (annotatedDescriptor != "") { |
| 1424 | return annotatedDescriptor; |
| 1425 | } |
| 1426 | return GetCanonicalName(); |
| 1427 | } |
| 1428 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 1429 | AidlImport::AidlImport(const AidlLocation& location, const std::string& needed_class) |
| 1430 | : AidlNode(location), needed_class_(needed_class) {} |