Skip to content

Commit

Permalink
Merge pull request #3438 from parrt/normalize-getSerializedATNSegment…
Browse files Browse the repository at this point in the history
…Limit

normalize targets to 80 char strings for ATN serialization segments.
  • Loading branch information
parrt authored Dec 27, 2021
2 parents 5d5ee84 + 3076640 commit a16b5ef
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 44 deletions.
5 changes: 4 additions & 1 deletion tool/src/org/antlr/v4/codegen/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ public String getBaseVisitorFileName(boolean header) {
* @return the serialized ATN segment limit
*/
public int getSerializedATNSegmentLimit() {
return Integer.MAX_VALUE;
// Make strings encoding ATN fit on a single line conveniently so
// we can march through generated code more easily. Only Java has
// an actual string len limit (16 bits).
return 80;
}

/** How many bits should be used to do inline token type tests? Java assumes
Expand Down
7 changes: 0 additions & 7 deletions tool/src/org/antlr/v4/codegen/target/CppTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ public String encodeIntAsCharEscape(int v) {
return "0x" + Integer.toHexString(v) + ", ";
}

@Override
public int getSerializedATNSegmentLimit() {
// 65535 is the class file format byte limit for a UTF-8 encoded string literal
// 3 is the maximum number of bytes it takes to encode a value in the range 0-0xFFFF
return 65535 / 3;
}

@Override
public String getRecognizerFileName(boolean header) {
ST extST = getTemplates().getInstanceOf(header ? "headerFileExtension" : "codeFileExtension");
Expand Down
7 changes: 0 additions & 7 deletions tool/src/org/antlr/v4/codegen/target/DartTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ protected void addBadWords() {
badWords.add("parserRule");
}

@Override
public int getSerializedATNSegmentLimit() {
// 65535 is the class file format byte limit for a UTF-8 encoded string literal
// 3 is the maximum number of bytes it takes to encode a value in the range 0-0xFFFF
return 65535 / 3;
}

@Override
protected boolean visibleGrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
return getBadWords().contains(idNode.getText());
Expand Down
8 changes: 0 additions & 8 deletions tool/src/org/antlr/v4/codegen/target/GoTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ public String encodeIntAsCharEscape(int v) {
return Integer.toString(v);
}

@Override
public int getSerializedATNSegmentLimit() {
// 65535 is the class file format byte limit for a UTF-8 encoded string literal
// 3 is the maximum number of bytes it takes to encode a value in the range 0-0xFFFF
// (Mimicking Java here; not sure of true limit)
return 65535 / 3;
}

@Override
public int getInlineTestSetWordSize() {
return 32;
Expand Down
8 changes: 0 additions & 8 deletions tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ public String encodeIntAsCharEscape(int v) {
return "\\u"+hex;
}

@Override
public int getSerializedATNSegmentLimit() {
// 65535 is the class file format byte limit for a UTF-8 encoded string literal
// 3 is the maximum number of bytes it takes to encode a value in the range 0-0xFFFF
// (Mimicking Java here; not sure of true limit)
return 65535 / 3;
}

@Override
public int getInlineTestSetWordSize() {
return 32;
Expand Down
6 changes: 0 additions & 6 deletions tool/src/org/antlr/v4/codegen/target/Python3Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ public Python3Target(CodeGenerator gen) {
super(gen, "Python3");
}

@Override
public int getSerializedATNSegmentLimit() {
// set to something stupid to avoid segmentation
return Integer.MAX_VALUE;
}

@Override
protected boolean visibleGrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
return getBadWords().contains(idNode.getText());
Expand Down
7 changes: 0 additions & 7 deletions tool/src/org/antlr/v4/codegen/target/SwiftTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ protected void addBadWords() {
badWords.add("parserRule");
}

@Override
public int getSerializedATNSegmentLimit() {
// 65535 is the class file format byte limit for a UTF-8 encoded string literal
// 3 is the maximum number of bytes it takes to encode a value in the range 0-0xFFFF
return 65535 / 3;
}

@Override
protected boolean visibleGrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
return getBadWords().contains(idNode.getText());
Expand Down

0 comments on commit a16b5ef

Please sign in to comment.