blob: 8b70d725db69636162a410ea8e36daf5f76cfa76 [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
Steven Moreland9df52442016-12-12 08:51:14 -080044 bool isElidableType() const override;
Andreas Huber737080b2016-08-02 15:38:04 -070045 const ScalarType *resolveToScalarType() const override;
46
Yifan Hongc6752dc2016-12-20 14:00:14 -080047 bool canCheckEquality() const override;
48
Steven Moreland30bb6a82016-11-30 09:18:34 -080049 std::string typeName() const override;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070050 bool isValidEnumStorageType() const;
51
Steven Moreland979e0992016-09-07 09:18:08 -070052 void addNamedTypesToSet(std::set<const FQName> &set) const override;
53
Andreas Huber4c865b72016-09-14 15:26:27 -070054 std::string getCppType(
55 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070056 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070057
Yifan Hong4ed13472016-11-02 10:44:11 -070058 std::string getJavaType(bool forInitializer) const override;
Andreas Huber4c865b72016-09-14 15:26:27 -070059
Andreas Huber85eabdb2016-08-25 11:24:49 -070060 std::string getJavaWrapperType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070061 std::string getJavaSuffix() const override;
62
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070063 std::string getVtsType() const override;
64 std::string getVtsScalarType() const;
65
Andreas Huber881227d2016-08-02 14:20:21 -070066 void emitReaderWriter(
67 Formatter &out,
68 const std::string &name,
69 const std::string &parcelObj,
70 bool parcelObjIsPointer,
71 bool isReader,
72 ErrorMode mode) const override;
73
Andreas Huber737080b2016-08-02 15:38:04 -070074 void emitReaderWriterWithCast(
75 Formatter &out,
76 const std::string &name,
77 const std::string &parcelObj,
78 bool parcelObjIsPointer,
79 bool isReader,
80 ErrorMode mode,
81 bool needsCast) const;
82
Yifan Hongf5cc2f72017-01-04 18:02:34 -080083 void emitHexDump(
84 Formatter &out,
85 const std::string &streamName,
86 const std::string &name) const;
87
Andreas Huber85eabdb2016-08-25 11:24:49 -070088 void emitJavaFieldReaderWriter(
89 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070090 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070091 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070092 const std::string &blobName,
93 const std::string &fieldName,
94 const std::string &offset,
95 bool isReader) const override;
96
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070097 status_t emitVtsTypeDeclarations(Formatter &out) const override;
98
Andreas Huber85eabdb2016-08-25 11:24:49 -070099 void getAlignmentAndSize(size_t *align, size_t *size) const override;
100
Yifan Hong57886972016-08-17 10:42:15 -0700101 Kind getKind() const;
102
Andreas Huberc9410c72016-07-28 12:18:40 -0700103private:
104 Kind mKind;
105
106 DISALLOW_COPY_AND_ASSIGN(ScalarType);
107};
108
109} // namespace android
110
111#endif // SCALAR_TYPE_H_