Avoid depending on protobuf internals
Reviewers: #core_team, shahms
@@ -561,9 +561,13 @@ void MarkedSourceGenerator::ReplaceMarkedSourceWithTemplateArgumentList(
// the type context.
// TODO(zarko): Pack expansions;
// see TemplateSpecializationType::PrintTemplateArgumentList
- llvm::raw_string_ostream stream(*next_arg->mutable_pre_text());
+ std::string pre_text;
+ {
+ llvm::raw_string_ostream stream(pre_text);
print_arg.print(policy, stream);
}
+ *next_arg->mutable_pre_text() = std::move(pre_text);
+ }
}
bool MarkedSourceGenerator::ReplaceMarkedSourceWithQualifiedName(
@@ -599,12 +603,18 @@ bool MarkedSourceGenerator::ReplaceMarkedSourceWithQualifiedName(
parent->set_kind(MarkedSource::BOX);
auto *class_name = parent->add_child();
class_name->set_kind(MarkedSource::IDENTIFIER);
- llvm::raw_string_ostream stream(*class_name->mutable_pre_text());
+ std::string pre_text;
+ {
+ llvm::raw_string_ostream stream(pre_text);
stream << spec->getName();
+ }
+ *class_name->mutable_pre_text() = std::move(pre_text);
ReplaceMarkedSourceWithTemplateArgumentList(parent->add_child(), spec);
} else {
parent->set_kind(MarkedSource::IDENTIFIER);
- llvm::raw_string_ostream stream(*parent->mutable_pre_text());
+ std::string pre_text;
+ {
+ llvm::raw_string_ostream stream(pre_text);
if (const auto *namespace_decl =
llvm::dyn_cast<clang::NamespaceDecl>(decl_context)) {
if (namespace_decl->isAnonymousNamespace()) {
@@ -629,6 +639,8 @@ bool MarkedSourceGenerator::ReplaceMarkedSourceWithQualifiedName(
stream << *llvm::cast<clang::NamedDecl>(decl_context);
}
}
+ *parent->mutable_pre_text() = std::move(pre_text);
+ }
}
}
self->set_kind(MarkedSource::IDENTIFIER);
@@ -656,15 +668,12 @@ MaybeFew<MarkedSource> MarkedSourceGenerator::GenerateMarkedSourceUsingSource(
<< decl_id.getRawIdentity();
return None();
}
- DCHECK(
- google::protobuf::internal::IsStructurallyValidUTF8(formatted_range));
DeclAnnotator annotator(cache_, &replacements, start_loc, formatted_range,
&out_sig, name_range_);
annotator.Annotate(decl_);
ReplaceMarkedSourceWithQualifiedName(annotator.ident_node());
} else {
auto range_string = range.str();
- DCHECK(google::protobuf::internal::IsStructurallyValidUTF8(range_string));
DeclAnnotator annotator(cache_, nullptr, start_loc, range_string, &out_sig,
name_range_);
annotator.Annotate(decl_);
