Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [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 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <string> |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 20 | #include <type_traits> |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 21 | |
| 22 | #include "aidl_language.h" |
| 23 | |
| 24 | // This is used to help generate code targetting C++ (the language) whether using the libbinder or |
| 25 | // libbinder_ndk backend. |
| 26 | |
| 27 | namespace android { |
| 28 | namespace aidl { |
| 29 | namespace cpp { |
| 30 | |
| 31 | // These roughly correspond to the various class names in the C++ hierarchy: |
| 32 | enum class ClassNames { |
| 33 | BASE, // Foo (not a real class, but useful in some circumstances). |
| 34 | CLIENT, // BpFoo |
| 35 | SERVER, // BnFoo |
| 36 | INTERFACE, // IFoo |
| 37 | DEFAULT_IMPL, // IFooDefault |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 38 | RAW, // (as shown in the file) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | string ClassName(const AidlDefinedType& defined_type, ClassNames type); |
| 42 | |
| 43 | // Generate the relative path to a header file. If |use_os_sep| we'll use the |
| 44 | // operating system specific path separator rather than C++'s expected '/' when |
| 45 | // including headers. |
| 46 | std::string HeaderFile(const AidlDefinedType& defined_type, ClassNames class_type, |
| 47 | bool use_os_sep = true); |
| 48 | |
| 49 | void EnterNamespace(CodeWriter& out, const AidlDefinedType& defined_type); |
| 50 | void LeaveNamespace(CodeWriter& out, const AidlDefinedType& defined_type); |
| 51 | |
Steven Moreland | 3b1325f | 2018-09-20 14:45:40 -0700 | [diff] [blame] | 52 | string BuildVarName(const AidlArgument& a); |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 53 | const string GenLogBeforeExecute(const string className, const AidlMethod& method, bool isServer, |
| 54 | bool isNdk); |
| 55 | const string GenLogAfterExecute(const string className, const AidlInterface& interface, |
| 56 | const AidlMethod& method, const string& statusVarName, |
| 57 | const string& returnVarName, bool isServer, bool isNdk); |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 58 | |
| 59 | template <typename T, typename = std::enable_if_t<std::is_copy_constructible_v<T>>> |
| 60 | std::vector<T> Append(std::vector<T> as, const std::vector<T>& bs) { |
| 61 | as.insert(as.end(), bs.begin(), bs.end()); |
| 62 | return as; |
| 63 | } |
| 64 | |
| 65 | template <typename T> |
| 66 | std::vector<T> Append(std::vector<T>&& as, std::vector<T>&& bs) { |
| 67 | std::vector<T> appended = std::move(as); |
| 68 | std::copy(std::move_iterator(bs.begin()), std::move_iterator(bs.end()), |
| 69 | std::back_inserter(appended)); |
| 70 | return appended; |
| 71 | } |
| 72 | |
| 73 | std::string GenerateEnumValues(const AidlEnumDeclaration& enum_decl, |
| 74 | const std::vector<std::string>& enclosing_namespaces_of_enum_decl); |
| 75 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 76 | } // namespace cpp |
| 77 | } // namespace aidl |
| 78 | } // namespace android |