From d2791c7283be71f6f3103fbedfd709c4d0f70c59 Mon Sep 17 00:00:00 2001 From: Robert Obkircher Date: Sat, 5 Oct 2024 00:51:33 +0200 Subject: fix parsing nested structs --- .../src/main/java/com/seaofnodes/simple/node/StartNode.java | 3 +++ .../src/test/java/com/seaofnodes/simple/Chapter15Test.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) (limited to 'chapter15/src') diff --git a/chapter15/src/main/java/com/seaofnodes/simple/node/StartNode.java b/chapter15/src/main/java/com/seaofnodes/simple/node/StartNode.java index 14bf37f5..5964e19f 100644 --- a/chapter15/src/main/java/com/seaofnodes/simple/node/StartNode.java +++ b/chapter15/src/main/java/com/seaofnodes/simple/node/StartNode.java @@ -45,6 +45,9 @@ public class StartNode extends CFGNode implements MultiNode { n._type = args[f._alias]; scope.define(name, tm_decl, n); } + for (int i = 0; i < args.length; i++) + if (args[i] == null) + args[i] = Type.TOP; // We parsed a nested struct/array. Avoid nulls until a caller replaces this alias. _type = _args = TypeTuple.make(args); } diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java index dff39ba3..88924c52 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -181,6 +181,19 @@ return root; assertEquals("Obj{_kids=Obj<*Tree?[]>{#=2,[]=[Obj{_kids=null},null]}}", Evaluator.evaluate(stop, 0).toString()); } + @Test + public void testNestedStructAddMemProj() { + Parser parser = new Parser( +""" +struct S { + int a; + int[] b; +} +return 0; +"""); + StopNode stop = parser.parse(false); + assertEquals("return 0;", stop.toString()); + } @Test public void testRollingSum() { -- cgit v1.2.3