From 766284b33d7357ee4012430168840e14d0239cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Tue, 11 Jun 2024 17:37:45 -0400 Subject: [PATCH] Move .msgb into the language/inputs crate and install into language/outputs The .msgb file is linked from the `Language` definition in order to embed the rules file as string when compiling the output language. --- Cargo.toml | 1 - .../language/definition/src/model/manifest.rs | 1 + .../language/tests/src/pass/tiny_language.rs | 1 + .../runtime/cargo/src/runtime/bindings/mod.rs | 9 + .../src/runtime/bindings_builder.rs.jinja2 | 9 + .../src/runtime/generated/bindings_builder.rs | 6 + .../codegen/runtime/cargo/src/runtime/mod.rs | 4 + crates/codegen/runtime/generator/src/lib.rs | 24 +- crates/codegen/runtime/generator/src/model.rs | 21 + crates/solidity/inputs/graph/Cargo.toml | 10 - crates/solidity/inputs/graph/src/lib.rs | 0 .../bindings/stack-graph.msgb} | 0 .../inputs/language/src/definition.rs | 1 + .../outputs/cargo/slang_solidity/build.rs | 4 +- .../slang_solidity/generated/stack-graph.msgb | 363 ++++++++++++++++++ .../src/generated/bindings/mod.rs | 9 + .../generated/generated/bindings_builder.rs | 6 + .../cargo/slang_solidity/src/generated/mod.rs | 4 + .../src/generated/bindings/mod.rs | 9 + .../generated/generated/bindings_builder.rs | 6 + .../cargo/slang_testlang/src/generated/mod.rs | 4 + 21 files changed, 479 insertions(+), 13 deletions(-) create mode 100644 crates/codegen/runtime/cargo/src/runtime/bindings_builder.rs.jinja2 create mode 100644 crates/codegen/runtime/cargo/src/runtime/generated/bindings_builder.rs delete mode 100644 crates/solidity/inputs/graph/Cargo.toml delete mode 100644 crates/solidity/inputs/graph/src/lib.rs rename crates/solidity/inputs/{graph/stack-graphs.msgb => language/bindings/stack-graph.msgb} (100%) create mode 100644 crates/solidity/outputs/cargo/slang_solidity/generated/stack-graph.msgb create mode 100644 crates/solidity/outputs/cargo/slang_solidity/src/generated/generated/bindings_builder.rs create mode 100644 crates/testlang/outputs/cargo/slang_testlang/src/generated/generated/bindings_builder.rs diff --git a/Cargo.toml b/Cargo.toml index b7aeb7a28..a44625caa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,6 @@ slang_solidity = { path = "crates/solidity/outputs/cargo/slang_solidity" } slang_solidity_node_addon = { path = "crates/solidity/outputs/cargo/slang_solidity_node_addon" } solidity_cargo_tests = { path = "crates/solidity/outputs/cargo/tests" } solidity_language = { path = "crates/solidity/inputs/language" } -solidity_stack_graph = { path = "crates/solidity/inputs/graph" } solidity_npm_package = { path = "crates/solidity/outputs/npm/package" } solidity_spec = { path = "crates/solidity/outputs/spec" } solidity_testing_sanctuary = { path = "crates/solidity/testing/sanctuary" } diff --git a/crates/codegen/language/definition/src/model/manifest.rs b/crates/codegen/language/definition/src/model/manifest.rs index 92158ab15..c98d6c9c0 100644 --- a/crates/codegen/language/definition/src/model/manifest.rs +++ b/crates/codegen/language/definition/src/model/manifest.rs @@ -14,6 +14,7 @@ pub struct Language { pub name: Identifier, pub documentation_dir: PathBuf, + pub bindings_graph_builder_path: Option, pub root_item: Identifier, pub leading_trivia: TriviaParser, diff --git a/crates/codegen/language/tests/src/pass/tiny_language.rs b/crates/codegen/language/tests/src/pass/tiny_language.rs index d39f12acf..9dbd976ef 100644 --- a/crates/codegen/language/tests/src/pass/tiny_language.rs +++ b/crates/codegen/language/tests/src/pass/tiny_language.rs @@ -47,6 +47,7 @@ fn definition() { Language { name: "Tiny".into(), documentation_dir: Path::repo_path("tiny/docs"), + bindings_graph_builder_path: None, root_item: "Foo".into(), leading_trivia: TriviaParser::Sequence { parsers: [].into() }, trailing_trivia: TriviaParser::Sequence { parsers: [].into() }, diff --git a/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs b/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs index 087b85e9b..3732e198b 100644 --- a/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs @@ -9,3 +9,12 @@ pub mod stack_graph { pub type Builder<'a> = stack_graph::Builder<'a, KindTypes>; pub type StackGraphLanguage = stack_graph::StackGraphLanguage; } + +use metaslang_graph_builder::ParseError; + +use super::bindings_builder; +use super::graph_builder::File as GraphBuilderFile; + +pub fn get_stack_graph_builder() -> Result { + GraphBuilderFile::from_str(bindings_builder::GRAPH_BUILDER_SOURCE) +} diff --git a/crates/codegen/runtime/cargo/src/runtime/bindings_builder.rs.jinja2 b/crates/codegen/runtime/cargo/src/runtime/bindings_builder.rs.jinja2 new file mode 100644 index 000000000..c51134b9a --- /dev/null +++ b/crates/codegen/runtime/cargo/src/runtime/bindings_builder.rs.jinja2 @@ -0,0 +1,9 @@ +// TODO: we will want to disable all the bindings API if the language doesn't +// have a .msgb stack graph builder + +pub const GRAPH_BUILDER_SOURCE: &str = +{%- if model.bindings.graph_builder_path -%} + include_str!("{{ model.bindings.graph_builder_path }}"); +{%- else -%} + ""; +{%- endif -%} diff --git a/crates/codegen/runtime/cargo/src/runtime/generated/bindings_builder.rs b/crates/codegen/runtime/cargo/src/runtime/generated/bindings_builder.rs new file mode 100644 index 000000000..e90d27802 --- /dev/null +++ b/crates/codegen/runtime/cargo/src/runtime/generated/bindings_builder.rs @@ -0,0 +1,6 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +// TODO: we will want to disable all the bindings API if the language doesn't +// have a .msgb stack graph builder + +pub const GRAPH_BUILDER_SOURCE: &str = ""; diff --git a/crates/codegen/runtime/cargo/src/runtime/mod.rs b/crates/codegen/runtime/cargo/src/runtime/mod.rs index d1bb6664b..e09ca0043 100644 --- a/crates/codegen/runtime/cargo/src/runtime/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/mod.rs @@ -92,3 +92,7 @@ pub mod graph_builder { #[cfg(feature = "__graph_builder")] pub mod bindings; + +#[cfg(feature = "__graph_builder")] +#[path = "generated/bindings_builder.rs"] +mod bindings_builder; diff --git a/crates/codegen/runtime/generator/src/lib.rs b/crates/codegen/runtime/generator/src/lib.rs index ee3b42b69..81baddf9b 100644 --- a/crates/codegen/runtime/generator/src/lib.rs +++ b/crates/codegen/runtime/generator/src/lib.rs @@ -1,7 +1,8 @@ use std::path::{Path, PathBuf}; use std::rc::Rc; +use std::{fs, io}; -use anyhow::Result; +use anyhow::{Context, Result}; use codegen_language_definition::model::Language; use infra_utils::cargo::CargoWorkspace; use infra_utils::codegen::CodegenTemplates; @@ -40,6 +41,27 @@ impl OutputLanguage { templates.render_directory(model, output_dir) } + pub fn copy_resources(&self, language: &Rc, output_dir: &Path) -> Result<()> { + if !matches!(self, Self::Cargo) { + return Ok(()); + } + + // Copy the bindings stack graph builder file if any + if let Some(graph_builder_path) = &language.bindings_graph_builder_path { + let graph_builder_filename = graph_builder_path.file_name().ok_or(io::Error::new( + io::ErrorKind::InvalidData, + "expected a filename", + ))?; + let output_path = output_dir.join(graph_builder_filename); + fs::create_dir_all(output_dir)?; + fs::copy(graph_builder_path, &output_path).with_context(|| { + format!("Failed to copy {graph_builder_path:?} into {output_path:?}") + })?; + } + + Ok(()) + } + pub fn generate_stubs(&self) -> Result<()> { let model = ModelWrapper { rendering_in_stubs: true, diff --git a/crates/codegen/runtime/generator/src/model.rs b/crates/codegen/runtime/generator/src/model.rs index cdc806110..d5481afd5 100644 --- a/crates/codegen/runtime/generator/src/model.rs +++ b/crates/codegen/runtime/generator/src/model.rs @@ -1,4 +1,5 @@ use std::collections::BTreeSet; +use std::path::PathBuf; use std::rc::Rc; use codegen_language_definition::model::Language; @@ -17,6 +18,7 @@ pub struct RuntimeModel { parser: ParserModel, ast: AstModel, kinds: KindsModel, + bindings: BindingsModel, } impl RuntimeModel { @@ -27,6 +29,25 @@ impl RuntimeModel { ast: AstModel::create(language), parser: ParserModel::from_language(language), kinds: KindsModel::create(language), + bindings: BindingsModel::create(language), + } + } +} + +#[derive(Default, Serialize)] +struct BindingsModel { + graph_builder_path: Option, +} + +impl BindingsModel { + fn create(language: &Rc) -> Self { + let graph_builder_path = language.bindings_graph_builder_path.as_ref().and_then(|path| { + let filename = path.file_name()?; + let path = PathBuf::from("..").join("..").join("generated").join(filename); + Some(path) + }); + Self { + graph_builder_path, } } } diff --git a/crates/solidity/inputs/graph/Cargo.toml b/crates/solidity/inputs/graph/Cargo.toml deleted file mode 100644 index 058b63ceb..000000000 --- a/crates/solidity/inputs/graph/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "solidity_stack_graph" -description = "Stack Graph builder for Solidity" -version.workspace = true -rust-version.workspace = true -edition.workspace = true -publish = false - -[lints] -workspace = true diff --git a/crates/solidity/inputs/graph/src/lib.rs b/crates/solidity/inputs/graph/src/lib.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/crates/solidity/inputs/graph/stack-graphs.msgb b/crates/solidity/inputs/language/bindings/stack-graph.msgb similarity index 100% rename from crates/solidity/inputs/graph/stack-graphs.msgb rename to crates/solidity/inputs/language/bindings/stack-graph.msgb diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 534453b2f..a5daf2a19 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -3,6 +3,7 @@ pub use solidity::SolidityDefinition; codegen_language_macros::compile!(Language( name = Solidity, documentation_dir = "crates/solidity/inputs/language/docs", + bindings_graph_builder_path = "crates/solidity/inputs/language/bindings/stack-graph.msgb", root_item = SourceUnit, // TODO(#638): For now this is on par with the DSL v1 definition to minimize the fallout. // We should replace this with the new definition from #629. diff --git a/crates/solidity/outputs/cargo/slang_solidity/build.rs b/crates/solidity/outputs/cargo/slang_solidity/build.rs index ba7114c8d..7438d8663 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/build.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/build.rs @@ -10,6 +10,8 @@ fn main() -> Result<()> { let language = SolidityDefinition::create(); let output_dir = CargoWorkspace::locate_source_crate("slang_solidity")?.join("src/generated"); + let resources_dir = CargoWorkspace::locate_source_crate("slang_solidity")?.join("generated"); - OutputLanguage::Cargo.generate_runtime(&language, &output_dir) + OutputLanguage::Cargo.generate_runtime(&language, &output_dir)?; + OutputLanguage::Cargo.copy_resources(&language, &resources_dir) } diff --git a/crates/solidity/outputs/cargo/slang_solidity/generated/stack-graph.msgb b/crates/solidity/outputs/cargo/slang_solidity/generated/stack-graph.msgb new file mode 100644 index 000000000..c1a7db0f9 --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity/generated/stack-graph.msgb @@ -0,0 +1,363 @@ +attribute node_definition = node => type = "pop_symbol", node_symbol = node, is_definition +attribute node_reference = node => type = "push_symbol", node_symbol = node, is_reference +attribute node_symbol = node => symbol = (source-text node), source_node = node +attribute pop_symbol = symbol => type = "pop_symbol", symbol = symbol +attribute push_symbol = symbol => type = "push_symbol", symbol = symbol +attribute symbol_definition = symbol => type = "pop_symbol", symbol = symbol, is_definition +attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, is_reference + +;; Generalities +;; - we will define two nodes for all meaningful CST nodes +;; - a lexical_scope node which will connect "upwards" towards the root of the CST +;; - a defs node to access the definitions reachable from each node (usually connecting "downwards") +;; - the pair will not be created for every CST node, as there is a lot of redundancy in the tree +;; - identifier nodes that are part of the definition of an artifact +;; will create graph nodes with the node_definition attributes +;; - identifier nodes that are references will create graph nodes with the node_reference attributes + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Source unit (aka .sol file) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@source_unit [SourceUnit] { + node @source_unit.lexical_scope + node @source_unit.defs +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Contract definitions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@contract [ContractDefinition] { + node @contract.lexical_scope + node @contract.defs +} + +@contract [ContractDefinition ... @name name: [Identifier] ...] { + node def + attr (def) node_definition = @name + + edge @contract.lexical_scope -> def + edge @contract.defs -> def +} + +;; Connect the contract to its containing source unit +@source_unit [SourceUnit ... [SourceUnitMembers + ... + [SourceUnitMember @contract [ContractDefinition]] + ... +] ...] { + edge @source_unit.defs -> @contract.defs + edge @contract.lexical_scope -> @source_unit.lexical_scope +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Interface definitions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@interface [InterfaceDefinition] { + node @interface.lexical_scope + node @interface.defs +} + +@interface [InterfaceDefinition ... @name name: [Identifier] ...] { + node def + attr (def) node_definition = @name + + edge @interface.lexical_scope -> def + edge @interface.defs -> def +} + +;; Connect the interface to its containing source unit +@source_unit [SourceUnit [SourceUnitMembers + ... + [SourceUnitMember @interface [InterfaceDefinition]] + ... +]] { + edge @source_unit.defs -> @interface.defs + edge @interface.lexical_scope -> @source_unit.lexical_scope +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Library definitions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@library [LibraryDefinition] { + node @library.lexical_scope + node @library.defs +} + +@library [LibraryDefinition ... @name name: [Identifier] ...] { + node def + attr (def) node_definition = @name + + edge @library.lexical_scope -> def + edge @library.defs -> def +} + +;; Connect the library to its containing source unit +@source_unit [SourceUnit [SourceUnitMembers + ... + [SourceUnitMember @library [LibraryDefinition]] + ... +]] { + edge @source_unit.defs -> @library.defs + edge @library.lexical_scope -> @source_unit.lexical_scope +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Function definitions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@function [FunctionDefinition] { + node @function.lexical_scope + node @function.defs +} + +@function [FunctionDefinition ... name: [FunctionName ... @name [Identifier] ...] ...] { + node def + attr (def) node_definition = @name + + edge @function.lexical_scope -> def + edge @function.defs -> def +} + +@param [Parameter] { + node @param.lexical_scope + node @param.defs +} + +@param [Parameter ... @name [Identifier]] { + node def + attr (def) node_definition = @name + + edge @param.lexical_scope -> def + edge @param.defs -> def +} + +;; Connect the parameters to the functions they belong to +@function [FunctionDefinition + ... + parameters: [_ ... parameters: [Parameters ... @param item: [Parameter] ...] ...] + ... +] { + edge @function.lexical_scope -> @param.defs + edge @function.defs -> @param.defs +} + +;; Connect the function to the contract/interface/library they belong to +[SourceUnitMember @unit_member variant: [_ + ... + members: [_ + ... + item: [_ @function variant: [FunctionDefinition]] + ... + ] + ... + ] +] { + edge @unit_member.lexical_scope -> @function.defs + edge @unit_member.defs -> @function.defs + edge @function.lexical_scope -> @unit_member.lexical_scope +} + +@body [FunctionBody] { + node @body.lexical_scope + node @body.defs +} + +;; Connect the function body to the function definition +@function [FunctionDefinition ... @body body: [FunctionBody] ...] { + edge @body.lexical_scope -> @function.lexical_scope + edge @function.defs -> @body.defs +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Blocks +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@block [Block] { + node @block.lexical_scope + node @block.defs +} + +@stmt [Statement] { + node @stmt.lexical_scope + node @stmt.defs +} + +@block [Block ... statements: [_ ... @stmt [Statement]...] ...] { + edge @stmt.lexical_scope -> @block.lexical_scope + edge @block.defs -> @stmt.defs +} + +@body [FunctionBody @block variant: [Block]] { + edge @block.lexical_scope -> @body.lexical_scope + edge @body.defs -> @block.defs +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Declaration Statements +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@stmt [Statement [VariableDeclarationStatement ... @name name: [Identifier] ...]] { + node def + attr (def) node_definition = @name + + edge @stmt.lexical_scope -> def + edge @stmt.defs -> def +} + +@stmt [Statement [TupleDeconstructionStatement + ... + [TupleDeconstructionElements + ... + item: [_ member: [_ variant: [_ ... @name name: [Identifier]]]] + ... + ] + ... +]] { + node def + attr (def) node_definition = @name + + edge @stmt.lexical_scope -> def + edge @stmt.defs -> def +} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; State Variables +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@state_var [StateVariableDefinition] { + node @state_var.lexical_scope + node @state_var.defs +} + +@state_var [StateVariableDefinition ... @name name: [Identifier] ...] { + node def + attr (def) node_definition = @name + + edge @state_var.lexical_scope -> def + edge @state_var.defs -> def +} + +[SourceUnitMember @unit_member variant: [_ + ... + members: [_ + ... + item: [_ @state_var variant: [StateVariableDefinition]] + ... + ] + ... + ] +] { + edge @unit_member.lexical_scope -> @state_var.defs + edge @unit_member.defs -> @state_var.defs + edge @state_var.lexical_scope -> @unit_member.lexical_scope +} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Structure definitions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@struct [StructDefinition] { + node @struct.lexical_scope + node @struct.defs +} + +@struct [StructDefinition ... @name name: [Identifier] ...] { + node def + attr (def) node_definition = @name + + edge @struct.lexical_scope -> def + edge @struct.defs -> def +} + +;; Connect the struct to the contract/interface/library they belong to +[SourceUnitMember @unit_member variant: [_ + ... + members: [_ + ... + item: [_ @struct variant: [StructDefinition]] + ... + ] + ... + ] +] { + edge @unit_member.lexical_scope -> @struct.defs + edge @unit_member.defs -> @struct.defs +} + +@member [StructMember] { + node @member.lexical_scope + node @member.defs +} + +@member item: [StructMember ... @name name: [Identifier] ...] { + node member + attr (member) pop_symbol = "." + edge @member.defs -> member + + node def + attr (def) node_definition = @name + edge member -> def +} + +;; TODO: missing connection between the struct field declarations and the struct + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; Expressions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +@expr [Expression] { + node @expr.lexical_scope +} + +@expr [Expression ... @name variant: [Identifier]] { + node ref + attr (ref) node_reference = @name + + edge ref -> @expr.lexical_scope +} + +@expr [Expression ... variant: [_ ... @child [Expression] ...] ...] { + edge @child.lexical_scope -> @expr.lexical_scope +} + +@stmt [Statement ... variant: [_ ... @expr [Expression] ...] ...] { + edge @expr.lexical_scope -> @stmt.lexical_scope +} + +@member [MemberAccess] { + node @member.lexical_scope +} + +@member [MemberAccess @name [Identifier]] { + node ref + attr (ref) node_reference = @name + + edge ref -> @member.lexical_scope +} + +[MemberAccessExpression + ... + @expr operand: [Expression] + ... + @member member: [MemberAccess] + ... +] { + node member + attr (member) push_symbol = "." + + edge @member.lexical_scope -> member + edge member -> @expr.lexical_scope +} \ No newline at end of file diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/bindings/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/bindings/mod.rs index afb53ee1e..a50f8f8c9 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/bindings/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/bindings/mod.rs @@ -11,3 +11,12 @@ pub mod stack_graph { pub type Builder<'a> = stack_graph::Builder<'a, KindTypes>; pub type StackGraphLanguage = stack_graph::StackGraphLanguage; } + +use metaslang_graph_builder::ParseError; + +use super::bindings_builder; +use super::graph_builder::File as GraphBuilderFile; + +pub fn get_stack_graph_builder() -> Result { + GraphBuilderFile::from_str(bindings_builder::GRAPH_BUILDER_SOURCE) +} diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/generated/bindings_builder.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/generated/bindings_builder.rs new file mode 100644 index 000000000..27b497361 --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/generated/bindings_builder.rs @@ -0,0 +1,6 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +// TODO: we will want to disable all the bindings API if the language doesn't +// have a .msgb stack graph builder + +pub const GRAPH_BUILDER_SOURCE: &str = include_str!("../../generated/stack-graph.msgb"); diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs index e69206fd0..b9a03ec37 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs @@ -94,3 +94,7 @@ pub mod graph_builder { #[cfg(feature = "__graph_builder")] pub mod bindings; + +#[cfg(feature = "__graph_builder")] +#[path = "generated/bindings_builder.rs"] +mod bindings_builder; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/bindings/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/bindings/mod.rs index afb53ee1e..a50f8f8c9 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/bindings/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/bindings/mod.rs @@ -11,3 +11,12 @@ pub mod stack_graph { pub type Builder<'a> = stack_graph::Builder<'a, KindTypes>; pub type StackGraphLanguage = stack_graph::StackGraphLanguage; } + +use metaslang_graph_builder::ParseError; + +use super::bindings_builder; +use super::graph_builder::File as GraphBuilderFile; + +pub fn get_stack_graph_builder() -> Result { + GraphBuilderFile::from_str(bindings_builder::GRAPH_BUILDER_SOURCE) +} diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/generated/bindings_builder.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/generated/bindings_builder.rs new file mode 100644 index 000000000..e90d27802 --- /dev/null +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/generated/bindings_builder.rs @@ -0,0 +1,6 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +// TODO: we will want to disable all the bindings API if the language doesn't +// have a .msgb stack graph builder + +pub const GRAPH_BUILDER_SOURCE: &str = ""; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs index e69206fd0..b9a03ec37 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs @@ -94,3 +94,7 @@ pub mod graph_builder { #[cfg(feature = "__graph_builder")] pub mod bindings; + +#[cfg(feature = "__graph_builder")] +#[path = "generated/bindings_builder.rs"] +mod bindings_builder;