Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018, 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 | */ |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 16 | #pragma once |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 17 | |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 18 | #include <functional> |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 19 | #include <map> |
| 20 | #include <memory> |
| 21 | #include <set> |
| 22 | #include <string> |
| 23 | #include <utility> |
| 24 | #include <vector> |
| 25 | |
| 26 | using std::map; |
| 27 | using std::pair; |
| 28 | using std::set; |
| 29 | using std::string; |
| 30 | using std::unique_ptr; |
| 31 | using std::vector; |
| 32 | |
| 33 | class AidlDefinedType; |
| 34 | class AidlTypeSpecifier; |
| 35 | |
| 36 | namespace android { |
| 37 | namespace aidl { |
| 38 | |
| 39 | // AidlTypenames is a collection of AIDL types available to a compilation unit. |
| 40 | // |
| 41 | // Basic types (such as int, String, etc.) are added by default, while defined |
| 42 | // types (such as IFoo, MyParcelable, etc.) and types from preprocessed inputs |
| 43 | // are added as they are recognized by the parser. |
| 44 | // |
| 45 | // When AidlTypeSpecifier is encountered during parsing, parser defers the |
| 46 | // resolution of it until the end of the parsing, where it uses AidlTypenames |
| 47 | // to resolve type names in AidlTypeSpecifier. |
| 48 | // |
| 49 | // Note that nothing here is specific to either Java or C++. |
Jiyong Park | ac89604 | 2018-07-23 21:23:05 +0900 | [diff] [blame] | 50 | class AidlTypenames final { |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 51 | public: |
| 52 | AidlTypenames() = default; |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 53 | void Reset(); |
| 54 | bool AddDefinedType(unique_ptr<AidlDefinedType> type); |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 55 | bool AddPreprocessedType(unique_ptr<AidlDefinedType> type); |
Jiyong Park | ac89604 | 2018-07-23 21:23:05 +0900 | [diff] [blame] | 56 | static bool IsBuiltinTypename(const string& type_name); |
Jeongik Cha | db0f59e | 2018-11-01 18:11:21 +0900 | [diff] [blame] | 57 | static bool IsPrimitiveTypename(const string& type_name); |
Jiyong Park | ac89604 | 2018-07-23 21:23:05 +0900 | [diff] [blame] | 58 | const AidlDefinedType* TryGetDefinedType(const string& type_name) const; |
| 59 | pair<string, bool> ResolveTypename(const string& type_name) const; |
Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 60 | bool CanBeOutParameter(const AidlTypeSpecifier& type) const; |
Jeongik Cha | 047c5ee | 2019-08-07 23:16:49 +0900 | [diff] [blame^] | 61 | bool IsIgnorableImport(const string& import) const; |
Steven Moreland | 6cee348 | 2018-07-18 14:39:58 -0700 | [diff] [blame] | 62 | // Iterates over all defined and then preprocessed types |
| 63 | void IterateTypes(const std::function<void(const AidlDefinedType&)>& body) const; |
| 64 | |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 65 | private: |
Jiyong Park | b034bf0 | 2018-07-30 17:44:33 +0900 | [diff] [blame] | 66 | map<string, unique_ptr<AidlDefinedType>> defined_types_; |
Jiyong Park | 1deecc3 | 2018-07-17 01:14:41 +0900 | [diff] [blame] | 67 | map<string, unique_ptr<AidlDefinedType>> preprocessed_types_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace aidl |
| 71 | } // namespace android |