Permalink
Browse files

Change Return to BoolReturn in preparation for creating the Unary/Bin…

…aryFunction grammars, which have return statements but do not return booleans.
  • Loading branch information...
1 parent c4800b7 commit 5f9da73815eda89bcc4ed98493e9933634c00d10 Shoaib Kamil committed Dec 5, 2011
Showing with 14 additions and 13 deletions.
  1. +2 −1 pcb_operator_convert.py
  2. +2 −2 pcb_operator_sm.py
  3. +10 −10 tests/pcb_operator_convert_test.py
View
@@ -34,12 +34,13 @@ def visit_UnaryPredicate(self, node):
cpp_ast.Block(contents=[self.visit(node.body)]))
def visit_BinaryPredicate(self, node):
+ #FIXME: same problem as UnaryPredicate
return cpp_ast.FunctionBody(cpp_ast.Template("class T", cpp_ast.FunctionDeclaration(cpp_ast.Value("bool", "call"),
[cpp_ast.Reference(cpp_ast.Value("T", self.visit(x))) for x in node.inputs])),
cpp_ast.Block(contents=[self.visit(node.body)]))
- def visit_Return(self, node):
+ def visit_BoolReturn(self, node):
return cpp_ast.ReturnStatement(self.visit(node.value))
def visit_BoolConstant(self, node):
View
@@ -21,7 +21,7 @@
BoolExpr = BoolConstant
| IfExp
| Attribute
- | Return
+ | BoolReturn
| Compare
@@ -44,5 +44,5 @@
Attribute(value=Identifier, attr=Identifier)
-Return(value = BoolExpr)
+BoolReturn(value = BoolExpr)
''', globals())
@@ -9,7 +9,7 @@ def strip_whitespace(x):
class UnaryPredBasicConvertTests(unittest.TestCase):
def test_basic(self):
f = UnaryPredicate(input=Identifier(name="foo"),
- body=Return(value=BoolConstant(True)))
+ body=BoolReturn(value=BoolConstant(True)))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),
@@ -24,8 +24,8 @@ def test_basic(self):
def test_with_if(self):
f = UnaryPredicate(input=Identifier(name="foo"),
body=IfExp(test=BoolConstant(False),
- body=Return(value=BoolConstant(True)),
- orelse=Return(value=BoolConstant(False))))
+ body=BoolReturn(value=BoolConstant(True)),
+ orelse=BoolReturn(value=BoolConstant(False))))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),
@@ -47,8 +47,8 @@ def test_with_comparison(self):
body=IfExp(test=Compare(left=Attribute(value=Identifier("foo"), attr=Identifier("thing")),
op=ast.Eq(),
right=Constant(10)),
- body=Return(value=BoolConstant(True)),
- orelse=Return(value=BoolConstant(False))))
+ body=BoolReturn(value=BoolConstant(True)),
+ orelse=BoolReturn(value=BoolConstant(False))))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),
@@ -71,8 +71,8 @@ def test_with_binop(self):
right=Constant(10)),
op=ast.Eq(),
right=Constant(10)),
- body=Return(value=BoolConstant(True)),
- orelse=Return(value=BoolConstant(False))))
+ body=BoolReturn(value=BoolConstant(True)),
+ orelse=BoolReturn(value=BoolConstant(False))))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),
@@ -91,7 +91,7 @@ def test_with_binop(self):
class BinaryPredBasicConvertTests(unittest.TestCase):
def test_basic(self):
f = BinaryPredicate(inputs=[Identifier(name="foo"), Identifier(name="bar")],
- body=Return(value=BoolConstant(True)))
+ body=BoolReturn(value=BoolConstant(True)))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),
@@ -106,8 +106,8 @@ def test_basic(self):
def test_with_if(self):
f = BinaryPredicate(inputs=[Identifier(name="foo"), Identifier(name="bar")],
body=IfExp(test=BoolConstant(False),
- body=Return(value=BoolConstant(True)),
- orelse=Return(value=BoolConstant(False))))
+ body=BoolReturn(value=BoolConstant(True)),
+ orelse=BoolReturn(value=BoolConstant(False))))
out = PcbOperatorConvert().convert(f)
print out
self.assertEqual(strip_whitespace(out),

0 comments on commit 5f9da73

Please sign in to comment.