blob: f47071145044ce6aef5970377c49666299f02b9f [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 Iskhakov505316c2017-08-05 03:38:59 +000024TypeDef::TypeDef(const char* localName, const Location& location, Scope* parent,
25 const Reference<Type>& type)
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070026 : NamedType(localName, 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");
30 return NULL;
Andreas Huber737080b2016-08-02 15:38:04 -070031}
32
Timur Iskhakov505316c2017-08-05 03:38:59 +000033Type* TypeDef::referencedType() const {
Andreas Huberc9410c72016-07-28 12:18:40 -070034 return mReferencedType;
35}
36
Andreas Huber5a545442016-08-03 10:44:56 -070037bool TypeDef::isInterface() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070038 return false;
Andreas Huber5a545442016-08-03 10:44:56 -070039}
40
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070041bool TypeDef::isEnum() const {
42 CHECK(!"Should not be here");
43 return false;
Andreas Huber881227d2016-08-02 14:20:21 -070044}
45
Steven Moreland0ecc7b82017-07-19 12:59:23 -070046std::string TypeDef::typeName() const {
47 return "typedef " + localName();
48}
49
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070050bool TypeDef::isTypeDef() const {
51 return true;
Andreas Huber881227d2016-08-02 14:20:21 -070052}
53
Andreas Huberbb797e42016-08-03 12:53:02 -070054bool TypeDef::needsEmbeddedReadWrite() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070055 CHECK(!"Should not be here");
56 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070057}
58
59bool TypeDef::resultNeedsDeref() const {
Andreas Huber8d3ac0c2016-08-04 14:49:23 -070060 CHECK(!"Should not be here");
61 return false;
Andreas Huberbb797e42016-08-03 12:53:02 -070062}
63
Steven Moreland2a55e052016-09-27 10:14:24 -070064status_t TypeDef::emitTypeDeclarations(Formatter &out) const {
Yifan Hong3b320f82016-11-01 15:15:54 -070065 out << "typedef "
66 << mReferencedType->getCppStackType()
67 << " "
68 << localName()
69 << ";\n\n";
Steven Moreland2a55e052016-09-27 10:14:24 -070070
71 return OK;
72}
73
Andreas Huberc9410c72016-07-28 12:18:40 -070074} // namespace android
75