Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 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 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 17 | #include "AST.h" |
| 18 | |
| 19 | #include "Annotation.h" |
| 20 | #include "Coordinator.h" |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 21 | #include "Interface.h" |
| 22 | #include "Method.h" |
| 23 | #include "Scope.h" |
| 24 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 25 | #include <hidl-util/Formatter.h> |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 26 | #include <android-base/logging.h> |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Steven Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 32 | void AST::emitVtsTypeDeclarations(Formatter& out) const { |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 33 | if (AST::isInterface()) { |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 34 | const Interface* iface = mRootScope.getInterface(); |
| 35 | return iface->emitVtsAttributeDeclaration(out); |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 36 | } |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 37 | |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 38 | for (const auto& type : mRootScope.getSubTypes()) { |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 39 | // 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 Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 45 | type->emitVtsTypeDeclarations(out); |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 46 | out.unindent(); |
| 47 | out << "}\n\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 48 | } |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Steven Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 51 | void AST::generateVts(Formatter& out) const { |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 52 | std::string baseName = AST::getBaseName(); |
| 53 | const Interface *iface = AST::getInterface(); |
| 54 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 55 | out << "component_class: HAL_HIDL\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 56 | out << "component_name: \"" |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 57 | << (iface ? iface->localName() : "types") |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 58 | << "\"\n\n"; |
| 59 | |
Hans Chen | 7ede304 | 2018-06-05 15:18:15 -0700 | [diff] [blame] | 60 | out << "component_type_version_major: " << mPackage.getPackageMajorVersion() << "\n"; |
| 61 | out << "component_type_version_minor: " << mPackage.getPackageMinorVersion() << "\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 62 | out << "package: \"" << mPackage.package() << "\"\n\n"; |
| 63 | |
Zhuoyao Zhang | c4e1060 | 2017-01-27 16:48:05 -0800 | [diff] [blame] | 64 | // Generate import statement for all imported interface/types. |
| 65 | std::set<FQName> allImportedNames; |
| 66 | getAllImportedNames(&allImportedNames); |
| 67 | for (const auto &name : allImportedNames) { |
Zhuoyao Zhang | 5deccac | 2016-12-16 10:07:34 -0800 | [diff] [blame] | 68 | // ignore IBase. |
Zhuoyao Zhang | c4e1060 | 2017-01-27 16:48:05 -0800 | [diff] [blame] | 69 | if (name != gIBaseFqName) { |
| 70 | out << "import: \"" << name.string() << "\"\n"; |
Zhuoyao Zhang | 5deccac | 2016-12-16 10:07:34 -0800 | [diff] [blame] | 71 | } |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | out << "\n"; |
| 75 | |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 76 | if (isInterface()) { |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 77 | const Interface* iface = mRootScope.getInterface(); |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 78 | out << "interface: {\n"; |
| 79 | out.indent(); |
| 80 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 81 | // Generate all the attribute declarations first. |
Steven Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 82 | emitVtsTypeDeclarations(out); |
| 83 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 84 | // Generate all the method declarations. |
Zhuoyao Zhang | e59c933 | 2018-07-20 14:16:04 -0700 | [diff] [blame] | 85 | for (const Interface* superInterface : iface->superTypeChain()) { |
| 86 | superInterface->emitVtsMethodDeclaration(out, true /*isInhereted*/); |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Zhuoyao Zhang | e59c933 | 2018-07-20 14:16:04 -0700 | [diff] [blame] | 89 | iface->emitVtsMethodDeclaration(out, false /*isInhereted*/); |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 90 | out.unindent(); |
| 91 | out << "}\n"; |
| 92 | } else { |
Steven Moreland | 6ec9eb9 | 2018-02-16 14:21:49 -0800 | [diff] [blame] | 93 | emitVtsTypeDeclarations(out); |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 94 | } |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } // namespace android |