blob: 0ff8ec54c74579ba650b621fad64325e9d95934e [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 SCALAR_TYPE_H_
18
19#define SCALAR_TYPE_H_
20
21#include "Type.h"
22
23namespace android {
24
25struct ScalarType : public Type {
26 enum Kind {
Andreas Huberc9410c72016-07-28 12:18:40 -070027 KIND_BOOL,
Andreas Huberc9410c72016-07-28 12:18:40 -070028 KIND_INT8,
29 KIND_UINT8,
30 KIND_INT16,
31 KIND_UINT16,
32 KIND_INT32,
33 KIND_UINT32,
34 KIND_INT64,
35 KIND_UINT64,
36 KIND_FLOAT,
37 KIND_DOUBLE,
38 };
39
40 ScalarType(Kind kind);
41
Yifan Hongabf73ee2016-12-05 18:47:00 -080042 bool isScalar() const override;
43
Andreas Huber737080b2016-08-02 15:38:04 -070044 const ScalarType *resolveToScalarType() const override;
45
Steven Moreland30bb6a82016-11-30 09:18:34 -080046 std::string typeName() const override;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070047 bool isValidEnumStorageType() const;
48
Steven Moreland979e0992016-09-07 09:18:08 -070049 void addNamedTypesToSet(std::set<const FQName> &set) const override;
50
Andreas Huber4c865b72016-09-14 15:26:27 -070051 std::string getCppType(
52 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070053 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070054
Yifan Hong4ed13472016-11-02 10:44:11 -070055 std::string getJavaType(bool forInitializer) const override;
Andreas Huber4c865b72016-09-14 15:26:27 -070056
Andreas Huber85eabdb2016-08-25 11:24:49 -070057 std::string getJavaWrapperType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070058 std::string getJavaSuffix() const override;
59
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070060 std::string getVtsType() const override;
61 std::string getVtsScalarType() const;
62
Andreas Huber881227d2016-08-02 14:20:21 -070063 void emitReaderWriter(
64 Formatter &out,
65 const std::string &name,
66 const std::string &parcelObj,
67 bool parcelObjIsPointer,
68 bool isReader,
69 ErrorMode mode) const override;
70
Andreas Huber737080b2016-08-02 15:38:04 -070071 void emitReaderWriterWithCast(
72 Formatter &out,
73 const std::string &name,
74 const std::string &parcelObj,
75 bool parcelObjIsPointer,
76 bool isReader,
77 ErrorMode mode,
78 bool needsCast) const;
79
Andreas Huber85eabdb2016-08-25 11:24:49 -070080 void emitJavaFieldReaderWriter(
81 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070082 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070083 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070084 const std::string &blobName,
85 const std::string &fieldName,
86 const std::string &offset,
87 bool isReader) const override;
88
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070089 status_t emitVtsTypeDeclarations(Formatter &out) const override;
90
Andreas Huber85eabdb2016-08-25 11:24:49 -070091 void getAlignmentAndSize(size_t *align, size_t *size) const override;
92
Yifan Hong57886972016-08-17 10:42:15 -070093 Kind getKind() const;
94
Andreas Huberc9410c72016-07-28 12:18:40 -070095private:
96 Kind mKind;
97
98 DISALLOW_COPY_AND_ASSIGN(ScalarType);
99};
100
101} // namespace android
102
103#endif // SCALAR_TYPE_H_