Index: tools/gn/scope.cc |
diff --git a/tools/gn/scope.cc b/tools/gn/scope.cc |
index f2fe7521dfafc8e94f5a6c35ff2723a9ec960c9f..be76c48277217e4a2e1ea37b8f7664a361f638cb 100644 |
--- a/tools/gn/scope.cc |
+++ b/tools/gn/scope.cc |
@@ -205,18 +205,31 @@ const Template* Scope::GetTemplate(const std::string& name) const { |
return nullptr; |
} |
-void Scope::MarkUsed(const base::StringPiece& ident) { |
+void Scope::MarkUsed(const base::StringPiece& ident, Err* err) { |
RecordMap::iterator found = values_.find(ident); |
if (found == values_.end()) { |
NOTREACHED(); |
return; |
} |
+ if (found->second.unusable) { |
+ *err = Err(found->second.value.origin(), "Variable was marked as unused.", |
+ "You marked the variable \"" + found->first.as_string() + |
+ "\" as unused, but it is being used."); |
+ return; |
+ } |
found->second.used = true; |
} |
-void Scope::MarkAllUsed() { |
- for (auto& cur : values_) |
+void Scope::MarkAllUsed(Err* err) { |
+ for (auto& cur : values_) { |
+ if (cur.second.unusable) { |
+ *err = Err(cur.second.value.origin(), "Variable was marked as unused.", |
+ "You marked the variable \"" + cur.first.as_string() + |
+ "\" as unused, but it is being used."); |
+ return; |
+ } |
cur.second.used = true; |
+ } |
} |
void Scope::MarkUnused(const base::StringPiece& ident) { |
@@ -228,6 +241,38 @@ void Scope::MarkUnused(const base::StringPiece& ident) { |
found->second.used = false; |
} |
+void Scope::MarkAllUnusable(Err* err, std::set<std::string> excluded_values) { |
+ for (auto& cur : values_) { |
+ if (!excluded_values.empty() && |
+ excluded_values.find(cur.first.as_string()) != excluded_values.end()) { |
+ continue; // Skip this excluded value. |
+ } |
+ |
+ if (cur.second.used) { |
+ *err = Err(cur.second.value.origin(), "Variable was marked as unused.", |
+ "You marked the variable \"" + cur.first.as_string() + |
+ "\" as unused, but it is being used."); |
+ return; |
+ } |
+ cur.second.unusable = true; |
+ } |
+} |
+ |
+void Scope::MarkUnusable(const base::StringPiece& ident, Err* err) { |
+ RecordMap::iterator found = values_.find(ident); |
+ if (found == values_.end()) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ if (found->second.used) { |
+ *err = Err(found->second.value.origin(), "Variable was marked as unused.", |
+ "You marked the variable \"" + ident.as_string() + |
+ "\" as unused, but it is being used."); |
+ return; |
+ } |
+ found->second.unusable = true; |
+} |
+ |
bool Scope::IsSetButUnused(const base::StringPiece& ident) const { |
RecordMap::const_iterator found = values_.find(ident); |
if (found != values_.end()) { |
@@ -240,7 +285,7 @@ bool Scope::IsSetButUnused(const base::StringPiece& ident) const { |
bool Scope::CheckForUnusedVars(Err* err) const { |
for (const auto& pair : values_) { |
- if (!pair.second.used) { |
+ if (!pair.second.unusable && !pair.second.used) { |
std::string help = "You set the variable \"" + pair.first.as_string() + |
"\" here and it was unused before it went\nout of scope."; |
@@ -301,7 +346,7 @@ bool Scope::NonRecursiveMergeTo(Scope* dest, |
dest->values_[current_name] = pair.second; |
if (options.mark_dest_used) |
- dest->MarkUsed(current_name); |
+ dest->MarkUsed(current_name, err); |
} |
// Target defaults are owning pointers. |