blob: 6ee76ca92e5f398714a4afb6785012cb5a42ac1a [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#ifndef TYPE_H_
2
3#define TYPE_H_
4
5#include <android-base/macros.h>
Andreas Huber881227d2016-08-02 14:20:21 -07006#include <string>
7#include <utils/Errors.h>
Andreas Huberc9410c72016-07-28 12:18:40 -07008
9namespace android {
10
11struct Formatter;
Andreas Huber737080b2016-08-02 15:38:04 -070012struct ScalarType;
Andreas Huberc9410c72016-07-28 12:18:40 -070013
14struct Type {
15 Type();
16 virtual ~Type();
17
Andreas Huberfd4afab2016-08-03 13:02:57 -070018 Type *ref() { return this; }
19
Andreas Huber5345ec22016-07-29 13:33:27 -070020 virtual bool isScope() const;
Andreas Hubera2723d22016-07-29 15:36:07 -070021 virtual bool isInterface() const;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070022 virtual bool isEnum() const;
23 virtual bool isTypeDef() const;
Andreas Huber295ad302016-08-16 11:35:00 -070024 virtual bool isBinder() const;
Andreas Huber39fa7182016-08-19 14:27:33 -070025 virtual bool isNamedType() const;
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070026
Andreas Huber737080b2016-08-02 15:38:04 -070027 virtual const ScalarType *resolveToScalarType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070028
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070029 bool isValidEnumStorageType() const;
30
Andreas Huber881227d2016-08-02 14:20:21 -070031 enum StorageMode {
32 StorageMode_Stack,
33 StorageMode_Argument,
34 StorageMode_Result
35 };
36 virtual std::string getCppType(
37 StorageMode mode, std::string *extra) const;
38
39 // Convenience, gets StorageMode_Stack type.
40 std::string getCppType(std::string *extra) const;
41
42 std::string getCppResultType(std::string *extra) const;
43 std::string getCppArgumentType(std::string *extra) const;
44
Andreas Huber2831d512016-08-15 09:33:47 -070045 virtual std::string getJavaType() const = 0;
46 virtual std::string getJavaSuffix() const;
47
Andreas Huber881227d2016-08-02 14:20:21 -070048 enum ErrorMode {
49 ErrorMode_Ignore,
50 ErrorMode_Goto,
51 ErrorMode_Break,
Andreas Huber737080b2016-08-02 15:38:04 -070052 ErrorMode_Return,
Andreas Huber881227d2016-08-02 14:20:21 -070053 };
54 virtual void emitReaderWriter(
55 Formatter &out,
56 const std::string &name,
57 const std::string &parcelObj,
58 bool parcelObjIsPointer,
59 bool isReader,
60 ErrorMode mode) const;
61
62 virtual void emitReaderWriterEmbedded(
63 Formatter &out,
64 const std::string &name,
65 bool nameIsPointer,
66 const std::string &parcelObj,
67 bool parcelObjIsPointer,
68 bool isReader,
69 ErrorMode mode,
70 const std::string &parentName,
71 const std::string &offsetText) const;
72
Andreas Huber2831d512016-08-15 09:33:47 -070073 virtual void emitJavaReaderWriter(
74 Formatter &out,
75 const std::string &parcelObj,
76 const std::string &argName,
77 bool isReader) const;
78
Andreas Huber881227d2016-08-02 14:20:21 -070079 virtual status_t emitTypeDeclarations(Formatter &out) const;
80
81 virtual status_t emitTypeDefinitions(
82 Formatter &out, const std::string prefix) const;
83
Andreas Huber2831d512016-08-15 09:33:47 -070084 virtual status_t emitJavaTypeDeclarations(Formatter &out) const;
85
Andreas Huber881227d2016-08-02 14:20:21 -070086 virtual bool needsEmbeddedReadWrite() const;
87 virtual bool resultNeedsDeref() const;
88
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070089 // Generates type declaration for vts proto file.
90 // TODO (b/30844146): make it a pure virtual method.
91 virtual status_t emitVtsTypeDeclarations(Formatter &out) const;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070092 // Generates type declaration as attribute of method (return value or method
93 // argument) or attribute of compound type for vts proto file.
94 virtual status_t emitVtsAttributeType(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070095
Andreas Huber70a59e12016-08-16 12:57:01 -070096 // Returns true iff this type is supported through the Java backend.
97 virtual bool isJavaCompatible() const;
98
Andreas Huber881227d2016-08-02 14:20:21 -070099protected:
100 void handleError(Formatter &out, ErrorMode mode) const;
101 void handleError2(Formatter &out, ErrorMode mode) const;
102
103 void emitReaderWriterEmbeddedForTypeName(
104 Formatter &out,
105 const std::string &name,
106 bool nameIsPointer,
107 const std::string &parcelObj,
108 bool parcelObjIsPointer,
109 bool isReader,
110 ErrorMode mode,
111 const std::string &parentName,
112 const std::string &offsetText,
113 const std::string &typeName,
114 const std::string &childName) const;
115
Andreas Huber2831d512016-08-15 09:33:47 -0700116 void emitJavaReaderWriterWithSuffix(
117 Formatter &out,
118 const std::string &parcelObj,
119 const std::string &argName,
120 bool isReader,
121 const std::string &suffix,
122 const std::string &extra) const;
123
Andreas Huberc9410c72016-07-28 12:18:40 -0700124private:
125 DISALLOW_COPY_AND_ASSIGN(Type);
126};
127
128} // namespace android
129
130#endif // TYPE_H_
131