blob: 8cd04778a9bdfd1ff3c70a7e60c726f6ef5dcdd4 [file] [log] [blame]
Steven Morelandf1a35f72016-08-17 08:41:49 -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
17#ifndef TYPE_H_
18#define TYPE_H_
19
20#include "Expression.h"
21
22#include <android-base/macros.h>
23#include <android-base/logging.h>
24#include <string>
25#include <vector>
26#include <map>
27
28namespace android {
29
30struct Type {
31
32 struct Qualifier {
33
34 enum Qualification {
35 NONE = 0,
36 STRUCT,
37 UNION,
38 SIGNED,
39 UNSIGNED,
40 VOID,
41 POINTER,
42 CONST,
43 GENERICS,
44 ID,
45 ENUM
46 } qualification;
47
48 union {
49 std::string id;
50 Type *generics;
51 };
52
53 Qualifier(Qualification qualification)
54 : qualification(qualification) {}
55 Qualifier(Qualification qualification, std::string id)
56 : qualification(qualification), id(id) {}
57 Qualifier(Qualification qualification, Type* generics)
58 : qualification(qualification), generics(generics) {}
59
60 ~Qualifier() {
61 if (qualification == GENERICS) {
62 delete generics;
63 }
64 }
65 };
66
67 Type(std::vector<Qualifier*> *qualifiers);
68 ~Type();
69
70 static std::string qualifierText(Qualifier::Qualification qual) {
71 switch(qual) {
72 case Qualifier::STRUCT: return "struct";
73 case Qualifier::UNION: return "union";
74 case Qualifier::ENUM: return "enum";
75 case Qualifier::SIGNED: return "signed";
76 case Qualifier::UNSIGNED: return "unsigned";
77 case Qualifier::VOID: return "void";
78 case Qualifier::POINTER: return "*";
79 case Qualifier::CONST: return "const";
80 case Qualifier::ID: return "ID";
81 case Qualifier::NONE: return "";
82 default: return "/* UNKNOWN TYPE QUALIFIER */";
83 }
84 }
85
Steven Morelandce651892016-09-19 13:12:58 -070086 void setArrays(std::vector<Expression *> *arrays);
Steven Morelandf1a35f72016-08-17 08:41:49 -070087
88 const std::string decorateName(const std::string &name) const;
89
90 bool isVoid() const;
Diego Wilson2b38e892016-10-12 11:16:43 -070091 bool isHwDevice() const;
Steven Morelandf1a35f72016-08-17 08:41:49 -070092 std::string removeLastId();
93
94private:
95
Steven Moreland05ebcf52016-09-19 13:57:40 -070096 static std::map<std::string, std::string> kSignedToUnsignedMap;
97 static const std::string signedToUnsigned(const std::string &signedType);
98
Steven Morelandf1a35f72016-08-17 08:41:49 -070099 static std::map<std::string, std::string> kCToHidlMap;
100 static const std::string cToHidlType(const std::string &cType);
101
Steven Moreland698da762016-09-02 13:45:50 -0700102 const std::string getHidlType() const;
Steven Morelandf1a35f72016-08-17 08:41:49 -0700103
104 const std::string getRawQualifierList() const;
105 const std::string getSpecialTypeName() const;
106
107 std::vector<Qualifier*> *mQualifiers = NULL;
Steven Morelandce651892016-09-19 13:12:58 -0700108
109 /* [ expression ] [ expression ] ... [ expression ] */
110 std::vector<Expression*> *mArrays = NULL;
Steven Morelandf1a35f72016-08-17 08:41:49 -0700111
112 DISALLOW_COPY_AND_ASSIGN(Type);
113};
114
115} // namespace android
116
Diego Wilson2b38e892016-10-12 11:16:43 -0700117#endif // TYPE_H_