Hello
I try to use TokenStreamwriter in order to implement a Preprocessor.
However when I call getText() method of the TokenStreamwriter object my program crash:
Reading symbols from demo2/antlr4-demo2...done.
(gdb) r
Starting program: /home/tom/prog/antlr4/Softgem/antlr4-cpp-runtime/demo2/antlr4-demo2
Program received signal SIGSEGV, Segmentation fault.
0x000055555574e2a6 in antlr4::TokenStreamRewriter::reduceToSingleOperationPerIndex (this=0x555555b09a40,
rewrites=std::vector of length 103, capacity 103 = {...})
at /home/tom/prog/antlr4/Softgem/antlr4-cpp-runtime/runtime/src/TokenStreamRewriter.cpp:417
417 if (iop->index == rop->index) {
(gdb) p rop->index
Cannot access memory at address 0x10
(gdb)
In my code the only operation on the TokenStreamRewrite object is done in an exit Listener function:
vPreprocessor.h:
class vPreprocessor : public vppBaseListener {
[...]
public:
TokenStreamRewriter * _rewriter;
vPreprocessor(TokenStream *tokens);
~vPreprocessor();
void enterDefine(vppParser::DefineContext * ctx);
void exitDefine(vppParser::DefineContext * );
void enterUndef(vppParser::UndefContext * ctx);
};
vPreprocessor.cpp
void vPreprocessor::exitDefine(vppParser::DefineContext * ctx ){
_rewriter->insertBefore(ctx->getStart(),"//");
}
when this function is call more than one time and I call _rewrite.getText() the program crash.
When input file trig only a single call to this function I do not observe crash and give the expected result.
I build my runtime on Linux ubuntu 16.10 with the source from:
http://www.soft-gems.net/index.php/all-downloads of the 4 November 2016
Where should I report this issue ? I can eventually provide a testcase.
Regards
Thomas