Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include "PointerType.h" |
| 18 | |
| 19 | #include <hidl-util/Formatter.h> |
| 20 | #include <android-base/logging.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
Timur Iskhakov | 63f3990 | 2017-08-29 15:47:29 -0700 | [diff] [blame] | 24 | PointerType::PointerType(Scope* parent) : Type(parent) {} |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 25 | |
| 26 | bool PointerType::isPointer() const { |
| 27 | return true; |
| 28 | } |
| 29 | |
Steven Moreland | 9df5244 | 2016-12-12 08:51:14 -0800 | [diff] [blame] | 30 | bool PointerType::isElidableType() const { |
| 31 | return true; |
| 32 | } |
| 33 | |
Steven Moreland | 1f57548 | 2018-10-05 11:26:20 -0700 | [diff] [blame] | 34 | std::string PointerType::getCppType(StorageMode /*mode*/, |
| 35 | bool /*specifyNamespaces*/) const { |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 36 | return "void*"; |
| 37 | } |
| 38 | |
Steven Moreland | 0ecc7b8 | 2017-07-19 12:59:23 -0700 | [diff] [blame] | 39 | std::string PointerType::typeName() const { |
| 40 | return "local pointer"; |
| 41 | } |
| 42 | |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 43 | std::string PointerType::getVtsType() const { |
| 44 | return "TYPE_POINTER"; |
| 45 | } |
| 46 | |
| 47 | void PointerType::emitReaderWriter( |
| 48 | Formatter& out, |
Steven Moreland | a6ce1e2 | 2017-06-19 09:42:23 -0700 | [diff] [blame] | 49 | const std::string& name, |
Steven Moreland | 1f57548 | 2018-10-05 11:26:20 -0700 | [diff] [blame] | 50 | const std::string& /*parcelObj*/, |
| 51 | bool /*parcelObjIsPointer*/, |
| 52 | bool /*isReader*/, |
| 53 | ErrorMode /*mode*/) const { |
Steven Moreland | a6ce1e2 | 2017-06-19 09:42:23 -0700 | [diff] [blame] | 54 | out << "(void)" << name << ";\n"; |
Steven Moreland | 1f57548 | 2018-10-05 11:26:20 -0700 | [diff] [blame] | 55 | out << "LOG_ALWAYS_FATAL(\"Pointer is only supported in passthrough mode\");\n\n"; |
| 56 | } |
| 57 | |
| 58 | void PointerType::emitReaderWriterEmbedded( |
| 59 | Formatter& out, |
| 60 | size_t /*depth*/, |
| 61 | const std::string& name, |
| 62 | const std::string& /*sanitizedName*/, |
| 63 | bool /*nameIsPointer*/, |
| 64 | const std::string& parcelObj, |
| 65 | bool parcelObjIsPointer, |
| 66 | bool isReader, |
| 67 | ErrorMode mode, |
| 68 | const std::string& parentName, |
| 69 | const std::string& offsetText) const { |
| 70 | out << "(void) " << parcelObj << ";\n"; |
| 71 | out << "(void) " << parentName << ";\n"; |
| 72 | out << "(void) (" << offsetText << ");\n"; |
| 73 | |
| 74 | // same exact code |
| 75 | emitReaderWriter(out, name, parcelObj, parcelObjIsPointer, isReader, mode); |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | bool PointerType::needsEmbeddedReadWrite() const { |
Steven Moreland | 1f57548 | 2018-10-05 11:26:20 -0700 | [diff] [blame] | 79 | return true; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | bool PointerType::resultNeedsDeref() const { |
| 83 | return false; |
| 84 | } |
| 85 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 86 | bool PointerType::deepIsJavaCompatible(std::unordered_set<const Type*>* /* visited */) const { |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 90 | bool PointerType::deepContainsPointer(std::unordered_set<const Type*>* /* visited */) const { |
Andreas Huber | 60d3b22 | 2017-03-30 09:10:56 -0700 | [diff] [blame] | 91 | return true; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Steven Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 94 | void PointerType::emitVtsTypeDeclarations(Formatter& out) const { |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 95 | out << "type: " << getVtsType() << "\n"; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace android |
| 99 | |