• 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 COMPOUND_TYPE_H_
18 
19 #define COMPOUND_TYPE_H_
20 
21 #include "Scope.h"
22 
23 #include <vector>
24 
25 namespace android {
26 
27 struct CompoundField;
28 
29 struct CompoundType : public Scope {
30     enum Style {
31         STYLE_STRUCT,
32         STYLE_UNION,
33     };
34 
35     CompoundType(Style style, const char* localName, const Location& location, Scope* parent);
36 
37     Style style() const;
38 
39     bool setFields(std::vector<CompoundField *> *fields, std::string *errorMsg);
40 
41     bool isCompoundType() const override;
42 
43     bool canCheckEquality() const override;
44 
45     std::string typeName() const override;
46 
47     std::string getCppType(StorageMode mode,
48                            bool specifyNamespaces) const override;
49 
50     std::string getJavaType(bool forInitializer) const override;
51 
52     std::string getVtsType() const override;
53 
54     void emitReaderWriter(
55             Formatter &out,
56             const std::string &name,
57             const std::string &parcelObj,
58             bool parcelObjIsPointer,
59             bool isReader,
60             ErrorMode mode) const override;
61 
62     void emitReaderWriterEmbedded(
63             Formatter &out,
64             size_t depth,
65             const std::string &name,
66             const std::string &sanitizedName,
67             bool nameIsPointer,
68             const std::string &parcelObj,
69             bool parcelObjIsPointer,
70             bool isReader,
71             ErrorMode mode,
72             const std::string &parentName,
73             const std::string &offsetText) const override;
74 
75     void emitResolveReferences(
76             Formatter &out,
77             const std::string &name,
78             bool nameIsPointer,
79             const std::string &parcelObj,
80             bool parcelObjIsPointer,
81             bool isReader,
82             ErrorMode mode) const override;
83 
84     void emitResolveReferencesEmbedded(
85             Formatter &out,
86             size_t depth,
87             const std::string &name,
88             const std::string &sanitizedName,
89             bool nameIsPointer,
90             const std::string &parcelObj,
91             bool parcelObjIsPointer,
92             bool isReader,
93             ErrorMode mode,
94             const std::string &parentName,
95             const std::string &offsetText) const override;
96 
97     void emitJavaReaderWriter(
98             Formatter &out,
99             const std::string &parcelObj,
100             const std::string &argName,
101             bool isReader) const override;
102 
103     void emitJavaFieldInitializer(
104             Formatter &out, const std::string &fieldName) const override;
105 
106     void emitJavaFieldReaderWriter(
107             Formatter &out,
108             size_t depth,
109             const std::string &parcelName,
110             const std::string &blobName,
111             const std::string &fieldName,
112             const std::string &offset,
113             bool isReader) const override;
114 
115     status_t emitTypeDeclarations(Formatter &out) const override;
116     status_t emitGlobalTypeDeclarations(Formatter &out) const override;
117     status_t emitGlobalHwDeclarations(Formatter &out) const override;
118 
119     status_t emitTypeDefinitions(
120             Formatter &out, const std::string prefix) const override;
121 
122     status_t emitJavaTypeDeclarations(
123             Formatter &out, bool atTopLevel) const override;
124 
125     bool needsEmbeddedReadWrite() const override;
126     bool needsResolveReferences() const override;
127     bool resultNeedsDeref() const override;
128 
129     status_t emitVtsTypeDeclarations(Formatter &out) const override;
130     status_t emitVtsAttributeType(Formatter &out) const override;
131 
132     bool isJavaCompatible() const override;
133     bool containsPointer() const override;
134 
135     void getAlignmentAndSize(size_t *align, size_t *size) const;
136 
137 private:
138     Style mStyle;
139     std::vector<CompoundField *> *mFields;
140 
141     void emitStructReaderWriter(
142             Formatter &out, const std::string &prefix, bool isReader) const;
143     void emitResolveReferenceDef(
144         Formatter &out, const std::string prefix, bool isReader) const;
145 
146     DISALLOW_COPY_AND_ASSIGN(CompoundType);
147 };
148 
149 struct CompoundField {
150     CompoundField(const char *name, Type *type);
151 
152     std::string name() const;
153     const Type &type() const;
154 
155 private:
156     std::string mName;
157     Type *mType;
158 
159     DISALLOW_COPY_AND_ASSIGN(CompoundField);
160 };
161 
162 }  // namespace android
163 
164 #endif  // COMPOUND_TYPE_H_
165 
166