Explorer: Add methods to trace for line prefixes (#3076)

Defines methods into `TraceStream` for adding line prefixes. Instead of
directly using string literals.

Example usage,
```
trace_stream_->Start() << "declaring ... " << ... ;
```
will result in,
```
->> declaring ... 
```
This commit is contained in:
Prabhat Sachdeva
2023-08-09 19:05:19 +00:00
committed by GitHub
parent a67aeb5724
commit 0bcba9d05e
19 changed files with 710 additions and 682 deletions
+11 -11
View File
@@ -27,9 +27,9 @@ auto StaticScope::Add(std::string_view name, ValueNodeView entity,
}
} else {
if (trace_stream_->is_enabled()) {
*trace_stream_ << "--- declared `" << name << "` as `" << entity
<< "` in `" << PrintAsID(*this) << "` ("
<< entity.base().source_loc() << ")\n";
trace_stream_->Result()
<< "declared `" << name << "` as `" << entity << "` in `"
<< PrintAsID(*this) << "` (" << entity.base().source_loc() << ")\n";
}
}
return Success();
@@ -57,9 +57,9 @@ void StaticScope::MarkDeclared(std::string_view name) {
if (it->second.status == NameStatus::KnownButNotDeclared) {
it->second.status = NameStatus::DeclaredButNotUsable;
if (trace_stream_->is_enabled()) {
*trace_stream_ << "--- marked `" << name
<< "` declared but not usable in `" << PrintAsID(*this)
<< "`\n";
trace_stream_->Result()
<< "marked `" << name << "` declared but not usable in `"
<< PrintAsID(*this) << "`\n";
}
}
}
@@ -69,8 +69,8 @@ void StaticScope::MarkUsable(std::string_view name) {
CARBON_CHECK(it != declared_names_.end()) << name << " not found";
it->second.status = NameStatus::Usable;
if (trace_stream_->is_enabled()) {
*trace_stream_ << "--- marked `" << name << "` usable in `"
<< PrintAsID(*this) << "`\n";
trace_stream_->Result()
<< "marked `" << name << "` usable in `" << PrintAsID(*this) << "`\n";
}
}
@@ -130,9 +130,9 @@ auto StaticScope::TryResolveHere(std::string_view name,
auto exit_scope_function = llvm::make_scope_exit([&]() {
if (trace_stream_->is_enabled()) {
*trace_stream_ << "--- resolved `" << name << "` as `"
<< it->second.entity << "` in `" << PrintAsID(*this)
<< "` (" << source_loc << ")\n";
trace_stream_->Result()
<< "resolved `" << name << "` as `" << it->second.entity << "` in `"
<< PrintAsID(*this) << "` (" << source_loc << ")\n";
}
});