blob: ca16cabb46e25dc3a265c7a27da3b76028dde3e3 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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
Andreas Huberc9410c72016-07-28 12:18:40 -070017#ifndef COMPOUND_TYPE_H_
18
19#define COMPOUND_TYPE_H_
20
Timur Iskhakov505316c2017-08-05 03:38:59 +000021#include "Reference.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070022#include "Scope.h"
23
Andreas Huber881227d2016-08-02 14:20:21 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Andreas Huberc9410c72016-07-28 12:18:40 -070028struct CompoundType : public Scope {
29 enum Style {
30 STYLE_STRUCT,
31 STYLE_UNION,
32 };
33
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070034 CompoundType(Style style, const char* localName, const Location& location, Scope* parent);
Andreas Huberc9410c72016-07-28 12:18:40 -070035
Yifan Hong27e85db2016-11-09 15:45:52 -080036 Style style() const;
37
Timur Iskhakovcec46c42017-08-09 00:22:02 -070038 void setFields(std::vector<NamedReference<Type>*>* fields);
Andreas Huberc9410c72016-07-28 12:18:40 -070039
Andreas Huberf630bc82016-09-09 14:52:25 -070040 bool isCompoundType() const override;
41
Yifan Hongc6752dc2016-12-20 14:00:14 -080042 bool canCheckEquality() const override;
43
Steven Moreland0ecc7b82017-07-19 12:59:23 -070044 std::string typeName() const override;
45
Timur Iskhakovcec46c42017-08-09 00:22:02 -070046 status_t evaluate() override;
47 status_t validate() const override;
48 status_t validateUniqueNames() const;
49
Steven Moreland979e0992016-09-07 09:18:08 -070050 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070051 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070052
Yifan Hong4ed13472016-11-02 10:44:11 -070053 std::string getJavaType(bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070054
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070055 std::string getVtsType() const override;
56
Andreas Huber881227d2016-08-02 14:20:21 -070057 void emitReaderWriter(
58 Formatter &out,
59 const std::string &name,
60 const std::string &parcelObj,
61 bool parcelObjIsPointer,
62 bool isReader,
63 ErrorMode mode) const override;
64
65 void emitReaderWriterEmbedded(
66 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070067 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070068 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070069 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070070 bool nameIsPointer,
71 const std::string &parcelObj,
72 bool parcelObjIsPointer,
73 bool isReader,
74 ErrorMode mode,
75 const std::string &parentName,
76 const std::string &offsetText) const override;
77
Yifan Hongbf459bc2016-08-23 16:50:37 -070078 void emitResolveReferences(
79 Formatter &out,
80 const std::string &name,
81 bool nameIsPointer,
82 const std::string &parcelObj,
83 bool parcelObjIsPointer,
84 bool isReader,
85 ErrorMode mode) const override;
86
87 void emitResolveReferencesEmbedded(
88 Formatter &out,
89 size_t depth,
90 const std::string &name,
91 const std::string &sanitizedName,
92 bool nameIsPointer,
93 const std::string &parcelObj,
94 bool parcelObjIsPointer,
95 bool isReader,
96 ErrorMode mode,
97 const std::string &parentName,
98 const std::string &offsetText) const override;
99
Andreas Huber85eabdb2016-08-25 11:24:49 -0700100 void emitJavaReaderWriter(
101 Formatter &out,
102 const std::string &parcelObj,
103 const std::string &argName,
104 bool isReader) const override;
105
106 void emitJavaFieldInitializer(
107 Formatter &out, const std::string &fieldName) const override;
108
109 void emitJavaFieldReaderWriter(
110 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700111 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700112 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700113 const std::string &blobName,
114 const std::string &fieldName,
115 const std::string &offset,
116 bool isReader) const override;
117
Andreas Huber881227d2016-08-02 14:20:21 -0700118 status_t emitTypeDeclarations(Formatter &out) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -0800119 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -0800120 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700121
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700122 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700123
Andreas Huber85eabdb2016-08-25 11:24:49 -0700124 status_t emitJavaTypeDeclarations(
125 Formatter &out, bool atTopLevel) const override;
126
Andreas Huber881227d2016-08-02 14:20:21 -0700127 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700128 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700129 bool resultNeedsDeref() const override;
130
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700131 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700132 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700133
Andreas Huber70a59e12016-08-16 12:57:01 -0700134 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700135 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700136
Andreas Huber85eabdb2016-08-25 11:24:49 -0700137 void getAlignmentAndSize(size_t *align, size_t *size) const;
138
Andreas Huberc9410c72016-07-28 12:18:40 -0700139private:
140 Style mStyle;
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700141 std::vector<NamedReference<Type>*>* mFields;
Andreas Huber881227d2016-08-02 14:20:21 -0700142
143 void emitStructReaderWriter(
144 Formatter &out, const std::string &prefix, bool isReader) const;
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700145 void emitResolveReferenceDef(Formatter& out, const std::string& prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700146
147 DISALLOW_COPY_AND_ASSIGN(CompoundType);
148};
149
Andreas Huberc9410c72016-07-28 12:18:40 -0700150} // namespace android
151
152#endif // COMPOUND_TYPE_H_
153