Skip to content

Commit

Permalink
Changing the type of File.tree
Browse files Browse the repository at this point in the history
  • Loading branch information
beta-ziliani committed Jan 10, 2025
1 parent 1fb766e commit 850b5f9
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use std::collections::BTreeMap;
use std::rc::Rc;

use metaslang_cst::text_index::TextIndex;

use crate::cst::{Cursor, Node};
use crate::cst::{Cursor, NonterminalNode};

#[derive(Clone)]
pub struct File {
id: String,
tree: Node,
tree: Rc<NonterminalNode>,

resolved_imports: BTreeMap<usize, String>,
}

impl File {
pub(super) fn new(id: String, tree: Node) -> Self {
pub(super) fn new(id: String, tree: Rc<NonterminalNode>) -> Self {
Self {
id,
tree,
Expand All @@ -26,12 +27,12 @@ impl File {
&self.id
}

pub fn tree(&self) -> &Node {
pub fn tree(&self) -> &Rc<NonterminalNode> {
&self.tree
}

pub fn create_tree_cursor(&self) -> Cursor {
self.tree.clone().cursor_with_offset(TextIndex::ZERO)
Rc::clone(&self.tree).cursor_with_offset(TextIndex::ZERO)
}

pub(super) fn resolve_import(&mut self, import_path: &Cursor, destination_file_id: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::BTreeMap;
use std::rc::Rc;

use metaslang_cst::nodes::Node;
use semver::Version;

use crate::compilation::{CompilationUnit, File};
Expand Down Expand Up @@ -44,10 +43,7 @@ impl InternalCompilationBuilder {

let import_paths = self.imports.extract(parse_output.create_tree_cursor());

let file = File::new(
id.clone(),
Node::Nonterminal(Rc::clone(parse_output.tree())),
);
let file = File::new(id.clone(), Rc::clone(parse_output.tree()));
self.files.insert(id, file);

AddFileResponse { import_paths }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface compilation {
use bindings.{binding-graph};
use cst.{node, cursor};
use cst.{nonterminal-node, cursor};

/// A builder for creating compilation units.
/// Allows incrementally building a transitive list of all files and their imports.
Expand Down Expand Up @@ -58,7 +58,7 @@ interface compilation {
id: func() -> string;

/// Returns the syntax tree of this file.
tree: func() -> node;
tree: func() -> nonterminal-node;

/// Creates a cursor for traversing the syntax tree of this file.
create-tree-cursor: func() -> cursor;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ mod ffi {
Guest, GuestCompilationUnit, GuestFile, GuestInternalCompilationBuilder,
InternalCompilationBuilder, InternalCompilationBuilderBorrow,
};
pub use crate::wasm_crate::bindgen::exports::nomic_foundation::slang::cst::{Cursor, Node};
pub use crate::wasm_crate::bindgen::exports::nomic_foundation::slang::cst::{
Cursor, NonterminalNode,
};
}

mod rust {
Expand Down Expand Up @@ -110,7 +112,7 @@ define_rc_wrapper! { File {
self._borrow_ffi().id().to_owned()
}

fn tree(&self) -> ffi::Node {
fn tree(&self) -> ffi::NonterminalNode {
self._borrow_ffi().tree().to_owned()._into_ffi()
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 850b5f9

Please sign in to comment.