mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Combine DiagnosticConverter into DiagnosticEmitter (#4878)
At present, we typically define a DiagnosticConverter, then store an instance of it and a DiagnosticEmitter that wraps it. This is relatively minor in general, but I've been trying to create more self-contained DiagnosticEmitter classes (which hold their own DiagnosticConverter, similar to NullDiagnosticEmitter), and there it just gets in the way. Since we don't reuse DiagnosticConverter instances, this combines the definition into DiagnosticEmitter. Mainly this means we don't have a separate object in play, and less to carry around. The most impact is probably to SemIRDiagnosticConverter, which was also the most complex. Now `SemIRLocDiagnosticEmitter`, this gets some different construction flow. Note in the PR I've split the file rename to its own commit, to try to help delta views. However, the most substantial parts of the refactoring are split into #4876, which this depends upon.
This commit is contained in:
@@ -26,18 +26,18 @@ namespace Carbon::Lower {
|
||||
FileContext::FileContext(
|
||||
llvm::LLVMContext& llvm_context,
|
||||
std::optional<llvm::ArrayRef<Parse::GetTreeAndSubtreesFn>>
|
||||
all_trees_and_subtrees_for_debug_info,
|
||||
tree_and_subtrees_getters_for_debug_info,
|
||||
llvm::StringRef module_name, const SemIR::File& sem_ir,
|
||||
const SemIR::InstNamer* inst_namer, llvm::raw_ostream* vlog_stream)
|
||||
: llvm_context_(&llvm_context),
|
||||
llvm_module_(std::make_unique<llvm::Module>(module_name, llvm_context)),
|
||||
di_builder_(*llvm_module_),
|
||||
di_compile_unit_(
|
||||
all_trees_and_subtrees_for_debug_info
|
||||
tree_and_subtrees_getters_for_debug_info
|
||||
? BuildDICompileUnit(module_name, *llvm_module_, di_builder_)
|
||||
: nullptr),
|
||||
all_trees_and_subtrees_for_debug_info_(
|
||||
all_trees_and_subtrees_for_debug_info),
|
||||
tree_and_subtrees_getters_for_debug_info_(
|
||||
tree_and_subtrees_getters_for_debug_info),
|
||||
sem_ir_(&sem_ir),
|
||||
inst_namer_(inst_namer),
|
||||
vlog_stream_(vlog_stream) {
|
||||
@@ -621,7 +621,8 @@ auto FileContext::BuildGlobalVariableDecl(SemIR::VarStorage var_storage)
|
||||
auto FileContext::GetLocForDI(SemIR::InstId inst_id) -> LocForDI {
|
||||
SemIR::AbsoluteNodeId resolved = GetAbsoluteNodeId(sem_ir_, inst_id).back();
|
||||
const auto& tree_and_subtrees =
|
||||
(*all_trees_and_subtrees_for_debug_info_)[resolved.check_ir_id.index]();
|
||||
(*tree_and_subtrees_getters_for_debug_info_)[resolved.check_ir_id
|
||||
.index]();
|
||||
const auto& tokens = tree_and_subtrees.tree().tokens();
|
||||
|
||||
if (resolved.node_id.has_value()) {
|
||||
|
||||
Reference in New Issue
Block a user