Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
chore: Switch from antlr 2.7.2 to antlr 2.7.7 (#63)
Browse files Browse the repository at this point in the history
In addition to adopting antlr 2.7.7, libantlr.jar is now built from source allowing the current libantlr.jar (2.7.2) to be deleted. This contributes to resolving #56.
  • Loading branch information
jasonborg authored Jan 10, 2023
1 parent 6808ee1 commit fd25930
Show file tree
Hide file tree
Showing 333 changed files with 62,695 additions and 1,735 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ PARALLEL_BUILD_OPTION="-j $(($(nproc 2> /dev/null || echo 4)*3/2))"
# Clean up previously generated files
pushd "${ROOT}"/third_party
rm -rf gflags* glog* jsoncpp* install
rm -rf antlr/build
rm -f antlr/lib/cpp/src/*.o
popd

Expand Down
6 changes: 3 additions & 3 deletions src/agent/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,14 @@ genrule(
name = "java_expression_grammar_gen",
srcs = ["java_expression.g"],
outs = [
"antlrgen/JavaExpressionCompiler.cc",
"antlrgen/JavaExpressionCompiler.cpp",
"antlrgen/JavaExpressionCompiler.hpp",
"antlrgen/JavaExpressionCompilerTokenTypes.hpp",
"antlrgen/JavaExpressionLexer.cc",
"antlrgen/JavaExpressionLexer.cpp",
"antlrgen/JavaExpressionLexer.hpp",
"antlrgen/JavaExpressionLexerTokenTypes.hpp",
"antlrgen/JavaExpressionLexerTokenTypes.txt",
"antlrgen/JavaExpressionParser.cc",
"antlrgen/JavaExpressionParser.cpp",
"antlrgen/JavaExpressionParser.hpp",
"antlrgen/JavaExpressionParserTokenTypes.hpp",
],
Expand Down
24 changes: 9 additions & 15 deletions src/agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ifneq ($(OS),Darwin)
ANTLR_DISABLED_WARNINGS = \
-Wno-unused-but-set-variable \
-Wno-stringop-overflow \
-Wno-use-after-free
-Wno-use-after-free \
-Wno-misleading-indentation
endif

# Ignore warning produced by glog
Expand Down Expand Up @@ -97,7 +98,6 @@ TARGET_VERSION_TXT = $(BUILD_TARGET_PATH)/version.txt
APPENGINE_FORMAT_SCRIPT = format-env-appengine-vm.sh

ANTLR_RUNTIME_SOURCES = \
$(ANTLR_CPP_LIB_SRC)/ANTLRException.cpp \
$(ANTLR_CPP_LIB_SRC)/ANTLRUtil.cpp \
$(ANTLR_CPP_LIB_SRC)/ASTFactory.cpp \
$(ANTLR_CPP_LIB_SRC)/ASTNULLType.cpp \
Expand All @@ -106,14 +106,10 @@ ANTLR_RUNTIME_SOURCES = \
$(ANTLR_CPP_LIB_SRC)/BitSet.cpp \
$(ANTLR_CPP_LIB_SRC)/CharBuffer.cpp \
$(ANTLR_CPP_LIB_SRC)/CharScanner.cpp \
$(ANTLR_CPP_LIB_SRC)/CharStreamException.cpp \
$(ANTLR_CPP_LIB_SRC)/CharStreamIOException.cpp \
$(ANTLR_CPP_LIB_SRC)/CommonAST.cpp \
$(ANTLR_CPP_LIB_SRC)/CommonASTWithHiddenTokens.cpp \
$(ANTLR_CPP_LIB_SRC)/CommonHiddenStreamToken.cpp \
$(ANTLR_CPP_LIB_SRC)/CommonToken.cpp \
$(ANTLR_CPP_LIB_SRC)/ExceptionSlot.cpp \
$(ANTLR_CPP_LIB_SRC)/IOException.cpp \
$(ANTLR_CPP_LIB_SRC)/InputBuffer.cpp \
$(ANTLR_CPP_LIB_SRC)/LLkParser.cpp \
$(ANTLR_CPP_LIB_SRC)/MismatchedCharException.cpp \
Expand All @@ -122,26 +118,23 @@ ANTLR_RUNTIME_SOURCES = \
$(ANTLR_CPP_LIB_SRC)/NoViableAltForCharException.cpp \
$(ANTLR_CPP_LIB_SRC)/Parser.cpp \
$(ANTLR_CPP_LIB_SRC)/RecognitionException.cpp \
$(ANTLR_CPP_LIB_SRC)/SemanticException.cpp \
$(ANTLR_CPP_LIB_SRC)/String.cpp \
$(ANTLR_CPP_LIB_SRC)/Token.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenBuffer.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenRefCount.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamBasicFilter.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamException.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamHiddenTokenFilter.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamIOException.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamRecognitionException.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamRetryException.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamRewriteEngine.cpp \
$(ANTLR_CPP_LIB_SRC)/TokenStreamSelector.cpp \
$(ANTLR_CPP_LIB_SRC)/TreeParser.cpp \

JAVA_EXPRESSION_GRAMMAR_FILE = \
java_expression.g \

ANTLR_JAVA_EXPRESSION_GENERATED_SOURCES = \
antlrgen/JavaExpressionCompiler.cc \
antlrgen/JavaExpressionLexer.cc \
antlrgen/JavaExpressionParser.cc \
antlrgen/JavaExpressionCompiler.cpp \
antlrgen/JavaExpressionLexer.cpp \
antlrgen/JavaExpressionParser.cpp \

ANTLR_JAVA_EXPRESSION_GENERATED_HEADERS = \
antlrgen/JavaExpressionCompiler.hpp \
Expand Down Expand Up @@ -201,8 +194,9 @@ all: \
target_version_txt \

antlrgen: $(JAVA_EXPRESSION_GRAMMAR_FILE)
make -C $(ANTLR_TOOL_PATH) libantlr.jar
mkdir antlrgen
java -classpath $(ANTLR_TOOL_PATH)/libantlr.jar antlr.Tool -o antlrgen $(JAVA_EXPRESSION_GRAMMAR_FILE)
java -classpath $(ANTLR_TOOL_PATH)/build/libantlr.jar antlr.Tool -o antlrgen $(JAVA_EXPRESSION_GRAMMAR_FILE)

$(ANTLR_JAVA_EXPRESSION_GENERATED_SOURCES) $(ANTLR_JAVA_EXPRESSION_GENERATED_HEADERS): antlrgen

Expand Down
7 changes: 4 additions & 3 deletions src/agent/expression_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ CompiledExpression CompileExpression(const std::string& string_expression,
JavaExpressionParser parser(lexer);
parser.Init();

parser.statement();
if (parser.ActiveException()) {
parser.reportError(parser.ActiveException()->getMessage());
try {
parser.statement();
} catch (const antlr::ANTLRException& e) {
parser.reportError(e.getMessage());
}

if (parser.num_errors() > 0) {
Expand Down
9 changes: 8 additions & 1 deletion src/agent/java_expression.g
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,14 @@ options {
return nullptr;
}

std::unique_ptr<JavaExpression> expression(statement(ast));
std::unique_ptr<JavaExpression> expression;
try {
expression.reset(statement(ast));
}
catch (const antlr::ANTLRException& e) {
reportError(e.getMessage());
}

if (expression == nullptr) {
// Set generic error message if specific error wasn't set.
SetErrorMessage({ ExpressionParserError });
Expand Down
14 changes: 8 additions & 6 deletions tests/agent/java_expression_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ static std::unique_ptr<JavaExpression> ParseExpression(const std::string& input,
JavaExpressionParser parser(lexer);
parser.Init();

parser.statement();
if (parser.ActiveException()) {
parser.reportError(parser.ActiveException()->getMessage());
try {
parser.statement();
} catch (const antlr::ANTLRException& e) {
parser.reportError(e.getMessage());
}

if (parser.num_errors() > 0) {
Expand Down Expand Up @@ -513,9 +514,10 @@ TEST(JavaExpressionTest, ParserNegative) {
JavaExpressionParser parser(lexer);
parser.Init();

parser.statement();
if (parser.ActiveException()) {
parser.reportError(parser.ActiveException()->getMessage());
try {
parser.statement();
} catch (const antlr::ANTLRException& e) {
parser.reportError(e.getMessage());
}

if (parser.num_errors() > 0) {
Expand Down
215 changes: 209 additions & 6 deletions third_party/antlr/BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,219 @@
package(default_visibility = ["//visibility:public"])

java_import(
name = "libantlr",
jars = [
"libantlr.jar",
]
java_library(
name = "antlr",
srcs = [
"antlr/ANTLRError.java",
"antlr/ANTLRException.java",
"antlr/ANTLRGrammarParseBehavior.java",
"antlr/ANTLRHashString.java",
"antlr/ANTLRLexer.java",
"antlr/ANTLRParser.java",
"antlr/ANTLRStringBuffer.java",
"antlr/ANTLRTokdefLexer.java",
"antlr/ANTLRTokdefParser.java",
"antlr/ANTLRTokdefParserTokenTypes.java",
"antlr/ANTLRTokenTypes.java",
"antlr/ASTFactory.java",
"antlr/ASTIterator.java",
"antlr/ASTNULLType.java",
"antlr/ASTPair.java",
"antlr/ASTVisitor.java",
"antlr/ActionElement.java",
"antlr/ActionTransInfo.java",
"antlr/Alternative.java",
"antlr/AlternativeBlock.java",
"antlr/AlternativeElement.java",
"antlr/BaseAST.java",
"antlr/BlockContext.java",
"antlr/BlockEndElement.java",
"antlr/BlockWithImpliedExitPath.java",
"antlr/ByteBuffer.java",
"antlr/CharBuffer.java",
"antlr/CharFormatter.java",
"antlr/CharLiteralElement.java",
"antlr/CharQueue.java",
"antlr/CharRangeElement.java",
"antlr/CharScanner.java",
"antlr/CharStreamException.java",
"antlr/CharStreamIOException.java",
"antlr/CodeGenerator.java",
"antlr/CommonAST.java",
"antlr/CommonASTWithHiddenTokens.java",
"antlr/CommonHiddenStreamToken.java",
"antlr/CommonToken.java",
"antlr/CppBlockFinishingInfo.java",
"antlr/CppCharFormatter.java",
"antlr/CppCodeGenerator.java",
"antlr/DefaultFileLineFormatter.java",
"antlr/DefaultJavaCodeGeneratorPrintWriterManager.java",
"antlr/DefaultToolErrorHandler.java",
"antlr/DefineGrammarSymbols.java",
"antlr/DiagnosticCodeGenerator.java",
"antlr/DocBookCodeGenerator.java",
"antlr/DumpASTVisitor.java",
"antlr/ExceptionHandler.java",
"antlr/ExceptionSpec.java",
"antlr/FileCopyException.java",
"antlr/FileLineFormatter.java",
"antlr/Grammar.java",
"antlr/GrammarAnalyzer.java",
"antlr/GrammarAtom.java",
"antlr/GrammarElement.java",
"antlr/GrammarSymbol.java",
"antlr/HTMLCodeGenerator.java",
"antlr/ImportVocabTokenManager.java",
"antlr/InputBuffer.java",
"antlr/JavaBlockFinishingInfo.java",
"antlr/JavaCharFormatter.java",
"antlr/JavaCodeGenerator.java",
"antlr/JavaCodeGeneratorPrintWriterManager.java",
"antlr/LLkAnalyzer.java",
"antlr/LLkGrammarAnalyzer.java",
"antlr/LLkParser.java",
"antlr/LexerGrammar.java",
"antlr/LexerSharedInputState.java",
"antlr/Lookahead.java",
"antlr/MakeGrammar.java",
"antlr/MismatchedCharException.java",
"antlr/MismatchedTokenException.java",
"antlr/NameSpace.java",
"antlr/NoViableAltException.java",
"antlr/NoViableAltForCharException.java",
"antlr/OneOrMoreBlock.java",
"antlr/Parser.java",
"antlr/ParserGrammar.java",
"antlr/ParserSharedInputState.java",
"antlr/ParseTree.java",
"antlr/ParseTreeRule.java",
"antlr/ParseTreeToken.java",
"antlr/PreservingFileWriter.java",
"antlr/PrintWriterWithSMAP.java",
"antlr/RecognitionException.java",
"antlr/RuleBlock.java",
"antlr/RuleEndElement.java",
"antlr/RuleRefElement.java",
"antlr/RuleSymbol.java",
"antlr/SemanticException.java",
"antlr/SimpleTokenManager.java",
"antlr/StringLiteralElement.java",
"antlr/StringLiteralSymbol.java",
"antlr/StringUtils.java",
"antlr/SynPredBlock.java",
"antlr/Token.java",
"antlr/TokenBuffer.java",
"antlr/TokenManager.java",
"antlr/TokenQueue.java",
"antlr/TokenRangeElement.java",
"antlr/TokenRefElement.java",
"antlr/TokenStream.java",
"antlr/TokenStreamBasicFilter.java",
"antlr/TokenStreamException.java",
"antlr/TokenStreamHiddenTokenFilter.java",
"antlr/TokenStreamIOException.java",
"antlr/TokenStreamRecognitionException.java",
"antlr/TokenStreamRetryException.java",
"antlr/TokenStreamRewriteEngine.java",
"antlr/TokenStreamSelector.java",
"antlr/TokenSymbol.java",
"antlr/TokenWithIndex.java",
"antlr/Tool.java",
"antlr/ToolErrorHandler.java",
"antlr/TreeBlockContext.java",
"antlr/TreeElement.java",
"antlr/TreeParser.java",
"antlr/TreeParserSharedInputState.java",
"antlr/TreeSpecifierNode.java",
"antlr/TreeWalkerGrammar.java",
"antlr/Utils.java",
"antlr/Version.java",
"antlr/WildcardElement.java",
"antlr/ZeroOrMoreBlock.java",
"antlr/ASdebug/ASDebugStream.java",
"antlr/ASdebug/IASDebugStream.java",
"antlr/ASdebug/TokenOffsetInfo.java",
"antlr/actions/cpp/ActionLexer.java",
"antlr/actions/cpp/ActionLexerTokenTypes.java",
"antlr/actions/java/ActionLexer.java",
"antlr/actions/java/ActionLexerTokenTypes.java",
"antlr/collections/AST.java",
"antlr/collections/ASTEnumeration.java",
"antlr/collections/Enumerator.java",
"antlr/collections/List.java",
"antlr/collections/Stack.java",
"antlr/collections/impl/ASTArray.java",
"antlr/collections/impl/ASTEnumerator.java",
"antlr/collections/impl/BitSet.java",
"antlr/collections/impl/IndexedVector.java",
"antlr/collections/impl/IntRange.java",
"antlr/collections/impl/LLCell.java",
"antlr/collections/impl/LLEnumeration.java",
"antlr/collections/impl/LList.java",
"antlr/collections/impl/Vector.java",
"antlr/collections/impl/VectorEnumeration.java",
"antlr/collections/impl/VectorEnumerator.java",
"antlr/debug/DebuggingCharScanner.java",
"antlr/debug/DebuggingInputBuffer.java",
"antlr/debug/DebuggingParser.java",
"antlr/debug/Event.java",
"antlr/debug/GuessingEvent.java",
"antlr/debug/InputBufferAdapter.java",
"antlr/debug/InputBufferEvent.java",
"antlr/debug/InputBufferEventSupport.java",
"antlr/debug/InputBufferListener.java",
"antlr/debug/InputBufferReporter.java",
"antlr/debug/LLkDebuggingParser.java",
"antlr/debug/ListenerBase.java",
"antlr/debug/MessageAdapter.java",
"antlr/debug/MessageEvent.java",
"antlr/debug/MessageListener.java",
"antlr/debug/NewLineEvent.java",
"antlr/debug/NewLineListener.java",
"antlr/debug/ParserAdapter.java",
"antlr/debug/ParserController.java",
"antlr/debug/ParserEventSupport.java",
"antlr/debug/ParserListener.java",
"antlr/debug/ParserMatchAdapter.java",
"antlr/debug/ParserMatchEvent.java",
"antlr/debug/ParserMatchListener.java",
"antlr/debug/ParserReporter.java",
"antlr/debug/ParserTokenAdapter.java",
"antlr/debug/ParserTokenEvent.java",
"antlr/debug/ParserTokenListener.java",
"antlr/debug/ParseTreeDebugParser.java",
"antlr/debug/SemanticPredicateAdapter.java",
"antlr/debug/SemanticPredicateEvent.java",
"antlr/debug/SemanticPredicateListener.java",
"antlr/debug/SyntacticPredicateAdapter.java",
"antlr/debug/SyntacticPredicateEvent.java",
"antlr/debug/SyntacticPredicateListener.java",
"antlr/debug/TraceAdapter.java",
"antlr/debug/TraceEvent.java",
"antlr/debug/TraceListener.java",
"antlr/debug/Tracer.java",
"antlr/debug/misc/ASTFrame.java",
"antlr/debug/misc/JTreeASTModel.java",
"antlr/debug/misc/JTreeASTPanel.java",
"antlr/preprocessor/Grammar.java",
"antlr/preprocessor/GrammarFile.java",
"antlr/preprocessor/Hierarchy.java",
"antlr/preprocessor/Option.java",
"antlr/preprocessor/Preprocessor.java",
"antlr/preprocessor/PreprocessorLexer.java",
"antlr/preprocessor/PreprocessorTokenTypes.java",
"antlr/preprocessor/Rule.java",
"antlr/preprocessor/Tool.java",
],
javacopts = [
"-Xep:EqualsHashCode:OFF",
"-Xep:EqualsIncompatibleType:OFF",
],
)

java_binary(
name = "antlr_tool",
main_class = "antlr.Tool",
runtime_deps = [
":libantlr",
":antlr",
]
)
Loading

0 comments on commit fd25930

Please sign in to comment.