blob: 1c0159b8705155fcf18c30c580f496c9aea5d26b [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 Iskhakovb58f4182017-08-29 15:19:24 -070046 std::vector<const Reference<Type>*> getReferences() const override;
Timur Iskhakov33431e62017-08-21 17:31:23 -070047
Timur Iskhakovcec46c42017-08-09 00:22:02 -070048 status_t validate() const override;
49 status_t validateUniqueNames() const;
50
Steven Moreland979e0992016-09-07 09:18:08 -070051 std::string getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -070052 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070053
Yifan Hong4ed13472016-11-02 10:44:11 -070054 std::string getJavaType(bool forInitializer) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070055
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070056 std::string getVtsType() const override;
57
Andreas Huber881227d2016-08-02 14:20:21 -070058 void emitReaderWriter(
59 Formatter &out,
60 const std::string &name,
61 const std::string &parcelObj,
62 bool parcelObjIsPointer,
63 bool isReader,
64 ErrorMode mode) const override;
65
66 void emitReaderWriterEmbedded(
67 Formatter &out,
Andreas Huberf9d49f12016-09-12 14:58:36 -070068 size_t depth,
Andreas Huber881227d2016-08-02 14:20:21 -070069 const std::string &name,
Yifan Hongbe2a3732016-10-05 13:33:41 -070070 const std::string &sanitizedName,
Andreas Huber881227d2016-08-02 14:20:21 -070071 bool nameIsPointer,
72 const std::string &parcelObj,
73 bool parcelObjIsPointer,
74 bool isReader,
75 ErrorMode mode,
76 const std::string &parentName,
77 const std::string &offsetText) const override;
78
Yifan Hongbf459bc2016-08-23 16:50:37 -070079 void emitResolveReferences(
80 Formatter &out,
81 const std::string &name,
82 bool nameIsPointer,
83 const std::string &parcelObj,
84 bool parcelObjIsPointer,
85 bool isReader,
86 ErrorMode mode) const override;
87
88 void emitResolveReferencesEmbedded(
89 Formatter &out,
90 size_t depth,
91 const std::string &name,
92 const std::string &sanitizedName,
93 bool nameIsPointer,
94 const std::string &parcelObj,
95 bool parcelObjIsPointer,
96 bool isReader,
97 ErrorMode mode,
98 const std::string &parentName,
99 const std::string &offsetText) const override;
100
Andreas Huber85eabdb2016-08-25 11:24:49 -0700101 void emitJavaReaderWriter(
102 Formatter &out,
103 const std::string &parcelObj,
104 const std::string &argName,
105 bool isReader) const override;
106
107 void emitJavaFieldInitializer(
108 Formatter &out, const std::string &fieldName) const override;
109
110 void emitJavaFieldReaderWriter(
111 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -0700112 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -0700113 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -0700114 const std::string &blobName,
115 const std::string &fieldName,
116 const std::string &offset,
117 bool isReader) const override;
118
Andreas Huber881227d2016-08-02 14:20:21 -0700119 status_t emitTypeDeclarations(Formatter &out) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -0800120 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Yifan Hong244e82d2016-11-11 11:13:57 -0800121 status_t emitGlobalHwDeclarations(Formatter &out) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700122
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700123 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700124
Andreas Huber85eabdb2016-08-25 11:24:49 -0700125 status_t emitJavaTypeDeclarations(
126 Formatter &out, bool atTopLevel) const override;
127
Andreas Huber881227d2016-08-02 14:20:21 -0700128 bool needsEmbeddedReadWrite() const override;
Yifan Hongbf459bc2016-08-23 16:50:37 -0700129 bool needsResolveReferences() const override;
Andreas Huber881227d2016-08-02 14:20:21 -0700130 bool resultNeedsDeref() const override;
131
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700132 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700133 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700134
Andreas Huber70a59e12016-08-16 12:57:01 -0700135 bool isJavaCompatible() const override;
Andreas Huber60d3b222017-03-30 09:10:56 -0700136 bool containsPointer() const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700137
Andreas Huber85eabdb2016-08-25 11:24:49 -0700138 void getAlignmentAndSize(size_t *align, size_t *size) const;
139
Andreas Huberc9410c72016-07-28 12:18:40 -0700140private:
141 Style mStyle;
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700142 std::vector<NamedReference<Type>*>* mFields;
Andreas Huber881227d2016-08-02 14:20:21 -0700143
144 void emitStructReaderWriter(
145 Formatter &out, const std::string &prefix, bool isReader) const;
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700146 void emitResolveReferenceDef(Formatter& out, const std::string& prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700147
148 DISALLOW_COPY_AND_ASSIGN(CompoundType);
149};
150
Andreas Huberc9410c72016-07-28 12:18:40 -0700151} // namespace android
152
153#endif // COMPOUND_TYPE_H_
154