blob: 35be6874f2cf2148b5959e1419f21e4d361e3000 [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
21#include "Scope.h"
22
Andreas Huber881227d2016-08-02 14:20:21 -070023#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070024
25namespace android {
26
Andreas Huber31629bc2016-08-03 09:06:40 -070027struct CompoundField;
Andreas Huberc9410c72016-07-28 12:18:40 -070028
29struct CompoundType : public Scope {
30 enum Style {
31 STYLE_STRUCT,
32 STYLE_UNION,
33 };
34
Andreas Huber9ed827c2016-08-22 12:31:13 -070035 CompoundType(Style style, const char *localName);
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Andreas Huber0d0f9a22016-08-17 10:26:11 -070037 bool setFields(std::vector<CompoundField *> *fields, std::string *errorMsg);
Andreas Huberc9410c72016-07-28 12:18:40 -070038
Andreas Huber881227d2016-08-02 14:20:21 -070039 std::string getCppType(StorageMode mode, std::string *extra) const override;
40
Andreas Huber85eabdb2016-08-25 11:24:49 -070041 std::string getJavaType() const override;
42
Andreas Huber881227d2016-08-02 14:20:21 -070043 void emitReaderWriter(
44 Formatter &out,
45 const std::string &name,
46 const std::string &parcelObj,
47 bool parcelObjIsPointer,
48 bool isReader,
49 ErrorMode mode) const override;
50
51 void emitReaderWriterEmbedded(
52 Formatter &out,
53 const std::string &name,
54 bool nameIsPointer,
55 const std::string &parcelObj,
56 bool parcelObjIsPointer,
57 bool isReader,
58 ErrorMode mode,
59 const std::string &parentName,
60 const std::string &offsetText) const override;
61
Andreas Huber85eabdb2016-08-25 11:24:49 -070062 void emitJavaReaderWriter(
63 Formatter &out,
64 const std::string &parcelObj,
65 const std::string &argName,
66 bool isReader) const override;
67
68 void emitJavaFieldInitializer(
69 Formatter &out, const std::string &fieldName) const override;
70
71 void emitJavaFieldReaderWriter(
72 Formatter &out,
73 const std::string &blobName,
74 const std::string &fieldName,
75 const std::string &offset,
76 bool isReader) const override;
77
Andreas Huber881227d2016-08-02 14:20:21 -070078 status_t emitTypeDeclarations(Formatter &out) const override;
79
80 status_t emitTypeDefinitions(
81 Formatter &out, const std::string prefix) const override;
82
Andreas Huber85eabdb2016-08-25 11:24:49 -070083 status_t emitJavaTypeDeclarations(
84 Formatter &out, bool atTopLevel) const override;
85
Andreas Huber881227d2016-08-02 14:20:21 -070086 bool needsEmbeddedReadWrite() const override;
87 bool resultNeedsDeref() const override;
88
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070089 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070090 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070091
Andreas Huber70a59e12016-08-16 12:57:01 -070092 bool isJavaCompatible() const override;
93
Andreas Huber85eabdb2016-08-25 11:24:49 -070094 void getAlignmentAndSize(size_t *align, size_t *size) const;
95
Andreas Huberc9410c72016-07-28 12:18:40 -070096private:
97 Style mStyle;
Andreas Huber881227d2016-08-02 14:20:21 -070098 std::vector<CompoundField *> *mFields;
99
100 void emitStructReaderWriter(
101 Formatter &out, const std::string &prefix, bool isReader) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700102
103 DISALLOW_COPY_AND_ASSIGN(CompoundType);
104};
105
Andreas Huber31629bc2016-08-03 09:06:40 -0700106struct CompoundField {
107 CompoundField(const char *name, Type *type);
108
109 std::string name() const;
110 const Type &type() const;
111
112private:
113 std::string mName;
114 Type *mType;
115
116 DISALLOW_COPY_AND_ASSIGN(CompoundField);
117};
118
Andreas Huberc9410c72016-07-28 12:18:40 -0700119} // namespace android
120
121#endif // COMPOUND_TYPE_H_
122