Commit 10f34769 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[torque] Don't report unused macros if they're marked as unused

Torque generally supports marking things as unused by adding a single
underscore to the front of identifiers. For locals, this feature works
fine. For macros, it's only half-implemented: attempting to look up a
macro that starts with _ fails (as it should), but the compiler also
complains if the macro is unused. This change avoids emitting the latter
error.

Bug: v8:7793
Change-Id: Ib021c053004a180dd31993d3ad06cde463bafd5d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2757208
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73397}
parent 895a825d
......@@ -5235,6 +5235,7 @@ void ReportAllUnusedMacros() {
"FromConstexpr<"};
const std::string name = macro->ReadableName();
const bool ignore =
StartsWithSingleUnderscore(name) ||
std::any_of(ignored_prefixes.begin(), ignored_prefixes.end(),
[&name](const std::string& prefix) {
return StringStartsWith(name, prefix);
......
......@@ -234,7 +234,7 @@ template <class T>
class BindingsManager {
public:
base::Optional<Binding<T>*> TryLookup(const std::string& name) {
if (name.length() >= 2 && name[0] == '_' && name[1] != '_') {
if (StartsWithSingleUnderscore(name)) {
Error("Trying to reference '", name, "' which is marked as unused.")
.Throw();
}
......
......@@ -313,6 +313,10 @@ std::string UnderlinifyPath(std::string path) {
return path;
}
bool StartsWithSingleUnderscore(const std::string& str) {
return str.length() >= 2 && str[0] == '_' && str[1] != '_';
}
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents) {
std::ifstream old_contents_stream(file_path.c_str());
......
......@@ -105,6 +105,8 @@ std::string SnakeifyString(const std::string& camel_string);
std::string DashifyString(const std::string& underscore_string);
std::string UnderlinifyPath(std::string path);
bool StartsWithSingleUnderscore(const std::string& str);
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment