• 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 #ifndef VECTOR_TYPE_H_
18 
19 #define VECTOR_TYPE_H_
20 
21 #include <vector>
22 
23 #include "Reference.h"
24 #include "Type.h"
25 
26 namespace android {
27 
28 struct VectorType : public TemplatedType {
29     VectorType(Scope* parent);
30 
31     bool isVector() const override;
32     bool isVectorOfBinders() const;
33 
34     std::string templatedTypeName() const override;
35     bool isCompatibleElementType(const Type* elementType) const override;
36 
37     std::vector<const Reference<Type>*> getStrongReferences() const override;
38 
39     bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
40 
41     std::string getCppType(
42             StorageMode mode,
43             bool specifyNamespaces) const override;
44 
45     std::string getJavaType(bool forInitializer) const override;
46     std::string getJavaTypeClass() const override;
47 
48     std::string getVtsType() const override;
49     std::string getVtsValueName() const override;
50 
51     void emitReaderWriter(
52             Formatter &out,
53             const std::string &name,
54             const std::string &parcelObj,
55             bool parcelObjIsPointer,
56             bool isReader,
57             ErrorMode mode) const override;
58 
59     void emitReaderWriterEmbedded(
60             Formatter &out,
61             size_t depth,
62             const std::string &name,
63             const std::string &sanitizedName,
64             bool nameIsPointer,
65             const std::string &parcelObj,
66             bool parcelObjIsPointer,
67             bool isReader,
68             ErrorMode mode,
69             const std::string &parentName,
70             const std::string &offsetText) const override;
71 
72     void emitResolveReferences(
73             Formatter &out,
74             const std::string &name,
75             bool nameIsPointer,
76             const std::string &parcelObj,
77             bool parcelObjIsPointer,
78             bool isReader,
79             ErrorMode mode) const override;
80 
81     void emitResolveReferencesEmbedded(
82             Formatter &out,
83             size_t depth,
84             const std::string &name,
85             const std::string &sanitizedName,
86             bool nameIsPointer,
87             const std::string &parcelObj,
88             bool parcelObjIsPointer,
89             bool isReader,
90             ErrorMode mode,
91             const std::string &parentName,
92             const std::string &offsetText) const override;
93 
94     bool useParentInEmitResolveReferencesEmbedded() const override;
95 
96     void emitJavaReaderWriter(
97             Formatter &out,
98             const std::string &parcelObj,
99             const std::string &argName,
100             bool isReader) const override;
101 
102     void emitJavaFieldInitializer(
103             Formatter &out, const std::string &fieldName) const override;
104 
105     void emitJavaFieldDefaultInitialValue(
106             Formatter &out, const std::string &declaredFieldName) const override;
107 
108     void emitJavaFieldReaderWriter(
109             Formatter &out,
110             size_t depth,
111             const std::string &parcelName,
112             const std::string &blobName,
113             const std::string &fieldName,
114             const std::string &offset,
115             bool isReader) const override;
116 
117     static void EmitJavaFieldReaderWriterForElementType(
118             Formatter &out,
119             size_t depth,
120             const Type *elementType,
121             const std::string &parcelName,
122             const std::string &blobName,
123             const std::string &fieldName,
124             const std::string &offset,
125             bool isReader);
126 
127     bool needsEmbeddedReadWrite() const override;
128     bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
129     bool resultNeedsDeref() const override;
130 
131     bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
132     bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
133 
134     void getAlignmentAndSize(size_t *align, size_t *size) const override;
135     static void getAlignmentAndSizeStatic(size_t *align, size_t *size);
136  private:
137     // Helper method for emitResolveReferences[Embedded].
138     // Pass empty childName and childOffsetText if the original
139     // childHandle is unknown.
140     // For example, given a vec<ref<T>> (T is a simple struct that
141     // contains primitive values only), then the following methods are
142     // invoked:
143     // 1. VectorType::emitResolveReferences
144     //    ... which calls the helper with empty childName and childOffsetText
145     // 2. RefType::emitResolveReferencesEmbedded
146     void emitResolveReferencesEmbeddedHelper(
147             Formatter &out,
148             size_t depth,
149             const std::string &name,
150             const std::string &sanitizedName,
151             bool nameIsPointer,
152             const std::string &parcelObj,
153             bool parcelObjIsPointer,
154             bool isReader,
155             ErrorMode mode,
156             const std::string &childName,
157             const std::string &childOffsetText) const;
158 
159     void emitReaderWriterForVectorOfBinders(
160             Formatter &out,
161             const std::string &name,
162             const std::string &parcelObj,
163             bool parcelObjIsPointer,
164             bool isReader,
165             ErrorMode mode) const;
166 
167     DISALLOW_COPY_AND_ASSIGN(VectorType);
168 };
169 
170 }  // namespace android
171 
172 #endif  // VECTOR_TYPE_H_
173 
174