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 "AST.h" 18 19 #include "Annotation.h" 20 #include "Coordinator.h" 21 #include "Interface.h" 22 #include "Method.h" 23 #include "Scope.h" 24 25 #include <hidl-util/Formatter.h> 26 #include <android-base/logging.h> 27 #include <string> 28 #include <vector> 29 30 namespace android { 31 emitVtsTypeDeclarations(Formatter & out) const32void AST::emitVtsTypeDeclarations(Formatter& out) const { 33 if (AST::isInterface()) { 34 const Interface* iface = mRootScope.getInterface(); 35 return iface->emitVtsAttributeDeclaration(out); 36 } 37 38 for (const auto& type : mRootScope.getSubTypes()) { 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(); 45 type->emitVtsTypeDeclarations(out); 46 out.unindent(); 47 out << "}\n\n"; 48 } 49 } 50 generateVts(Formatter & out) const51void AST::generateVts(Formatter& out) const { 52 std::string baseName = AST::getBaseName(); 53 const Interface *iface = AST::getInterface(); 54 55 out << "component_class: HAL_HIDL\n"; 56 out << "component_type_version: " << mPackage.version() 57 << "\n"; 58 out << "component_name: \"" 59 << (iface ? iface->localName() : "types") 60 << "\"\n\n"; 61 62 out << "package: \"" << mPackage.package() << "\"\n\n"; 63 64 // Generate import statement for all imported interface/types. 65 std::set<FQName> allImportedNames; 66 getAllImportedNames(&allImportedNames); 67 for (const auto &name : allImportedNames) { 68 // ignore IBase. 69 if (name != gIBaseFqName) { 70 out << "import: \"" << name.string() << "\"\n"; 71 } 72 } 73 74 out << "\n"; 75 76 if (isInterface()) { 77 const Interface* iface = mRootScope.getInterface(); 78 out << "interface: {\n"; 79 out.indent(); 80 81 std::vector<const Interface *> chain = iface->typeChain(); 82 83 // Generate all the attribute declarations first. 84 emitVtsTypeDeclarations(out); 85 86 // Generate all the method declarations. 87 for (auto it = chain.rbegin(); it != chain.rend(); ++it) { 88 const Interface *superInterface = *it; 89 superInterface->emitVtsMethodDeclaration(out); 90 } 91 92 out.unindent(); 93 out << "}\n"; 94 } else { 95 emitVtsTypeDeclarations(out); 96 } 97 } 98 99 } // namespace android 100