mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Introduce a Clang diagnostic instruction and use it to point to C++ source locations on Clang errors and warnings (#5262)
Introduce `ImportIRId::Cpp` and refer to clang source location in its `ImportIRInst`. Part of #5245.
This commit is contained in:
@@ -34,7 +34,11 @@ static auto GetImportedIRCount(UnitAndImports* unit_and_imports) -> int {
|
||||
count += package_imports.imports.size();
|
||||
}
|
||||
if (!unit_and_imports->api_for_impl) {
|
||||
// Leave an empty slot for ImportIRId::ApiForImpl.
|
||||
// Leave an empty slot for `ImportIRId::ApiForImpl`.
|
||||
++count;
|
||||
}
|
||||
if (!unit_and_imports->cpp_import_names.empty()) {
|
||||
// Leave an empty slot for `ImportIRId::Cpp`.
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
@@ -101,20 +105,20 @@ auto CheckUnit::InitPackageScopeAndImports() -> void {
|
||||
.import_id = SemIR::InstId::None});
|
||||
CARBON_CHECK(package_inst_id == SemIR::Namespace::PackageInstId);
|
||||
|
||||
// If there is an implicit `api` import, set it first so that it uses the
|
||||
// ImportIRId::ApiForImpl when processed for imports.
|
||||
// Call `SetSpecialImportIRs()` to set `ImportIRId::ApiForImpl` and
|
||||
// `ImportIRId::Cpp` first, as required.
|
||||
if (unit_and_imports_->api_for_impl) {
|
||||
const auto& names = context_.parse_tree().packaging_decl()->names;
|
||||
auto import_decl_id = AddInst<SemIR::ImportDecl>(
|
||||
context_, names.node_id,
|
||||
{.package_id = SemIR::NameId::ForPackageName(names.package_id)});
|
||||
SetApiImportIR(context_,
|
||||
{.decl_id = import_decl_id,
|
||||
.is_export = false,
|
||||
.sem_ir = unit_and_imports_->api_for_impl->unit->sem_ir});
|
||||
SetSpecialImportIRs(
|
||||
context_, {.decl_id = import_decl_id,
|
||||
.is_export = false,
|
||||
.sem_ir = unit_and_imports_->api_for_impl->unit->sem_ir});
|
||||
} else {
|
||||
SetApiImportIR(context_,
|
||||
{.decl_id = SemIR::InstId::None, .sem_ir = nullptr});
|
||||
SetSpecialImportIRs(context_,
|
||||
{.decl_id = SemIR::InstId::None, .sem_ir = nullptr});
|
||||
}
|
||||
|
||||
// Add import instructions for everything directly imported. Implicit imports
|
||||
@@ -327,9 +331,9 @@ auto CheckUnit::ImportOtherPackages(SemIR::TypeId namespace_type_id) -> void {
|
||||
if (local_imports) {
|
||||
CARBON_CHECK(package_id == api_imports_entry.first);
|
||||
} else {
|
||||
auto import_ir_inst_id = context_.import_ir_insts().Add(
|
||||
{.ir_id = SemIR::ImportIRId::ApiForImpl,
|
||||
.inst_id = api_imports->import_decl_id});
|
||||
auto import_ir_inst_id =
|
||||
context_.import_ir_insts().Add(SemIR::ImportIRInst(
|
||||
SemIR::ImportIRId::ApiForImpl, api_imports->import_decl_id));
|
||||
import_decl_id =
|
||||
AddInst(context_, MakeImportedLocIdAndInst<SemIR::ImportDecl>(
|
||||
context_, import_ir_inst_id,
|
||||
@@ -411,7 +415,7 @@ auto CheckUnit::CheckRequiredDeclarations() -> void {
|
||||
auto import_ir_id = context_.sem_ir()
|
||||
.import_ir_insts()
|
||||
.Get(function_loc_id.import_ir_inst_id())
|
||||
.ir_id;
|
||||
.ir_id();
|
||||
auto& import_ir = context_.import_irs().Get(import_ir_id);
|
||||
if (import_ir.sem_ir->package_id().has_value() !=
|
||||
context_.sem_ir().package_id().has_value()) {
|
||||
|
||||
Reference in New Issue
Block a user