• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
PointerType(Scope * parent)24 PointerType::PointerType(Scope* parent) : Type(parent, "pointer") {}
25 
isPointer() const26 bool PointerType::isPointer() const {
27     return true;
28 }
29 
isElidableType() const30 bool PointerType::isElidableType() const {
31     return true;
32 }
33 
getCppType(StorageMode,bool) const34 std::string PointerType::getCppType(StorageMode /*mode*/,
35                                     bool /*specifyNamespaces*/) const {
36     return "void*";
37 }
38 
typeName() const39 std::string PointerType::typeName() const {
40     return "local pointer";
41 }
42 
getVtsType() const43 std::string PointerType::getVtsType() const {
44     return "TYPE_POINTER";
45 }
46 
emitReaderWriter(Formatter & out,const std::string & name,const std::string &,bool,bool,ErrorMode mode) const47 void PointerType::emitReaderWriter(
48         Formatter& out,
49         const std::string& name,
50         const std::string& /*parcelObj*/,
51         bool /*parcelObjIsPointer*/,
52         bool /*isReader*/,
53         ErrorMode mode) const {
54     out << "(void)" << name << ";\n";
55     out << "LOG_ALWAYS_FATAL(\"Pointer is only supported in passthrough mode\");\n\n";
56 
57     // always use label if mode is goto
58     handleError(out, mode);
59 }
60 
emitReaderWriterEmbedded(Formatter & out,size_t,const std::string & name,const std::string &,bool,const std::string & parcelObj,bool parcelObjIsPointer,bool isReader,ErrorMode mode,const std::string & parentName,const std::string & offsetText) const61 void 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);
79 }
80 
needsEmbeddedReadWrite() const81 bool PointerType::needsEmbeddedReadWrite() const {
82     return true;
83 }
84 
resultNeedsDeref() const85 bool PointerType::resultNeedsDeref() const {
86     return false;
87 }
88 
deepIsJavaCompatible(std::unordered_set<const Type * > *) const89 bool PointerType::deepIsJavaCompatible(std::unordered_set<const Type*>* /* visited */) const {
90     return false;
91 }
92 
deepContainsPointer(std::unordered_set<const Type * > *) const93 bool PointerType::deepContainsPointer(std::unordered_set<const Type*>* /* visited */) const {
94     return true;
95 }
96 
emitVtsTypeDeclarations(Formatter & out) const97 void PointerType::emitVtsTypeDeclarations(Formatter& out) const {
98     out << "type: " << getVtsType() << "\n";
99 }
100 
101 }  // namespace android
102 
103