],
)
+NormalNegationExpression = collections.namedtuple(
+ 'NormalNegationExpression',
+ [
+ 'internal_expression',
+ ],
+)
+
NormalInfixExpression = collections.namedtuple(
'NormalInfixExpression',
[
'or_level': normalize_boolean_expression,
}[expression.order](counter, expression)
+def normalize_negation_expression(counter, expression):
+ counter, prestatements, internal_expression = normalize_expression(counter, expression.value)
+
+ internal_variable = '${}'.format(counter)
+ counter += 1
+
+ return (
+ counter,
+ prestatements + (NormalVariableInitializationStatement(variable=internal_variable, expression=internal_expression),),
+ NormalNegationExpression(internal_expression=NormalVariableExpression(variable=internal_variable)),
+ )
+
+def normalize_parenthesized_expression(counter, expression):
+ return normalize_expression(counter, expression.internal)
+
def normalize_expression(counter, expression):
return {
NormalInfixExpression: fake_normalization,
parsing.FurFunctionCallExpression: normalize_function_call_expression,
parsing.FurInfixExpression: normalize_infix_expression,
parsing.FurIntegerLiteralExpression: fake_normalization,
- parsing.FurNegationExpression: fake_normalization, # TODO Don't fake this
- parsing.FurParenthesizedExpression: fake_normalization, # TODO Don't fake this
+ parsing.FurNegationExpression: normalize_negation_expression,
+ parsing.FurParenthesizedExpression: normalize_parenthesized_expression,
parsing.FurStringLiteralExpression: fake_normalization,
parsing.FurSymbolExpression: fake_normalization,
}[type(expression)](counter, expression)
parsing.FurInfixExpression: transform_infix_expression, # TODO Shouldn't need this
normalization.NormalFunctionCallExpression: transform_function_call_expression,
normalization.NormalInfixExpression: transform_infix_expression,
+ normalization.NormalNegationExpression: transform_negation_expression,
normalization.NormalVariableExpression: transform_variable_expression,
}[type(expression)](accumulators, expression)
),
)
-def transform_negation_expression(accumulators, negation_expression):
+def transform_negation_expression(accumulators, expression):
return CNegationExpression(
- value=transform_expression(accumulators, negation_expression.value),
+ value=transform_expression(accumulators, expression.internal_expression),
)
def transform_function_call_expression(accumulators, function_call):