Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 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 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 | |
| 28 | namespace android { |
| 29 | |
| 30 | struct 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 Moreland | ce65189 | 2016-09-19 13:12:58 -0700 | [diff] [blame] | 86 | void setArrays(std::vector<Expression *> *arrays); |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 87 | |
| 88 | const std::string decorateName(const std::string &name) const; |
| 89 | |
| 90 | bool isVoid() const; |
Diego Wilson | 2b38e89 | 2016-10-12 11:16:43 -0700 | [diff] [blame] | 91 | bool isHwDevice() const; |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 92 | std::string removeLastId(); |
| 93 | |
| 94 | private: |
| 95 | |
Steven Moreland | 05ebcf5 | 2016-09-19 13:57:40 -0700 | [diff] [blame] | 96 | static std::map<std::string, std::string> kSignedToUnsignedMap; |
| 97 | static const std::string signedToUnsigned(const std::string &signedType); |
| 98 | |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 99 | static std::map<std::string, std::string> kCToHidlMap; |
| 100 | static const std::string cToHidlType(const std::string &cType); |
| 101 | |
Steven Moreland | 698da76 | 2016-09-02 13:45:50 -0700 | [diff] [blame] | 102 | const std::string getHidlType() const; |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 103 | |
| 104 | const std::string getRawQualifierList() const; |
| 105 | const std::string getSpecialTypeName() const; |
| 106 | |
| 107 | std::vector<Qualifier*> *mQualifiers = NULL; |
Steven Moreland | ce65189 | 2016-09-19 13:12:58 -0700 | [diff] [blame] | 108 | |
| 109 | /* [ expression ] [ expression ] ... [ expression ] */ |
| 110 | std::vector<Expression*> *mArrays = NULL; |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 111 | |
| 112 | DISALLOW_COPY_AND_ASSIGN(Type); |
| 113 | }; |
| 114 | |
| 115 | } // namespace android |
| 116 | |
Diego Wilson | 2b38e89 | 2016-10-12 11:16:43 -0700 | [diff] [blame] | 117 | #endif // TYPE_H_ |