Skip to content

Commit

Permalink
Fix HllParseTree type (FuelLabs#447)
Browse files Browse the repository at this point in the history
* fix HllParseTree type

* Add name to TreeType::Library

* replace HllParseTreeKind with TreeType

* run rustfmt
  • Loading branch information
canndrew authored Dec 9, 2021
1 parent 1f3cfb5 commit e77027e
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 375 deletions.
20 changes: 10 additions & 10 deletions core_lang/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'sc> ControlFlowGraph<'sc> {

pub(crate) fn append_to_dead_code_graph(
ast: &TypedParseTree<'sc>,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
graph: &mut ControlFlowGraph<'sc>,
// the `Result` return is just to handle `Unimplemented` errors
) -> Result<(), CompileError<'sc>> {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'sc> ControlFlowGraph<'sc> {
.unwrap(),
]
}
TreeType::Contract | TreeType::Library => graph
TreeType::Contract | TreeType::Library { .. } => graph
.graph
.node_indices()
.filter(|i| match graph.graph[*i] {
Expand Down Expand Up @@ -184,7 +184,7 @@ fn connect_node<'sc>(
graph: &mut ControlFlowGraph<'sc>,
leaves: &[NodeIndex],
exit_node: Option<NodeIndex>,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
) -> Result<(Vec<NodeIndex>, Option<NodeIndex>), CompileError<'sc>> {
// let mut graph = graph.clone();
let span = node.span.clone();
Expand Down Expand Up @@ -319,7 +319,7 @@ fn connect_declaration<'sc>(
entry_node: NodeIndex,
span: Span<'sc>,
exit_node: Option<NodeIndex>,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
leaves: &[NodeIndex],
) -> Result<Vec<NodeIndex>, CompileError<'sc>> {
use TypedDeclaration::*;
Expand Down Expand Up @@ -384,7 +384,7 @@ fn connect_struct_declaration<'sc>(
struct_decl: &TypedStructDeclaration<'sc>,
graph: &mut ControlFlowGraph<'sc>,
entry_node: NodeIndex,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
) {
let TypedStructDeclaration {
name,
Expand All @@ -401,7 +401,7 @@ fn connect_struct_declaration<'sc>(
//
// this is important because if the struct is public, you want to be able to signal that all
// fields are accessible by just adding an edge to the struct declaration node
if [TreeType::Contract, TreeType::Library].contains(&tree_type)
if matches!(tree_type, TreeType::Contract | TreeType::Library { .. })
&& *visibility == Visibility::Public
{
for (_name, node) in &field_nodes {
Expand All @@ -426,7 +426,7 @@ fn connect_impl_trait<'sc>(
graph: &mut ControlFlowGraph<'sc>,
methods: &[TypedFunctionDeclaration<'sc>],
entry_node: NodeIndex,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
) -> Result<(), CompileError<'sc>> {
let graph_c = graph.clone();
let trait_decl_node = graph_c.namespace.find_trait(trait_name);
Expand Down Expand Up @@ -542,7 +542,7 @@ fn connect_typed_fn_decl<'sc>(
entry_node: NodeIndex,
span: Span<'sc>,
exit_node: Option<NodeIndex>,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
) -> Result<(), CompileError<'sc>> {
let fn_exit_node = graph.add_node(format!("\"{}\" fn exit", fn_decl.name.primary_name).into());
let (_exit_nodes, _exit_node) = depth_first_insertion_code_block(
Expand Down Expand Up @@ -577,7 +577,7 @@ fn depth_first_insertion_code_block<'sc>(
graph: &mut ControlFlowGraph<'sc>,
leaves: &[NodeIndex],
exit_node: Option<NodeIndex>,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
) -> Result<(Vec<NodeIndex>, Option<NodeIndex>), CompileError<'sc>> {
let mut leaves = leaves.to_vec();
let mut exit_node = exit_node;
Expand All @@ -597,7 +597,7 @@ fn connect_expression<'sc>(
leaves: &[NodeIndex],
exit_node: Option<NodeIndex>,
label: &'static str,
tree_type: TreeType,
tree_type: &TreeType<'sc>,
expression_span: Span<'sc>,
) -> Result<Vec<NodeIndex>, CompileError<'sc>> {
use TypedExpressionVariant::*;
Expand Down
Loading

0 comments on commit e77027e

Please sign in to comment.