Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -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 | #pragma once |
| 17 | |
| 18 | #include "aidl_language.h" |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 19 | #include "aidl_to_cpp_common.h" |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | namespace aidl { |
| 23 | namespace ndk { |
| 24 | |
| 25 | enum class StorageMode { |
| 26 | STACK, |
| 27 | ARGUMENT, // Value for primitives, const& for larger types |
| 28 | OUT_ARGUMENT, // Pointer to raw type |
| 29 | }; |
| 30 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 31 | std::string NdkHeaderFile(const AidlDefinedType& defined_type, cpp::ClassNames name, |
| 32 | bool use_os_sep = true); |
| 33 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 34 | // Returns ::aidl::some_package::some_sub_package::foo::IFoo/BpFoo/BnFoo |
| 35 | std::string NdkFullClassName(const AidlDefinedType& type, cpp::ClassNames name); |
| 36 | |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 37 | // Returns the corresponding Ndk type name for an AIDL type spec including |
| 38 | // array modifiers. |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 39 | std::string NdkNameOf(const AidlTypenames& types, const AidlTypeSpecifier& aidl, StorageMode mode); |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 40 | |
| 41 | struct CodeGeneratorContext { |
| 42 | CodeWriter& writer; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 43 | |
| 44 | const AidlTypenames& types; |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 45 | const AidlTypeSpecifier& type; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 46 | |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 47 | const string parcel; |
| 48 | const string var; |
| 49 | }; |
| 50 | |
| 51 | void WriteToParcelFor(const CodeGeneratorContext& c); |
| 52 | void ReadFromParcelFor(const CodeGeneratorContext& c); |
| 53 | |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 54 | // Returns argument list of a method where each arg is formatted by the fomatter |
| 55 | std::string NdkArgList( |
| 56 | const AidlTypenames& types, const AidlMethod& method, |
| 57 | std::function<std::string(const std::string& type, const std::string& name, bool isOut)> |
| 58 | formatter); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 59 | |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 60 | inline std::string FormatArgForDecl(const std::string& type, const std::string& name, |
| 61 | bool /*isOut*/) { |
| 62 | return type + " " + name; |
| 63 | } |
| 64 | |
| 65 | inline std::string FormatArgNameUnused(const std::string& type, const std::string& name, |
| 66 | bool /*isOut*/) { |
| 67 | return type + " /*" + name + "*/"; |
| 68 | } |
| 69 | |
| 70 | inline std::string FormatArgForCall(const std::string& /*type*/, const std::string& name, |
| 71 | bool isOut) { |
| 72 | std::string reference_prefix = isOut ? "&" : ""; |
| 73 | return reference_prefix + name; |
| 74 | } |
| 75 | |
| 76 | inline std::string FormatArgNameOnly(const std::string& /*type*/, const std::string& name, |
| 77 | bool /*isOut*/) { |
| 78 | return name; |
| 79 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 80 | |
| 81 | // -> 'status (class::)name(type name, ...)' for a method |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 82 | std::string NdkMethodDecl(const AidlTypenames& types, const AidlMethod& method, |
| 83 | const std::string& clazz = ""); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 84 | |
Steven Moreland | e8a3a19 | 2018-09-20 14:14:28 -0700 | [diff] [blame] | 85 | } // namespace ndk |
| 86 | } // namespace aidl |
| 87 | } // namespace android |