Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019, 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 | |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 17 | #pragma once |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 18 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 19 | #include "aidl_typenames.h" |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 20 | #include "code_writer.h" |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 21 | #include "io_delegate.h" |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 22 | #include "options.h" |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 23 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 24 | #include <memory> |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 25 | #include <regex> |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 26 | #include <string> |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 27 | #include <unordered_set> |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 28 | #include <vector> |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 29 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 30 | #include <android-base/strings.h> |
Casey Dahlin | 73d46b0 | 2015-09-11 02:47:54 +0000 | [diff] [blame] | 31 | |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 32 | using android::aidl::AidlTypenames; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 33 | using android::aidl::CodeWriter; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame] | 34 | using android::aidl::Options; |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 35 | using std::shared_ptr; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 36 | using std::string; |
| 37 | using std::unique_ptr; |
| 38 | using std::vector; |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 39 | class AidlNode; |
| 40 | |
| 41 | namespace android { |
| 42 | namespace aidl { |
| 43 | namespace mappings { |
| 44 | std::string dump_location(const AidlNode& method); |
| 45 | } // namespace mappings |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 46 | namespace java { |
| 47 | std::string dump_location(const AidlNode& method); |
| 48 | } // namespace java |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 49 | } // namespace aidl |
| 50 | } // namespace android |
| 51 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 52 | class AidlLocation { |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 53 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 54 | struct Point { |
Dan Willemsen | 609ba6d | 2019-12-30 10:44:00 -0800 | [diff] [blame] | 55 | int line; |
| 56 | int column; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 59 | enum class Source { |
| 60 | // From internal aidl source code |
| 61 | INTERNAL = 0, |
| 62 | // From a parsed file |
| 63 | EXTERNAL = 1 |
| 64 | }; |
| 65 | |
| 66 | AidlLocation(const std::string& file, Point begin, Point end, Source source); |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 67 | AidlLocation(const std::string& file, Source source) |
| 68 | : AidlLocation(file, {0, 0}, {0, 0}, source) {} |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 69 | |
| 70 | bool IsInternal() const { return source_ == Source::INTERNAL; } |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 71 | |
Devin Moore | 5de18ed | 2020-04-02 13:52:29 -0700 | [diff] [blame] | 72 | // The first line of a file is line 1. |
| 73 | bool LocationKnown() const { return begin_.line != 0; } |
| 74 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 75 | friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l); |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 76 | friend class AidlNode; |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 77 | |
| 78 | private: |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 79 | // INTENTIONALLY HIDDEN: only operator<< should access details here. |
| 80 | // Otherwise, locations should only ever be copied around to construct new |
| 81 | // objects. |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 82 | const std::string file_; |
| 83 | Point begin_; |
| 84 | Point end_; |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 85 | Source source_; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 88 | #define AIDL_LOCATION_HERE \ |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 89 | (AidlLocation{__FILE__, {__LINE__, 0}, {__LINE__, 0}, AidlLocation::Source::INTERNAL}) |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 90 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 91 | std::ostream& operator<<(std::ostream& os, const AidlLocation& l); |
| 92 | |
| 93 | // Anything that is locatable in a .aidl file. |
| 94 | class AidlNode { |
| 95 | public: |
| 96 | AidlNode(const AidlLocation& location); |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 97 | |
| 98 | AidlNode(const AidlNode&) = default; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 99 | virtual ~AidlNode() = default; |
| 100 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 101 | AidlNode(AidlNode&&) = delete; |
| 102 | AidlNode& operator=(AidlNode&&) = delete; |
| 103 | |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 104 | // To be able to print AidlLocation |
Steven Moreland | b0d15a5 | 2020-03-31 14:03:47 -0700 | [diff] [blame] | 105 | friend class AidlErrorLog; |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 106 | friend std::string android::aidl::mappings::dump_location(const AidlNode&); |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 107 | friend std::string android::aidl::java::dump_location(const AidlNode&); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 108 | |
Devin Moore | df93ebb | 2020-03-25 14:03:35 -0700 | [diff] [blame] | 109 | const AidlLocation& GetLocation() const { return location_; } |
| 110 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 111 | private: |
Mathew Inwood | adb7467 | 2019-11-29 14:01:53 +0000 | [diff] [blame] | 112 | std::string PrintLine() const; |
Andrei Onea | 8714b02 | 2019-02-01 18:55:54 +0000 | [diff] [blame] | 113 | std::string PrintLocation() const; |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 114 | const AidlLocation location_; |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 117 | namespace android { |
| 118 | namespace aidl { |
| 119 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 120 | class AidlTypenames; |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 121 | |
| 122 | } // namespace aidl |
| 123 | } // namespace android |
| 124 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 125 | // unique_ptr<AidlTypeSpecifier> for type arugment, |
| 126 | // std::string for type parameter(T, U, and so on). |
| 127 | template <typename T> |
| 128 | class AidlParameterizable { |
| 129 | public: |
| 130 | AidlParameterizable(std::vector<T>* type_params) : type_params_(type_params) {} |
| 131 | virtual ~AidlParameterizable() = default; |
| 132 | bool IsGeneric() const { return type_params_ != nullptr; } |
| 133 | const std::vector<T>& GetTypeParameters() const { return *type_params_; } |
| 134 | bool CheckValid() const; |
| 135 | |
Steven Moreland | 6c07b83 | 2020-10-29 23:39:53 +0000 | [diff] [blame] | 136 | __attribute__((warn_unused_result)) bool SetTypeParameters(std::vector<T>* type_params) { |
| 137 | if (type_params_) return false; |
| 138 | type_params_.reset(type_params); |
| 139 | return true; |
| 140 | } |
| 141 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 142 | virtual const AidlNode& AsAidlNode() const = 0; |
| 143 | |
| 144 | protected: |
| 145 | AidlParameterizable(const AidlParameterizable&); |
| 146 | |
| 147 | private: |
Steven Moreland | 6c07b83 | 2020-10-29 23:39:53 +0000 | [diff] [blame] | 148 | unique_ptr<std::vector<T>> type_params_; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 149 | static_assert(std::is_same<T, unique_ptr<AidlTypeSpecifier>>::value || |
| 150 | std::is_same<T, std::string>::value); |
| 151 | }; |
| 152 | template <> |
| 153 | bool AidlParameterizable<std::string>::CheckValid() const; |
| 154 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 155 | class AidlConstantValue; |
| 156 | class AidlConstantDeclaration; |
| 157 | |
| 158 | // Transforms a value string into a language specific form. Raw value as produced by |
| 159 | // AidlConstantValue. |
| 160 | using ConstantValueDecorator = |
| 161 | std::function<std::string(const AidlTypeSpecifier& type, const std::string& raw_value)>; |
| 162 | |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 163 | class AidlAnnotation : public AidlNode { |
| 164 | public: |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 165 | enum class Type { |
| 166 | BACKING = 1, |
| 167 | HIDE, |
| 168 | JAVA_STABLE_PARCELABLE, |
| 169 | UNSUPPORTED_APP_USAGE, |
| 170 | VINTF_STABILITY, |
| 171 | NULLABLE, |
| 172 | UTF8_IN_CPP, |
Steven Moreland | a7764e5 | 2020-10-27 17:29:29 +0000 | [diff] [blame] | 173 | SENSITIVE_DATA, |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 174 | JAVA_PASSTHROUGH, |
Jooyung Han | 9034500 | 2020-10-23 15:28:53 +0900 | [diff] [blame] | 175 | JAVA_DERIVE, |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 176 | JAVA_ONLY_IMMUTABLE, |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 177 | FIXED_SIZE, |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 178 | DESCRIPTOR, |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 179 | RUST_DERIVE, |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 180 | }; |
| 181 | static std::string TypeToString(Type type); |
| 182 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 183 | static AidlAnnotation* Parse( |
| 184 | const AidlLocation& location, const string& name, |
| 185 | std::map<std::string, std::shared_ptr<AidlConstantValue>>* parameter_list); |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 186 | |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 187 | AidlAnnotation(const AidlAnnotation&) = default; |
Steven Moreland | 3be7577 | 2018-08-20 13:27:43 -0700 | [diff] [blame] | 188 | AidlAnnotation(AidlAnnotation&&) = default; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 189 | virtual ~AidlAnnotation() = default; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 190 | bool CheckValid() const; |
Steven Moreland | 3be7577 | 2018-08-20 13:27:43 -0700 | [diff] [blame] | 191 | |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 192 | const string& GetName() const { return schema_.name; } |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 193 | const Type& GetType() const { return schema_.type; } |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 194 | bool Repeatable() const { return schema_.repeatable; } |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 195 | |
| 196 | // ToString is for dumping AIDL. |
| 197 | // Returns string representation of this annotation. |
| 198 | // e.g) "@RustDerive(Clone=true, Copy=true)" |
| 199 | string ToString() const; |
| 200 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 201 | std::map<std::string, std::string> AnnotationParams( |
| 202 | const ConstantValueDecorator& decorator) const; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 203 | const string& GetComments() const { return comments_; } |
| 204 | void SetComments(const string& comments) { comments_ = comments; } |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 205 | |
| 206 | private: |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 207 | struct Schema { |
| 208 | AidlAnnotation::Type type; |
| 209 | |
| 210 | // text name in .aidl file, e.g. "nullable" |
| 211 | std::string name; |
| 212 | |
| 213 | // map from param name -> value type |
| 214 | std::map<std::string, std::string> supported_parameters; |
Jooyung Han | d902a97 | 2020-10-23 17:32:44 +0900 | [diff] [blame] | 215 | |
| 216 | bool repeatable; |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 217 | }; |
| 218 | static const std::vector<Schema>& AllSchemas(); |
| 219 | |
| 220 | AidlAnnotation(const AidlLocation& location, const Schema& schema, |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 221 | std::map<std::string, std::shared_ptr<AidlConstantValue>>&& parameters); |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 222 | |
| 223 | const Schema& schema_; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 224 | string comments_; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 225 | std::map<std::string, std::shared_ptr<AidlConstantValue>> parameters_; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 226 | }; |
| 227 | |
Steven Moreland | 3be7577 | 2018-08-20 13:27:43 -0700 | [diff] [blame] | 228 | static inline bool operator<(const AidlAnnotation& lhs, const AidlAnnotation& rhs) { |
| 229 | return lhs.GetName() < rhs.GetName(); |
| 230 | } |
| 231 | static inline bool operator==(const AidlAnnotation& lhs, const AidlAnnotation& rhs) { |
| 232 | return lhs.GetName() == rhs.GetName(); |
| 233 | } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 234 | |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 235 | class AidlAnnotatable : public AidlNode { |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 236 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 237 | AidlAnnotatable(const AidlLocation& location); |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 238 | |
| 239 | AidlAnnotatable(const AidlAnnotatable&) = default; |
| 240 | AidlAnnotatable(AidlAnnotatable&&) = default; |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 241 | virtual ~AidlAnnotatable() = default; |
| 242 | |
Artur Satayev | 91fe871 | 2019-07-29 13:06:01 +0100 | [diff] [blame] | 243 | void Annotate(vector<AidlAnnotation>&& annotations) { |
| 244 | for (auto& annotation : annotations) { |
| 245 | annotations_.emplace_back(std::move(annotation)); |
| 246 | } |
| 247 | } |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 248 | bool IsNullable() const; |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 249 | bool IsUtf8InCpp() const; |
Steven Moreland | a7764e5 | 2020-10-27 17:29:29 +0000 | [diff] [blame] | 250 | bool IsSensitiveData() const; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 251 | bool IsVintfStability() const; |
Jeongik Cha | d0a1027 | 2020-08-06 16:33:36 +0900 | [diff] [blame] | 252 | bool IsJavaOnlyImmutable() const; |
Devin Moore | c7e47a3 | 2020-08-07 10:55:25 -0700 | [diff] [blame] | 253 | bool IsFixedSize() const; |
Jeongik Cha | 88f95a8 | 2020-01-15 13:02:16 +0900 | [diff] [blame] | 254 | bool IsStableApiParcelable(Options::Language lang) const; |
Makoto Onuki | 78a1c1c | 2020-03-04 16:57:23 -0800 | [diff] [blame] | 255 | bool IsHide() const; |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 256 | bool JavaDerive(const std::string& method) const; |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 257 | std::string GetDescriptor() const; |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 258 | |
Steven Moreland | 7e4b950 | 2020-02-20 18:10:42 -0800 | [diff] [blame] | 259 | void DumpAnnotations(CodeWriter* writer) const; |
| 260 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 261 | const AidlAnnotation* UnsupportedAppUsage() const; |
Andrei Homescu | e61feb5 | 2020-08-18 15:44:24 -0700 | [diff] [blame] | 262 | const AidlAnnotation* RustDerive() const; |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 263 | const AidlTypeSpecifier* BackingType(const AidlTypenames& typenames) const; |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 264 | |
| 265 | // ToString is for dumping AIDL. |
| 266 | // Returns string representation of annotations. |
| 267 | // e.g) "@JavaDerive(toString=true) @RustDerive(Clone=true, Copy=true)" |
Jiyong Park | 68bc77a | 2018-07-19 19:00:45 +0900 | [diff] [blame] | 268 | std::string ToString() const; |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 269 | |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 270 | const vector<AidlAnnotation>& GetAnnotations() const { return annotations_; } |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 271 | virtual bool CheckValid(const AidlTypenames&) const; |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 272 | |
Steven Moreland | 181144c | 2020-04-20 19:57:56 -0700 | [diff] [blame] | 273 | protected: |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 274 | virtual std::set<AidlAnnotation::Type> GetSupportedAnnotations() const = 0; |
Steven Moreland | 181144c | 2020-04-20 19:57:56 -0700 | [diff] [blame] | 275 | |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 276 | private: |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 277 | vector<AidlAnnotation> annotations_; |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 278 | }; |
| 279 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 280 | // AidlTypeSpecifier represents a reference to either a built-in type, |
| 281 | // a defined type, or a variant (e.g., array of generic) of a type. |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 282 | class AidlTypeSpecifier final : public AidlAnnotatable, |
| 283 | public AidlParameterizable<unique_ptr<AidlTypeSpecifier>> { |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 284 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 285 | AidlTypeSpecifier(const AidlLocation& location, const string& unresolved_name, bool is_array, |
| 286 | vector<unique_ptr<AidlTypeSpecifier>>* type_params, const string& comments); |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 287 | virtual ~AidlTypeSpecifier() = default; |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 288 | |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 289 | // Copy of this type which is not an array. |
Jooyung Han | d2fa023 | 2020-10-19 02:51:41 +0900 | [diff] [blame] | 290 | const AidlTypeSpecifier& ArrayBase() const; |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 291 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 292 | // Returns the full-qualified name of the base type. |
| 293 | // int -> int |
| 294 | // int[] -> int |
| 295 | // List<String> -> List |
| 296 | // IFoo -> foo.bar.IFoo (if IFoo is in package foo.bar) |
| 297 | const string& GetName() const { |
| 298 | if (IsResolved()) { |
| 299 | return fully_qualified_name_; |
| 300 | } else { |
| 301 | return GetUnresolvedName(); |
| 302 | } |
| 303 | } |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 304 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 305 | // ToString is for dumping AIDL. |
| 306 | // Returns string representation of this type specifier including annotations. |
| 307 | // This is "annotations type_name type_params? array_marker?". |
| 308 | // e.g) "@utf8InCpp String[]"; |
| 309 | std::string ToString() const; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 310 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 311 | // Signature is for comparing AIDL types. |
| 312 | // Returns string representation of this type specifier. |
| 313 | // This is "type_name type_params? array_marker?". |
| 314 | // e.g.) "String[]" (even if it is annotated with @utf8InCpp) |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 315 | std::string Signature() const; |
| 316 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 317 | const string& GetUnresolvedName() const { return unresolved_name_; } |
| 318 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 319 | bool IsHidden() const; |
| 320 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 321 | const string& GetComments() const { return comments_; } |
| 322 | |
Jeongik Cha | 1a7ab64 | 2019-07-29 17:31:02 +0900 | [diff] [blame] | 323 | const std::vector<std::string> GetSplitName() const { return split_name_; } |
| 324 | |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 325 | void SetComments(const string& comment) { comments_ = comment; } |
| 326 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 327 | bool IsResolved() const { return fully_qualified_name_ != ""; } |
| 328 | |
| 329 | bool IsArray() const { return is_array_; } |
| 330 | |
Steven Moreland | 6c07b83 | 2020-10-29 23:39:53 +0000 | [diff] [blame] | 331 | __attribute__((warn_unused_result)) bool SetArray() { |
| 332 | if (is_array_) return false; |
| 333 | is_array_ = true; |
| 334 | return true; |
| 335 | } |
| 336 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 337 | // Resolve the base type name to a fully-qualified name. Return false if the |
| 338 | // resolution fails. |
Daniel Norman | 716d311 | 2019-09-10 13:11:56 -0700 | [diff] [blame] | 339 | bool Resolve(const AidlTypenames& typenames); |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 340 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 341 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 342 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 343 | bool LanguageSpecificCheckValid(const AidlTypenames& typenames, Options::Language lang) const; |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 344 | const AidlNode& AsAidlNode() const override { return *this; } |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 345 | |
Jooyung Han | e9bb9de | 2020-11-01 22:16:57 +0900 | [diff] [blame] | 346 | const AidlDefinedType* GetDefinedType() const; |
| 347 | |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 348 | private: |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 349 | AidlTypeSpecifier(const AidlTypeSpecifier&) = default; |
| 350 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 351 | const string unresolved_name_; |
| 352 | string fully_qualified_name_; |
Steven Moreland | 3f658cf | 2018-08-20 13:40:54 -0700 | [diff] [blame] | 353 | bool is_array_; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 354 | string comments_; |
Jeongik Cha | 1a7ab64 | 2019-07-29 17:31:02 +0900 | [diff] [blame] | 355 | vector<string> split_name_; |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 356 | const AidlDefinedType* defined_type_ = nullptr; // set when Resolve() for defined types |
Jooyung Han | d2fa023 | 2020-10-19 02:51:41 +0900 | [diff] [blame] | 357 | mutable shared_ptr<AidlTypeSpecifier> array_base_; |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 360 | // Returns the universal value unaltered. |
| 361 | std::string AidlConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value); |
| 362 | |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 363 | class AidlConstantValue; |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 364 | class AidlMethod; |
| 365 | class AidlConstantDeclaration; |
| 366 | class AidlVariableDeclaration; |
| 367 | |
| 368 | class AidlMember : public AidlNode { |
| 369 | public: |
| 370 | AidlMember(const AidlLocation& location); |
| 371 | virtual ~AidlMember() = default; |
| 372 | |
| 373 | // non-copyable, non-movable |
| 374 | AidlMember(const AidlMember&) = delete; |
| 375 | AidlMember(AidlMember&&) = delete; |
| 376 | AidlMember& operator=(const AidlMember&) = delete; |
| 377 | AidlMember& operator=(AidlMember&&) = delete; |
| 378 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 379 | virtual const AidlMethod* AsMethod() const { return nullptr; } |
| 380 | virtual const AidlConstantDeclaration* AsConstantDeclaration() const { return nullptr; } |
| 381 | virtual const AidlVariableDeclaration* AsVariableDeclaration() const { return nullptr; } |
| 382 | |
| 383 | AidlMethod* AsMethod() { |
| 384 | return const_cast<AidlMethod*>(const_cast<const AidlMember*>(this)->AsMethod()); |
| 385 | } |
| 386 | AidlConstantDeclaration* AsConstantDeclaration() { |
| 387 | return const_cast<AidlConstantDeclaration*>( |
| 388 | const_cast<const AidlMember*>(this)->AsConstantDeclaration()); |
| 389 | } |
| 390 | AidlVariableDeclaration* AsVariableDeclaration() { |
| 391 | return const_cast<AidlVariableDeclaration*>( |
| 392 | const_cast<const AidlMember*>(this)->AsVariableDeclaration()); |
| 393 | } |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 394 | }; |
| 395 | |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 396 | // TODO: This class is used for method arguments and also parcelable fields, |
| 397 | // and it should be split up since default values don't apply to method |
| 398 | // arguments |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 399 | class AidlVariableDeclaration : public AidlMember { |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 400 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 401 | AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type, |
| 402 | const std::string& name); |
| 403 | AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type, |
| 404 | const std::string& name, AidlConstantValue* default_value); |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 405 | virtual ~AidlVariableDeclaration() = default; |
| 406 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 407 | // non-copyable, non-movable |
| 408 | AidlVariableDeclaration(const AidlVariableDeclaration&) = delete; |
| 409 | AidlVariableDeclaration(AidlVariableDeclaration&&) = delete; |
| 410 | AidlVariableDeclaration& operator=(const AidlVariableDeclaration&) = delete; |
| 411 | AidlVariableDeclaration& operator=(AidlVariableDeclaration&&) = delete; |
| 412 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 413 | const AidlVariableDeclaration* AsVariableDeclaration() const override { return this; } |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 414 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 415 | std::string GetName() const { return name_; } |
Jooyung Han | acae85d | 2020-10-28 16:39:09 +0900 | [diff] [blame] | 416 | std::string GetCapitalizedName() const; |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 417 | const AidlTypeSpecifier& GetType() const { return *type_; } |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 418 | // if this was constructed explicitly with a default value |
| 419 | bool IsDefaultUserSpecified() const { return default_user_specified_; } |
| 420 | // will return the default value this is constructed with or a default value |
| 421 | // if one is available |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 422 | const AidlConstantValue* GetDefaultValue() const { return default_value_.get(); } |
Jooyung Han | 53fb424 | 2020-12-17 16:03:49 +0900 | [diff] [blame] | 423 | bool HasUsefulDefaultValue() const; |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 424 | |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 425 | AidlTypeSpecifier* GetMutableType() { return type_.get(); } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 426 | |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 427 | bool CheckValid(const AidlTypenames& typenames) const; |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 428 | |
| 429 | // ToString is for dumping AIDL. |
| 430 | // Returns string representation of this variable decl including default value. |
| 431 | // This is "annotations type name default_value?". |
| 432 | // e.g) "@utf8InCpp String[] names = {"hello"}" |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 433 | std::string ToString() const; |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 434 | |
| 435 | // Signature is for comparing AIDL types. |
| 436 | // Returns string representation of this variable decl. |
| 437 | // This is "type name". |
| 438 | // e.g) "String[] name" (even if it is annotated with @utf8InCpp and has a default value.) |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 439 | std::string Signature() const; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 440 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 441 | std::string ValueString(const ConstantValueDecorator& decorator) const; |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 442 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 443 | private: |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 444 | std::unique_ptr<AidlTypeSpecifier> type_; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 445 | std::string name_; |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 446 | bool default_user_specified_; |
Steven Moreland | 9ea10e3 | 2018-07-19 15:26:09 -0700 | [diff] [blame] | 447 | std::unique_ptr<AidlConstantValue> default_value_; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | class AidlArgument : public AidlVariableDeclaration { |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 451 | public: |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 452 | enum Direction { IN_DIR = 1, OUT_DIR = 2, INOUT_DIR = 3 }; |
| 453 | |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 454 | AidlArgument(const AidlLocation& location, AidlArgument::Direction direction, |
| 455 | AidlTypeSpecifier* type, const std::string& name); |
| 456 | AidlArgument(const AidlLocation& location, AidlTypeSpecifier* type, const std::string& name); |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 457 | virtual ~AidlArgument() = default; |
| 458 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 459 | // non-copyable, non-movable |
| 460 | AidlArgument(const AidlArgument&) = delete; |
| 461 | AidlArgument(AidlArgument&&) = delete; |
| 462 | AidlArgument& operator=(const AidlArgument&) = delete; |
| 463 | AidlArgument& operator=(AidlArgument&&) = delete; |
| 464 | |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 465 | Direction GetDirection() const { return direction_; } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 466 | bool IsOut() const { return direction_ & OUT_DIR; } |
| 467 | bool IsIn() const { return direction_ & IN_DIR; } |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 468 | bool DirectionWasSpecified() const { return direction_specified_; } |
Jiyong Park | 3656c3c | 2018-08-01 20:02:01 +0900 | [diff] [blame] | 469 | string GetDirectionSpecifier() const; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 470 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 471 | // ToString is for dumping AIDL. |
| 472 | // Returns string representation of this argument including direction |
| 473 | // This is "direction annotations type name". |
| 474 | // e.g) "in @utf8InCpp String[] names" |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 475 | std::string ToString() const; |
| 476 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 477 | private: |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 478 | Direction direction_; |
| 479 | bool direction_specified_; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 480 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 481 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 482 | class AidlUnaryConstExpression; |
| 483 | class AidlBinaryConstExpression; |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 484 | class AidlConstantReference; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 485 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 486 | class AidlConstantValue : public AidlNode { |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 487 | public: |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 488 | enum class Type { |
| 489 | // WARNING: Don't change this order! The order is used to determine type |
| 490 | // promotion during a binary expression. |
| 491 | BOOLEAN, |
| 492 | INT8, |
| 493 | INT32, |
| 494 | INT64, |
| 495 | ARRAY, |
| 496 | CHARACTER, |
| 497 | STRING, |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 498 | REF, |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 499 | FLOATING, |
| 500 | UNARY, |
| 501 | BINARY, |
| 502 | ERROR, |
| 503 | }; |
| 504 | |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 505 | struct Visitor { |
| 506 | virtual ~Visitor() {} |
| 507 | virtual void Visit(AidlConstantValue&) = 0; |
| 508 | virtual void Visit(AidlConstantReference&) = 0; |
| 509 | virtual void Visit(AidlUnaryConstExpression&) = 0; |
| 510 | virtual void Visit(AidlBinaryConstExpression&) = 0; |
| 511 | }; |
| 512 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Return the value casted to the given type. |
| 515 | */ |
| 516 | template <typename T> |
| 517 | T cast() const; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 518 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 519 | virtual ~AidlConstantValue() = default; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 520 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 521 | // non-copyable, non-movable |
| 522 | AidlConstantValue(const AidlConstantValue&) = delete; |
| 523 | AidlConstantValue(AidlConstantValue&&) = delete; |
| 524 | AidlConstantValue& operator=(const AidlConstantValue&) = delete; |
| 525 | AidlConstantValue& operator=(AidlConstantValue&&) = delete; |
| 526 | |
Steven Moreland | 541788d | 2020-05-21 22:05:52 +0000 | [diff] [blame] | 527 | // creates default value, when one isn't specified |
| 528 | // nullptr if no default available |
| 529 | static AidlConstantValue* Default(const AidlTypeSpecifier& specifier); |
| 530 | |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 531 | static AidlConstantValue* Boolean(const AidlLocation& location, bool value); |
| 532 | static AidlConstantValue* Character(const AidlLocation& location, char value); |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 533 | // example: 123, -5498, maybe any size |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 534 | static AidlConstantValue* Integral(const AidlLocation& location, const string& value); |
| 535 | static AidlConstantValue* Floating(const AidlLocation& location, const std::string& value); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 536 | static AidlConstantValue* Array(const AidlLocation& location, |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 537 | std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 538 | // example: "\"asdf\"" |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 539 | static AidlConstantValue* String(const AidlLocation& location, const string& value); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 540 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 541 | Type GetType() const { return final_type_; } |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 542 | const std::string& Literal() const { return value_; } |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 543 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 544 | virtual bool CheckValid() const; |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 545 | |
| 546 | // Raw value of type (currently valid in C++ and Java). Empty string on error. |
Steven Moreland | 4bcb05c | 2019-11-27 18:57:47 -0800 | [diff] [blame] | 547 | string ValueString(const AidlTypeSpecifier& type, const ConstantValueDecorator& decorator) const; |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 548 | virtual void Accept(Visitor& visitor) { |
| 549 | visitor.Visit(*this); |
| 550 | if (type_ == Type::ARRAY) { |
| 551 | for (const auto& v : values_) { |
| 552 | v.get()->Accept(visitor); |
| 553 | } |
| 554 | } |
| 555 | } |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 556 | |
| 557 | private: |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 558 | AidlConstantValue(const AidlLocation& location, Type parsed_type, int64_t parsed_value, |
| 559 | const string& checked_value); |
| 560 | AidlConstantValue(const AidlLocation& location, Type type, const string& checked_value); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 561 | AidlConstantValue(const AidlLocation& location, Type type, |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 562 | std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values, |
| 563 | const std::string& value); |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 564 | static string ToString(Type type); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 565 | static bool ParseIntegral(const string& value, int64_t* parsed_value, Type* parsed_type); |
| 566 | static bool IsHex(const string& value); |
Steven Moreland | 4bcb05c | 2019-11-27 18:57:47 -0800 | [diff] [blame] | 567 | |
Jooyung Han | 74675c2 | 2020-12-15 08:39:57 +0900 | [diff] [blame] | 568 | virtual bool evaluate() const; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 569 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 570 | const Type type_ = Type::ERROR; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 571 | const vector<unique_ptr<AidlConstantValue>> values_; // if type_ == ARRAY |
| 572 | const string value_; // otherwise |
| 573 | |
| 574 | // State for tracking evaluation of expressions |
Steven Moreland | 4bcb05c | 2019-11-27 18:57:47 -0800 | [diff] [blame] | 575 | mutable bool is_valid_ = false; // cache of CheckValid, but may be marked false in evaluate |
| 576 | mutable bool is_evaluated_ = false; // whether evaluate has been called |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 577 | mutable Type final_type_; |
| 578 | mutable int64_t final_value_; |
| 579 | mutable string final_string_value_ = ""; |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 580 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 581 | friend AidlUnaryConstExpression; |
| 582 | friend AidlBinaryConstExpression; |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 583 | friend AidlConstantReference; |
| 584 | }; |
| 585 | |
| 586 | // Represents "<type>.<field>" which resolves to a constant which is one of |
| 587 | // - constant declartion |
| 588 | // - enumerator |
| 589 | // When a <type> is missing, <field> is of the enclosing type. |
| 590 | class AidlConstantReference : public AidlConstantValue { |
| 591 | public: |
| 592 | AidlConstantReference(const AidlLocation& location, const std::string& value, |
| 593 | const std::string& comments); |
| 594 | |
| 595 | const std::unique_ptr<AidlTypeSpecifier>& GetRefType() const { return ref_type_; } |
| 596 | void SetRefType(std::unique_ptr<AidlTypeSpecifier> type) { ref_type_ = std::move(type); } |
| 597 | const std::string& GetFieldName() const { return field_name_; } |
| 598 | const std::string& GetComments() const { return comments_; } |
| 599 | |
| 600 | bool CheckValid() const override; |
| 601 | void Accept(Visitor& visitor) override { visitor.Visit(*this); } |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 602 | const AidlConstantValue* Resolve(); |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 603 | |
| 604 | private: |
Jooyung Han | 74675c2 | 2020-12-15 08:39:57 +0900 | [diff] [blame] | 605 | bool evaluate() const override; |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 606 | |
| 607 | std::unique_ptr<AidlTypeSpecifier> ref_type_; |
| 608 | std::string field_name_; |
| 609 | const std::string comments_; |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 610 | const AidlConstantValue* resolved_ = nullptr; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 611 | }; |
| 612 | |
| 613 | class AidlUnaryConstExpression : public AidlConstantValue { |
| 614 | public: |
| 615 | AidlUnaryConstExpression(const AidlLocation& location, const string& op, |
| 616 | std::unique_ptr<AidlConstantValue> rval); |
| 617 | |
| 618 | static bool IsCompatibleType(Type type, const string& op); |
| 619 | bool CheckValid() const override; |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 620 | void Accept(Visitor& visitor) override { |
| 621 | visitor.Visit(*this); |
| 622 | unary_->Accept(visitor); |
| 623 | } |
| 624 | |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 625 | private: |
Jooyung Han | 74675c2 | 2020-12-15 08:39:57 +0900 | [diff] [blame] | 626 | bool evaluate() const override; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 627 | |
| 628 | std::unique_ptr<AidlConstantValue> unary_; |
| 629 | const string op_; |
| 630 | }; |
| 631 | |
| 632 | class AidlBinaryConstExpression : public AidlConstantValue { |
| 633 | public: |
| 634 | AidlBinaryConstExpression(const AidlLocation& location, std::unique_ptr<AidlConstantValue> lval, |
| 635 | const string& op, std::unique_ptr<AidlConstantValue> rval); |
| 636 | |
| 637 | bool CheckValid() const override; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 638 | |
| 639 | static bool AreCompatibleTypes(Type t1, Type t2); |
| 640 | // Returns the promoted kind for both operands |
| 641 | static Type UsualArithmeticConversion(Type left, Type right); |
| 642 | // Returns the promoted integral type where INT32 is the smallest type |
| 643 | static Type IntegralPromotion(Type in); |
Jooyung Han | 690f584 | 2020-12-04 13:02:04 +0900 | [diff] [blame] | 644 | void Accept(Visitor& visitor) override { |
| 645 | visitor.Visit(*this); |
| 646 | left_val_->Accept(visitor); |
| 647 | right_val_->Accept(visitor); |
| 648 | } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 649 | |
| 650 | private: |
Jooyung Han | 74675c2 | 2020-12-15 08:39:57 +0900 | [diff] [blame] | 651 | bool evaluate() const override; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 652 | |
| 653 | std::unique_ptr<AidlConstantValue> left_val_; |
| 654 | std::unique_ptr<AidlConstantValue> right_val_; |
| 655 | const string op_; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 656 | }; |
| 657 | |
Andrei Onea | 9445fc6 | 2019-06-27 18:11:59 +0100 | [diff] [blame] | 658 | struct AidlAnnotationParameter { |
| 659 | std::string name; |
| 660 | std::unique_ptr<AidlConstantValue> value; |
| 661 | }; |
| 662 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 663 | class AidlConstantDeclaration : public AidlMember { |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 664 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 665 | AidlConstantDeclaration(const AidlLocation& location, AidlTypeSpecifier* specifier, |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 666 | const string& name, AidlConstantValue* value); |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 667 | virtual ~AidlConstantDeclaration() = default; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 668 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 669 | // non-copyable, non-movable |
| 670 | AidlConstantDeclaration(const AidlConstantDeclaration&) = delete; |
| 671 | AidlConstantDeclaration(AidlConstantDeclaration&&) = delete; |
| 672 | AidlConstantDeclaration& operator=(const AidlConstantDeclaration&) = delete; |
| 673 | AidlConstantDeclaration& operator=(AidlConstantDeclaration&&) = delete; |
| 674 | |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 675 | const AidlTypeSpecifier& GetType() const { return *type_; } |
Steven Moreland | 4d12f9a | 2018-10-31 14:30:55 -0700 | [diff] [blame] | 676 | AidlTypeSpecifier* GetMutableType() { return type_.get(); } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 677 | const string& GetName() const { return name_; } |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 678 | const AidlConstantValue& GetValue() const { return *value_; } |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 679 | bool CheckValid(const AidlTypenames& typenames) const; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 680 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 681 | // ToString is for dumping AIDL. |
| 682 | // Returns string representation of this const decl including a const value. |
| 683 | // This is "`const` annotations type name value". |
| 684 | // e.g) "const @utf8InCpp String[] names = { "hello" }" |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 685 | string ToString() const; |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 686 | |
| 687 | // Signature is for comparing types. |
| 688 | // Returns string representation of this const decl. |
| 689 | // This is "direction annotations type name". |
| 690 | // e.g) "String[] names" |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 691 | string Signature() const; |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 692 | |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 693 | string ValueString(const ConstantValueDecorator& decorator) const { |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 694 | return value_->ValueString(GetType(), decorator); |
Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 695 | } |
Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 696 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 697 | const AidlConstantDeclaration* AsConstantDeclaration() const override { return this; } |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 698 | |
| 699 | private: |
Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 700 | const unique_ptr<AidlTypeSpecifier> type_; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 701 | const string name_; |
| 702 | unique_ptr<AidlConstantValue> value_; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 703 | }; |
| 704 | |
| 705 | class AidlMethod : public AidlMember { |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 706 | public: |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 707 | AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, const string& name, |
| 708 | vector<unique_ptr<AidlArgument>>* args, const string& comments); |
| 709 | AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, const string& name, |
| 710 | vector<unique_ptr<AidlArgument>>* args, const string& comments, int id, |
| 711 | bool is_user_defined = true); |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 712 | virtual ~AidlMethod() = default; |
| 713 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 714 | // non-copyable, non-movable |
| 715 | AidlMethod(const AidlMethod&) = delete; |
| 716 | AidlMethod(AidlMethod&&) = delete; |
| 717 | AidlMethod& operator=(const AidlMethod&) = delete; |
| 718 | AidlMethod& operator=(AidlMethod&&) = delete; |
| 719 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 720 | const AidlMethod* AsMethod() const override { return this; } |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 721 | bool IsHidden() const; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 722 | const string& GetComments() const { return comments_; } |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 723 | const AidlTypeSpecifier& GetType() const { return *type_; } |
| 724 | AidlTypeSpecifier* GetMutableType() { return type_.get(); } |
Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 725 | |
Steven Moreland | 8c70ba9 | 2018-12-17 10:20:31 -0800 | [diff] [blame] | 726 | // set if this method is part of an interface that is marked oneway |
| 727 | void ApplyInterfaceOneway(bool oneway) { oneway_ = oneway_ || oneway; } |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 728 | bool IsOneway() const { return oneway_; } |
Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 729 | |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 730 | const std::string& GetName() const { return name_; } |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 731 | bool HasId() const { return has_id_; } |
Jiyong Park | ed65bf4 | 2018-08-28 15:43:27 +0900 | [diff] [blame] | 732 | int GetId() const { return id_; } |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 733 | void SetId(unsigned id) { id_ = id; } |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 734 | |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 735 | bool IsUserDefined() const { return is_user_defined_; } |
| 736 | |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 737 | const std::vector<std::unique_ptr<AidlArgument>>& GetArguments() const { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 738 | return arguments_; |
| 739 | } |
| 740 | // An inout parameter will appear in both GetInArguments() |
| 741 | // and GetOutArguments(). AidlMethod retains ownership of the argument |
| 742 | // pointers returned in this way. |
| 743 | const std::vector<const AidlArgument*>& GetInArguments() const { |
| 744 | return in_arguments_; |
| 745 | } |
| 746 | const std::vector<const AidlArgument*>& GetOutArguments() const { |
| 747 | return out_arguments_; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 748 | } |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 749 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 750 | // ToString is for dumping AIDL. |
| 751 | // Returns string representation of this method including everything. |
| 752 | // This is "ret_type name ( arg_list ) = id". |
| 753 | // e.g) "boolean foo(int, @Nullable String) = 1" |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 754 | std::string ToString() const; |
| 755 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 756 | // Signature is for comparing AIDL types. |
| 757 | // Returns string representation of this method's name & type. |
| 758 | // e.g) "foo(int, String)" |
| 759 | std::string Signature() const; |
| 760 | |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 761 | private: |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 762 | bool oneway_; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 763 | std::string comments_; |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 764 | std::unique_ptr<AidlTypeSpecifier> type_; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 765 | std::string name_; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 766 | const std::vector<std::unique_ptr<AidlArgument>> arguments_; |
| 767 | std::vector<const AidlArgument*> in_arguments_; |
| 768 | std::vector<const AidlArgument*> out_arguments_; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 769 | bool has_id_; |
| 770 | int id_; |
Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 771 | bool is_user_defined_ = true; |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 772 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 773 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 774 | class AidlDefinedType; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 775 | class AidlInterface; |
| 776 | class AidlParcelable; |
| 777 | class AidlStructuredParcelable; |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 778 | class AidlUnionDecl; |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 779 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 780 | // AidlDefinedType represents either an interface, parcelable, or enum that is |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 781 | // defined in the source file. |
| 782 | class AidlDefinedType : public AidlAnnotatable { |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 783 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 784 | AidlDefinedType(const AidlLocation& location, const std::string& name, |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 785 | const std::string& comments, const std::string& package, |
| 786 | std::vector<std::unique_ptr<AidlMember>>* members); |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 787 | virtual ~AidlDefinedType() = default; |
| 788 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 789 | // non-copyable, non-movable |
| 790 | AidlDefinedType(const AidlDefinedType&) = delete; |
| 791 | AidlDefinedType(AidlDefinedType&&) = delete; |
| 792 | AidlDefinedType& operator=(const AidlDefinedType&) = delete; |
| 793 | AidlDefinedType& operator=(AidlDefinedType&&) = delete; |
| 794 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 795 | const std::string& GetName() const { return name_; }; |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 796 | bool IsHidden() const; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 797 | const std::string& GetComments() const { return comments_; } |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 798 | void SetComments(const std::string comments) { comments_ = comments; } |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 799 | |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 800 | /* dot joined package, example: "android.package.foo" */ |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 801 | std::string GetPackage() const { return package_; } |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 802 | /* dot joined package and name, example: "android.package.foo.IBar" */ |
| 803 | std::string GetCanonicalName() const; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 804 | const std::vector<std::string>& GetSplitPackage() const { return split_package_; } |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 805 | |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 806 | virtual std::string GetPreprocessDeclarationName() const = 0; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 807 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 808 | virtual const AidlStructuredParcelable* AsStructuredParcelable() const { return nullptr; } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 809 | virtual const AidlParcelable* AsParcelable() const { return nullptr; } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 810 | virtual const AidlEnumDeclaration* AsEnumDeclaration() const { return nullptr; } |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 811 | virtual const AidlUnionDecl* AsUnionDeclaration() const { return nullptr; } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 812 | virtual const AidlInterface* AsInterface() const { return nullptr; } |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 813 | virtual const AidlParameterizable<std::string>* AsParameterizable() const { return nullptr; } |
Devin Moore | 24f6857 | 2020-02-26 13:20:59 -0800 | [diff] [blame] | 814 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 815 | virtual bool LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 816 | Options::Language lang) const = 0; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 817 | AidlStructuredParcelable* AsStructuredParcelable() { |
| 818 | return const_cast<AidlStructuredParcelable*>( |
| 819 | const_cast<const AidlDefinedType*>(this)->AsStructuredParcelable()); |
| 820 | } |
| 821 | AidlParcelable* AsParcelable() { |
| 822 | return const_cast<AidlParcelable*>(const_cast<const AidlDefinedType*>(this)->AsParcelable()); |
| 823 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 824 | AidlEnumDeclaration* AsEnumDeclaration() { |
| 825 | return const_cast<AidlEnumDeclaration*>( |
| 826 | const_cast<const AidlDefinedType*>(this)->AsEnumDeclaration()); |
| 827 | } |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 828 | AidlUnionDecl* AsUnionDeclaration() { |
| 829 | return const_cast<AidlUnionDecl*>( |
| 830 | const_cast<const AidlDefinedType*>(this)->AsUnionDeclaration()); |
| 831 | } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 832 | AidlInterface* AsInterface() { |
| 833 | return const_cast<AidlInterface*>(const_cast<const AidlDefinedType*>(this)->AsInterface()); |
| 834 | } |
| 835 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 836 | AidlParameterizable<std::string>* AsParameterizable() { |
| 837 | return const_cast<AidlParameterizable<std::string>*>( |
| 838 | const_cast<const AidlDefinedType*>(this)->AsParameterizable()); |
| 839 | } |
| 840 | |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 841 | const AidlParcelable* AsUnstructuredParcelable() const { |
| 842 | if (this->AsStructuredParcelable() != nullptr) return nullptr; |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 843 | if (this->AsUnionDeclaration() != nullptr) return nullptr; |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 844 | return this->AsParcelable(); |
| 845 | } |
| 846 | AidlParcelable* AsUnstructuredParcelable() { |
| 847 | return const_cast<AidlParcelable*>( |
| 848 | const_cast<const AidlDefinedType*>(this)->AsUnstructuredParcelable()); |
| 849 | } |
| 850 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 851 | virtual void Dump(CodeWriter* writer) const = 0; |
Steven Moreland | a5d9c5c | 2020-02-21 16:01:09 -0800 | [diff] [blame] | 852 | void DumpHeader(CodeWriter* writer) const; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 853 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 854 | const std::vector<std::unique_ptr<AidlVariableDeclaration>>& GetFields() const { |
| 855 | return variables_; |
| 856 | } |
| 857 | const std::vector<std::unique_ptr<AidlConstantDeclaration>>& GetConstantDeclarations() const { |
| 858 | return constants_; |
| 859 | } |
| 860 | const std::vector<std::unique_ptr<AidlMethod>>& GetMethods() const { return methods_; } |
| 861 | void AddMethod(std::unique_ptr<AidlMethod> method) { methods_.push_back(std::move(method)); } |
| 862 | const std::vector<const AidlMember*>& GetMembers() const { return members_; } |
| 863 | |
| 864 | protected: |
| 865 | // utility for subclasses with getter names |
| 866 | bool CheckValidForGetterNames() const; |
| 867 | |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 868 | private: |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 869 | bool CheckValidWithMembers(const AidlTypenames& typenames) const; |
| 870 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 871 | std::string name_; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 872 | std::string comments_; |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 873 | const std::string package_; |
| 874 | const std::vector<std::string> split_package_; |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 875 | std::vector<std::unique_ptr<AidlVariableDeclaration>> variables_; |
| 876 | std::vector<std::unique_ptr<AidlConstantDeclaration>> constants_; |
| 877 | std::vector<std::unique_ptr<AidlMethod>> methods_; |
| 878 | std::vector<const AidlMember*> members_; // keep members in order of appearance. |
Steven Moreland | 787b043 | 2018-07-03 09:00:58 -0700 | [diff] [blame] | 879 | }; |
| 880 | |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 881 | class AidlParcelable : public AidlDefinedType, public AidlParameterizable<std::string> { |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 882 | public: |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 883 | AidlParcelable(const AidlLocation& location, const std::string& name, const std::string& package, |
| 884 | const std::string& comments, const std::string& cpp_header = "", |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 885 | std::vector<std::string>* type_params = nullptr, |
| 886 | std::vector<std::unique_ptr<AidlMember>>* members = nullptr); |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 887 | virtual ~AidlParcelable() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 888 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 889 | // non-copyable, non-movable |
| 890 | AidlParcelable(const AidlParcelable&) = delete; |
| 891 | AidlParcelable(AidlParcelable&&) = delete; |
| 892 | AidlParcelable& operator=(const AidlParcelable&) = delete; |
| 893 | AidlParcelable& operator=(AidlParcelable&&) = delete; |
| 894 | |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 895 | std::string GetCppHeader() const { return cpp_header_; } |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 896 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 897 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
Jeongik Cha | 82317dd | 2019-02-27 20:26:11 +0900 | [diff] [blame] | 898 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 899 | bool LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 900 | Options::Language lang) const override; |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 901 | const AidlParcelable* AsParcelable() const override { return this; } |
Jeongik Cha | df76dc7 | 2019-11-28 00:08:47 +0900 | [diff] [blame] | 902 | const AidlParameterizable<std::string>* AsParameterizable() const override { return this; } |
| 903 | const AidlNode& AsAidlNode() const override { return *this; } |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 904 | std::string GetPreprocessDeclarationName() const override { return "parcelable"; } |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 905 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 906 | void Dump(CodeWriter* writer) const override; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 907 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 908 | private: |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 909 | std::string cpp_header_; |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 910 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 911 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 912 | class AidlStructuredParcelable : public AidlParcelable { |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 913 | public: |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 914 | AidlStructuredParcelable(const AidlLocation& location, const std::string& name, |
| 915 | const std::string& package, const std::string& comments, |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 916 | std::vector<std::string>* type_params, |
| 917 | std::vector<std::unique_ptr<AidlMember>>* members); |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 918 | virtual ~AidlStructuredParcelable() = default; |
| 919 | |
| 920 | // non-copyable, non-movable |
| 921 | AidlStructuredParcelable(const AidlStructuredParcelable&) = delete; |
| 922 | AidlStructuredParcelable(AidlStructuredParcelable&&) = delete; |
| 923 | AidlStructuredParcelable& operator=(const AidlStructuredParcelable&) = delete; |
| 924 | AidlStructuredParcelable& operator=(AidlStructuredParcelable&&) = delete; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 925 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 926 | const AidlStructuredParcelable* AsStructuredParcelable() const override { return this; } |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 927 | std::string GetPreprocessDeclarationName() const override { return "structured_parcelable"; } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 928 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 929 | void Dump(CodeWriter* writer) const override; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 930 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 931 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 932 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 933 | bool LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 934 | Options::Language lang) const override; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 935 | }; |
| 936 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 937 | class AidlEnumerator : public AidlNode { |
| 938 | public: |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 939 | AidlEnumerator(const AidlLocation& location, const std::string& name, AidlConstantValue* value, |
| 940 | const std::string& comments); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 941 | virtual ~AidlEnumerator() = default; |
| 942 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 943 | // non-copyable, non-movable |
| 944 | AidlEnumerator(const AidlEnumerator&) = delete; |
| 945 | AidlEnumerator(AidlEnumerator&&) = delete; |
| 946 | AidlEnumerator& operator=(const AidlEnumerator&) = delete; |
| 947 | AidlEnumerator& operator=(AidlEnumerator&&) = delete; |
| 948 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 949 | const std::string& GetName() const { return name_; } |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 950 | AidlConstantValue* GetValue() const { return value_.get(); } |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 951 | const std::string& GetComments() const { return comments_; } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 952 | bool CheckValid(const AidlTypeSpecifier& enum_backing_type) const; |
| 953 | |
| 954 | string ValueString(const AidlTypeSpecifier& backing_type, |
| 955 | const ConstantValueDecorator& decorator) const; |
| 956 | |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 957 | void SetValue(std::unique_ptr<AidlConstantValue> value) { value_ = std::move(value); } |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 958 | bool IsValueUserSpecified() const { return value_user_specified_; } |
Daniel Norman | b28684e | 2019-10-17 15:31:39 -0700 | [diff] [blame] | 959 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 960 | private: |
| 961 | const std::string name_; |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 962 | unique_ptr<AidlConstantValue> value_; |
Daniel Norman | 2e4112d | 2019-10-03 10:22:35 -0700 | [diff] [blame] | 963 | const std::string comments_; |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 964 | const bool value_user_specified_; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | class AidlEnumDeclaration : public AidlDefinedType { |
| 968 | public: |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 969 | AidlEnumDeclaration(const AidlLocation& location, const string& name, |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 970 | std::vector<std::unique_ptr<AidlEnumerator>>* enumerators, |
Jiyong Park | 1813218 | 2020-06-08 20:24:40 +0900 | [diff] [blame] | 971 | const std::string& package, const std::string& comments); |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 972 | virtual ~AidlEnumDeclaration() = default; |
| 973 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 974 | // non-copyable, non-movable |
| 975 | AidlEnumDeclaration(const AidlEnumDeclaration&) = delete; |
| 976 | AidlEnumDeclaration(AidlEnumDeclaration&&) = delete; |
| 977 | AidlEnumDeclaration& operator=(const AidlEnumDeclaration&) = delete; |
| 978 | AidlEnumDeclaration& operator=(AidlEnumDeclaration&&) = delete; |
| 979 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 980 | void SetBackingType(std::unique_ptr<const AidlTypeSpecifier> type); |
| 981 | const AidlTypeSpecifier& GetBackingType() const { return *backing_type_; } |
| 982 | const std::vector<std::unique_ptr<AidlEnumerator>>& GetEnumerators() const { |
| 983 | return enumerators_; |
| 984 | } |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 985 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 986 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 987 | bool LanguageSpecificCheckValid(const AidlTypenames& /*typenames*/, |
| 988 | Options::Language) const override { |
| 989 | return true; |
| 990 | } |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 991 | std::string GetPreprocessDeclarationName() const override { return "enum"; } |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 992 | void Dump(CodeWriter* writer) const override; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 993 | |
| 994 | const AidlEnumDeclaration* AsEnumDeclaration() const override { return this; } |
| 995 | |
| 996 | private: |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 997 | void Autofill(); |
| 998 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 999 | const std::string name_; |
| 1000 | const std::vector<std::unique_ptr<AidlEnumerator>> enumerators_; |
| 1001 | std::unique_ptr<const AidlTypeSpecifier> backing_type_; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 1002 | }; |
| 1003 | |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 1004 | class AidlUnionDecl : public AidlParcelable { |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1005 | public: |
| 1006 | AidlUnionDecl(const AidlLocation& location, const std::string& name, const std::string& package, |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 1007 | const std::string& comments, std::vector<std::string>* type_params, |
| 1008 | std::vector<std::unique_ptr<AidlMember>>* members); |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1009 | virtual ~AidlUnionDecl() = default; |
| 1010 | |
| 1011 | // non-copyable, non-movable |
| 1012 | AidlUnionDecl(const AidlUnionDecl&) = delete; |
| 1013 | AidlUnionDecl(AidlUnionDecl&&) = delete; |
| 1014 | AidlUnionDecl& operator=(const AidlUnionDecl&) = delete; |
| 1015 | AidlUnionDecl& operator=(AidlUnionDecl&&) = delete; |
| 1016 | |
| 1017 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
| 1018 | |
| 1019 | const AidlNode& AsAidlNode() const override { return *this; } |
| 1020 | |
Jooyung Han | fe89f12 | 2020-10-14 03:49:18 +0900 | [diff] [blame] | 1021 | bool CheckValid(const AidlTypenames& typenames) const override; |
| 1022 | bool LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 1023 | Options::Language lang) const override; |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1024 | std::string GetPreprocessDeclarationName() const override { return "union"; } |
| 1025 | |
| 1026 | void Dump(CodeWriter* writer) const override; |
| 1027 | const AidlUnionDecl* AsUnionDeclaration() const override { return this; } |
Jooyung Han | 2946afc | 2020-10-05 20:29:16 +0900 | [diff] [blame] | 1028 | }; |
| 1029 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 1030 | class AidlInterface final : public AidlDefinedType { |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 1031 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 1032 | AidlInterface(const AidlLocation& location, const std::string& name, const std::string& comments, |
Jooyung Han | 829ec7c | 2020-12-02 12:07:36 +0900 | [diff] [blame] | 1033 | bool oneway_, const std::string& package, |
| 1034 | std::vector<std::unique_ptr<AidlMember>>* members); |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 1035 | virtual ~AidlInterface() = default; |
| 1036 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 1037 | // non-copyable, non-movable |
| 1038 | AidlInterface(const AidlInterface&) = delete; |
| 1039 | AidlInterface(AidlInterface&&) = delete; |
| 1040 | AidlInterface& operator=(const AidlInterface&) = delete; |
| 1041 | AidlInterface& operator=(AidlInterface&&) = delete; |
| 1042 | |
Steven Moreland | c258abc | 2018-07-10 14:03:38 -0700 | [diff] [blame] | 1043 | const AidlInterface* AsInterface() const override { return this; } |
Steven Moreland | ed83a28 | 2018-07-17 13:27:29 -0700 | [diff] [blame] | 1044 | std::string GetPreprocessDeclarationName() const override { return "interface"; } |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 1045 | |
Jeongik Cha | 997281d | 2020-01-16 15:23:59 +0900 | [diff] [blame] | 1046 | void Dump(CodeWriter* writer) const override; |
Jiyong Park | 02da742 | 2018-07-16 16:00:26 +0900 | [diff] [blame] | 1047 | |
Steven Moreland | 0cea4aa | 2020-04-20 21:06:02 -0700 | [diff] [blame] | 1048 | std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1049 | bool CheckValid(const AidlTypenames& typenames) const override; |
Steven Moreland | d59e317 | 2020-05-11 16:42:09 -0700 | [diff] [blame] | 1050 | bool LanguageSpecificCheckValid(const AidlTypenames& typenames, |
| 1051 | Options::Language lang) const override; |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 1052 | |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 1053 | std::string GetDescriptor() const; |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 1054 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1055 | |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 1056 | class AidlImport : public AidlNode { |
| 1057 | public: |
Steven Moreland | 46e9da8 | 2018-07-27 15:45:29 -0700 | [diff] [blame] | 1058 | AidlImport(const AidlLocation& location, const std::string& needed_class); |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 1059 | virtual ~AidlImport() = default; |
| 1060 | |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 1061 | // non-copyable, non-movable |
| 1062 | AidlImport(const AidlImport&) = delete; |
| 1063 | AidlImport(AidlImport&&) = delete; |
| 1064 | AidlImport& operator=(const AidlImport&) = delete; |
| 1065 | AidlImport& operator=(AidlImport&&) = delete; |
| 1066 | |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 1067 | const std::string& GetNeededClass() const { return needed_class_; } |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 1068 | |
| 1069 | private: |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 1070 | std::string needed_class_; |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 1071 | }; |
| 1072 | |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 1073 | // AidlDocument models an AIDL file |
| 1074 | class AidlDocument : public AidlNode { |
| 1075 | public: |
| 1076 | AidlDocument(const AidlLocation& location, std::vector<std::unique_ptr<AidlImport>>& imports, |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 1077 | std::vector<std::unique_ptr<AidlDefinedType>>&& defined_types) |
| 1078 | : AidlNode(location), |
| 1079 | imports_(std::move(imports)), |
| 1080 | defined_types_(std::move(defined_types)) {} |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 1081 | ~AidlDocument() = default; |
| 1082 | |
| 1083 | // non-copyable, non-movable |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 1084 | AidlDocument(const AidlDocument&) = delete; |
| 1085 | AidlDocument(AidlDocument&&) = delete; |
| 1086 | AidlDocument& operator=(const AidlDocument&) = delete; |
| 1087 | AidlDocument& operator=(AidlDocument&&) = delete; |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 1088 | |
Jooyung Han | 2981384 | 2020-12-08 01:28:03 +0900 | [diff] [blame] | 1089 | std::optional<std::string> ResolveName(const std::string& unresolved_type) const; |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 1090 | const std::vector<std::unique_ptr<AidlImport>>& Imports() const { return imports_; } |
| 1091 | const std::vector<std::unique_ptr<AidlDefinedType>>& DefinedTypes() const { |
| 1092 | return defined_types_; |
| 1093 | } |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 1094 | |
| 1095 | private: |
| 1096 | const std::vector<std::unique_ptr<AidlImport>> imports_; |
Jiyong Park | 8e79b7f | 2020-07-20 20:52:38 +0900 | [diff] [blame] | 1097 | const std::vector<std::unique_ptr<AidlDefinedType>> defined_types_; |
Jiyong Park | 6251551 | 2020-06-08 15:57:11 +0900 | [diff] [blame] | 1098 | }; |