diff options
| author | Cliff Click <cliffc@acm.org> | 2023-10-26 14:28:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-26 14:28:36 -0700 |
| commit | 0049146baf2502809ed3f29b07cc5f90513cb747 (patch) | |
| tree | 946ce628b8c9e630a33b681f768177650249b23c /chapter04/src/test/java | |
| parent | ed7e01a7bf7b038a38d975358e85fb3d281b47bb (diff) | |
| download | Simple-0049146baf2502809ed3f29b07cc5f90513cb747.tar.gz Simple-0049146baf2502809ed3f29b07cc5f90513cb747.zip | |
Replace Parser scopes with ScopeNode (#14)
Fixes #12
* Replace Parser scopes with ScopeNode
Basically move the Stack of HashMaps to a ScopeNode, with wrappers.
The HashMap maps String names to Integer indices; inputs to the ScopeNode.
This way, the ScopeNode keeps alive Nodes that are only alive because they are alive in the HashMap.
Fix bug isDead -> isUnused in deadCodeElim.
Support routines for adding/removing edges in ScopeNode.
Set $ctrl to null after a Return; there is no control.
Regression tests.
* One more test case
Diffstat (limited to 'chapter04/src/test/java')
| -rw-r--r-- | chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java index 988e3608..8cc78af0 100644 --- a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java +++ b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java @@ -99,6 +99,20 @@ public class Chapter04Test { } @Test + public void testChapter4Bug1() { + Parser parser = new Parser("int a=arg+1; int b=a; b=1; return a+2; #showGraph;", TypeInteger.BOT); + ReturnNode ret = parser.parse(); + assertEquals("return (Proj_3+3);", ret.print()); + } + + @Test + public void testChapter4Bug2() { + Parser parser = new Parser("int a=arg+1; a=a; return a; #showGraph;", TypeInteger.BOT); + ReturnNode ret = parser.parse(); + assertEquals("return (Proj_3+1);", ret.print()); + } + + @Test public void testVarDecl() { Parser parser = new Parser("int a=1; return a;"); ReturnNode ret = parser.parse(); @@ -135,6 +149,13 @@ public class Chapter04Test { assertEquals("return 8;", ret.print()); } + @Test + public void testSelfAssign() { + exceptionRule.expect(RuntimeException.class); + exceptionRule.expectMessage("Undefined name 'a'"); + new Parser("int a=a; return a;").parse(); + } + @Test public void testChapter2ParseGrammar() { |
