• 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 ARRAY_TYPE_H_
18 
19 #define ARRAY_TYPE_H_
20 
21 #include "Reference.h"
22 #include "Type.h"
23 
24 #include <vector>
25 
26 namespace android {
27 
28 struct ConstantExpression;
29 
30 struct ArrayType : public Type {
31     ArrayType(const Reference<Type>& elementType, ConstantExpression* size, Scope* parent);
32 
33     bool isArray() const override;
34     bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
35 
36     const Type* getElementType() const;
37 
38     void appendDimension(ConstantExpression *size);
39     size_t countDimensions() const;
40 
41     std::string typeName() const override;
42 
43     std::vector<const Reference<Type>*> getReferences() const override;
44 
45     std::vector<const ConstantExpression*> getConstantExpressions() const override;
46 
47     // Extends existing array by adding another dimension.
48     status_t resolveInheritance() override;
49 
50     status_t validate() const override;
51 
52     std::string getCppType(StorageMode mode,
53                            bool specifyNamespaces) const override;
54 
55     std::string getInternalDataCppType() const;
56 
57     std::string getJavaType(bool forInitializer) const override;
58 
59     std::string getVtsType() const override;
60 
61     void emitReaderWriter(
62             Formatter &out,
63             const std::string &name,
64             const std::string &parcelObj,
65             bool parcelObjIsPointer,
66             bool isReader,
67             ErrorMode mode) const override;
68 
69     void emitReaderWriterEmbedded(
70             Formatter &out,
71             size_t depth,
72             const std::string &name,
73             const std::string &sanitizedName,
74             bool nameIsPointer,
75             const std::string &parcelObj,
76             bool parcelObjIsPointer,
77             bool isReader,
78             ErrorMode mode,
79             const std::string &parentName,
80             const std::string &offsetText) const override;
81 
82     void emitResolveReferences(
83             Formatter &out,
84             const std::string &name,
85             bool nameIsPointer,
86             const std::string &parcelObj,
87             bool parcelObjIsPointer,
88             bool isReader,
89             ErrorMode mode) const override;
90 
91     void emitResolveReferencesEmbedded(
92             Formatter &out,
93             size_t depth,
94             const std::string &name,
95             const std::string &sanitizedName,
96             bool nameIsPointer,
97             const std::string &parcelObj,
98             bool parcelObjIsPointer,
99             bool isReader,
100             ErrorMode mode,
101             const std::string &parentName,
102             const std::string &offsetText) const override;
103 
104     void emitJavaDump(
105             Formatter &out,
106             const std::string &streamName,
107             const std::string &name) const override;
108 
109     bool needsEmbeddedReadWrite() const override;
110     bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
111     bool resultNeedsDeref() const override;
112 
113     void emitJavaReaderWriter(
114             Formatter &out,
115             const std::string &parcelObj,
116             const std::string &argName,
117             bool isReader) const override;
118 
119     void emitJavaFieldInitializer(
120             Formatter &out, const std::string &fieldName) const override;
121 
122     void emitJavaFieldDefaultInitialValue(
123             Formatter &out, const std::string &declaredFieldName) const override;
124 
125     void emitJavaFieldReaderWriter(
126             Formatter &out,
127             size_t depth,
128             const std::string &parcelName,
129             const std::string &blobName,
130             const std::string &fieldName,
131             const std::string &offset,
132             bool isReader) const override;
133 
134     void emitVtsTypeDeclarations(Formatter& out) const override;
135 
136     bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
137     bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
138 
139     void getAlignmentAndSize(size_t *align, size_t *size) const override;
140 
141    private:
142     Reference<Type> mElementType;
143     std::vector<ConstantExpression*> mSizes;
144 
145     size_t dimension() const;
146 
147     DISALLOW_COPY_AND_ASSIGN(ArrayType);
148 };
149 
150 }  // namespace android
151 
152 #endif  // ARRAY_TYPE_H_
153 
154