Skip to content

Commit

Permalink
Merge pull request #9 from antlr/Test-word-size
Browse files Browse the repository at this point in the history
Complement and validate bitset bug fix
  • Loading branch information
ericvergnaud committed Dec 27, 2014
2 parents 25053b7 + aa0532f commit 5fb5938
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ TestSetInline(s) ::= <<
<s.bitsets:{bits | <if(rest(rest(bits.ttypes)))><bitsetBitfieldComparison(s, bits)><else><bitsetInlineComparison(s, bits)><endif>}; separator=" || ">
>>

// Java language spec 15.19 - shift operators mask operands rather than overflow to 0... need range test
// Javascript language spec - shift operators are 32 bits long max
testShiftInRange(shiftAmount) ::= <<
((<shiftAmount>) & ~0x3f) == 0
((<shiftAmount>) & ~0x1f) == 0
>>

// produces smaller bytecode only when bits.ttypes contains more than two items
Expand Down
2 changes: 1 addition & 1 deletion tool/src/org/antlr/v4/codegen/JavaScriptTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

/**
*
* @author Sam Harwell
* @author Eric Vergnaud
*/
public class JavaScriptTarget extends Target {

Expand Down
35 changes: 35 additions & 0 deletions tool/test/org/antlr/v4/test/rt/js/node/TestBitSetWordSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.antlr.v4.test.rt.js.node;

import org.junit.Test;
import static org.junit.Assert.*;

public class TestBitSetWordSize extends BaseTest {

@Test
public void testBitSetWordSize() throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("grammar T;\n");
// create 40 tokens so we exceed 32 bits size
for(int i=1;i<=40;i++) {
sb.append("T");
sb.append(i);
sb.append(" : 'x");
sb.append(i);
sb.append("';\n");
}
// create a rule which will generate bit set test
sb.append("o : T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8;\n");
// create a rule where expected token - 32 uses same bit than optional token
sb.append("a : o? T36 {console.log('ok');};\n");
sb.append("WS : (' '|'\\n') -> skip ;");
String grammar = sb.toString();
// use input which triggers bug when word size is 64
String input = "x36";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false);
assertEquals("ok\n", found);
assertNull(this.stderrDuringParse);
}



}

0 comments on commit 5fb5938

Please sign in to comment.