blob: 8e3efc367c5230ce7d07b3098e9d904f674a578e [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
Timur Iskhakov63f39902017-08-29 15:47:29 -070040 ScalarType(Kind kind, Scope* parent);
Andreas Huberc9410c72016-07-28 12:18:40 -070041
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
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -070047 bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
Yifan Hongc6752dc2016-12-20 14:00:14 -080048
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
Andreas Huber4c865b72016-09-14 15:26:27 -070052 std::string getCppType(
53 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070054 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070055
Yifan Hong4ed13472016-11-02 10:44:11 -070056 std::string getJavaType(bool forInitializer) const override;
Nirav Atre66842a92018-06-28 18:14:13 -070057 std::string getJavaTypeClass() const override;
Andreas Huber4c865b72016-09-14 15:26:27 -070058
Andreas Huber2831d512016-08-15 09:33:47 -070059 std::string getJavaSuffix() const override;
60
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -070061 std::string getVtsType() const override;
62 std::string getVtsScalarType() const;
63
Neel Mehta4b6f4392019-05-09 16:03:47 -070064 void emitJavaFieldInitializer(Formatter&, const std::string&) const override;
65
66 void emitJavaFieldDefaultInitialValue(Formatter&, const std::string&) const override;
67
Andreas Huber881227d2016-08-02 14:20:21 -070068 void emitReaderWriter(
69 Formatter &out,
70 const std::string &name,
71 const std::string &parcelObj,
72 bool parcelObjIsPointer,
73 bool isReader,
74 ErrorMode mode) const override;
75
Andreas Huber737080b2016-08-02 15:38:04 -070076 void emitReaderWriterWithCast(
77 Formatter &out,
78 const std::string &name,
79 const std::string &parcelObj,
80 bool parcelObjIsPointer,
81 bool isReader,
82 ErrorMode mode,
83 bool needsCast) const;
84
Yifan Hongf5cc2f72017-01-04 18:02:34 -080085 void emitHexDump(
86 Formatter &out,
87 const std::string &streamName,
88 const std::string &name) const;
89
Yifan Honge45b5302017-02-22 10:49:07 -080090 void emitConvertToJavaHexString(
91 Formatter &out,
92 const std::string &name) const;
93
Andreas Huber85eabdb2016-08-25 11:24:49 -070094 void emitJavaFieldReaderWriter(
95 Formatter &out,
Andreas Huber4c865b72016-09-14 15:26:27 -070096 size_t depth,
Andreas Huber709b62d2016-09-19 11:21:18 -070097 const std::string &parcelName,
Andreas Huber85eabdb2016-08-25 11:24:49 -070098 const std::string &blobName,
99 const std::string &fieldName,
100 const std::string &offset,
101 bool isReader) const override;
102
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800103 void emitVtsTypeDeclarations(Formatter& out) const override;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700104
Andreas Huber85eabdb2016-08-25 11:24:49 -0700105 void getAlignmentAndSize(size_t *align, size_t *size) const override;
106
Yifan Hong57886972016-08-17 10:42:15 -0700107 Kind getKind() const;
108
Andreas Huberc9410c72016-07-28 12:18:40 -0700109private:
110 Kind mKind;
111
112 DISALLOW_COPY_AND_ASSIGN(ScalarType);
113};
114
115} // namespace android
116
117#endif // SCALAR_TYPE_H_