Files
carbon-lang/toolchain/driver/driver_env.h
T
Jon Ross-PerkinsandChandler Carruth 7befe2ce9f Switch custom error stream output to diagnostic (#4846)
This switches most error printing to use diagnostics instead of direct
stream writes, even when not a specific file diagnostic. I'm allowing
empty filenames for this use-case.

This allows a little more specific testing to validate coverage of
output using the diagnostic coverage test. I'm adding a few tests to
cover things that weren't previously tested.

Separately, this also forces a little more standardization in format...
considering how changes like #4568 show effort being spent to _mirror_
diagnostic style, my thought is now to just use diagnostic code where
possible.

Note this also allows incrementally better testing of the language
server; I'm changing the crash fix from #4847 in favor of diagnostic
testing.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-01-30 01:58:07 +00:00

64 lines
2.0 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
#define CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
#include <cstdio>
#include <utility>
#include "common/ostream.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "toolchain/diagnostics/diagnostic_emitter.h"
#include "toolchain/install/install_paths.h"
namespace Carbon {
// Driver environment information, encapsulated for easy passing to subcommands.
struct DriverEnv {
explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
const InstallPaths* installation, FILE* input_stream,
llvm::raw_pwrite_stream* output_stream,
llvm::raw_pwrite_stream* error_stream, bool fuzzing)
: fs(std::move(fs)),
installation(installation),
input_stream(input_stream),
output_stream(output_stream),
error_stream(error_stream),
fuzzing(fuzzing),
consumer(error_stream),
emitter(&consumer) {}
// The filesystem for source code.
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
// Helper to locate the toolchain installation's files.
const InstallPaths* installation;
// Standard input; stdin. May be null, to prevent accidental use.
FILE* input_stream;
// Standard output; stdout.
llvm::raw_pwrite_stream* output_stream;
// Error output; stderr.
llvm::raw_pwrite_stream* error_stream;
// Tracks when the driver is being fuzzed. This allows specific commands to
// error rather than perform operations that aren't well behaved during
// fuzzing.
bool fuzzing;
// A diagnostic consumer, to be able to connect output.
StreamDiagnosticConsumer consumer;
// A diagnostic emitter that has no locations.
NoLocDiagnosticEmitter emitter;
// For CARBON_VLOG.
llvm::raw_pwrite_stream* vlog_stream = nullptr;
};
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_