Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more proper code mappings in starknet plugins. #6227

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/cairo-lang-defs/src/patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl RewriteNode {
Self::Text(text.to_string())
}

pub fn mapped_text(text: &str, origin: TextSpan) -> Self {
RewriteNode::Text(text.to_string()).mapped(origin)
pub fn mapped_text(text: &str, db: &dyn SyntaxGroup, origin: &impl TypedSyntaxNode) -> Self {
RewriteNode::Text(text.to_string()).mapped(db, origin)
}

pub fn empty() -> Self {
Expand Down Expand Up @@ -203,8 +203,11 @@ impl RewriteNode {
}

/// Creates a new rewrite node wrapped in a mapping to the original code.
pub fn mapped(self, origin: TextSpan) -> Self {
RewriteNode::Mapped { origin, node: Box::new(self) }
pub fn mapped(self, db: &dyn SyntaxGroup, origin: &impl TypedSyntaxNode) -> Self {
RewriteNode::Mapped {
origin: origin.as_syntax_node().span_without_trivia(db),
node: Box::new(self),
}
}
}
impl Default for RewriteNode {
Expand Down
11 changes: 8 additions & 3 deletions crates/cairo-lang-semantic/src/inline_macros/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ impl FormattingInfo {
&mut pending_chars,
RewriteNode::mapped_text(
&format!("__write_macro_arg{positional}__"),
arg.as_syntax_node().span_without_trivia(builder.db),
builder.db,
arg,
),
argument_info.formatting_trait,
);
Expand All @@ -297,7 +298,8 @@ impl FormattingInfo {
&mut pending_chars,
RewriteNode::mapped_text(
&format!("__write_macro_arg{i}__"),
self.args[i].as_syntax_node().span_without_trivia(builder.db),
builder.db,
&self.args[i],
),
argument_info.formatting_trait,
);
Expand All @@ -315,7 +317,10 @@ impl FormattingInfo {
&mut pending_chars,
RewriteNode::new_modified(vec![
RewriteNode::text("@"),
RewriteNode::mapped_text(&argument, TextSpan { start, end }),
RewriteNode::Mapped {
origin: TextSpan { start, end },
node: RewriteNode::text(&argument).into(),
},
]),
argument_info.formatting_trait,
);
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-lang-starknet/src/plugin/derive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use cairo_lang_defs::patcher::PatchBuilder;
use cairo_lang_defs::plugin::{
DynGeneratedFileAuxData, MacroPluginMetadata, PluginGeneratedFile, PluginResult,
};
use cairo_lang_syntax::node::ast;
use cairo_lang_syntax::node::db::SyntaxGroup;
use cairo_lang_syntax::node::helpers::QueryAttrs;
use cairo_lang_syntax::node::{ast, TypedSyntaxNode};

use super::consts::{EVENT_TRAIT, STORE_TRAIT};
use super::utils::has_derive;
Expand All @@ -31,13 +31,13 @@ pub fn handle_derive(
if let Some((node, starknet_aux_data)) =
event::handle_event_derive(db, &item_ast, &mut diagnostics)
{
builder.add_modified(node.mapped(derive_arg.as_syntax_node().span_without_trivia(db)));
builder.add_modified(node.mapped(db, &derive_arg));
aux_data = Some(DynGeneratedFileAuxData::new(starknet_aux_data));
}
}
if let Some(derive_arg) = has_derive(&item_ast, db, STORE_TRAIT) {
if let Some(node) = store::handle_store_derive(db, &item_ast, &mut diagnostics, metadata) {
builder.add_modified(node.mapped(derive_arg.as_syntax_node().span_without_trivia(db)));
builder.add_modified(node.mapped(db, &derive_arg));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-starknet/src/plugin/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ fn generate_entry_point_wrapper(
("implicit_precedence".to_string(), implicit_precedence),
]
.into(),
))
).mapped(db, function))
}

/// Validates the first parameter of an L1 handler is `from_address: felt252` or `_from_address:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,18 +1005,18 @@ impl LogIsEvent of starknet::Event<Log> {
}


lib.cairo:6:1
#[starknet::component]
^********************^
lib.cairo:11:5
#[storage]
^********^
impls:

impl StorageStorageBaseDrop of core::traits::Drop::<StorageStorageBase>;
impl StorageStorageBaseCopy of core::traits::Copy::<StorageStorageBase>;


lib.cairo:6:1
#[starknet::component]
^********************^
lib.cairo:11:5
#[storage]
^********^
impls:

impl StorageStorageBaseMutDrop of core::traits::Drop::<StorageStorageBaseMut>;
Expand Down Expand Up @@ -1103,6 +1103,6 @@ warning: Usage of deprecated feature `"deprecated_legacy_map"` with no `#[featur
^*******^

warning: Usage of deprecated feature `"deprecated_legacy_map"` with no `#[feature("deprecated_legacy_map")]` attribute. Note: "Use `starknet::storage::Map` instead."
--> lib.cairo:6:1
#[starknet::component]
^********************^
--> lib.cairo:11:5
#[storage]
^********^
Loading