aboutsummaryrefslogtreecommitdiff
path: root/diagnostics.cpp
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2020-12-31 10:42:28 +0900
committerJiyong Park <jiyong@google.com>2020-12-31 11:08:45 +0900
commit4585445f323026f4195f2b44cc2cdcab103c6f64 (patch)
tree487b92c4b985d0b86e79fb1995d88ed2797d33df /diagnostics.cpp
parentd911332007bee13e81b829b64d674e8c95d38cec (diff)
downloadaidl-4585445f323026f4195f2b44cc2cdcab103c6f64.tar.gz
Visit() doesn't return bool
Previously, the function was designed to control the traversal; returning false stops the traversal down to its children. But that feature was never used, and isn't expected to have a use case in a forseable feature. So dropping the feature. Bug: N/A Test: aidl_unittests Change-Id: I3ffaf427db433b7bf18bd03bb6c20439c49850a0
Diffstat (limited to 'diagnostics.cpp')
-rw-r--r--diagnostics.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/diagnostics.cpp b/diagnostics.cpp
index 5656f920..5579b70a 100644
--- a/diagnostics.cpp
+++ b/diagnostics.cpp
@@ -99,21 +99,20 @@ class DiagnosticsVisitor : public AidlVisitor {
struct Hook : public AidlVisitor {
Fun fun;
Hook(Fun fun) : fun(fun) {}
- bool Visit(const AidlInterface& a) override { fun(a); return true; }
- bool Visit(const AidlEnumDeclaration& a) override { fun(a); return true; }
- bool Visit(const AidlStructuredParcelable& a) override { fun(a); return true; }
- bool Visit(const AidlUnionDecl& a) override { fun(a); return true; }
- bool Visit(const AidlParcelable& a) override { fun(a); return true; }
- bool Visit(const AidlMethod& a) override { fun(a.GetType()); return true; }
+ void Visit(const AidlInterface& a) override { fun(a); }
+ void Visit(const AidlEnumDeclaration& a) override { fun(a); }
+ void Visit(const AidlStructuredParcelable& a) override { fun(a); }
+ void Visit(const AidlUnionDecl& a) override { fun(a); }
+ void Visit(const AidlParcelable& a) override { fun(a); }
+ void Visit(const AidlMethod& a) override { fun(a.GetType()); }
};
Hook suppress{std::bind(&DiagnosticsContext::Suppress, &diag, _1)};
Hook restore{std::bind(&DiagnosticsContext::Restore, &diag, _1)};
std::function<void(const AidlTraversable&)> topDown =
[&topDown, &suppress, &restore, visitor](const AidlTraversable& a) {
a.DispatchVisit(suppress);
- if (a.DispatchVisit(*visitor)) {
- a.TraverseChildren(topDown);
- }
+ a.DispatchVisit(*visitor);
+ a.TraverseChildren(topDown);
a.DispatchVisit(restore);
};
topDown(doc);
@@ -124,18 +123,17 @@ class DiagnosticsVisitor : public AidlVisitor {
struct DiagnoseInterfaceName : DiagnosticsVisitor {
DiagnoseInterfaceName(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
- bool Visit(const AidlInterface& i) override {
+ void Visit(const AidlInterface& i) override {
if (auto name = i.GetName(); name.size() < 1 || name[0] != 'I') {
diag.Report(i.GetLocation(), DiagnosticID::interface_name)
<< "Interface names should start with I.";
}
- return true;
}
};
struct DiagnoseEnumZero : DiagnosticsVisitor {
DiagnoseEnumZero(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
- bool Visit(const AidlEnumDeclaration& e) override {
+ void Visit(const AidlEnumDeclaration& e) override {
AIDL_FATAL_IF(e.GetEnumerators().empty(), e)
<< "The enum '" << e.GetName() << "' has no enumerators.";
const auto& first = e.GetEnumerators()[0];
@@ -145,38 +143,34 @@ struct DiagnoseEnumZero : DiagnosticsVisitor {
<< "The first enumerator '" << first->GetName() << "' should be 0, but it is "
<< first_value << ".";
}
- return true;
}
};
struct DiagnoseInoutParameter : DiagnosticsVisitor {
DiagnoseInoutParameter(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
- bool Visit(const AidlArgument& a) override {
+ void Visit(const AidlArgument& a) override {
if (a.GetDirection() == AidlArgument::INOUT_DIR) {
diag.Report(a.GetLocation(), DiagnosticID::inout_parameter)
<< a.GetName()
<< " is 'inout'. Avoid inout parameters. This is somewhat confusing for clients "
"because although the parameters are 'in', they look out 'out' parameters.";
}
- return true;
}
};
struct DiagnoseConstName : DiagnosticsVisitor {
DiagnoseConstName(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
- bool Visit(const AidlEnumerator& e) override {
+ void Visit(const AidlEnumerator& e) override {
if (ToUpper(e.GetName()) != e.GetName()) {
diag.Report(e.GetLocation(), DiagnosticID::const_name)
<< "Enum values should be named in upper cases: " << ToUpper(e.GetName());
}
- return true;
}
- bool Visit(const AidlConstantDeclaration& c) override {
+ void Visit(const AidlConstantDeclaration& c) override {
if (ToUpper(c.GetName()) != c.GetName()) {
diag.Report(c.GetLocation(), DiagnosticID::const_name)
<< "Constants should be named in upper cases: " << ToUpper(c.GetName());
}
- return true;
}
static std::string ToUpper(std::string name) {
for (auto& c : name) c = std::toupper(c);