From 2634246b0788b8a4b97350c09e1049aa5ef431d8 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 9 Dec 2017 23:16:19 +0100 Subject: [PATCH 1/3] Add missing override keyword to virtual functions Add missing override markers to the following functions of the C++ runtime: - TokensStartState::getStateType() - TagChunk::toString() - TextChunk::toString() The missing markers made builds against the API with -Wsuggest-override choke. --- runtime/Cpp/runtime/src/atn/TokensStartState.h | 2 +- runtime/Cpp/runtime/src/tree/pattern/TagChunk.h | 2 +- runtime/Cpp/runtime/src/tree/pattern/TextChunk.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/Cpp/runtime/src/atn/TokensStartState.h b/runtime/Cpp/runtime/src/atn/TokensStartState.h index 7657ffb75..e534d04ee 100755 --- a/runtime/Cpp/runtime/src/atn/TokensStartState.h +++ b/runtime/Cpp/runtime/src/atn/TokensStartState.h @@ -14,7 +14,7 @@ namespace atn { class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { public: - virtual size_t getStateType(); + virtual size_t getStateType() override; }; } // namespace atn diff --git a/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h b/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h index a39e34f23..3d0c9f8d8 100755 --- a/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +++ b/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h @@ -70,7 +70,7 @@ namespace pattern { /// are returned in the form {@code label:tag}, and unlabeled tags are /// returned as just the tag name. /// - virtual std::string toString(); + virtual std::string toString() override; private: /// This is the backing field for . diff --git a/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h b/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h index 3b828a84d..1cbc0ddb2 100755 --- a/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +++ b/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h @@ -43,7 +43,7 @@ namespace pattern { /// The implementation for returns the result of /// in single quotes. /// - virtual std::string toString(); + virtual std::string toString() override; }; } // namespace pattern From 4e3c5ddffb7a813bf42340e62d155008470af4c9 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 10 Dec 2017 11:30:21 +0100 Subject: [PATCH 2/3] Make C++ Parser::exitRule() non-virtual Parser::exitRule() in the C++ runtime is a virtual function which is not reimplemented anywhere. OTOH, it is invoked during the execution of every rule, which can cause a noticeable performance hit. This commit removes its virtual qualifier. It should make a difference particularly for large grammars, because the number of rules corresponds to the number of the Parser object's virtual functions, and, consequently, its vtable lookup time. Tested with a VHDL grammar of 436 rules, where it brings down parsing time from 75 to 44 seconds on unoptimized compilation, i.e. a 40% speed gain. Still a lot slower than an equivalent java parser, though, which takes 2.64 seconds for the same input. --- runtime/Cpp/runtime/src/Parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Cpp/runtime/src/Parser.h b/runtime/Cpp/runtime/src/Parser.h index 14a41ba9c..515f83548 100755 --- a/runtime/Cpp/runtime/src/Parser.h +++ b/runtime/Cpp/runtime/src/Parser.h @@ -272,7 +272,7 @@ namespace antlr4 { /// get the current context. virtual void enterRule(ParserRuleContext *localctx, size_t state, size_t ruleIndex); - virtual void exitRule(); + void exitRule(); virtual void enterOuterAlt(ParserRuleContext *localctx, size_t altNum); From cf9d70dc028cfe54b5ad1aef81fd527e7cea2d86 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 13 Dec 2017 15:40:37 +0100 Subject: [PATCH 3/3] Sign contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index b85abf0ed..146359175 100644 --- a/contributors.txt +++ b/contributors.txt @@ -178,3 +178,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/01, DavidMoraisFerreira, David Morais Ferreira, david.moraisferreira@gmail.com 2017/12/01, SebastianLng, Sebastian Lang, sebastian.lang@outlook.com 2017/12/03, oranoran, Oran Epelbaum, oran / epelbaum me +2017/12/12, janlinde, Jan Lindemann, jan@janware.com