various: translation resources from cg backend
Extend `CodegenBackend` trait with a function returning the translation resources from the codegen backend, which can be added to the complete list of resources provided to the emitter. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
a8e37507f4
commit
26255186e2
23 changed files with 86 additions and 48 deletions
|
@ -17,11 +17,11 @@ use rustc_span::{BytePos, FileName, Pos, Span};
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
static TEST_LOCALE_RESOURCES: &[&str] =
|
||||
&[crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE];
|
||||
|
||||
fn sess() -> ParseSess {
|
||||
ParseSess::new(TEST_LOCALE_RESOURCES, FilePathMapping::empty())
|
||||
ParseSess::new(
|
||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||
FilePathMapping::empty(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Parses an item.
|
||||
|
|
|
@ -34,7 +34,10 @@ where
|
|||
|
||||
/// Maps a string to tts, using a made-up filename.
|
||||
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
|
||||
let ps = ParseSess::new(TEST_LOCALE_RESOURCES, FilePathMapping::empty());
|
||||
let ps = ParseSess::new(
|
||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||
FilePathMapping::empty(),
|
||||
);
|
||||
source_file_to_stream(
|
||||
&ps,
|
||||
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
|
||||
|
@ -45,7 +48,10 @@ pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
|
|||
|
||||
/// Parses a string, returns a crate.
|
||||
pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
|
||||
let ps = ParseSess::new(TEST_LOCALE_RESOURCES, FilePathMapping::empty());
|
||||
let ps = ParseSess::new(
|
||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||
FilePathMapping::empty(),
|
||||
);
|
||||
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
|
||||
}
|
||||
|
||||
|
@ -123,14 +129,14 @@ impl<T: Write> Write for Shared<T> {
|
|||
}
|
||||
}
|
||||
|
||||
static TEST_LOCALE_RESOURCES: &[&str] =
|
||||
&[crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE];
|
||||
|
||||
fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
|
||||
create_default_session_if_not_set_then(|_| {
|
||||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(TEST_LOCALE_RESOURCES, false);
|
||||
let fallback_bundle = rustc_errors::fallback_fluent_bundle(
|
||||
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
|
||||
false,
|
||||
);
|
||||
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue