summaryrefslogtreecommitdiff
path: root/chapter15/src/main/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-09-30 08:56:50 -0700
committerCliff Click <cliffc@acm.org>2024-10-06 08:56:22 -0700
commit31ba4ecbc5214b3c25917fd97d030bfd39a784a3 (patch)
tree75a11c32d9062ade79d531d25c0d8508996fcd5b /chapter15/src/main/java
parent6af26a247bf583f0a6a50f44539655367bf800bb (diff)
downloadSimple-31ba4ecbc5214b3c25917fd97d030bfd39a784a3.tar.gz
Simple-31ba4ecbc5214b3c25917fd97d030bfd39a784a3.zip
Fix 2 test cases
Diffstat (limited to 'chapter15/src/main/java')
-rw-r--r--chapter15/src/main/java/com/seaofnodes/simple/Parser.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/chapter15/src/main/java/com/seaofnodes/simple/Parser.java b/chapter15/src/main/java/com/seaofnodes/simple/Parser.java
index 2b09e943..d9726d28 100644
--- a/chapter15/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter15/src/main/java/com/seaofnodes/simple/Parser.java
@@ -489,13 +489,17 @@ public class Parser {
// Convert the type name to a type.
Type t0 = TYPES.get(tname);
Type t1 = t0==null ? TypeStruct.BOT : t0; // Null: assume a forward ref type
+ // Nest arrays as needed
while( match("[]") ) {
Type t2 = TYPES.get("[]"+tname);
if( t2==null ) {
TYPES.put("[]"+tname,t1 = TypeStruct.makeAry(TypeInteger.BOT,ALIAS++,t1,ALIAS++));
START.addMemProj((TypeStruct)t1, _scope); // Insert memory edges
+ } else {
+ t1 = t2;
}
}
+ // Handle trailing '?' for nullable
Type t2 = t1 instanceof TypeStruct obj ? TypeMemPtr.make(obj,match("?")) : t1;
// Check no forward ref
@@ -708,6 +712,10 @@ public class Parser {
private Node newArray(Type t) {
Node len = parseExpression().keep();
TypeStruct ary = (TypeStruct)TYPES.get("[]"+t.str());
+ if( ary == null ) {
+ TYPES.put("[]"+t.str(), ary = TypeStruct.makeAry(TypeInteger.BOT,ALIAS++,t,ALIAS++));
+ START.addMemProj(ary, _scope); // Insert memory edges
+ }
int base = ary.aryBase ();
int scale= ary.aryScale();
Node size = new AddNode(con(base),new ShlNode(len,con(scale)).peephole()).peephole();