blob: f419efefb7b6c03e0af1950e5d5ff6d9bb04cb1c [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
Steven Moreland6f2f2c02017-08-05 00:32:14 +000024TypeDef::TypeDef(const char* localName, const Location& location, Scope* parent, Type* type)
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070025 : NamedType(localName, location, parent), mReferencedType(type) {}
Andreas Huberc9410c72016-07-28 12:18:40 -070026
Andreas Huber737080b2016-08-02 15:38:04 -070027const ScalarType *TypeDef::resolveToScalarType() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070028 CHECK(!"Should not be here");
29 return NULL;
Andreas Huber737080b2016-08-02 15:38:04 -070030}
31
Steven Moreland6f2f2c02017-08-05 00:32:14 +000032Type *TypeDef::referencedType() const {
Andreas Huberc9410c72016-07-28 12:18:40 -070033 return mReferencedType;
34}
35
Andreas Huber5a545442016-08-03 10:44:56 -070036bool TypeDef::isInterface() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070037 return false;
Andreas Huber5a545442016-08-03 10:44:56 -070038}
39
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070040bool TypeDef::isEnum() const {
41 CHECK(!"Should not be here");
42 return false;
Andreas Huber881227d2016-08-02 14:20:21 -070043}
44
Steven Moreland0ecc7b82017-07-19 12:59:23 -070045std::string TypeDef::typeName() const {
46 return "typedef " + localName();
47}
48
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070049bool TypeDef::isTypeDef() const {
50 return true;
Andreas Huber881227d2016-08-02 14:20:21 -070051}
52
Andreas Huberbb797e42016-08-03 12:53:02 -070053bool TypeDef::needsEmbeddedReadWrite() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070054 CHECK(!"Should not be here");
55 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070056}
57
58bool TypeDef::resultNeedsDeref() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070059 CHECK(!"Should not be here");
60 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070061}
62
Steven Moreland2a55e052016-09-27 10:14:24 -070063status_t TypeDef::emitTypeDeclarations(Formatter &out) const {
Yifan Hong3b320f82016-11-01 15:15:54 -070064 out << "typedef "
65 << mReferencedType->getCppStackType()
66 << " "
67 << localName()
68 << ";\n\n";
Steven Moreland2a55e052016-09-27 10:14:24 -070069
70 return OK;
71}
72
Andreas Huberc9410c72016-07-28 12:18:40 -070073} // namespace android
74