blob: 722a65668117999a8c2d441b08e8a76315bdad65 [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
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070017#include "AST.h"
18
19#include "Annotation.h"
20#include "Coordinator.h"
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070021#include "Interface.h"
22#include "Method.h"
23#include "Scope.h"
24
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070025#include <hidl-util/Formatter.h>
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070026#include <android-base/logging.h>
27#include <string>
28#include <vector>
29
30namespace android {
31
Steven Moreland6ec9eb92018-02-16 14:21:49 -080032void AST::emitVtsTypeDeclarations(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -070033 if (AST::isInterface()) {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070034 const Interface* iface = mRootScope.getInterface();
35 return iface->emitVtsAttributeDeclaration(out);
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070036 }
Steven Moreland19f11b52017-05-12 18:22:21 -070037
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070038 for (const auto& type : mRootScope.getSubTypes()) {
Steven Moreland19f11b52017-05-12 18:22:21 -070039 // Skip for TypeDef as it is just an alias of a defined type.
40 if (type->isTypeDef()) {
41 continue;
42 }
43 out << "attribute: {\n";
44 out.indent();
Steven Moreland6ec9eb92018-02-16 14:21:49 -080045 type->emitVtsTypeDeclarations(out);
Steven Moreland19f11b52017-05-12 18:22:21 -070046 out.unindent();
47 out << "}\n\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070048 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070049}
50
Steven Moreland6ec9eb92018-02-16 14:21:49 -080051void AST::generateVts(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -070052 std::string baseName = AST::getBaseName();
53 const Interface *iface = AST::getInterface();
54
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070055 out << "component_class: HAL_HIDL\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070056 out << "component_name: \""
Steven Moreland19f11b52017-05-12 18:22:21 -070057 << (iface ? iface->localName() : "types")
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070058 << "\"\n\n";
59
Hans Chen7ede3042018-06-05 15:18:15 -070060 out << "component_type_version_major: " << mPackage.getPackageMajorVersion() << "\n";
61 out << "component_type_version_minor: " << mPackage.getPackageMinorVersion() << "\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070062 out << "package: \"" << mPackage.package() << "\"\n\n";
63
Zhuoyao Zhangc4e10602017-01-27 16:48:05 -080064 // Generate import statement for all imported interface/types.
65 std::set<FQName> allImportedNames;
66 getAllImportedNames(&allImportedNames);
67 for (const auto &name : allImportedNames) {
Zhuoyao Zhang5deccac2016-12-16 10:07:34 -080068 // ignore IBase.
Zhuoyao Zhangc4e10602017-01-27 16:48:05 -080069 if (name != gIBaseFqName) {
70 out << "import: \"" << name.string() << "\"\n";
Zhuoyao Zhang5deccac2016-12-16 10:07:34 -080071 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070072 }
73
74 out << "\n";
75
Steven Moreland19f11b52017-05-12 18:22:21 -070076 if (isInterface()) {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070077 const Interface* iface = mRootScope.getInterface();
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070078 out << "interface: {\n";
79 out.indent();
80
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070081 // Generate all the attribute declarations first.
Steven Moreland6ec9eb92018-02-16 14:21:49 -080082 emitVtsTypeDeclarations(out);
83
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070084 // Generate all the method declarations.
Zhuoyao Zhange59c9332018-07-20 14:16:04 -070085 for (const Interface* superInterface : iface->superTypeChain()) {
86 superInterface->emitVtsMethodDeclaration(out, true /*isInhereted*/);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070087 }
88
Zhuoyao Zhange59c9332018-07-20 14:16:04 -070089 iface->emitVtsMethodDeclaration(out, false /*isInhereted*/);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070090 out.unindent();
91 out << "}\n";
92 } else {
Steven Moreland6ec9eb92018-02-16 14:21:49 -080093 emitVtsTypeDeclarations(out);
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070094 }
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070095}
96
97} // namespace android