blob: cf7c0ab4f457c625cf92e4cdfb2d1bc47c7d7c35 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -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
Andreas Huberc9410c72016-07-28 12:18:40 -070017#include "TypeDef.h"
18
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070019#include <hidl-util/Formatter.h>
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070020#include <android-base/logging.h>
21
Andreas Huberc9410c72016-07-28 12:18:40 -070022namespace android {
23
Yifan Honga4b53d02016-10-31 17:29:10 -070024TypeDef::TypeDef(const char* localName, const Location &location, Type *type)
25 : NamedType(localName, location),
Andreas Huberc9410c72016-07-28 12:18:40 -070026 mReferencedType(type) {
27}
28
Andreas Huber737080b2016-08-02 15:38:04 -070029const ScalarType *TypeDef::resolveToScalarType() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070030 CHECK(!"Should not be here");
31 return NULL;
Andreas Huber737080b2016-08-02 15:38:04 -070032}
33
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070034Type *TypeDef::referencedType() const {
Andreas Huberc9410c72016-07-28 12:18:40 -070035 return mReferencedType;
36}
37
Andreas Huber5a545442016-08-03 10:44:56 -070038bool TypeDef::isInterface() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070039 return false;
Andreas Huber5a545442016-08-03 10:44:56 -070040}
41
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070042bool TypeDef::isEnum() const {
43 CHECK(!"Should not be here");
44 return false;
Andreas Huber881227d2016-08-02 14:20:21 -070045}
46
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070047bool TypeDef::isTypeDef() const {
48 return true;
Andreas Huber881227d2016-08-02 14:20:21 -070049}
50
Andreas Huberbb797e42016-08-03 12:53:02 -070051bool TypeDef::needsEmbeddedReadWrite() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070052 CHECK(!"Should not be here");
53 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070054}
55
56bool TypeDef::resultNeedsDeref() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070057 CHECK(!"Should not be here");
58 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070059}
60
Steven Moreland2a55e052016-09-27 10:14:24 -070061status_t TypeDef::emitTypeDeclarations(Formatter &out) const {
Yifan Hong3b320f82016-11-01 15:15:54 -070062 out << "typedef "
63 << mReferencedType->getCppStackType()
64 << " "
65 << localName()
66 << ";\n\n";
Steven Moreland2a55e052016-09-27 10:14:24 -070067
68 return OK;
69}
70
Andreas Huberc9410c72016-07-28 12:18:40 -070071} // namespace android
72