• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "TypeDef.h"
18 
19 #include <android-base/logging.h>
20 #include <hidl-util/Formatter.h>
21 #include <string>
22 
23 namespace android {
24 
TypeDef(const std::string & localName,const FQName & fullName,const Location & location,Scope * parent,const Reference<Type> & type)25 TypeDef::TypeDef(const std::string& localName, const FQName& fullName, const Location& location,
26                  Scope* parent, const Reference<Type>& type)
27     : NamedType(localName, fullName, location, parent), mReferencedType(type) {}
28 
resolveToScalarType() const29 const ScalarType *TypeDef::resolveToScalarType() const {
30     CHECK(!"Should not be here");
31     return nullptr;
32 }
33 
referencedType()34 Type* TypeDef::referencedType() {
35     return mReferencedType.get();
36 }
37 
referencedType() const38 const Type* TypeDef::referencedType() const {
39     return mReferencedType.get();
40 }
41 
isInterface() const42 bool TypeDef::isInterface() const {
43     return false;
44 }
45 
isEnum() const46 bool TypeDef::isEnum() const {
47     return false;
48 }
49 
typeName() const50 std::string TypeDef::typeName() const {
51     return "typedef " + definedName();
52 }
53 
isTypeDef() const54 bool TypeDef::isTypeDef() const {
55     return true;
56 }
57 
resolve() const58 const Type* TypeDef::resolve() const {
59     return mReferencedType.get();
60 }
61 
getReferences() const62 std::vector<const Reference<Type>*> TypeDef::getReferences() const {
63     return {&mReferencedType};
64 }
65 
needsEmbeddedReadWrite() const66 bool TypeDef::needsEmbeddedReadWrite() const {
67     CHECK(!"Should not be here");
68     return false;
69 }
70 
resultNeedsDeref() const71 bool TypeDef::resultNeedsDeref() const {
72     CHECK(!"Should not be here");
73     return false;
74 }
75 
emitTypeDeclarations(Formatter & out) const76 void TypeDef::emitTypeDeclarations(Formatter& out) const {
77     out << "typedef " << mReferencedType->getCppStackType() << " " << definedName() << ";\n\n";
78 }
79 
emitHidlDefinition(Formatter & out) const80 void TypeDef::emitHidlDefinition(Formatter& out) const {
81     out << "typedef " << mReferencedType.localName() << " " << definedName() << ";\n";
82 }
83 
84 }  // namespace android
85 
86