blob: 2543d49a133c8897e0148edcf0e8f2fe55e7083a [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
Timur Iskhakov565b0132017-09-06 18:07:11 -070024TypeDef::TypeDef(const char* localName, const FQName& fullName, const Location& location,
25 Scope* parent, const Reference<Type>& type)
26 : NamedType(localName, fullName, location, parent), mReferencedType(type) {}
Andreas Huberc9410c72016-07-28 12:18:40 -070027
Andreas Huber737080b2016-08-02 15:38:04 -070028const ScalarType *TypeDef::resolveToScalarType() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070029 CHECK(!"Should not be here");
Yi Kong56758da2018-07-24 16:21:37 -070030 return nullptr;
Andreas Huber737080b2016-08-02 15:38:04 -070031}
32
Timur Iskhakov24e605b2017-08-30 14:02:55 -070033Type* TypeDef::referencedType() {
34 return mReferencedType.get();
35}
36
37const Type* TypeDef::referencedType() const {
Timur Iskhakovb3f8bcb2017-08-30 15:33:29 -070038 return mReferencedType.get();
Andreas Huberc9410c72016-07-28 12:18:40 -070039}
40
Andreas Huber5a545442016-08-03 10:44:56 -070041bool TypeDef::isInterface() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070042 return false;
Andreas Huber5a545442016-08-03 10:44:56 -070043}
44
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070045bool TypeDef::isEnum() const {
46 CHECK(!"Should not be here");
47 return false;
Andreas Huber881227d2016-08-02 14:20:21 -070048}
49
Steven Moreland0ecc7b82017-07-19 12:59:23 -070050std::string TypeDef::typeName() const {
51 return "typedef " + localName();
52}
53
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070054bool TypeDef::isTypeDef() const {
55 return true;
Andreas Huber881227d2016-08-02 14:20:21 -070056}
57
Timur Iskhakovdbaed332017-08-31 16:33:41 -070058const Type* TypeDef::resolve() const {
59 return mReferencedType.get();
60}
61
Timur Iskhakov542920e2017-08-30 21:31:18 -070062std::vector<const Reference<Type>*> TypeDef::getReferences() const {
63 return {&mReferencedType};
64}
65
Andreas Huberbb797e42016-08-03 12:53:02 -070066bool TypeDef::needsEmbeddedReadWrite() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070067 CHECK(!"Should not be here");
68 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070069}
70
71bool TypeDef::resultNeedsDeref() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070072 CHECK(!"Should not be here");
73 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070074}
75
Steven Moreland6ec9eb92018-02-16 14:21:49 -080076void TypeDef::emitTypeDeclarations(Formatter& out) const {
Yifan Hong3b320f82016-11-01 15:15:54 -070077 out << "typedef "
78 << mReferencedType->getCppStackType()
79 << " "
80 << localName()
81 << ";\n\n";
Steven Moreland2a55e052016-09-27 10:14:24 -070082}
83
Andreas Huberc9410c72016-07-28 12:18:40 -070084} // namespace android
85