Removed "bool AST::isInterface(std::string*)"
Test: links
Change-Id: I603831ed8aa8a8794a54d38ce0e1d0b6c68701cb
diff --git a/AST.cpp b/AST.cpp
index 4b10fb0..cecdabd 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -86,8 +86,8 @@
return mPackage;
}
-bool AST::isInterface(std::string *ifaceName) const {
- return mRootScope->containsSingleInterface(ifaceName);
+bool AST::isInterface() const {
+ return mRootScope->getInterface() != nullptr;
}
bool AST::containsInterfaces() const {
@@ -530,8 +530,7 @@
}
bool AST::isJavaCompatible() const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
for (const auto *type : mRootScope->getSubTypes()) {
if (!type->isJavaCompatible()) {
return false;
@@ -559,4 +558,10 @@
return mRootScope->getInterface();
}
+std::string AST::getBaseName() const {
+ const Interface *iface = mRootScope->getInterface();
+
+ return iface ? iface->getBaseName() : "types";
+}
+
} // namespace android;
diff --git a/AST.h b/AST.h
index e510cbe..1efb78d 100644
--- a/AST.h
+++ b/AST.h
@@ -48,7 +48,7 @@
// package and version really.
FQName package() const;
- bool isInterface(std::string *ifaceName) const;
+ bool isInterface() const;
bool containsInterfaces() const;
void enterScope(Scope *container);
@@ -118,8 +118,12 @@
bool isIBase() const;
+ // or nullptr if not isInterface
const Interface *getInterface() const;
+ // types or Interface base name (e.x. Foo)
+ std::string getBaseName() const;
+
private:
const Coordinator *mCoordinator;
std::string mPath;
diff --git a/Coordinator.cpp b/Coordinator.cpp
index 1ec0554..9b31c77 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -122,17 +122,16 @@
err = UNKNOWN_ERROR;
} else {
- std::string ifaceName;
- if (ast->isInterface(&ifaceName)) {
+ if (ast->isInterface()) {
if (fqName.name() == "types") {
fprintf(stderr,
"ERROR: File at '%s' declares an interface '%s' "
"instead of the expected types common to the package.\n",
path.c_str(),
- ifaceName.c_str());
+ ast->getInterface()->localName().c_str());
err = UNKNOWN_ERROR;
- } else if (ifaceName != fqName.name()) {
+ } else if (ast->getInterface()->localName() != fqName.name()) {
fprintf(stderr,
"ERROR: File at '%s' does not declare interface type "
"'%s'.\n",
diff --git a/Scope.cpp b/Scope.cpp
index aad55c9..b2414b3 100644
--- a/Scope.cpp
+++ b/Scope.cpp
@@ -95,17 +95,6 @@
return NULL;
}
-bool Scope::containsSingleInterface(std::string *ifaceName) const {
- Interface *iface = getInterface();
-
- if (iface != NULL) {
- *ifaceName = iface->localName();
- return true;
- }
-
- return false;
-}
-
bool Scope::containsInterfaces() const {
for (const NamedType *type : mTypes) {
if (type->isInterface()) {
diff --git a/Scope.h b/Scope.h
index de53974..122520b 100644
--- a/Scope.h
+++ b/Scope.h
@@ -47,7 +47,6 @@
// Returns the single interface or NULL.
Interface *getInterface() const;
- bool containsSingleInterface(std::string *ifaceName) const;
bool containsInterfaces() const;
status_t emitTypeDeclarations(Formatter &out) const override;
diff --git a/generateCpp.cpp b/generateCpp.cpp
index fb0c2c1..cb6039f 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -371,17 +371,12 @@
}
status_t AST::generateInterfaceHeader(const std::string &outputPath) const {
+ const Interface *iface = getInterface();
+ std::string ifaceName = iface ? iface->localName() : "types";
std::string path = outputPath;
path.append(mCoordinator->convertPackageRootToPath(mPackage));
path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
-
- std::string ifaceName;
- bool isInterface = true;
- if (!AST::isInterface(&ifaceName)) {
- ifaceName = "types";
- isInterface = false;
- }
path.append(ifaceName);
path.append(".h");
@@ -407,7 +402,7 @@
out << "\n";
}
- if (isInterface) {
+ if (iface) {
if (isIBase()) {
out << "// skipped #include IServiceNotification.h\n\n";
} else {
@@ -418,7 +413,7 @@
out << "#include <hidl/HidlSupport.h>\n";
out << "#include <hidl/MQDescriptor.h>\n";
- if (isInterface) {
+ if (iface) {
out << "#include <hidl/Status.h>\n";
}
@@ -428,11 +423,10 @@
enterLeaveNamespace(out, true /* enter */);
out << "\n";
- if (isInterface) {
+ if (iface) {
out << "struct "
<< ifaceName;
- const Interface *iface = mRootScope->getInterface();
const Interface *superType = iface->superType();
if (superType == NULL) {
@@ -454,9 +448,7 @@
return err;
}
- if (isInterface) {
- const Interface *iface = mRootScope->getInterface();
-
+ if (iface) {
out << "virtual bool isRemote() const ";
if (!isIBase()) {
out << "override ";
@@ -530,7 +522,7 @@
}
}
- if (isInterface) {
+ if (iface) {
out.unindent();
out << "};\n\n";
@@ -551,17 +543,8 @@
}
status_t AST::generateHwBinderHeader(const std::string &outputPath) const {
- std::string ifaceName;
- bool isInterface = AST::isInterface(&ifaceName);
- const Interface *iface = nullptr;
- std::string klassName{};
-
- if(isInterface) {
- iface = mRootScope->getInterface();
- klassName = iface->getHwName();
- } else {
- klassName = "hwtypes";
- }
+ const Interface *iface = getInterface();
+ std::string klassName = iface ? iface->getHwName() : "hwtypes";
std::string path = outputPath;
path.append(mCoordinator->convertPackageRootToPath(mPackage));
@@ -581,11 +564,7 @@
out << "#ifndef " << guard << "\n";
out << "#define " << guard << "\n\n";
- if (isInterface) {
- generateCppPackageInclude(out, mPackage, ifaceName);
- } else {
- generateCppPackageInclude(out, mPackage, "types");
- }
+ generateCppPackageInclude(out, mPackage, iface ? iface->localName() : "types");
out << "\n";
@@ -787,7 +766,6 @@
}
status_t AST::generateMethods(Formatter &out, MethodGenerator gen) const {
-
const Interface *iface = mRootScope->getInterface();
const Interface *prevIterface = nullptr;
@@ -817,8 +795,7 @@
}
status_t AST::generateStubHeader(const std::string &outputPath) const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
// types.hal does not get a stub header.
return OK;
}
@@ -866,11 +843,11 @@
out.indent();
out << "explicit "
<< klassName
- << "(const ::android::sp<" << ifaceName << "> &_hidl_impl);"
+ << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl);"
<< "\n";
out << "explicit "
<< klassName
- << "(const ::android::sp<" << ifaceName << "> &_hidl_impl,"
+ << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl,"
<< " const std::string& HidlInstrumentor_package,"
<< " const std::string& HidlInstrumentor_interface);"
<< "\n\n";
@@ -885,7 +862,7 @@
out.unindent();
out.unindent();
- out << "::android::sp<" << ifaceName << "> getImpl() { return _hidl_mImpl; };\n";
+ out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; };\n";
out.unindent();
out << "private:\n";
out.indent();
@@ -910,7 +887,7 @@
return err;
}
- out << "::android::sp<" << ifaceName << "> _hidl_mImpl;\n";
+ out << "::android::sp<" << iface->localName() << "> _hidl_mImpl;\n";
out.unindent();
out << "};\n\n";
@@ -922,8 +899,7 @@
}
status_t AST::generateProxyHeader(const std::string &outputPath) const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
// types.hal does not get a proxy header.
return OK;
}
@@ -1005,25 +981,12 @@
}
status_t AST::generateCppSources(const std::string &outputPath) const {
+ std::string baseName = getBaseName();
+ const Interface *iface = getInterface();
std::string path = outputPath;
path.append(mCoordinator->convertPackageRootToPath(mPackage));
path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
-
- std::string ifaceName;
- std::string baseName;
-
- const Interface *iface = nullptr;
- bool isInterface;
- if (!AST::isInterface(&ifaceName)) {
- baseName = "types";
- isInterface = false;
- } else {
- iface = mRootScope->getInterface();
- baseName = iface->getBaseName();
- isInterface = true;
- }
-
path.append(baseName);
if (baseName != "types") {
@@ -1048,7 +1011,7 @@
out << "#include <android/log.h>\n";
out << "#include <cutils/trace.h>\n";
out << "#include <hidl/HidlTransportSupport.h>\n\n";
- if (isInterface) {
+ if (iface) {
// This is a no-op for IServiceManager itself.
out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n";
@@ -1076,9 +1039,9 @@
enterLeaveNamespace(out, true /* enter */);
out << "\n";
- status_t err = generateTypeSource(out, ifaceName);
+ status_t err = generateTypeSource(out, iface ? iface->localName() : "");
- if (err == OK && isInterface) {
+ if (err == OK && iface) {
const Interface *iface = mRootScope->getInterface();
// need to be put here, generateStubSource is using this.
@@ -1137,19 +1100,19 @@
err = generateInterfaceSource(out);
}
- if (err == OK && isInterface) {
+ if (err == OK && iface) {
err = generateProxySource(out, iface->fqName());
}
- if (err == OK && isInterface) {
+ if (err == OK && iface) {
err = generateStubSource(out, iface);
}
- if (err == OK && isInterface) {
+ if (err == OK && iface) {
err = generatePassthroughSource(out);
}
- if (err == OK && isInterface) {
+ if (err == OK && iface) {
const Interface *iface = mRootScope->getInterface();
if (isIBase()) {
@@ -1807,13 +1770,13 @@
}
status_t AST::generatePassthroughHeader(const std::string &outputPath) const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
// types.hal does not get a stub header.
return OK;
}
const Interface *iface = mRootScope->getInterface();
+ CHECK(iface != nullptr);
const std::string klassName = iface->getPassthroughName();
@@ -1847,7 +1810,7 @@
out << "#include <cutils/trace.h>\n";
out << "#include <future>\n";
- generateCppPackageInclude(out, mPackage, ifaceName);
+ generateCppPackageInclude(out, mPackage, iface->localName());
out << "\n";
out << "#include <hidl/HidlPassthroughSupport.h>\n";
@@ -1860,14 +1823,14 @@
out << "struct "
<< klassName
- << " : " << ifaceName
+ << " : " << iface->localName()
<< ", ::android::hardware::details::HidlInstrumentor {\n";
out.indent();
out << "explicit "
<< klassName
<< "(const ::android::sp<"
- << ifaceName
+ << iface->localName()
<< "> impl);\n";
status_t err = generateMethods(out, [&](const Method *method, const Interface *) {
@@ -1881,7 +1844,7 @@
out.unindent();
out << "private:\n";
out.indent();
- out << "const ::android::sp<" << ifaceName << "> mImpl;\n";
+ out << "const ::android::sp<" << iface->localName() << "> mImpl;\n";
if (supportOneway) {
out << "::android::hardware::details::TaskRunner mOnewayQueue;\n";
diff --git a/generateCppImpl.cpp b/generateCppImpl.cpp
index 874743b..7025a87 100644
--- a/generateCppImpl.cpp
+++ b/generateCppImpl.cpp
@@ -80,14 +80,12 @@
}
status_t AST::generateStubImplHeader(const std::string &outputPath) const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
// types.hal does not get a stub header.
return OK;
}
const Interface *iface = mRootScope->getInterface();
-
const std::string baseName = iface->getBaseName();
std::string path = outputPath;
@@ -129,7 +127,7 @@
out << "struct "
<< baseName
<< " : public "
- << ifaceName
+ << iface->localName()
<< " {\n";
out.indent();
@@ -155,9 +153,9 @@
out << "// FIXME: most likely delete, this is only for passthrough implementations\n"
<< "// extern \"C\" "
- << ifaceName
+ << iface->localName()
<< "* ";
- generateFetchSymbol(out, ifaceName);
+ generateFetchSymbol(out, iface->localName());
out << "(const char* name);\n\n";
out << "} // namespace implementation\n";
@@ -169,8 +167,7 @@
}
status_t AST::generateStubImplSource(const std::string &outputPath) const {
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
// types.hal does not get a stub header.
return OK;
}
@@ -205,9 +202,9 @@
}
out.setLinePrefix("//");
- out << ifaceName
+ out << iface->localName()
<< "* ";
- generateFetchSymbol(out, ifaceName);
+ generateFetchSymbol(out, iface->localName());
out << "(const char* /* name */) {\n";
out.indent();
out << "return new " << baseName << "();\n";
diff --git a/generateJava.cpp b/generateJava.cpp
index c0f8768..9f8f1dd 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -108,12 +108,12 @@
return UNKNOWN_ERROR;
}
- std::string ifaceName;
- if (!AST::isInterface(&ifaceName)) {
+ if (!AST::isInterface()) {
return generateJavaTypes(outputPath, limitToType);
}
const Interface *iface = mRootScope->getInterface();
+ std::string ifaceName = iface->localName();
const std::string baseName = iface->getBaseName();
diff --git a/generateVts.cpp b/generateVts.cpp
index b7e2e2b..f695bec 100644
--- a/generateVts.cpp
+++ b/generateVts.cpp
@@ -30,49 +30,36 @@
namespace android {
status_t AST::emitVtsTypeDeclarations(Formatter &out) const {
- std::string ifaceName;
- if (AST::isInterface(&ifaceName)) {
- const Interface *iface = mRootScope->getInterface();
- status_t status = iface->emitVtsAttributeDeclaration(out);
- if (status != OK) {
- return status;
+ if (AST::isInterface()) {
+ const Interface *iface = mRootScope->getInterface();
+ return iface->emitVtsAttributeDeclaration(out);
}
- } else {
+
for (const auto &type : mRootScope->getSubTypes()) {
- // Skip for TypeDef as it is just an alias of a defined type.
- if (type->isTypeDef()) {
- continue;
- }
- out << "attribute: {\n";
- out.indent();
- status_t status = type->emitVtsTypeDeclarations(out);
- if (status != OK) {
- return status;
- }
- out.unindent();
- out << "}\n\n";
+ // Skip for TypeDef as it is just an alias of a defined type.
+ if (type->isTypeDef()) {
+ continue;
+ }
+ out << "attribute: {\n";
+ out.indent();
+ status_t status = type->emitVtsTypeDeclarations(out);
+ if (status != OK) {
+ return status;
+ }
+ out.unindent();
+ out << "}\n\n";
}
- }
- return OK;
+
+ return OK;
}
status_t AST::generateVts(const std::string &outputPath) const {
+ std::string baseName = AST::getBaseName();
+ const Interface *iface = AST::getInterface();
+
std::string path = outputPath;
path.append(mCoordinator->convertPackageRootToPath(mPackage));
path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
-
- std::string ifaceName;
- std::string baseName;
-
- bool isInterface = true;
- if (!AST::isInterface(&ifaceName)) {
- baseName = "types";
- isInterface = false;
- } else {
- const Interface *iface = mRootScope->getInterface();
- baseName = iface->getBaseName();
- }
-
path.append(baseName);
path.append(".vts");
@@ -89,7 +76,7 @@
out << "component_type_version: " << mPackage.version()
<< "\n";
out << "component_name: \""
- << (isInterface ? ifaceName : "types")
+ << (iface ? iface->localName() : "types")
<< "\"\n\n";
out << "package: \"" << mPackage.package() << "\"\n\n";
@@ -106,7 +93,7 @@
out << "\n";
- if (isInterface) {
+ if (isInterface()) {
const Interface *iface = mRootScope->getInterface();
out << "interface: {\n";
out.indent();