mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 14:51:15 +00:00
Fix return type of compile_syntax_node
All call sites are only interested in the root component, so might as well return that.
This commit is contained in:
parent
2425c366db
commit
09cae799d3
6 changed files with 12 additions and 12 deletions
|
@ -103,7 +103,7 @@ pub fn compile(path: impl AsRef<std::path::Path>) -> Result<(), CompileError> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (doc, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
let (root_component, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
||||||
|
|
||||||
if diag.has_error() {
|
if diag.has_error() {
|
||||||
let vec = diag.to_string_vec();
|
let vec = diag.to_string_vec();
|
||||||
|
@ -121,7 +121,7 @@ pub fn compile(path: impl AsRef<std::path::Path>) -> Result<(), CompileError> {
|
||||||
|
|
||||||
let file = std::fs::File::create(&output_file_path).map_err(CompileError::SaveError)?;
|
let file = std::fs::File::create(&output_file_path).map_err(CompileError::SaveError)?;
|
||||||
let mut code_formater = CodeFormatter { indentation: 0, in_string: false, sink: file };
|
let mut code_formater = CodeFormatter { indentation: 0, in_string: false, sink: file };
|
||||||
let generated = generator::rust::generate(&doc.root_component, &mut diag).ok_or_else(|| {
|
let generated = generator::rust::generate(&root_component, &mut diag).ok_or_else(|| {
|
||||||
let vec = diag.to_string_vec();
|
let vec = diag.to_string_vec();
|
||||||
diag.print();
|
diag.print();
|
||||||
CompileError::CompileError(vec)
|
CompileError::CompileError(vec)
|
||||||
|
|
|
@ -223,14 +223,14 @@ pub fn sixtyfps(stream: TokenStream) -> TokenStream {
|
||||||
//println!("{:#?}", syntax_node);
|
//println!("{:#?}", syntax_node);
|
||||||
let compiler_config =
|
let compiler_config =
|
||||||
CompilerConfiguration { include_paths: &include_paths, ..Default::default() };
|
CompilerConfiguration { include_paths: &include_paths, ..Default::default() };
|
||||||
let (tree, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
let (root_component, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
||||||
//println!("{:#?}", tree);
|
//println!("{:#?}", tree);
|
||||||
if diag.has_error() {
|
if diag.has_error() {
|
||||||
diag.map_offsets_to_span(&tokens);
|
diag.map_offsets_to_span(&tokens);
|
||||||
return diag.into_token_stream().into();
|
return diag.into_token_stream().into();
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = generator::rust::generate(&tree.root_component, &mut diag);
|
let result = generator::rust::generate(&root_component, &mut diag);
|
||||||
|
|
||||||
result
|
result
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub fn compile_syntax_node(
|
||||||
doc_node: parser::SyntaxNodeWithSourceFile,
|
doc_node: parser::SyntaxNodeWithSourceFile,
|
||||||
mut diagnostics: diagnostics::FileDiagnostics,
|
mut diagnostics: diagnostics::FileDiagnostics,
|
||||||
compiler_config: &CompilerConfiguration,
|
compiler_config: &CompilerConfiguration,
|
||||||
) -> (object_tree::Document, diagnostics::BuildDiagnostics) {
|
) -> (Rc<crate::object_tree::Component>, diagnostics::BuildDiagnostics) {
|
||||||
let mut build_diagnostics = diagnostics::BuildDiagnostics::default();
|
let mut build_diagnostics = diagnostics::BuildDiagnostics::default();
|
||||||
|
|
||||||
let global_type_registry = typeregister::TypeRegister::builtin();
|
let global_type_registry = typeregister::TypeRegister::builtin();
|
||||||
|
@ -88,7 +88,7 @@ pub fn compile_syntax_node(
|
||||||
|
|
||||||
run_passes(&doc, &mut build_diagnostics, compiler_config);
|
run_passes(&doc, &mut build_diagnostics, compiler_config);
|
||||||
|
|
||||||
(doc, build_diagnostics)
|
(doc.root_component, build_diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_passes(
|
pub fn run_passes(
|
||||||
|
|
|
@ -232,11 +232,11 @@ pub fn load(
|
||||||
) -> Result<Rc<ComponentDescription>, sixtyfps_compilerlib::diagnostics::BuildDiagnostics> {
|
) -> Result<Rc<ComponentDescription>, sixtyfps_compilerlib::diagnostics::BuildDiagnostics> {
|
||||||
let (syntax_node, diag) = parser::parse(source, Some(path));
|
let (syntax_node, diag) = parser::parse(source, Some(path));
|
||||||
let compiler_config = CompilerConfiguration { include_paths, ..Default::default() };
|
let compiler_config = CompilerConfiguration { include_paths, ..Default::default() };
|
||||||
let (tree, diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
let (root_component, diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
||||||
if diag.has_error() {
|
if diag.has_error() {
|
||||||
return Err(diag);
|
return Err(diag);
|
||||||
}
|
}
|
||||||
Ok(generate_component(&tree.root_component))
|
Ok(generate_component(&root_component))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_component(root_component: &Rc<object_tree::Component>) -> Rc<ComponentDescription> {
|
fn generate_component(root_component: &Rc<object_tree::Component>) -> Rc<ComponentDescription> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
|
||||||
|
|
||||||
let (syntax_node, diag) = parser::parse(source.clone(), Some(&testcase.absolute_path));
|
let (syntax_node, diag) = parser::parse(source.clone(), Some(&testcase.absolute_path));
|
||||||
let compiler_config = CompilerConfiguration { include_paths, ..Default::default() };
|
let compiler_config = CompilerConfiguration { include_paths, ..Default::default() };
|
||||||
let (doc, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
let (root_component, mut diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
||||||
|
|
||||||
if diag.has_error() {
|
if diag.has_error() {
|
||||||
let vec = diag.to_string_vec();
|
let vec = diag.to_string_vec();
|
||||||
|
@ -24,7 +24,7 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box<dyn Error>>
|
||||||
generator::generate(
|
generator::generate(
|
||||||
generator::OutputFormat::Cpp,
|
generator::OutputFormat::Cpp,
|
||||||
&mut generated_cpp,
|
&mut generated_cpp,
|
||||||
&doc.root_component,
|
&root_component,
|
||||||
&mut diag,
|
&mut diag,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,11 @@ fn main() -> std::io::Result<()> {
|
||||||
//println!("{:#?}", syntax_node);
|
//println!("{:#?}", syntax_node);
|
||||||
let compiler_config =
|
let compiler_config =
|
||||||
CompilerConfiguration { include_paths: &args.include_paths, ..Default::default() };
|
CompilerConfiguration { include_paths: &args.include_paths, ..Default::default() };
|
||||||
let (doc, diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
let (root_component, diag) = compile_syntax_node(syntax_node, diag, &compiler_config);
|
||||||
|
|
||||||
let mut diag = diag.check_and_exit_on_error();
|
let mut diag = diag.check_and_exit_on_error();
|
||||||
|
|
||||||
generator::generate(args.format, &mut std::io::stdout(), &doc.root_component, &mut diag)?;
|
generator::generate(args.format, &mut std::io::stdout(), &root_component, &mut diag)?;
|
||||||
diag.check_and_exit_on_error();
|
diag.check_and_exit_on_error();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue