Explorar o código

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
```
Jon Ross-Perkins %!s(int64=2) %!d(string=hai) anos
pai
achega
4421a75c36

+ 3 - 3
toolchain/diagnostics/diagnostic_emitter.h

@@ -49,10 +49,10 @@ enum class DiagnosticLevel : int8_t {
 
 // A location for a diagnostic in a file. The lifetime of a DiagnosticLocation
 // is required to be less than SourceBuffer that it refers to due to the
-// contained file_name and line references.
+// contained filename and line references.
 struct DiagnosticLocation {
   // Name of the file or buffer that this diagnostic refers to.
-  llvm::StringRef file_name;
+  llvm::StringRef filename;
   // A reference to the line of the error.
   llvm::StringRef line;
   // 1-based line number.
@@ -395,7 +395,7 @@ class StreamDiagnosticConsumer : public DiagnosticConsumer {
   }
   auto Print(const DiagnosticMessage& message, llvm::StringRef prefix = "")
       -> void {
-    *stream_ << message.location.file_name;
+    *stream_ << message.location.filename;
     if (message.location.line_number > 0) {
       *stream_ << ":" << message.location.line_number;
       if (message.location.column_number > 0) {

+ 1 - 1
toolchain/diagnostics/mocks.cpp

@@ -9,7 +9,7 @@ namespace Carbon {
 void PrintTo(const Diagnostic& diagnostic, std::ostream* os) {
   *os << "Diagnostic{" << diagnostic.message.kind << ", ";
   PrintTo(diagnostic.level, os);
-  *os << ", " << diagnostic.message.location.file_name << ":"
+  *os << ", " << diagnostic.message.location.filename << ":"
       << diagnostic.message.location.line_number << ":"
       << diagnostic.message.location.column_number << ", \""
       << diagnostic.message.format_fn(diagnostic.message) << "\"}";

+ 25 - 25
toolchain/driver/driver.cpp

@@ -86,7 +86,7 @@ The input Carbon source file to compile.
         },
         [&](auto& arg_b) {
           arg_b.Required(true);
-          arg_b.Append(&input_file_names);
+          arg_b.Append(&input_filenames);
         });
 
     b.AddOneOfOption(
@@ -128,7 +128,7 @@ Passing `--output=-` will write the output to stdout. In that case, the flag
 object output can be forced by enabling `--force-obj-output`.
 )""",
         },
-        [&](auto& arg_b) { arg_b.Set(&output_file_name); });
+        [&](auto& arg_b) { arg_b.Set(&output_filename); });
 
     b.AddStringOption(
         {
@@ -262,8 +262,8 @@ Dump the generated assembly to stdout after codegen.
   std::string host = llvm::sys::getDefaultTargetTriple();
   llvm::StringRef target;
 
-  llvm::StringRef output_file_name;
-  llvm::SmallVector<llvm::StringRef> input_file_names;
+  llvm::StringRef output_filename;
+  llvm::SmallVector<llvm::StringRef> input_filenames;
 
   bool asm_output = false;
   bool force_obj_output = false;
@@ -395,10 +395,10 @@ auto Driver::ValidateCompileOptions(const CompileOptions& options) const
 class Driver::CompilationUnit {
  public:
   explicit CompilationUnit(Driver* driver, const CompileOptions& options,
-                           llvm::StringRef input_file_name)
+                           llvm::StringRef input_filename)
       : driver_(driver),
         options_(options),
-        input_file_name_(input_file_name),
+        input_filename_(input_filename),
         vlog_stream_(driver_->vlog_stream_),
         stream_consumer_(driver_->error_stream_) {
     if (vlog_stream_ != nullptr || options_.stream_errors) {
@@ -412,10 +412,10 @@ class Driver::CompilationUnit {
   // Loads source and lexes it. Returns true on success.
   auto RunLex() -> void {
     LogCall("SourceBuffer::MakeFromFile", [&] {
-      if (input_file_name_ == "-") {
+      if (input_filename_ == "-") {
         source_ = SourceBuffer::MakeFromStdin(*consumer_);
       } else {
-        source_ = SourceBuffer::MakeFromFile(driver_->fs_, input_file_name_,
+        source_ = SourceBuffer::MakeFromFile(driver_->fs_, input_filename_,
                                              *consumer_);
       }
     });
@@ -501,7 +501,7 @@ class Driver::CompilationUnit {
 
     LogCall("Lower::LowerToLLVM", [&] {
       llvm_context_ = std::make_unique<llvm::LLVMContext>();
-      module_ = Lower::LowerToLLVM(*llvm_context_, input_file_name_, *sem_ir_,
+      module_ = Lower::LowerToLLVM(*llvm_context_, input_filename_, *sem_ir_,
                                    vlog_stream_);
     });
     if (vlog_stream_) {
@@ -526,10 +526,10 @@ class Driver::CompilationUnit {
 
   auto PrintSharedValues() const -> void {
     Yaml::Print(driver_->output_stream_,
-                value_stores_.OutputYaml(input_file_name_));
+                value_stores_.OutputYaml(input_filename_));
   }
 
-  auto input_file_name() -> llvm::StringRef { return input_file_name_; }
+  auto input_filename() -> llvm::StringRef { return input_filename_; }
   auto success() -> bool { return success_; }
   auto has_source() -> bool { return source_.has_value(); }
 
@@ -546,7 +546,7 @@ class Driver::CompilationUnit {
       codegen->EmitAssembly(*vlog_stream_);
     }
 
-    if (options_.output_file_name == "-") {
+    if (options_.output_filename == "-") {
       // TODO: the output file name, forcing object output, and requesting
       // textual assembly output are all somewhat linked flags. We should add
       // some validation that they are used correctly.
@@ -560,17 +560,17 @@ class Driver::CompilationUnit {
         }
       }
     } else {
-      llvm::SmallString<256> output_file_name = options_.output_file_name;
-      if (output_file_name.empty()) {
+      llvm::SmallString<256> output_filename = options_.output_filename;
+      if (output_filename.empty()) {
         if (!source_->is_regular_file()) {
           // Don't invent file names like `-.o` or `/dev/stdin.o`.
           driver_->error_stream_
               << "ERROR: Output file name must be specified for input '"
-              << input_file_name_ << "' that is not a regular file.\n";
+              << input_filename_ << "' that is not a regular file.\n";
           return false;
         }
-        output_file_name = input_file_name_;
-        llvm::sys::path::replace_extension(output_file_name,
+        output_filename = input_filename_;
+        llvm::sys::path::replace_extension(output_filename,
                                            options_.asm_output ? ".s" : ".o");
       } else {
         // TODO: Handle the case where multiple input files were specified
@@ -579,14 +579,14 @@ class Driver::CompilationUnit {
         // Currently each unit overwrites the output from the previous one in
         // this case.
       }
-      CARBON_VLOG() << "Writing output to: " << output_file_name << "\n";
+      CARBON_VLOG() << "Writing output to: " << output_filename << "\n";
 
       std::error_code ec;
-      llvm::raw_fd_ostream output_file(output_file_name, ec,
+      llvm::raw_fd_ostream output_file(output_filename, ec,
                                        llvm::sys::fs::OF_None);
       if (ec) {
         driver_->error_stream_ << "ERROR: Could not open output file '"
-                               << output_file_name << "': " << ec.message()
+                               << output_filename << "': " << ec.message()
                                << "\n";
         return false;
       }
@@ -606,7 +606,7 @@ class Driver::CompilationUnit {
   // Wraps a call with log statements to indicate start and end.
   auto LogCall(llvm::StringLiteral label, llvm::function_ref<void()> fn)
       -> void {
-    CARBON_VLOG() << "*** " << label << ": " << input_file_name_ << " ***\n";
+    CARBON_VLOG() << "*** " << label << ": " << input_filename_ << " ***\n";
     fn();
     CARBON_VLOG() << "*** " << label << " done ***\n";
   }
@@ -614,7 +614,7 @@ class Driver::CompilationUnit {
   Driver* driver_;
   SharedValueStores value_stores_;
   const CompileOptions& options_;
-  llvm::StringRef input_file_name_;
+  llvm::StringRef input_filename_;
 
   // Copied from driver_ for CARBON_VLOG.
   llvm::raw_pwrite_stream* vlog_stream_;
@@ -646,7 +646,7 @@ auto Driver::Compile(const CompileOptions& options) -> RunResult {
     for (const auto& unit : units) {
       result.success &= unit->success();
       result.per_file_success.push_back(
-          {unit->input_file_name(), unit->success()});
+          {unit->input_filename(), unit->success()});
     }
     return result;
   };
@@ -666,9 +666,9 @@ auto Driver::Compile(const CompileOptions& options) -> RunResult {
       }
     }
   });
-  for (const auto& input_file_name : options.input_file_names) {
+  for (const auto& input_filename : options.input_filenames) {
     units.push_back(
-        std::make_unique<CompilationUnit>(this, options, input_file_name));
+        std::make_unique<CompilationUnit>(this, options, input_filename));
   }
 
   // Lex.

+ 3 - 3
toolchain/driver/driver_test.cpp

@@ -47,11 +47,11 @@ class DriverTest : public testing::Test {
   }
 
   auto MakeTestFile(llvm::StringRef text,
-                    llvm::StringRef file_name = "test_file.carbon")
+                    llvm::StringRef filename = "test_file.carbon")
       -> llvm::StringRef {
-    fs_.addFile(file_name, /*ModificationTime=*/0,
+    fs_.addFile(filename, /*ModificationTime=*/0,
                 llvm::MemoryBuffer::getMemBuffer(text));
-    return file_name;
+    return filename;
   }
 
   // Makes a temp directory and changes the working directory to it. Returns an

+ 1 - 1
toolchain/lex/tokenized_buffer.cpp

@@ -384,7 +384,7 @@ auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
     }
   }
 
-  return {.file_name = buffer_->source_->filename(),
+  return {.filename = buffer_->source_->filename(),
           .line = line,
           .line_number = line_number + 1,
           .column_number = column_number + 1};

+ 1 - 1
toolchain/parse/tree_node_location_translator.h

@@ -49,7 +49,7 @@ class NodeLocationTranslator
     // Support the invalid token as a way to emit only the filename, when there
     // is no line association.
     if (!node_location.node_id().is_valid()) {
-      return {.file_name = filename_};
+      return {.filename = filename_};
     }
 
     if (node_location.token_only()) {

+ 1 - 1
toolchain/source/source_buffer.cpp

@@ -13,7 +13,7 @@ namespace Carbon {
 namespace {
 struct FilenameTranslator : DiagnosticLocationTranslator<llvm::StringRef> {
   auto GetLocation(llvm::StringRef filename) -> DiagnosticLocation override {
-    return {.file_name = filename};
+    return {.filename = filename};
   }
 };
 }  // namespace