Skip to content

Commit

Permalink
Fix typename case updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhiteninja committed Feb 17, 2023
1 parent 32e5f8b commit 67e713c
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions modules/optimizations/simplifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,31 @@ def opt_type_constraint_from_convert(ast):


def opt_type_constraint_case(ast):
def get_new_value(t):
new_val = t
new_val = ".".join(
[BAREWORDS[t.lower()] if t.lower() in BAREWORDS else t for t in new_val.split(".")])
new_val = "-".join(
[BAREWORDS[t.lower()] if t.lower() in BAREWORDS else t for t in new_val.split("-")])
return new_val

for node in ast.iter():
if node.tag in ["TypeConstraintAst", "TypeExpressionAst"]:
typename = node.attrib["TypeName"]
if node.tag == "ConvertExpressionAst":
typename = node.attrib["StaticType"]
new_value = get_new_value(typename)

if typename != new_value:
node.attrib["StaticType"] = new_value
log_debug("Fix typename case from '%s' to '%s'" % (typename, new_value))
return True

new_value = typename
new_value = ".".join(
[BAREWORDS[t.lower()] if t.lower() in BAREWORDS else t for t in new_value.split(".")])
new_value = "-".join(
[BAREWORDS[t.lower()] if t.lower() in BAREWORDS else t for t in new_value.split("-")])
elif node.tag in ["TypeConstraintAst", "TypeExpressionAst"]:
typename = node.attrib["TypeName"]
new_value = get_new_value(typename)

if typename != new_value:
node.attrib["TypeName"] = new_value

log_debug("Fix typename case from '%s' to '%s'" % (typename, new_value))

return True

return False
Expand Down

0 comments on commit 67e713c

Please sign in to comment.