Skip to content

Commit 9f108ba

Browse files
authored
Rename cpp_ast to clang_ast_unit (#5926)
Followup of #5924.
1 parent d5cb9a7 commit 9f108ba

File tree

13 files changed

+42
-36
lines changed

13 files changed

+42
-36
lines changed

toolchain/check/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ static auto MaybeDumpCppAST(llvm::ArrayRef<Unit> units,
400400
}
401401

402402
for (const Unit& unit : units) {
403-
if (!unit.cpp_ast || !*unit.cpp_ast) {
403+
if (!unit.clang_ast_unit || !*unit.clang_ast_unit) {
404404
continue;
405405
}
406-
clang::ASTContext& ast_context = (*unit.cpp_ast)->getASTContext();
406+
clang::ASTContext& ast_context = (*unit.clang_ast_unit)->getASTContext();
407407
ast_context.getTranslationUnitDecl()->dump(*options.dump_cpp_ast_stream);
408408
}
409409
}

toolchain/check/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Unit {
3030

3131
// Storage for the unit's Clang AST. The unique_ptr should start empty, and
3232
// can be assigned as part of checking.
33-
std::unique_ptr<clang::ASTUnit>* cpp_ast;
33+
std::unique_ptr<clang::ASTUnit>* clang_ast_unit;
3434
};
3535

3636
struct CheckParseTreesOptions {

toolchain/check/check_unit.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ auto CheckUnit::InitPackageScopeAndImports() -> void {
154154

155155
const auto& cpp_imports = unit_and_imports_->cpp_imports;
156156
if (!cpp_imports.empty()) {
157-
auto* cpp_ast = unit_and_imports_->unit->cpp_ast;
158-
CARBON_CHECK(cpp_ast);
159-
CARBON_CHECK(!cpp_ast->get());
160-
*cpp_ast = ImportCppFiles(context_, cpp_imports, fs_, clang_invocation_);
157+
auto* clang_ast_unit = unit_and_imports_->unit->clang_ast_unit;
158+
CARBON_CHECK(clang_ast_unit);
159+
CARBON_CHECK(!clang_ast_unit->get());
160+
*clang_ast_unit =
161+
ImportCppFiles(context_, cpp_imports, fs_, clang_invocation_);
161162
}
162163
}
163164

toolchain/check/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class Context {
269269
return sem_ir().import_ir_insts();
270270
}
271271
auto ast_context() -> clang::ASTContext& {
272-
return sem_ir().cpp_ast()->getASTContext();
272+
return sem_ir().clang_ast_unit()->getASTContext();
273273
}
274274
auto names() -> SemIR::NameStoreWrapper { return sem_ir().names(); }
275275
auto name_scopes() -> SemIR::NameScopeStore& {

toolchain/check/cpp_thunk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
290290
context, *callee_function_decl, thunk_param_types);
291291

292292
// Build the thunk function body.
293-
clang::Sema& sema = context.sem_ir().cpp_ast()->getSema();
293+
clang::Sema& sema = context.sem_ir().clang_ast_unit()->getSema();
294294
clang::Sema::ContextRAII context_raii(sema, thunk_function_decl);
295295
sema.ActOnStartOfFunctionDef(nullptr, thunk_function_decl);
296296

toolchain/check/import_cpp.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class CarbonClangDiagnosticConsumer : public clang::DiagnosticConsumer {
230230
// Outputs Carbon diagnostics based on the collected Clang diagnostics. Must
231231
// be called after the AST is set in the context.
232232
auto EmitDiagnostics() -> void {
233-
CARBON_CHECK(sem_ir_->cpp_ast(),
233+
CARBON_CHECK(sem_ir_->clang_ast_unit(),
234234
"Attempted to emit diagnostics before the AST Unit is loaded");
235235

236236
for (size_t i = 0; i != diagnostic_infos_.size(); ++i) {
@@ -386,7 +386,7 @@ static auto GenerateAst(
386386
// Attach the AST to SemIR. This needs to be done before we can emit any
387387
// diagnostics, so their locations can be properly interpreted by our
388388
// diagnostics machinery.
389-
context.sem_ir().set_cpp_ast(ast.get());
389+
context.sem_ir().set_clang_ast_unit(ast.get());
390390

391391
// Emit any diagnostics we queued up while building the AST.
392392
context.emitter().Flush();
@@ -431,7 +431,7 @@ auto ImportCppFiles(Context& context,
431431
return nullptr;
432432
}
433433

434-
CARBON_CHECK(!context.sem_ir().cpp_ast());
434+
CARBON_CHECK(!context.sem_ir().clang_ast_unit());
435435

436436
PackageNameId package_id = imports.front().package_id;
437437
CARBON_CHECK(
@@ -468,7 +468,7 @@ static auto ClangLookupName(Context& context, SemIR::NameScopeId scope_id,
468468
return std::nullopt;
469469
}
470470

471-
clang::ASTUnit* ast = context.sem_ir().cpp_ast();
471+
clang::ASTUnit* ast = context.sem_ir().clang_ast_unit();
472472
CARBON_CHECK(ast);
473473
clang::Sema& sema = ast->getSema();
474474

@@ -504,7 +504,7 @@ static auto ClangConstructorLookup(const Context& context,
504504
-> clang::DeclContextLookupResult {
505505
const SemIR::NameScope& scope = context.sem_ir().name_scopes().Get(scope_id);
506506

507-
clang::Sema& sema = context.sem_ir().cpp_ast()->getSema();
507+
clang::Sema& sema = context.sem_ir().clang_ast_unit()->getSema();
508508
clang::Decl* decl =
509509
context.sem_ir().clang_decls().Get(scope.clang_decl_context_id()).decl;
510510
return sema.LookupConstructors(cast<clang::CXXRecordDecl>(decl));
@@ -531,7 +531,7 @@ static auto IsDeclInjectedClassName(const Context& context,
531531
const auto* scope_record_decl = cast<clang::CXXRecordDecl>(clang_decl.decl);
532532

533533
const clang::ASTContext& ast_context =
534-
context.sem_ir().cpp_ast()->getASTContext();
534+
context.sem_ir().clang_ast_unit()->getASTContext();
535535
CARBON_CHECK(
536536
ast_context.getCanonicalType(
537537
ast_context.getRecordType(scope_record_decl)) ==
@@ -974,7 +974,7 @@ static auto BuildClassDefinition(Context& context,
974974
auto ImportCppClassDefinition(Context& context, SemIR::LocId loc_id,
975975
SemIR::ClassId class_id,
976976
SemIR::ClangDeclId clang_decl_id) -> bool {
977-
clang::ASTUnit* ast = context.sem_ir().cpp_ast();
977+
clang::ASTUnit* ast = context.sem_ir().clang_ast_unit();
978978
CARBON_CHECK(ast);
979979

980980
auto* clang_decl = cast<clang::CXXRecordDecl>(

toolchain/driver/compile_subcommand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class CompilationUnit {
532532
std::optional<std::function<auto()->const Parse::TreeAndSubtrees&>>
533533
tree_and_subtrees_getter_;
534534
std::optional<SemIR::File> sem_ir_;
535-
std::unique_ptr<clang::ASTUnit> cpp_ast_;
535+
std::unique_ptr<clang::ASTUnit> clang_ast_unit_;
536536
std::unique_ptr<llvm::LLVMContext> llvm_context_;
537537
std::unique_ptr<llvm::Module> module_;
538538
};
@@ -703,7 +703,7 @@ auto CompilationUnit::GetCheckUnit() -> Check::Unit {
703703
.value_stores = &value_stores_,
704704
.timings = timings_ ? &*timings_ : nullptr,
705705
.sem_ir = &*sem_ir_,
706-
.cpp_ast = &cpp_ast_};
706+
.clang_ast_unit = &clang_ast_unit_};
707707
}
708708

709709
auto CompilationUnit::PostCheck() -> void {

toolchain/language_server/context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ auto Context::File::SetText(Context& context, std::optional<int64_t> version,
148148

149149
SemIR::File sem_ir(tree_.get(), SemIR::CheckIRId(0), tree_->packaging_decl(),
150150
*value_stores_, uri_.file().str());
151-
std::unique_ptr<clang::ASTUnit> cpp_ast;
151+
std::unique_ptr<clang::ASTUnit> clang_ast_unt;
152152
// TODO: Support cross-file checking when multiple files have edits.
153153
llvm::SmallVector<Check::Unit> units = {{{.consumer = &consumer,
154154
.value_stores = value_stores_.get(),
155155
.timings = nullptr,
156156
.sem_ir = &sem_ir,
157-
.cpp_ast = &cpp_ast}}};
157+
.clang_ast_unit = &clang_ast_unt}}};
158158

159159
auto getter = [this]() -> const Parse::TreeAndSubtrees& {
160160
return *tree_and_subtrees_;

toolchain/lower/file_context.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ auto FileContext::PrepareToLower() -> void {
7171
// Clang code generation should not actually modify the AST, but isn't
7272
// const-correct.
7373
cpp_code_generator_->Initialize(
74-
const_cast<clang::ASTContext&>(cpp_ast()->getASTContext()));
74+
const_cast<clang::ASTContext&>(clang_ast_unit()->getASTContext()));
7575
}
7676

7777
// Lower all types that were required to be complete.
@@ -158,7 +158,7 @@ auto FileContext::Finalize() -> void {
158158
// Clang code generation should not actually modify the AST, but isn't
159159
// const-correct.
160160
cpp_code_generator_->HandleTranslationUnit(
161-
const_cast<clang::ASTContext&>(cpp_ast()->getASTContext()));
161+
const_cast<clang::ASTContext&>(clang_ast_unit()->getASTContext()));
162162
bool link_error = llvm::Linker::linkModules(
163163
/*Dest=*/llvm_module(),
164164
/*Src=*/std::unique_ptr<llvm::Module>(
@@ -174,7 +174,7 @@ auto FileContext::Finalize() -> void {
174174

175175
auto FileContext::CreateCppCodeGenerator()
176176
-> std::unique_ptr<clang::CodeGenerator> {
177-
if (!cpp_ast()) {
177+
if (!clang_ast_unit()) {
178178
return nullptr;
179179
}
180180

@@ -185,7 +185,7 @@ auto FileContext::CreateCppCodeGenerator()
185185
cpp_code_gen_options_.EmitVersionIdentMetadata = false;
186186

187187
return std::unique_ptr<clang::CodeGenerator>(clang::CreateLLVMCodeGen(
188-
cpp_ast()->getASTContext().getDiagnostics(),
188+
clang_ast_unit()->getASTContext().getDiagnostics(),
189189
clang_module_name_stream.TakeStr(), context().file_system(),
190190
cpp_header_search_options_, cpp_preprocessor_options_,
191191
cpp_code_gen_options_, llvm_context()));

toolchain/lower/file_context.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ class FileContext {
106106
return *cpp_code_generator_;
107107
}
108108
auto sem_ir() const -> const SemIR::File& { return *sem_ir_; }
109-
auto cpp_ast() -> const clang::ASTUnit* { return sem_ir().cpp_ast(); }
109+
auto clang_ast_unit() -> const clang::ASTUnit* {
110+
return sem_ir().clang_ast_unit();
111+
}
110112
auto inst_namer() -> const SemIR::InstNamer* { return inst_namer_; }
111113
auto global_variables() -> const Map<SemIR::InstId, llvm::GlobalVariable*>& {
112114
return global_variables_;

0 commit comments

Comments
 (0)