[fidl][errors] Move std::string errors into the reporter
Any error message is likely to have dynamic or contextual information,
and thus be an allocated std::string rather than a const char*. Making
the reporting infrastructure just take std::strings accordingly, since
all its callers are making one anyway.
Change-Id: I1165c773ac3c90e6664658b24b0cba6cc899d0d2
diff --git a/system/host/fidl/include/fidl/error_reporter.h b/system/host/fidl/include/fidl/error_reporter.h
index d040d30..da7ad5a 100644
--- a/system/host/fidl/include/fidl/error_reporter.h
+++ b/system/host/fidl/include/fidl/error_reporter.h
@@ -8,13 +8,11 @@
#include <string>
#include <vector>
-#include "string_view.h"
-
namespace fidl {
class ErrorReporter {
public:
- void ReportError(StringView error);
+ void ReportError(std::string error);
void PrintReports();
private:
diff --git a/system/host/fidl/lib/error_reporter.cpp b/system/host/fidl/lib/error_reporter.cpp
index bd1bdc4..1779088 100644
--- a/system/host/fidl/lib/error_reporter.cpp
+++ b/system/host/fidl/lib/error_reporter.cpp
@@ -6,8 +6,8 @@
namespace fidl {
-void ErrorReporter::ReportError(StringView error) {
- errors_.push_back(error);
+void ErrorReporter::ReportError(std::string error) {
+ errors_.push_back(std::move(error));
}
void ErrorReporter::PrintReports() {
diff --git a/system/host/fidl/lib/flat_ast.cpp b/system/host/fidl/lib/flat_ast.cpp
index 4eed33f..067454b 100644
--- a/system/host/fidl/lib/flat_ast.cpp
+++ b/system/host/fidl/lib/flat_ast.cpp
@@ -142,7 +142,7 @@
bool Library::Fail(StringView message) {
auto formatted_message = std::string(message) + "\n";
- error_reporter_->ReportError(formatted_message);
+ error_reporter_->ReportError(std::move(formatted_message));
return false;
}
diff --git a/system/host/fidl/lib/parser.cpp b/system/host/fidl/lib/parser.cpp
index 84ae72c..51d9d50 100644
--- a/system/host/fidl/lib/parser.cpp
+++ b/system/host/fidl/lib/parser.cpp
@@ -97,7 +97,7 @@
error += surrounding_line;
error += squiggle + "\n";
- error_reporter_->ReportError(error);
+ error_reporter_->ReportError(std::move(error));
ok_ = false;
}
return nullptr;