Skip to content

Commit 4421a75

Browse files
authored
file_name -> filename (#3791)
I wanted to choose one or the other. I think some code has been using each from early on. We're predominately using `filename`, so consolidating on that. This conveniently matches the [Google dev doc style guide](https://developers.google.com/style/word-list#filename) (which we use for docs) which says "filename: Not file name". In toolchain: ``` ╚╡git grep file_name . | wc -l 35 ╚╡git grep filename . | wc -l 489 ```
1 parent 3884d3c commit 4421a75

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

toolchain/diagnostics/diagnostic_emitter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ enum class DiagnosticLevel : int8_t {
4949

5050
// A location for a diagnostic in a file. The lifetime of a DiagnosticLocation
5151
// is required to be less than SourceBuffer that it refers to due to the
52-
// contained file_name and line references.
52+
// contained filename and line references.
5353
struct DiagnosticLocation {
5454
// Name of the file or buffer that this diagnostic refers to.
55-
llvm::StringRef file_name;
55+
llvm::StringRef filename;
5656
// A reference to the line of the error.
5757
llvm::StringRef line;
5858
// 1-based line number.
@@ -395,7 +395,7 @@ class StreamDiagnosticConsumer : public DiagnosticConsumer {
395395
}
396396
auto Print(const DiagnosticMessage& message, llvm::StringRef prefix = "")
397397
-> void {
398-
*stream_ << message.location.file_name;
398+
*stream_ << message.location.filename;
399399
if (message.location.line_number > 0) {
400400
*stream_ << ":" << message.location.line_number;
401401
if (message.location.column_number > 0) {

toolchain/diagnostics/mocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Carbon {
99
void PrintTo(const Diagnostic& diagnostic, std::ostream* os) {
1010
*os << "Diagnostic{" << diagnostic.message.kind << ", ";
1111
PrintTo(diagnostic.level, os);
12-
*os << ", " << diagnostic.message.location.file_name << ":"
12+
*os << ", " << diagnostic.message.location.filename << ":"
1313
<< diagnostic.message.location.line_number << ":"
1414
<< diagnostic.message.location.column_number << ", \""
1515
<< diagnostic.message.format_fn(diagnostic.message) << "\"}";

toolchain/driver/driver.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The input Carbon source file to compile.
8686
},
8787
[&](auto& arg_b) {
8888
arg_b.Required(true);
89-
arg_b.Append(&input_file_names);
89+
arg_b.Append(&input_filenames);
9090
});
9191

9292
b.AddOneOfOption(
@@ -128,7 +128,7 @@ Passing `--output=-` will write the output to stdout. In that case, the flag
128128
object output can be forced by enabling `--force-obj-output`.
129129
)""",
130130
},
131-
[&](auto& arg_b) { arg_b.Set(&output_file_name); });
131+
[&](auto& arg_b) { arg_b.Set(&output_filename); });
132132

133133
b.AddStringOption(
134134
{
@@ -262,8 +262,8 @@ Dump the generated assembly to stdout after codegen.
262262
std::string host = llvm::sys::getDefaultTargetTriple();
263263
llvm::StringRef target;
264264

265-
llvm::StringRef output_file_name;
266-
llvm::SmallVector<llvm::StringRef> input_file_names;
265+
llvm::StringRef output_filename;
266+
llvm::SmallVector<llvm::StringRef> input_filenames;
267267

268268
bool asm_output = false;
269269
bool force_obj_output = false;
@@ -395,10 +395,10 @@ auto Driver::ValidateCompileOptions(const CompileOptions& options) const
395395
class Driver::CompilationUnit {
396396
public:
397397
explicit CompilationUnit(Driver* driver, const CompileOptions& options,
398-
llvm::StringRef input_file_name)
398+
llvm::StringRef input_filename)
399399
: driver_(driver),
400400
options_(options),
401-
input_file_name_(input_file_name),
401+
input_filename_(input_filename),
402402
vlog_stream_(driver_->vlog_stream_),
403403
stream_consumer_(driver_->error_stream_) {
404404
if (vlog_stream_ != nullptr || options_.stream_errors) {
@@ -412,10 +412,10 @@ class Driver::CompilationUnit {
412412
// Loads source and lexes it. Returns true on success.
413413
auto RunLex() -> void {
414414
LogCall("SourceBuffer::MakeFromFile", [&] {
415-
if (input_file_name_ == "-") {
415+
if (input_filename_ == "-") {
416416
source_ = SourceBuffer::MakeFromStdin(*consumer_);
417417
} else {
418-
source_ = SourceBuffer::MakeFromFile(driver_->fs_, input_file_name_,
418+
source_ = SourceBuffer::MakeFromFile(driver_->fs_, input_filename_,
419419
*consumer_);
420420
}
421421
});
@@ -501,7 +501,7 @@ class Driver::CompilationUnit {
501501

502502
LogCall("Lower::LowerToLLVM", [&] {
503503
llvm_context_ = std::make_unique<llvm::LLVMContext>();
504-
module_ = Lower::LowerToLLVM(*llvm_context_, input_file_name_, *sem_ir_,
504+
module_ = Lower::LowerToLLVM(*llvm_context_, input_filename_, *sem_ir_,
505505
vlog_stream_);
506506
});
507507
if (vlog_stream_) {
@@ -526,10 +526,10 @@ class Driver::CompilationUnit {
526526

527527
auto PrintSharedValues() const -> void {
528528
Yaml::Print(driver_->output_stream_,
529-
value_stores_.OutputYaml(input_file_name_));
529+
value_stores_.OutputYaml(input_filename_));
530530
}
531531

532-
auto input_file_name() -> llvm::StringRef { return input_file_name_; }
532+
auto input_filename() -> llvm::StringRef { return input_filename_; }
533533
auto success() -> bool { return success_; }
534534
auto has_source() -> bool { return source_.has_value(); }
535535

@@ -546,7 +546,7 @@ class Driver::CompilationUnit {
546546
codegen->EmitAssembly(*vlog_stream_);
547547
}
548548

549-
if (options_.output_file_name == "-") {
549+
if (options_.output_filename == "-") {
550550
// TODO: the output file name, forcing object output, and requesting
551551
// textual assembly output are all somewhat linked flags. We should add
552552
// some validation that they are used correctly.
@@ -560,17 +560,17 @@ class Driver::CompilationUnit {
560560
}
561561
}
562562
} else {
563-
llvm::SmallString<256> output_file_name = options_.output_file_name;
564-
if (output_file_name.empty()) {
563+
llvm::SmallString<256> output_filename = options_.output_filename;
564+
if (output_filename.empty()) {
565565
if (!source_->is_regular_file()) {
566566
// Don't invent file names like `-.o` or `/dev/stdin.o`.
567567
driver_->error_stream_
568568
<< "ERROR: Output file name must be specified for input '"
569-
<< input_file_name_ << "' that is not a regular file.\n";
569+
<< input_filename_ << "' that is not a regular file.\n";
570570
return false;
571571
}
572-
output_file_name = input_file_name_;
573-
llvm::sys::path::replace_extension(output_file_name,
572+
output_filename = input_filename_;
573+
llvm::sys::path::replace_extension(output_filename,
574574
options_.asm_output ? ".s" : ".o");
575575
} else {
576576
// TODO: Handle the case where multiple input files were specified
@@ -579,14 +579,14 @@ class Driver::CompilationUnit {
579579
// Currently each unit overwrites the output from the previous one in
580580
// this case.
581581
}
582-
CARBON_VLOG() << "Writing output to: " << output_file_name << "\n";
582+
CARBON_VLOG() << "Writing output to: " << output_filename << "\n";
583583

584584
std::error_code ec;
585-
llvm::raw_fd_ostream output_file(output_file_name, ec,
585+
llvm::raw_fd_ostream output_file(output_filename, ec,
586586
llvm::sys::fs::OF_None);
587587
if (ec) {
588588
driver_->error_stream_ << "ERROR: Could not open output file '"
589-
<< output_file_name << "': " << ec.message()
589+
<< output_filename << "': " << ec.message()
590590
<< "\n";
591591
return false;
592592
}
@@ -606,15 +606,15 @@ class Driver::CompilationUnit {
606606
// Wraps a call with log statements to indicate start and end.
607607
auto LogCall(llvm::StringLiteral label, llvm::function_ref<void()> fn)
608608
-> void {
609-
CARBON_VLOG() << "*** " << label << ": " << input_file_name_ << " ***\n";
609+
CARBON_VLOG() << "*** " << label << ": " << input_filename_ << " ***\n";
610610
fn();
611611
CARBON_VLOG() << "*** " << label << " done ***\n";
612612
}
613613

614614
Driver* driver_;
615615
SharedValueStores value_stores_;
616616
const CompileOptions& options_;
617-
llvm::StringRef input_file_name_;
617+
llvm::StringRef input_filename_;
618618

619619
// Copied from driver_ for CARBON_VLOG.
620620
llvm::raw_pwrite_stream* vlog_stream_;
@@ -646,7 +646,7 @@ auto Driver::Compile(const CompileOptions& options) -> RunResult {
646646
for (const auto& unit : units) {
647647
result.success &= unit->success();
648648
result.per_file_success.push_back(
649-
{unit->input_file_name(), unit->success()});
649+
{unit->input_filename(), unit->success()});
650650
}
651651
return result;
652652
};
@@ -666,9 +666,9 @@ auto Driver::Compile(const CompileOptions& options) -> RunResult {
666666
}
667667
}
668668
});
669-
for (const auto& input_file_name : options.input_file_names) {
669+
for (const auto& input_filename : options.input_filenames) {
670670
units.push_back(
671-
std::make_unique<CompilationUnit>(this, options, input_file_name));
671+
std::make_unique<CompilationUnit>(this, options, input_filename));
672672
}
673673

674674
// Lex.

toolchain/driver/driver_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class DriverTest : public testing::Test {
4747
}
4848

4949
auto MakeTestFile(llvm::StringRef text,
50-
llvm::StringRef file_name = "test_file.carbon")
50+
llvm::StringRef filename = "test_file.carbon")
5151
-> llvm::StringRef {
52-
fs_.addFile(file_name, /*ModificationTime=*/0,
52+
fs_.addFile(filename, /*ModificationTime=*/0,
5353
llvm::MemoryBuffer::getMemBuffer(text));
54-
return file_name;
54+
return filename;
5555
}
5656

5757
// Makes a temp directory and changes the working directory to it. Returns an

toolchain/lex/tokenized_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
384384
}
385385
}
386386

387-
return {.file_name = buffer_->source_->filename(),
387+
return {.filename = buffer_->source_->filename(),
388388
.line = line,
389389
.line_number = line_number + 1,
390390
.column_number = column_number + 1};

toolchain/parse/tree_node_location_translator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class NodeLocationTranslator
4949
// Support the invalid token as a way to emit only the filename, when there
5050
// is no line association.
5151
if (!node_location.node_id().is_valid()) {
52-
return {.file_name = filename_};
52+
return {.filename = filename_};
5353
}
5454

5555
if (node_location.token_only()) {

toolchain/source/source_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Carbon {
1313
namespace {
1414
struct FilenameTranslator : DiagnosticLocationTranslator<llvm::StringRef> {
1515
auto GetLocation(llvm::StringRef filename) -> DiagnosticLocation override {
16-
return {.file_name = filename};
16+
return {.filename = filename};
1717
}
1818
};
1919
} // namespace

0 commit comments

Comments
 (0)