Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Jul 27, 2017
2 parents b360441 + 56f5190 commit 1b11cbe
Show file tree
Hide file tree
Showing 53 changed files with 595 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private List<List<String>> processGrammarFiles(
String tokensFileName = grammarFile.getName().split("\\.")[0] + ".tokens";
File outputFile = new File(outputDirectory, tokensFileName);
if ( (! outputFile.exists()) ||
outputFile.lastModified() < grammarFile.lastModified() ||
outputFile.lastModified() <= grammarFile.lastModified() ||
dependencies.isDependencyChanged(grammarFile)) {
grammarFilesToProcess.add(grammarFile);
}
Expand All @@ -412,10 +412,7 @@ private List<List<String>> processGrammarFiles(
// Iterate each grammar file we were given and add it into the tool's list of
// grammars to process.
for (File grammarFile : grammarFiles) {
if (!buildContext.hasDelta(grammarFile)) {
continue;
}

buildContext.refresh(grammarFile);
buildContext.removeMessages(grammarFile);

getLog().debug("Grammar file '" + grammarFile.getPath() + "' detected.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ private void analyse(File grammarFile, Collection<File> grammarFiles, Tool tool)
return;

for (GrammarAST importDecl : grammar.getAllChildrenWithType(ANTLRParser.IMPORT)) {
Tree id = importDecl.getFirstChildWithType(ANTLRParser.ID);
for (Tree id: importDecl.getAllChildrenWithType(ANTLRParser.ID)) {
// missing id is not valid, but we don't want to prevent the root cause from
// being reported by the ANTLR tool
if (id != null) {
String grammarPath = getRelativePath(grammarFile);

// missing id is not valid, but we don't want to prevent the root cause from
// being reported by the ANTLR tool
if (id != null) {
String grammarPath = getRelativePath(grammarFile);

graph.addEdge(id.getText() + ".g4", grammarPath);
graph.addEdge(id.getText() + ".g4", grammarPath);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public void importsStandardLayout() throws Exception {
Path genHello = generatedSources.resolve("test/HelloParser.java");

Path baseGrammar = antlrDir.resolve("imports/TestBaseLexer.g4");
Path baseGrammar2 = antlrDir.resolve("imports/TestBaseLexer2.g4");
Path lexerGrammar = antlrDir.resolve("test/TestLexer.g4");
Path parserGrammar = antlrDir.resolve("test/TestParser.g4");

Expand All @@ -222,21 +223,20 @@ public void importsStandardLayout() throws Exception {
assertTrue(Files.exists(genHello));
assertTrue(Files.exists(genTestParser));
assertTrue(Files.exists(genTestLexer));
byte[] origTestLexerSum = checksum(genTestLexer);
byte[] origTestParserSum = checksum(genTestParser);
byte[] origHelloSum = checksum(genHello);

////////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
////////////////////////////////////////////////////////////////////////

{
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -245,50 +245,71 @@ public void importsStandardLayout() throws Exception {

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(baseGrammar, "DOT: '.' ;")) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 4th - the lexer grammar changed, the parser grammar has to be processed as well
// 4th - the second imported grammar changed, every dependency has to be processed
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(lexerGrammar)) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
try(Change change = Change.of(baseGrammar2, "BANG: '!' ;")) {
maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 5th - the lexer grammar changed, the parser grammar has to be processed as well
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(lexerGrammar, "FOO: 'foo' ;")) {
maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 5th - the parser grammar changed, no other grammars have to be processed
// 6th - the parser grammar changed, no other grammars have to be processed
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(parserGrammar, " t : WS* ;")) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ fragment
Whitespace : ' ' | '\n' | '\t' | '\r' ;

fragment
Hexdigit : [a-fA-F0-9] ;

fragment
Digit : [0-9] ;
Hexdigit : [a-fA-F0-9] ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lexer grammar TestBaseLexer2;

fragment
Digit : [0-9] ;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lexer grammar TestLexer;

import TestBaseLexer;
import TestBaseLexer, TestBaseLexer2;

WS : Whitespace+ -> skip;
TEXT : ~[<&]+ ; // match any 16 bit char other than < and &
TEXT : ~[<&]+ ; // match any 16 bit char other than < and &
3 changes: 2 additions & 1 deletion contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ YYYY/MM/DD, github id, Full name, email
2017/06/11, erikbra, Erik A. Brandstadmoen, [email protected]
2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, [email protected]
2017/06/25, alimg, Alim Gökkaya, [email protected]
2017/07/07, shirou, WAKAYAMA Shirou, [email protected]
2017/07/11, dhalperi, Daniel Halperin, [email protected]
2017/07/27, shirou, WAKAYAMA Shirou, [email protected]
10 changes: 5 additions & 5 deletions runtime/Cpp/demo/Mac/antlrcpp Tests/InputHandlingTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (void)testANTLRInputStreamCreation {

- (void)testANTLRInputStreamUse {
std::string text(u8"🚧Lorem ipsum dolor sit amet🕶");
std::u32string wtext = utfConverter.from_bytes(text); // Convert to UTF-32.
std::u32string wtext = utf8_to_utf32(text.c_str(), text.c_str() + text.size()); // Convert to UTF-32.
ANTLRInputStream stream(text);
XCTAssertEqual(stream.index(), 0U);
XCTAssertEqual(stream.size(), wtext.size());
Expand All @@ -116,8 +116,8 @@ - (void)testANTLRInputStreamUse {

XCTAssertEqual(stream.LA(0), 0ULL);
for (size_t i = 1; i < wtext.size(); ++i) {
XCTAssertEqual(stream.LA((ssize_t)i), wtext[i - 1]); // LA(1) means: current char.
XCTAssertEqual(stream.LT((ssize_t)i), wtext[i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.LA(static_cast<ssize_t>(i)), wtext[i - 1]); // LA(1) means: current char.
XCTAssertEqual(stream.LT(static_cast<ssize_t>(i)), wtext[i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.index(), 0U); // No consumption when looking ahead.
}

Expand All @@ -128,7 +128,7 @@ - (void)testANTLRInputStreamUse {
XCTAssertEqual(stream.index(), wtext.size() / 2);

stream.seek(wtext.size() - 1);
for (ssize_t i = 1; i < (ssize_t)wtext.size() - 1; ++i) {
for (ssize_t i = 1; i < static_cast<ssize_t>(wtext.size()) - 1; ++i) {
XCTAssertEqual(stream.LA(-i), wtext[wtext.size() - i - 1]); // LA(-1) means: previous char.
XCTAssertEqual(stream.LT(-i), wtext[wtext.size() - i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.index(), wtext.size() - 1); // No consumption when looking ahead.
Expand All @@ -150,7 +150,7 @@ - (void)testANTLRInputStreamUse {

misc::Interval interval1(2, 10UL); // From - to, inclusive.
std::string output = stream.getText(interval1);
std::string sub = utfConverter.to_bytes(wtext.substr(2, 9));
std::string sub = utf32_to_utf8(wtext.substr(2, 9));
XCTAssertEqual(output, sub);

misc::Interval interval2(200, 10UL); // Start beyond bounds.
Expand Down
69 changes: 41 additions & 28 deletions runtime/Cpp/demo/Mac/antlrcpp Tests/MiscClassTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ - (void)testMurmurHash {
// in a deterministic and a random sequence of 100K values each.
std::set<size_t> hashs;
for (size_t i = 0; i < 100000; ++i) {
std::vector<size_t> data = { i, (size_t)(i * M_PI), arc4random()};
std::vector<size_t> data = { i, static_cast<size_t>(i * M_PI), arc4random() };
size_t hash = 0;
for (auto value : data)
hash = MurmurHash::update(hash, value);
Expand All @@ -103,7 +103,7 @@ - (void)testMurmurHash {

hashs.clear();
for (size_t i = 0; i < 100000; ++i) {
std::vector<size_t> data = { i, (size_t)(i * M_PI)};
std::vector<size_t> data = { i, static_cast<size_t>(i * M_PI) };
size_t hash = 0;
for (auto value : data)
hash = MurmurHash::update(hash, value);
Expand Down Expand Up @@ -232,19 +232,25 @@ - (void)testInterval {
{ 78, Interval(1000, 1000UL), Interval(20, 100UL), { false, false, true, true, false, true, false, false } },

// It's possible to add more tests with borders that touch each other (e.g. first starts before/on/after second
// and first ends directly before/after second. However, such cases are not handled differently in the Interval class
// and first ends directly before/after second. However, such cases are not handled differently in the Interval
// class
// (only adjacent intervals, where first ends directly before second starts and vice versa. So I ommitted them here.
};

for (auto &entry : testData) {
XCTAssert(entry.interval1.startsBeforeDisjoint(entry.interval2) == entry.results[0], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.startsBeforeNonDisjoint(entry.interval2) == entry.results[1], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.startsBeforeDisjoint(entry.interval2) == entry.results[0], @"entry: %zu",
entry.runningNumber);
XCTAssert(entry.interval1.startsBeforeNonDisjoint(entry.interval2) == entry.results[1], @"entry: %zu",
entry.runningNumber);
XCTAssert(entry.interval1.startsAfter(entry.interval2) == entry.results[2], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.startsAfterDisjoint(entry.interval2) == entry.results[3], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.startsAfterNonDisjoint(entry.interval2) == entry.results[4], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.startsAfterDisjoint(entry.interval2) == entry.results[3], @"entry: %zu",
entry.runningNumber);
XCTAssert(entry.interval1.startsAfterNonDisjoint(entry.interval2) == entry.results[4], @"entry: %zu",
entry.runningNumber);
XCTAssert(entry.interval1.disjoint(entry.interval2) == entry.results[5], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.adjacent(entry.interval2) == entry.results[6], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.properlyContains(entry.interval2) == entry.results[7], @"entry: %zu", entry.runningNumber);
XCTAssert(entry.interval1.properlyContains(entry.interval2) == entry.results[7], @"entry: %zu",
entry.runningNumber);
}

XCTAssert(Interval().Union(Interval(10, 100UL)) == Interval(-1L, 100));
Expand Down Expand Up @@ -327,39 +333,45 @@ - (void)testIntervalSet {
try {
set4.clear();
XCTFail(@"Expected exception");
}
catch (IllegalStateException &e) {
} catch (IllegalStateException &e) {
}

try {
set4.setReadOnly(false);
XCTFail(@"Expected exception");
} catch (IllegalStateException &e) {
}
catch (IllegalStateException &e) {

try {
set4 = IntervalSet::of(12345);
XCTFail(@"Expected exception");
} catch (IllegalStateException &e) {
}
set4 = IntervalSet::of(12345);
XCTAssertEqual(set4.getSingleElement(), 12345);
XCTAssertEqual(set4.getMinElement(), 12345);
XCTAssertEqual(set4.getMaxElement(), 12345);

IntervalSet set5(10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50);
XCTAssertEqual(set5.getMinElement(), 5);
XCTAssertEqual(set5.getMaxElement(), 50);
XCTAssertEqual(set5.size(), 10U);
set5.add(12, 18);
XCTAssertEqual(set5.size(), 16U); // (15, 15) replaced by (12, 18)
set5.add(9, 33);
XCTAssertEqual(set5.size(), 30U); // (10, 10), (12, 18), (20, 20), (25, 25) and (30, 30) replaced by (9, 33)

IntervalSet set5 = IntervalSet::of(12345);
XCTAssertEqual(set5.getSingleElement(), 12345);
XCTAssertEqual(set5.getMinElement(), 12345);
XCTAssertEqual(set5.getMaxElement(), 12345);

IntervalSet set6(10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50);
XCTAssertEqual(set6.getMinElement(), 5);
XCTAssertEqual(set6.getMaxElement(), 50);
XCTAssertEqual(set6.size(), 10U);
set6.add(12, 18);
XCTAssertEqual(set6.size(), 16U); // (15, 15) replaced by (12, 18)
set6.add(9, 33);
XCTAssertEqual(set6.size(), 30U); // (10, 10), (12, 18), (20, 20), (25, 25) and (30, 30) replaced by (9, 33)

XCTAssert(IntervalSet(3, 1, 2, 10).Or(IntervalSet(3, 1, 2, 5)) == IntervalSet(4, 1, 2, 5, 10));
XCTAssert(IntervalSet({ Interval(2, 10UL) }).Or(IntervalSet({ Interval(5, 8UL) })) == IntervalSet({ Interval(2, 10UL) }));

XCTAssert(IntervalSet::of(1, 10).complement(IntervalSet::of(7, 55)) == IntervalSet::of(11, 55));
XCTAssert(IntervalSet::of(1, 10).complement(IntervalSet::of(20, 55)) == IntervalSet::of(20, 55));
XCTAssert(IntervalSet::of(1, 10).complement(IntervalSet::of(5, 6)) == IntervalSet::EMPTY_SET);
XCTAssert(IntervalSet::of(15, 20).complement(IntervalSet::of(7, 55)) == IntervalSet({ Interval(7, 14UL), Interval(21, 55UL) }));
XCTAssert(IntervalSet({ Interval(1, 10UL), Interval(30, 35UL) }).complement(IntervalSet::of(7, 55)) == IntervalSet({ Interval(11, 29UL), Interval(36, 55UL) }));
XCTAssert(IntervalSet::of(15, 20).complement(IntervalSet::of(7, 55)) ==
IntervalSet({ Interval(7, 14UL), Interval(21, 55UL) }));
XCTAssert(IntervalSet({ Interval(1, 10UL), Interval(30, 35UL) }).complement(IntervalSet::of(7, 55)) ==
IntervalSet({ Interval(11, 29UL), Interval(36, 55UL) }));

XCTAssert(IntervalSet::of(1, 10).And(IntervalSet::of(7, 55)) == IntervalSet::of(7, 10));
XCTAssert(IntervalSet::of(1, 10).And(IntervalSet::of(20, 55)) == IntervalSet::EMPTY_SET);
Expand All @@ -368,7 +380,8 @@ - (void)testIntervalSet {

XCTAssert(IntervalSet::of(1, 10).subtract(IntervalSet::of(7, 55)) == IntervalSet::of(1, 6));
XCTAssert(IntervalSet::of(1, 10).subtract(IntervalSet::of(20, 55)) == IntervalSet::of(1, 10));
XCTAssert(IntervalSet::of(1, 10).subtract(IntervalSet::of(5, 6)) == IntervalSet({ Interval(1, 4UL), Interval(7, 10UL) }));
XCTAssert(IntervalSet::of(1, 10).subtract(IntervalSet::of(5, 6)) ==
IntervalSet({ Interval(1, 4UL), Interval(7, 10UL) }));
XCTAssert(IntervalSet::of(15, 20).subtract(IntervalSet::of(7, 55)) == IntervalSet::EMPTY_SET);
}

Expand Down
3 changes: 2 additions & 1 deletion runtime/Cpp/deploy-windows.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ rem Headers
xcopy runtime\src\*.h antlr4-runtime\ /s

rem Binaries
if exist "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
rem VS 2013 disabled by default. Change the X to a C to enable it.
if exist "X:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"

pushd runtime
Expand Down
Loading

0 comments on commit 1b11cbe

Please sign in to comment.