• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 emitReaderWriter(
65             Formatter &out,
66             const std::string &name,
67             const std::string &parcelObj,
68             bool parcelObjIsPointer,
69             bool isReader,
70             ErrorMode mode) const override;
71 
72     void emitReaderWriterWithCast(
73             Formatter &out,
74             const std::string &name,
75             const std::string &parcelObj,
76             bool parcelObjIsPointer,
77             bool isReader,
78             ErrorMode mode,
79             bool needsCast) const;
80 
81     void emitHexDump(
82             Formatter &out,
83             const std::string &streamName,
84             const std::string &name) const;
85 
86     void emitConvertToJavaHexString(
87             Formatter &out,
88             const std::string &name) const;
89 
90     void emitJavaFieldReaderWriter(
91             Formatter &out,
92             size_t depth,
93             const std::string &parcelName,
94             const std::string &blobName,
95             const std::string &fieldName,
96             const std::string &offset,
97             bool isReader) const override;
98 
99     void emitVtsTypeDeclarations(Formatter& out) const override;
100 
101     void getAlignmentAndSize(size_t *align, size_t *size) const override;
102 
103     Kind getKind() const;
104 
105 private:
106     Kind mKind;
107 
108     DISALLOW_COPY_AND_ASSIGN(ScalarType);
109 };
110 
111 }  // namespace android
112 
113 #endif  // SCALAR_TYPE_H_
114