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