Skip to content

Commit

Permalink
Merge branch 'main' into ferra/gromet_wiring_detector
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentraymond-ua authored Dec 15, 2023
2 parents 4b66c84 + 0b4935f commit d5f4c61
Show file tree
Hide file tree
Showing 32 changed files with 1,207 additions and 302 deletions.
9 changes: 7 additions & 2 deletions skema/program_analysis/CAST/fortran/node_helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import itertools
from typing import List, Dict
from skema.program_analysis.CAST2FN.model.cast import SourceRef

from tree_sitter import Node

from skema.program_analysis.CAST2FN.model.cast import SourceRef

CONTROL_CHARACTERS = [
",",
"=",
Expand Down Expand Up @@ -41,7 +43,7 @@ def __init__(self, source: str, source_file_name: str):
# get_identifier optimization variables
self.source_lines = source.splitlines(keepends=True)
self.line_lengths = [len(line) for line in self.source_lines]
self.line_length_sums = [sum(self.line_lengths[:i+1]) for i in range(len(self.source_lines))]
self.line_length_sums = list(itertools.accumulate(self.line_lengths))#[sum(self.line_lengths[:i+1]) for i in range(len(self.source_lines))]

def get_source_ref(self, node: Node) -> SourceRef:
"""Given a node and file name, return a CAST SourceRef object."""
Expand Down Expand Up @@ -96,6 +98,9 @@ def get_children_by_types(node: Node, types: List):
"""Takes in a node and a list of types as inputs and returns all children matching those types. Otherwise, return an empty list"""
return [child for child in node.children if child.type in types]

def get_children_except_types(node: Node, types: List):
"""Takes in a node and a list of types as inputs and returns all children not matching those types. Otherwise, return an empty list"""
return [child for child in node.children if child.type not in types]

def get_first_child_index(node, type: str):
"""Get the index of the first child of node with type type."""
Expand Down
Loading

0 comments on commit d5f4c61

Please sign in to comment.