blob: 58c79cf5431f3678a12ca9c36bd10d227ec18d7e [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 ENUM_TYPE_H_
18
19#define ENUM_TYPE_H_
20
Yifan Hong57886972016-08-17 10:42:15 -070021#include "ConstantExpression.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070022#include "NamedType.h"
23
Andreas Huber881227d2016-08-02 14:20:21 -070024#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070025
26namespace android {
27
Andreas Huber31629bc2016-08-03 09:06:40 -070028struct EnumValue;
Andreas Huberc9410c72016-07-28 12:18:40 -070029
30struct EnumType : public NamedType {
Andreas Huber9ed827c2016-08-22 12:31:13 -070031 EnumType(const char *localName,
32 std::vector<EnumValue *> *values,
Andreas Huberc9410c72016-07-28 12:18:40 -070033 Type *storageType = NULL);
34
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070035 const Type *storageType() const;
36 const std::vector<EnumValue *> &values() const;
37
Andreas Huber737080b2016-08-02 15:38:04 -070038 const ScalarType *resolveToScalarType() const override;
39
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070040 bool isEnum() const override;
41
Steven Moreland979e0992016-09-07 09:18:08 -070042 std::string getCppType(StorageMode mode,
43 std::string *extra,
44 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070045
Andreas Huber4c865b72016-09-14 15:26:27 -070046 std::string getJavaType(
47 std::string *extra, bool forInitializer) const override;
48
Andreas Huber2831d512016-08-15 09:33:47 -070049 std::string getJavaSuffix() const override;
50
Andreas Hubera3558b32016-09-14 09:12:42 -070051 std::string getJavaWrapperType() const override;
52
Andreas Huber881227d2016-08-02 14:20:21 -070053 void emitReaderWriter(
54 Formatter &out,
55 const std::string &name,
56 const std::string &parcelObj,
57 bool parcelObjIsPointer,
58 bool isReader,
59 ErrorMode mode) const override;
60
Andreas Huber85eabdb2016-08-25 11:24:49 -070061 void emitJavaFieldReaderWriter(
62 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070063 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070064 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070065 const std::string &blobName,
66 const std::string &fieldName,
67 const std::string &offset,
68 bool isReader) const override;
69
Andreas Huber881227d2016-08-02 14:20:21 -070070 status_t emitTypeDeclarations(Formatter &out) const override;
Andreas Huber85eabdb2016-08-25 11:24:49 -070071
72 status_t emitJavaTypeDeclarations(
73 Formatter &out, bool atTopLevel) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070074
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070075 status_t emitVtsTypeDeclarations(Formatter &out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070076 status_t emitVtsAttributeType(Formatter &out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070077
Andreas Huber85eabdb2016-08-25 11:24:49 -070078 void getAlignmentAndSize(size_t *align, size_t *size) const override;
79
Andreas Huberc9410c72016-07-28 12:18:40 -070080private:
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070081 void getTypeChain(std::vector<const EnumType *> *out) const;
Andreas Huber881227d2016-08-02 14:20:21 -070082 std::vector<EnumValue *> *mValues;
Andreas Huberc9410c72016-07-28 12:18:40 -070083 Type *mStorageType;
84
85 DISALLOW_COPY_AND_ASSIGN(EnumType);
86};
87
Andreas Huber31629bc2016-08-03 09:06:40 -070088struct EnumValue {
Yifan Hong57886972016-08-17 10:42:15 -070089 EnumValue(const char *name, const ConstantExpression *value = nullptr);
Andreas Huber31629bc2016-08-03 09:06:40 -070090
91 std::string name() const;
92 const char *value() const;
Yifan Hong57886972016-08-17 10:42:15 -070093 const char *cppValue(ScalarType::Kind castKind) const;
Yifan Hong19ca75a2016-08-31 10:20:03 -070094 const char *javaValue(ScalarType::Kind castKind) const;
Yifan Hong57886972016-08-17 10:42:15 -070095 const char *comment() const;
Andreas Huber31629bc2016-08-03 09:06:40 -070096
97private:
98 std::string mName;
Yifan Hong57886972016-08-17 10:42:15 -070099 const ConstantExpression *mValue;
Andreas Huber31629bc2016-08-03 09:06:40 -0700100
101 DISALLOW_COPY_AND_ASSIGN(EnumValue);
102};
103
Andreas Huberc9410c72016-07-28 12:18:40 -0700104} // namespace android
105
106#endif // ENUM_TYPE_H_
107