Make ParseTreeWalker::DEFAULT provide an IterativeParseTreeWalker

as intended.

The existing code intended for ParseTreeWalker::DEFAULT to provide a
IterativeParseTreeWalker. However, the implementation initialized
ParseTreeWalker::DEFAULT by doing a (value) copy of an
IterativeParseTreeWalker, which sliced the object and therefore,
unfortunately, transformed it back into a regular ParseTreeWalker.

This change implements the desired behavior. Furthermore by making DEFAULT
a reference, we are able to preserve the interface to existing code.
This commit is contained in:
Corey Kosak 2017-05-29 22:21:01 -04:00
parent d0eaf29e51
commit 381fddebd5
3 changed files with 4 additions and 2 deletions

View File

@ -146,3 +146,4 @@ YYYY/MM/DD, github id, Full name, email
2017/04/12, lys0716, Yishuang Lu, luyscmu@gmail.com
2017/05/11, jimallman, Jim Allman, jim@ibang.com
2017/05/26, waf, Will Fuqua, wafuqua@gmail.com
2017/05/29, kosak, Corey Kosak, kosak@kosak.com

View File

@ -14,7 +14,8 @@
using namespace antlr4::tree;
using namespace antlrcpp;
ParseTreeWalker ParseTreeWalker::DEFAULT = IterativeParseTreeWalker();
static IterativeParseTreeWalker defaultWalker;
ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker;
void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const {
if (is<ErrorNode *>(t)) {

View File

@ -12,7 +12,7 @@ namespace tree {
class ANTLR4CPP_PUBLIC ParseTreeWalker {
public:
static ParseTreeWalker DEFAULT;
static ParseTreeWalker &DEFAULT;
virtual ~ParseTreeWalker() {};