diff options
author | Jooyung Han <jooyung@google.com> | 2020-12-31 10:59:43 +0900 |
---|---|---|
committer | Jooyung Han <jooyung@google.com> | 2020-12-31 11:12:12 +0900 |
commit | 209c2866f40ce364724c4982241ced7fc8c0539d (patch) | |
tree | f287986439b3b3260c8584bba1a600264343f122 /diagnostics.cpp | |
parent | d25527a4f81ceccabbea47ff40a5159b47a36130 (diff) | |
download | aidl-209c2866f40ce364724c4982241ced7fc8c0539d.tar.gz |
Add -Wmixed-oneway
Warns if an interface has both oneway and non-oneway methods.
Do not mix oneway with non-oneway methods, because it makes
understanding the threading model complicated for clients and servers.
Specifically, when reading client code of a particular interface, you
need to look up for each method if that method will block or not.
Bug: 168028537
Test: aidl_unittests
Change-Id: If3b4eca0c33532becf7ff90af0d3c6379b7f6821
Diffstat (limited to 'diagnostics.cpp')
-rw-r--r-- | diagnostics.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/diagnostics.cpp b/diagnostics.cpp index bf50cc2e..4af90331 100644 --- a/diagnostics.cpp +++ b/diagnostics.cpp @@ -211,6 +211,19 @@ struct DiagnoseExplicitDefault : DiagnosticsVisitor { } }; +struct DiagnoseMixedOneway : DiagnosticsVisitor { + DiagnoseMixedOneway(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {} + void Visit(const AidlInterface& i) override { + const auto& methods = i.GetMethods(); + if (std::adjacent_find(begin(methods), end(methods), [](const auto& a, const auto& b) { + return a->IsOneway() != b->IsOneway(); + }) != end(methods)) { + diag.Report(i.GetLocation(), DiagnosticID::mixed_oneway) + << "The interface '" << i.GetName() << "' has both one-way and two-way methods."; + } + } +}; + bool Diagnose(const AidlDocument& doc, const DiagnosticMapping& mapping) { DiagnosticsContext diag(mapping); @@ -219,6 +232,7 @@ bool Diagnose(const AidlDocument& doc, const DiagnosticMapping& mapping) { DiagnoseInoutParameter{diag}.Check(doc); DiagnoseConstName{diag}.Check(doc); DiagnoseExplicitDefault{diag}.Check(doc); + DiagnoseMixedOneway{diag}.Check(doc); return diag.ErrorCount() == 0; } |