blob: 29b25f1faf432507f1f6b4c49388d0be3478506b [file] [log] [blame]
Martijn Coenen99e6beb2016-12-01 15:48:42 +01001/*
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
22namespace android {
23
Neel Mehta3b414a82019-07-02 15:47:48 -070024PointerType::PointerType(Scope* parent) : Type(parent, "pointer") {}
Martijn Coenen99e6beb2016-12-01 15:48:42 +010025
26bool PointerType::isPointer() const {
27 return true;
28}
29
Steven Moreland9df52442016-12-12 08:51:14 -080030bool PointerType::isElidableType() const {
31 return true;
32}
33
Steven Moreland1f575482018-10-05 11:26:20 -070034std::string PointerType::getCppType(StorageMode /*mode*/,
35 bool /*specifyNamespaces*/) const {
Martijn Coenen99e6beb2016-12-01 15:48:42 +010036 return "void*";
37}
38
Steven Moreland0ecc7b82017-07-19 12:59:23 -070039std::string PointerType::typeName() const {
40 return "local pointer";
41}
42
Martijn Coenen99e6beb2016-12-01 15:48:42 +010043std::string PointerType::getVtsType() const {
44 return "TYPE_POINTER";
45}
46
47void PointerType::emitReaderWriter(
48 Formatter& out,
Steven Morelanda6ce1e22017-06-19 09:42:23 -070049 const std::string& name,
Steven Moreland1f575482018-10-05 11:26:20 -070050 const std::string& /*parcelObj*/,
51 bool /*parcelObjIsPointer*/,
52 bool /*isReader*/,
Steven Moreland70f66252020-01-09 17:26:57 -080053 ErrorMode mode) const {
Steven Morelanda6ce1e22017-06-19 09:42:23 -070054 out << "(void)" << name << ";\n";
Steven Moreland1f575482018-10-05 11:26:20 -070055 out << "LOG_ALWAYS_FATAL(\"Pointer is only supported in passthrough mode\");\n\n";
Steven Moreland70f66252020-01-09 17:26:57 -080056
57 // always use label if mode is goto
58 handleError(out, mode);
Steven Moreland1f575482018-10-05 11:26:20 -070059}
60
61void PointerType::emitReaderWriterEmbedded(
62 Formatter& out,
63 size_t /*depth*/,
64 const std::string& name,
65 const std::string& /*sanitizedName*/,
66 bool /*nameIsPointer*/,
67 const std::string& parcelObj,
68 bool parcelObjIsPointer,
69 bool isReader,
70 ErrorMode mode,
71 const std::string& parentName,
72 const std::string& offsetText) const {
73 out << "(void) " << parcelObj << ";\n";
74 out << "(void) " << parentName << ";\n";
75 out << "(void) (" << offsetText << ");\n";
76
77 // same exact code
78 emitReaderWriter(out, name, parcelObj, parcelObjIsPointer, isReader, mode);
Martijn Coenen99e6beb2016-12-01 15:48:42 +010079}
80
81bool PointerType::needsEmbeddedReadWrite() const {
Steven Moreland1f575482018-10-05 11:26:20 -070082 return true;
Martijn Coenen99e6beb2016-12-01 15:48:42 +010083}
84
85bool PointerType::resultNeedsDeref() const {
86 return false;
87}
88
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -070089bool PointerType::deepIsJavaCompatible(std::unordered_set<const Type*>* /* visited */) const {
Martijn Coenen99e6beb2016-12-01 15:48:42 +010090 return false;
91}
92
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -070093bool PointerType::deepContainsPointer(std::unordered_set<const Type*>* /* visited */) const {
Andreas Huber60d3b222017-03-30 09:10:56 -070094 return true;
Martijn Coenen99e6beb2016-12-01 15:48:42 +010095}
96
Steven Moreland6ec9eb92018-02-16 14:21:49 -080097void PointerType::emitVtsTypeDeclarations(Formatter& out) const {
Martijn Coenen99e6beb2016-12-01 15:48:42 +010098 out << "type: " << getVtsType() << "\n";
Martijn Coenen99e6beb2016-12-01 15:48:42 +010099}
100
101} // namespace android
102