1 /*
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 
17 #ifndef SCALAR_TYPE_H_
18 
19 #define SCALAR_TYPE_H_
20 
21 #include "Type.h"
22 
23 namespace android {
24 
25 struct ScalarType : public Type {
26     enum Kind {
27         KIND_BOOL,
28         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, Scope* parent);
41 
42     bool isScalar() const override;
43 
44     bool isElidableType() const override;
45     const ScalarType *resolveToScalarType() const override;
46 
47     bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
48 
49     std::string typeName() const override;
50     bool isValidEnumStorageType() const;
51 
52     std::string getCppType(
53             StorageMode mode,
54             bool specifyNamespaces) const override;
55 
56     std::string getJavaType(bool forInitializer) const override;
57     std::string getJavaTypeClass() const override;
58 
59     std::string getJavaSuffix() const override;
60 
61     std::string getVtsType() const override;
62     std::string getVtsScalarType() const;
63 
64     void emitJavaFieldInitializer(Formatter&, const std::string&) const override;
65 
66     void emitJavaFieldDefaultInitialValue(Formatter&, const std::string&) const override;
67 
68     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 
76     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 
85     void emitHexDump(
86             Formatter &out,
87             const std::string &streamName,
88             const std::string &name) const;
89 
90     void emitConvertToJavaHexString(
91             Formatter &out,
92             const std::string &name) const;
93 
94     void emitJavaFieldReaderWriter(
95             Formatter &out,
96             size_t depth,
97             const std::string &parcelName,
98             const std::string &blobName,
99             const std::string &fieldName,
100             const std::string &offset,
101             bool isReader) const override;
102 
103     void emitVtsTypeDeclarations(Formatter& out) const override;
104 
105     void getAlignmentAndSize(size_t *align, size_t *size) const override;
106 
107     Kind getKind() const;
108 
109 private:
110     Kind mKind;
111 
112     DISALLOW_COPY_AND_ASSIGN(ScalarType);
113 };
114 
115 }  // namespace android
116 
117 #endif  // SCALAR_TYPE_H_
118