Skip to content

Commit

Permalink
change ConditionStatement to ConditionalStatement (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashrick12 authored Feb 27, 2024
1 parent e6ee7f7 commit c30fae4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion glitch/analysis/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def get_line(i ,lines):

return errors

def check_condition(self, c: ConditionStatement, file: str) -> list[Error]:
def check_condition(self, c: ConditionalStatement, file: str) -> list[Error]:
return super().check_condition(c, file)

def check_atomicunit(self, au: AtomicUnit, file: str) -> list[Error]:
Expand Down
4 changes: 2 additions & 2 deletions glitch/analysis/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def check_element(self, c, file: str) -> list[Error]:
return self.check_attribute(c, file)
elif isinstance(c, Variable):
return self.check_variable(c, file)
elif isinstance(c, ConditionStatement):
elif isinstance(c, ConditionalStatement):
return self.check_condition(c, file)
elif isinstance(c, Comment):
return self.check_comment(c, file)
Expand Down Expand Up @@ -173,7 +173,7 @@ def check_attribute(self, a: Attribute, file: str) -> list[Error]:
def check_variable(self, v: Variable, file: str) -> list[Error]:
pass

def check_condition(self, c: ConditionStatement, file: str) -> list[Error]:
def check_condition(self, c: ConditionalStatement, file: str) -> list[Error]:
errors = []

for s in c.statements:
Expand Down
4 changes: 2 additions & 2 deletions glitch/analysis/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def check_atomicunit(self, au: AtomicUnit, file: str) -> List[Error]:
continue
for a in au.attributes:
values = [a.value]
if isinstance(a.value, ConditionStatement):
if isinstance(a.value, ConditionalStatement):
statements = a.value.statements
if len(statements) == 0:
continue
Expand Down Expand Up @@ -198,7 +198,7 @@ def check_comment(self, c: Comment, file: str) -> List[Error]:
break
return errors

def check_condition(self, c: ConditionStatement, file: str) -> List[Error]:
def check_condition(self, c: ConditionalStatement, file: str) -> List[Error]:
errors = super().check_condition(c, file)

condition = c
Expand Down
30 changes: 15 additions & 15 deletions glitch/parsers/cmof.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,17 +840,17 @@ def is_case_condition(self, ast):
if (ChefParser._check_node(ast, ["when"], 3) \
or ChefParser._check_node(ast, ["when"], 2)):
if self.condition is None:
self.condition = ConditionStatement(
self.condition = ConditionalStatement(
self.case_head + " == " + ChefParser._get_content(ast.args[0][0], self.source),
ConditionStatement.ConditionType.SWITCH
ConditionalStatement.ConditionType.SWITCH
)
self.condition.code = ChefParser._get_source(ast, self.source)
self.condition.line = ChefParser._get_content_bounds(ast, self.source)[0]
self.current_condition = self.condition
else:
self.current_condition.else_statement = ConditionStatement(
self.current_condition.else_statement = ConditionalStatement(
self.case_head + " == " + ChefParser._get_content(ast.args[0][0], self.source),
ConditionStatement.ConditionType.SWITCH
ConditionalStatement.ConditionType.SWITCH
)
self.current_condition = self.current_condition.else_statement
self.current_condition.code = ChefParser._get_source(ast, self.source)
Expand All @@ -859,9 +859,9 @@ def is_case_condition(self, ast):
self.push([self.is_case_condition], ast.args[2])
return True
elif (ChefParser._check_node(ast, ["else"], 1)):
self.current_condition.else_statement = ConditionStatement(
self.current_condition.else_statement = ConditionalStatement(
"",
ConditionStatement.ConditionType.SWITCH,
ConditionalStatement.ConditionType.SWITCH,
is_default=True
)
self.current_condition.else_statement.code = \
Expand Down Expand Up @@ -1069,7 +1069,7 @@ def add_variable_to_unit_block(variable, unit_block_vars):
unit_block.add_unit_block(ce)
elif isinstance(ce, Attribute):
unit_block.add_attribute(ce)
elif isinstance(ce, ConditionStatement):
elif isinstance(ce, ConditionalStatement):
unit_block.add_statement(ce)
elif isinstance(ce, list):
for c in ce:
Expand Down Expand Up @@ -1334,14 +1334,14 @@ def process_hash_value(name: str, temp_value):
expressions = PuppetParser.__process_codeelement(match.expressions, path, code)
for expression in expressions:
if expression != "default":
condition = ConditionStatement(control + "==" + expression,
ConditionStatement.ConditionType.SWITCH, False)
condition = ConditionalStatement(control + "==" + expression,
ConditionalStatement.ConditionType.SWITCH, False)
condition.line, condition.column = match.line, match.col
condition.code = get_code(match)
conditions.append(condition)
else:
condition = ConditionStatement("",
ConditionStatement.ConditionType.SWITCH, True)
condition = ConditionalStatement("",
ConditionalStatement.ConditionType.SWITCH, True)
condition.line, condition.column = match.line, match.col
condition.code = get_code(match)
conditions.append(condition)
Expand All @@ -1360,16 +1360,16 @@ def process_hash_value(name: str, temp_value):
value = PuppetParser.__process_codeelement(value_element, path, code)

if key != "default":
condition = ConditionStatement(control + "==" + key,
ConditionStatement.ConditionType.SWITCH, False)
condition = ConditionalStatement(control + "==" + key,
ConditionalStatement.ConditionType.SWITCH, False)
condition.line, condition.column = key_element.line, key_element.col
# HACK: the get_code function should be changed to receive a range
key_element.end_line, key_element.end_col = value_element.end_line, value_element.end_col
condition.code = get_code(key_element)
conditions.append(condition)
else:
condition = ConditionStatement("",
ConditionStatement.ConditionType.SWITCH, True)
condition = ConditionalStatement("",
ConditionalStatement.ConditionType.SWITCH, True)
condition.line, condition.column = key_element.line, key_element.col
key_element.end_line, key_element.end_col = value_element.end_line, value_element.end_col
condition.code = get_code(key_element)
Expand Down
2 changes: 1 addition & 1 deletion glitch/repr/inter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self) -> None:
def add_statement(self, statement):
self.statements.append(statement)

class ConditionStatement(Block):
class ConditionalStatement(Block):
class ConditionType(Enum):
IF = 1
SWITCH = 2
Expand Down
6 changes: 3 additions & 3 deletions glitch/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def compute(self, c):
self.compute_attribute(c)
elif isinstance(c, Variable):
self.compute_variable(c)
elif isinstance(c, ConditionStatement):
elif isinstance(c, ConditionalStatement):
self.compute_condition(c)
elif isinstance(c, Comment):
self.compute_comment(c)
Expand Down Expand Up @@ -57,7 +57,7 @@ def compute_variable(self, v: Variable):
pass

@abstractmethod
def compute_condition(self, c: ConditionStatement):
def compute_condition(self, c: ConditionalStatement):
pass

@abstractmethod
Expand Down Expand Up @@ -107,7 +107,7 @@ def compute_attribute(self, a: Attribute):
def compute_variable(self, v: Variable):
pass

def compute_condition(self, c: ConditionStatement):
def compute_condition(self, c: ConditionalStatement):
pass

def compute_comment(self, c: Comment):
Expand Down

0 comments on commit c30fae4

Please sign in to comment.