Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -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 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | #include "TypeDef.h" |
| 18 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 19 | #include <hidl-util/Formatter.h> |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 20 | #include <android-base/logging.h> |
| 21 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 22 | namespace android { |
| 23 | |
Steven Moreland | 6f2f2c0 | 2017-08-05 00:32:14 +0000 | [diff] [blame] | 24 | TypeDef::TypeDef(const char* localName, const Location& location, Scope* parent, Type* type) |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 25 | : NamedType(localName, location, parent), mReferencedType(type) {} |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 26 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 27 | const ScalarType *TypeDef::resolveToScalarType() const { |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 28 | CHECK(!"Should not be here"); |
| 29 | return NULL; |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Steven Moreland | 6f2f2c0 | 2017-08-05 00:32:14 +0000 | [diff] [blame] | 32 | Type *TypeDef::referencedType() const { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 33 | return mReferencedType; |
| 34 | } |
| 35 | |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 36 | bool TypeDef::isInterface() const { |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 37 | return false; |
Andreas Huber | 5a54544 | 2016-08-03 10:44:56 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 40 | bool TypeDef::isEnum() const { |
| 41 | CHECK(!"Should not be here"); |
| 42 | return false; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Steven Moreland | 0ecc7b8 | 2017-07-19 12:59:23 -0700 | [diff] [blame] | 45 | std::string TypeDef::typeName() const { |
| 46 | return "typedef " + localName(); |
| 47 | } |
| 48 | |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 49 | bool TypeDef::isTypeDef() const { |
| 50 | return true; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Andreas Huber | bb797e4 | 2016-08-03 12:53:02 -0700 | [diff] [blame] | 53 | bool TypeDef::needsEmbeddedReadWrite() const { |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 54 | CHECK(!"Should not be here"); |
| 55 | return false; |
Andreas Huber | bb797e4 | 2016-08-03 12:53:02 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | bool TypeDef::resultNeedsDeref() const { |
Andreas Huber | 8d3ac0c | 2016-08-04 14:49:23 -0700 | [diff] [blame] | 59 | CHECK(!"Should not be here"); |
| 60 | return false; |
Andreas Huber | bb797e4 | 2016-08-03 12:53:02 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Steven Moreland | 2a55e05 | 2016-09-27 10:14:24 -0700 | [diff] [blame] | 63 | status_t TypeDef::emitTypeDeclarations(Formatter &out) const { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 64 | out << "typedef " |
| 65 | << mReferencedType->getCppStackType() |
| 66 | << " " |
| 67 | << localName() |
| 68 | << ";\n\n"; |
Steven Moreland | 2a55e05 | 2016-09-27 10:14:24 -0700 | [diff] [blame] | 69 | |
| 70 | return OK; |
| 71 | } |
| 72 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 73 | } // namespace android |
| 74 | |