aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2020-09-22 14:13:36 -0700
committerDevin Moore <devinmoore@google.com>2020-09-22 15:40:26 -0700
commitcbbda28db60f3df9dd02b579f2ca748bf784e801 (patch)
treeb916745f9d70bfe732fb85a5eb7882ff7fba1129
parent60abe5dfd3cc1ee4c1b189eb75b5e67c84ca01ba (diff)
downloadplatform_system_tools_hidl-cbbda28db60f3df9dd02b579f2ca748bf784e801.tar.gz
platform_system_tools_hidl-cbbda28db60f3df9dd02b579f2ca748bf784e801.tar.bz2
platform_system_tools_hidl-cbbda28db60f3df9dd02b579f2ca748bf784e801.zip
Process all compound types a single time
This change moves the processing of compound types into the top level, right before emiting all of the types. This way we will have all of the types in place before we move to emitting AIDL. Test: mm & hidl2aidl -o out -rhidl2aidl:system/tools/hidl/hidl2aidl/test hidl2aidl@1.2 Change-Id: I1a98c38ae4c948ca48bafed87603ce1fe330a771
-rw-r--r--hidl2aidl/AidlHelper.cpp17
-rw-r--r--hidl2aidl/AidlHelper.h15
-rw-r--r--hidl2aidl/AidlInterface.cpp6
-rw-r--r--hidl2aidl/AidlNamedType.cpp19
-rw-r--r--hidl2aidl/main.cpp17
5 files changed, 54 insertions, 20 deletions
diff --git a/hidl2aidl/AidlHelper.cpp b/hidl2aidl/AidlHelper.cpp
index 4ea8fc668..eab6918fa 100644
--- a/hidl2aidl/AidlHelper.cpp
+++ b/hidl2aidl/AidlHelper.cpp
@@ -89,7 +89,9 @@ void AidlHelper::importLocallyReferencedType(const Type& type, std::set<std::str
// it has to encode the logic in the rest of hidl2aidl. It would be better
// if we could iterate over the AIDL structure which has already been
// processed.
-void AidlHelper::emitFileHeader(Formatter& out, const NamedType& type) {
+void AidlHelper::emitFileHeader(
+ Formatter& out, const NamedType& type,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes) {
out << "// FIXME: license file if you have one\n\n";
out << "package " << getAidlPackage(type.fqName()) << ";\n\n";
@@ -117,8 +119,10 @@ void AidlHelper::emitFileHeader(Formatter& out, const NamedType& type) {
} else if (type.isCompoundType()) {
// Get all of the imports for the flattened compound type that may
// include additional fields and subtypes from older versions
- ProcessedCompoundType processedType;
- processCompoundType(static_cast<const CompoundType&>(type), &processedType);
+ const auto& it = processedTypes.find(&type);
+ CHECK(it != processedTypes.end()) << "Failed to find " << type.fullName();
+ const ProcessedCompoundType& processedType = it->second;
+
for (const auto& field : processedType.fields) {
importLocallyReferencedType(*field.field->get(), &imports);
}
@@ -144,13 +148,14 @@ void AidlHelper::emitFileHeader(Formatter& out, const NamedType& type) {
}
}
-Formatter AidlHelper::getFileWithHeader(const NamedType& namedType,
- const Coordinator& coordinator) {
+Formatter AidlHelper::getFileWithHeader(
+ const NamedType& namedType, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes) {
std::string aidlPackage = getAidlPackage(namedType.fqName());
Formatter out = coordinator.getFormatter(namedType.fqName(), Coordinator::Location::DIRECT,
base::Join(base::Split(aidlPackage, "."), "/") + "/" +
getAidlName(namedType.fqName()) + ".aidl");
- emitFileHeader(out, namedType);
+ emitFileHeader(out, namedType, processedTypes);
return out;
}
diff --git a/hidl2aidl/AidlHelper.h b/hidl2aidl/AidlHelper.h
index 73c6c8c42..e66a5d869 100644
--- a/hidl2aidl/AidlHelper.h
+++ b/hidl2aidl/AidlHelper.h
@@ -61,18 +61,25 @@ struct AidlHelper {
// getAidlFQName = getAidlPackage + "." + getAidlName
static std::string getAidlFQName(const FQName& fqName);
- static void emitFileHeader(Formatter& out, const NamedType& type);
+ static void emitFileHeader(
+ Formatter& out, const NamedType& type,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes);
static void importLocallyReferencedType(const Type& type, std::set<std::string>* imports);
- static Formatter getFileWithHeader(const NamedType& namedType, const Coordinator& coordinator);
+ static Formatter getFileWithHeader(
+ const NamedType& namedType, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes);
/* Methods for Type */
static std::string getAidlType(const Type& type, const FQName& relativeTo);
/* Methods for NamedType */
- static void emitAidl(const NamedType& namedType, const Coordinator& coordinator);
+ static void emitAidl(
+ const NamedType& namedType, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes);
/* Methods for Interface */
- static void emitAidl(const Interface& interface, const Coordinator& coordinator);
+ static void emitAidl(const Interface& interface, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>&);
// Returns all methods that would exist in an AIDL equivalent interface
static std::vector<const Method*> getUserDefinedMethods(const Interface& interface);
diff --git a/hidl2aidl/AidlInterface.cpp b/hidl2aidl/AidlInterface.cpp
index c260b4c4f..b1562802d 100644
--- a/hidl2aidl/AidlInterface.cpp
+++ b/hidl2aidl/AidlInterface.cpp
@@ -142,8 +142,10 @@ static bool shouldWarnStatusType(const std::string& typeName) {
return false;
}
-void AidlHelper::emitAidl(const Interface& interface, const Coordinator& coordinator) {
- Formatter out = getFileWithHeader(interface, coordinator);
+void AidlHelper::emitAidl(
+ const Interface& interface, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes) {
+ Formatter out = getFileWithHeader(interface, coordinator, processedTypes);
interface.emitDocComment(out);
if (interface.superType() && interface.superType()->fqName() != gIBaseFqName) {
diff --git a/hidl2aidl/AidlNamedType.cpp b/hidl2aidl/AidlNamedType.cpp
index d0f8ec358..e3c6316f7 100644
--- a/hidl2aidl/AidlNamedType.cpp
+++ b/hidl2aidl/AidlNamedType.cpp
@@ -58,11 +58,14 @@ static void emitEnumAidlDefinition(Formatter& out, const EnumType& enumType) {
});
}
-static void emitCompoundTypeAidlDefinition(Formatter& out, const CompoundType& compoundType) {
+static void emitCompoundTypeAidlDefinition(
+ Formatter& out, const CompoundType& compoundType,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes) {
// Get all of the subtypes and fields from this type and any older versions
// that it references.
- ProcessedCompoundType processedType;
- AidlHelper::processCompoundType(compoundType, &processedType);
+ const auto& it = processedTypes.find(&compoundType);
+ CHECK(it != processedTypes.end()) << "Failed to find " << compoundType.fullName();
+ const ProcessedCompoundType& processedType = it->second;
compoundType.emitDocComment(out);
out << "@VintfStability \n";
@@ -86,20 +89,22 @@ static void emitCompoundTypeAidlDefinition(Formatter& out, const CompoundType& c
}
// TODO: Enum/Typedef should just emit to hidl-error.log or similar
-void AidlHelper::emitAidl(const NamedType& namedType, const Coordinator& coordinator) {
- Formatter out = getFileWithHeader(namedType, coordinator);
+void AidlHelper::emitAidl(
+ const NamedType& namedType, const Coordinator& coordinator,
+ const std::map<const NamedType*, const ProcessedCompoundType>& processedTypes) {
+ Formatter out = getFileWithHeader(namedType, coordinator, processedTypes);
if (namedType.isTypeDef()) {
const TypeDef& typeDef = static_cast<const TypeDef&>(namedType);
emitTypeDefAidlDefinition(out, typeDef);
} else if (namedType.isCompoundType()) {
const CompoundType& compoundType = static_cast<const CompoundType&>(namedType);
- emitCompoundTypeAidlDefinition(out, compoundType);
+ emitCompoundTypeAidlDefinition(out, compoundType, processedTypes);
} else if (namedType.isEnum()) {
const EnumType& enumType = static_cast<const EnumType&>(namedType);
emitEnumAidlDefinition(out, enumType);
} else if (namedType.isInterface()) {
const Interface& iface = static_cast<const Interface&>(namedType);
- emitAidl(iface, coordinator);
+ emitAidl(iface, coordinator, processedTypes);
} else {
out << "// TODO: Fix this " << namedType.definedName() << "\n";
}
diff --git a/hidl2aidl/main.cpp b/hidl2aidl/main.cpp
index 9018e7c95..ad0ad9e83 100644
--- a/hidl2aidl/main.cpp
+++ b/hidl2aidl/main.cpp
@@ -348,12 +348,27 @@ int main(int argc, char** argv) {
});
namedTypesInPackage.erase(endNamedTypes, namedTypesInPackage.end());
+ // Process and flatten all of the types. Many types include fields of older
+ // versions of that type.
+ // This step recursively finds all of those fields and adds their fields to
+ // the most recent top level type.
+ std::map<const NamedType*, const ProcessedCompoundType> processedTypesInPackage;
+ for (const auto& namedType : namedTypesInPackage) {
+ if (namedType->isCompoundType()) {
+ ProcessedCompoundType processed;
+ AidlHelper::processCompoundType(static_cast<const CompoundType&>(*namedType),
+ &processed);
+ processedTypesInPackage.insert(
+ std::pair<const NamedType*, const ProcessedCompoundType>(namedType, processed));
+ }
+ }
+
// Emit all types and interfaces
// The interfaces and types are still be further manipulated inside
// emitAidl. The interfaces are consolidating methods from their typechains
// and the composite types are being flattened.
for (const auto& namedType : namedTypesInPackage) {
- AidlHelper::emitAidl(*namedType, coordinator);
+ AidlHelper::emitAidl(*namedType, coordinator, processedTypesInPackage);
}
err << "END OF LOG\n";