From 14cdedba2d76b5562e08ad6d814b1d943ef0ac9e Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 10 May 2024 15:30:23 +0200 Subject: [PATCH] Don't reuse length variables in generated Lexer/Parser initialization --- .../java/org/sablecc/sablecc/lexer/Lexer.java | 30 +++++++------- .../org/sablecc/sablecc/parser/Parser.java | 40 +++++++++---------- .../resources/org/sablecc/sablecc/lexer.txt | 30 +++++++------- .../resources/org/sablecc/sablecc/parser.txt | 40 +++++++++---------- 4 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java index d5a7e59..fc0b4a3 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java +++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java @@ -906,17 +906,17 @@ public class Lexer DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read gotoTable - int length = s.readInt(); - gotoTable = new int[length][][][]; - for(int i = 0; i < gotoTable.length; i++) + int gotoTableLength1 = s.readInt(); + gotoTable = new int[gotoTableLength1][][][]; + for(int i = 0; i < gotoTableLength1; i++) { - length = s.readInt(); - gotoTable[i] = new int[length][][]; - for(int j = 0; j < gotoTable[i].length; j++) + int gotoTableLength2 = s.readInt(); + gotoTable[i] = new int[gotoTableLength2][][]; + for(int j = 0; j < gotoTableLength2; j++) { - length = s.readInt(); - gotoTable[i][j] = new int[length][3]; - for(int k = 0; k < gotoTable[i][j].length; k++) + int gotoTableLength3 = s.readInt(); + gotoTable[i][j] = new int[gotoTableLength3][3]; + for(int k = 0; k < gotoTableLength3; k++) { for(int l = 0; l < 3; l++) { @@ -927,13 +927,13 @@ public class Lexer } // read accept - length = s.readInt(); - accept = new int[length][]; - for(int i = 0; i < accept.length; i++) + int acceptLength1 = s.readInt(); + accept = new int[acceptLength1][]; + for(int i = 0; i < acceptLength1; i++) { - length = s.readInt(); - accept[i] = new int[length]; - for(int j = 0; j < accept[i].length; j++) + int acceptLength2 = s.readInt(); + accept[i] = new int[acceptLength2]; + for(int j = 0; j < acceptLength2; j++) { accept[i][j] = s.readInt(); } diff --git a/src/main/java/org/sablecc/sablecc/parser/Parser.java b/src/main/java/org/sablecc/sablecc/parser/Parser.java index bfa21aa..acaa05a 100644 --- a/src/main/java/org/sablecc/sablecc/parser/Parser.java +++ b/src/main/java/org/sablecc/sablecc/parser/Parser.java @@ -6270,13 +6270,13 @@ public class Parser implements IParser DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read actionTable - int length = s.readInt(); - actionTable = new int[length][][]; - for(int i = 0; i < actionTable.length; i++) + int actionTableLength1 = s.readInt(); + actionTable = new int[actionTableLength1][][]; + for(int i = 0; i < actionTableLength1; i++) { - length = s.readInt(); - actionTable[i] = new int[length][3]; - for(int j = 0; j < actionTable[i].length; j++) + int actionTableLength2 = s.readInt(); + actionTable[i] = new int[actionTableLength2][3]; + for(int j = 0; j < actionTableLength2; j++) { for(int k = 0; k < 3; k++) { @@ -6286,13 +6286,13 @@ public class Parser implements IParser } // read gotoTable - length = s.readInt(); - gotoTable = new int[length][][]; - for(int i = 0; i < gotoTable.length; i++) + int gotoTableLength1 = s.readInt(); + gotoTable = new int[gotoTableLength1][][]; + for(int i = 0; i < gotoTableLength1; i++) { - length = s.readInt(); - gotoTable[i] = new int[length][2]; - for(int j = 0; j < gotoTable[i].length; j++) + int gotoTableLength2 = s.readInt(); + gotoTable[i] = new int[gotoTableLength2][2]; + for(int j = 0; j < gotoTableLength2; j++) { for(int k = 0; k < 2; k++) { @@ -6302,14 +6302,14 @@ public class Parser implements IParser } // read errorMessages - length = s.readInt(); - errorMessages = new String[length]; - for(int i = 0; i < errorMessages.length; i++) + int errorMessagesLength = s.readInt(); + errorMessages = new String[errorMessagesLength]; + for(int i = 0; i < errorMessagesLength; i++) { - length = s.readInt(); + int errorMessageLength = s.readInt(); StringBuilder buffer = new StringBuilder(); - for(int j = 0; j < length; j++) + for(int j = 0; j < errorMessageLength; j++) { buffer.append(s.readChar()); } @@ -6317,9 +6317,9 @@ public class Parser implements IParser } // read errors - length = s.readInt(); - errors = new int[length]; - for(int i = 0; i < errors.length; i++) + int errorsLength = s.readInt(); + errors = new int[errorsLength]; + for(int i = 0; i < errorsLength; i++) { errors[i] = s.readInt(); } diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index 3b52417..3be7cbf 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -375,17 +375,17 @@ Macro:LexerTail DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read gotoTable - int length = s.readInt(); - gotoTable = new int[length][][][]; - for(int i = 0; i < gotoTable.length; i++) + int gotoTableLength1 = s.readInt(); + gotoTable = new int[gotoTableLength1][][][]; + for(int i = 0; i < gotoTableLength1; i++) { - length = s.readInt(); - gotoTable[i] = new int[length][][]; - for(int j = 0; j < gotoTable[i].length; j++) + int gotoTableLength2 = s.readInt(); + gotoTable[i] = new int[gotoTableLength2][][]; + for(int j = 0; j < gotoTableLength2; j++) { - length = s.readInt(); - gotoTable[i][j] = new int[length][3]; - for(int k = 0; k < gotoTable[i][j].length; k++) + int gotoTableLength3 = s.readInt(); + gotoTable[i][j] = new int[gotoTableLength3][3]; + for(int k = 0; k < gotoTableLength3; k++) { for(int l = 0; l < 3; l++) { @@ -396,13 +396,13 @@ Macro:LexerTail } // read accept - length = s.readInt(); - accept = new int[length][]; - for(int i = 0; i < accept.length; i++) + int acceptLength1 = s.readInt(); + accept = new int[acceptLength1][]; + for(int i = 0; i < acceptLength1; i++) { - length = s.readInt(); - accept[i] = new int[length]; - for(int j = 0; j < accept[i].length; j++) + int acceptLength2 = s.readInt(); + accept[i] = new int[acceptLength2]; + for(int j = 0; j < acceptLength2; j++) { accept[i][j] = s.readInt(); } diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 82ac796..c952614 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -434,13 +434,13 @@ Macro:ParserTail DataInputStream s = new DataInputStream(new BufferedInputStream(resStream)); // read actionTable - int length = s.readInt(); - actionTable = new int[length][][]; - for(int i = 0; i < actionTable.length; i++) + int actionTableLength1 = s.readInt(); + actionTable = new int[actionTableLength1][][]; + for(int i = 0; i < actionTableLength1; i++) { - length = s.readInt(); - actionTable[i] = new int[length][3]; - for(int j = 0; j < actionTable[i].length; j++) + int actionTableLength2 = s.readInt(); + actionTable[i] = new int[actionTableLength2][3]; + for(int j = 0; j < actionTableLength2; j++) { for(int k = 0; k < 3; k++) { @@ -450,13 +450,13 @@ Macro:ParserTail } // read gotoTable - length = s.readInt(); - gotoTable = new int[length][][]; - for(int i = 0; i < gotoTable.length; i++) + int gotoTableLength1 = s.readInt(); + gotoTable = new int[gotoTableLength1][][]; + for(int i = 0; i < gotoTableLength1; i++) { - length = s.readInt(); - gotoTable[i] = new int[length][2]; - for(int j = 0; j < gotoTable[i].length; j++) + int gotoTableLength2 = s.readInt(); + gotoTable[i] = new int[gotoTableLength2][2]; + for(int j = 0; j < gotoTableLength2; j++) { for(int k = 0; k < 2; k++) { @@ -466,14 +466,14 @@ Macro:ParserTail } // read errorMessages - length = s.readInt(); - errorMessages = new String[length]; - for(int i = 0; i < errorMessages.length; i++) + int errorMessagesLength = s.readInt(); + errorMessages = new String[errorMessagesLength]; + for(int i = 0; i < errorMessagesLength; i++) { - length = s.readInt(); + int errorMessageLength = s.readInt(); StringBuilder buffer = new StringBuilder(); - for(int j = 0; j < length; j++) + for(int j = 0; j < errorMessageLength; j++) { buffer.append(s.readChar()); } @@ -481,9 +481,9 @@ Macro:ParserTail } // read errors - length = s.readInt(); - errors = new int[length]; - for(int i = 0; i < errors.length; i++) + int errorsLength = s.readInt(); + errors = new int[errorsLength]; + for(int i = 0; i < errorsLength; i++) { errors[i] = s.readInt(); } -- GitLab