Skip to content

Commit

Permalink
Collect Expression from asm register decls (FuelLabs#4128)
Browse files Browse the repository at this point in the history
## Description
Collects `Expression` variants in `AsmRegisterDeclaration` and
`TyAsmRegisterDeclaration` if there are any.

Closes FuelLabs#3715
  • Loading branch information
JoshuaBatty authored Feb 20, 2023
1 parent 44aa2e2 commit 5c4da9b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions sway-core/src/language/parsed/expression/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use sway_types::{ident::Ident, span::Span};

#[derive(Debug, Clone)]
pub struct AsmExpression {
pub(crate) registers: Vec<AsmRegisterDeclaration>,
pub registers: Vec<AsmRegisterDeclaration>,
pub(crate) body: Vec<AsmOp>,
pub(crate) returns: Option<(AsmRegister, Span)>,
pub(crate) return_type: TypeInfo,
pub(crate) whole_block_span: Span,
}

#[derive(Debug, Clone)]
pub(crate) struct AsmRegisterDeclaration {
pub struct AsmRegisterDeclaration {
pub(crate) name: Ident,
pub(crate) initializer: Option<Expression>,
pub initializer: Option<Expression>,
}
2 changes: 1 addition & 1 deletion sway-core/src/language/ty/expression/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{engine_threading::*, language::ty::*, type_system::*};

#[derive(Clone, Debug)]
pub struct TyAsmRegisterDeclaration {
pub(crate) initializer: Option<TyExpression>,
pub initializer: Option<TyExpression>,
pub(crate) name: Ident,
}

Expand Down
8 changes: 6 additions & 2 deletions sway-lsp/src/traverse/parsed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,12 @@ impl<'a> ParsedTree<'a> {
self.handle_expression(&branch.result);
}
}
ExpressionKind::Asm(_) => {
//TODO handle asm expressions
ExpressionKind::Asm(asm) => {
for register in &asm.registers {
if let Some(initializer) = &register.initializer {
self.handle_expression(initializer);
}
}
}
ExpressionKind::MethodApplication(method_application_expression) => {
let MethodApplicationExpression {
Expand Down
8 changes: 7 additions & 1 deletion sway-lsp/src/traverse/typed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,13 @@ impl<'a> TypedTree<'a> {
self.handle_expression(r#else, namespace);
}
}
ty::TyExpressionVariant::AsmExpression { .. } => {}
ty::TyExpressionVariant::AsmExpression { registers, .. } => {
for register in registers {
if let Some(initializer) = &register.initializer {
self.handle_expression(initializer, namespace);
}
}
}
ty::TyExpressionVariant::StructFieldAccess {
prefix,
field_to_access,
Expand Down

0 comments on commit 5c4da9b

Please sign in to comment.