Skip to content

Commit

Permalink
Add Span to break and continue declarations (FuelLabs#2213)
Browse files Browse the repository at this point in the history
Add span to Break and Continue declarations

Co-authored-by: John Adler <[email protected]>
  • Loading branch information
mohammadfawaz and adlerjohn authored Jul 5, 2022
1 parent f9fb2a8 commit 8592e50
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions sway-core/src/control_flow_analysis/analyze_return_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn connect_declaration(
Ok(leaves.to_vec())
}
ErrorRecovery => Ok(leaves.to_vec()),
Break => {
Break { .. } => {
let entry_node = graph.add_node(node.into());
for leaf in leaves {
graph.add_edge(*leaf, entry_node, "".into());
Expand All @@ -274,7 +274,7 @@ fn connect_declaration(
None => Err(CompileError::BreakOutsideLoop { span }),
}
}
Continue => {
Continue { .. } => {
let entry_node = graph.add_node(node.into());
for leaf in leaves {
graph.add_edge(*leaf, entry_node, "".into());
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fn connect_declaration(
Ok(leaves.to_vec())
}
ErrorRecovery | GenericTypeForFunctionScope { .. } => Ok(leaves.to_vec()),
Break | Continue => Ok(vec![]),
Break { .. } | Continue { .. } => Ok(vec![]),
}
}

Expand Down
8 changes: 6 additions & 2 deletions sway-core/src/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,14 @@ fn item_to_ast_nodes(ec: &mut ErrorContext, item: Item) -> Result<Vec<AstNode>,
)]
}
ItemKind::Break(_) => {
vec![AstNodeContent::Declaration(Declaration::Break)]
vec![AstNodeContent::Declaration(Declaration::Break {
span: span.clone(),
})]
}
ItemKind::Continue(_) => {
vec![AstNodeContent::Declaration(Declaration::Continue)]
vec![AstNodeContent::Declaration(Declaration::Continue {
span: span.clone(),
})]
}
};
Ok(contents
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ fn compile_declarations(
| TypedDeclaration::GenericTypeForFunctionScope { .. }
| TypedDeclaration::StorageDeclaration(_)
| TypedDeclaration::ErrorRecovery
| TypedDeclaration::Break
| TypedDeclaration::Continue => (),
| TypedDeclaration::Break { .. }
| TypedDeclaration::Continue { .. } => (),
}
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ impl FnCompiler {
ast_block.contents.clone().into_iter().position(|r| {
matches!(
r.content,
TypedAstNodeContent::Declaration(TypedDeclaration::Break)
| TypedAstNodeContent::Declaration(TypedDeclaration::Continue)
TypedAstNodeContent::Declaration(TypedDeclaration::Break { .. })
| TypedAstNodeContent::Declaration(TypedDeclaration::Continue { .. })
)
});

Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/parse_tree/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ pub enum Declaration {
AbiDeclaration(AbiDeclaration),
ConstantDeclaration(ConstantDeclaration),
StorageDeclaration(StorageDeclaration),
Break,
Continue,
Break { span: sway_types::Span },
Continue { span: sway_types::Span },
}
29 changes: 16 additions & 13 deletions sway-core/src/semantic_analysis/ast_node/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub enum TypedDeclaration {
ErrorRecovery,
StorageDeclaration(TypedStorageDeclaration),
StorageReassignment(TypeCheckedStorageReassignment),
Break,
Continue,
Break { span: Span },
Continue { span: Span },
}

impl CopyTypes for TypedDeclaration {
Expand All @@ -57,10 +57,13 @@ impl CopyTypes for TypedDeclaration {
Reassignment(ref mut reassignment) => reassignment.copy_types(type_mapping),
ImplTrait(impl_trait) => impl_trait.copy_types(type_mapping),
// generics in an ABI is unsupported by design
AbiDeclaration(..) => (),
StorageDeclaration(..) => (),
StorageReassignment(..) => (),
GenericTypeForFunctionScope { .. } | ErrorRecovery | Break | Continue => (),
AbiDeclaration(..)
| StorageDeclaration(..)
| StorageReassignment(..)
| GenericTypeForFunctionScope { .. }
| ErrorRecovery
| Break { .. }
| Continue { .. } => (),
}
}
}
Expand All @@ -86,7 +89,7 @@ impl Spanned for TypedDeclaration {
ImplTrait(TypedImplTrait { span, .. }) => span.clone(),
StorageDeclaration(decl) => decl.span(),
StorageReassignment(decl) => decl.span(),
ErrorRecovery | GenericTypeForFunctionScope { .. } | Break | Continue => {
ErrorRecovery | GenericTypeForFunctionScope { .. } | Break { .. } | Continue { .. } => {
unreachable!("No span exists for these ast node types")
}
}
Expand Down Expand Up @@ -205,8 +208,8 @@ impl UnresolvedTypeCheck for TypedDeclaration {
| ImplTrait { .. }
| AbiDeclaration(_)
| GenericTypeForFunctionScope { .. }
| Break
| Continue => vec![],
| Break { .. }
| Continue { .. } => vec![],
}
}
}
Expand Down Expand Up @@ -373,8 +376,8 @@ impl TypedDeclaration {
ErrorRecovery => "error",
StorageDeclaration(_) => "contract storage declaration",
StorageReassignment(_) => "contract storage reassignment",
Break => "break",
Continue => "continue",
Break { .. } => "break",
Continue { .. } => "continue",
}
}

Expand Down Expand Up @@ -425,8 +428,8 @@ impl TypedDeclaration {
| StorageReassignment { .. }
| AbiDeclaration(..)
| ErrorRecovery
| Break
| Continue => Visibility::Public,
| Break { .. }
| Continue { .. } => Visibility::Public,
VariableDeclaration(TypedVariableDeclaration { is_mutable, .. }) => {
is_mutable.visibility()
}
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ impl TypedAstNode {
);
TypedDeclaration::StorageDeclaration(decl)
}
Declaration::Break => TypedDeclaration::Break,
Declaration::Continue => TypedDeclaration::Continue,
Declaration::Break { span } => TypedDeclaration::Break { span },
Declaration::Continue { span } => TypedDeclaration::Continue { span },
})
}
AstNodeContent::Expression(expr) => {
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ impl Dependencies {
deps.gather_from_typeinfo(type_info)
}),
// Nothing to do for `break` and `continue`
Declaration::Break => self,
Declaration::Continue => self,
Declaration::Break { .. } => self,
Declaration::Continue { .. } => self,
}
}

Expand Down Expand Up @@ -705,8 +705,8 @@ fn decl_name(decl: &Declaration) -> Option<DependentSymbol> {
// Storage cannot be depended upon or exported
Declaration::StorageDeclaration(_) => None,
// Nothing depends on a `break` and `continue`
Declaration::Break => None,
Declaration::Continue => None,
Declaration::Break { .. } => None,
Declaration::Continue { .. } => None,
}
}

Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/src/core/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ fn handle_declaration(declaration: Declaration, tokens: &mut Vec<Token>) {
tokens.push(token);
}
}
Declaration::Break => {}
Declaration::Continue => {}
Declaration::Break { .. } => {}
Declaration::Continue { .. } => {}
};
}

Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/src/core/traverse_typed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ fn handle_declaration(declaration: &TypedDeclaration, tokens: &mut TokenMap) {
}
handle_expression(&storage_reassignment.rhs, tokens);
}
TypedDeclaration::Break => {}
TypedDeclaration::Continue => {}
TypedDeclaration::Break { .. } => {}
TypedDeclaration::Continue { .. } => {}
}
}

Expand Down

0 comments on commit 8592e50

Please sign in to comment.