From f03d33317e125975053aadb47386d66f983a4c6e Mon Sep 17 00:00:00 2001 From: Ivan Brezina Date: Fri, 7 Feb 2014 18:28:30 +0100 Subject: [PATCH 01/53] When you name your source files *.c, MSVC (2010) assumes it's compiling C, which means C89. All block-local variables need to be declared at the beginning of your functions. Or at begginning of {} block. --- runtime/C/src/antlr3baserecognizer.c | 18 ++++++++++-------- runtime/C/src/antlr3basetree.c | 8 +++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/runtime/C/src/antlr3baserecognizer.c b/runtime/C/src/antlr3baserecognizer.c index 8c6b105c7..667ad7ac9 100644 --- a/runtime/C/src/antlr3baserecognizer.c +++ b/runtime/C/src/antlr3baserecognizer.c @@ -2141,14 +2141,16 @@ reset(pANTLR3_BASE_RECOGNIZER recognizer) recognizer->state->ruleMemo = antlr3IntTrieNew(15); /* 16 bit depth is enough for 32768 rules! */ } } - - // ml: 2013-11-05, added reset of old exceptions. - pANTLR3_EXCEPTION thisE = recognizer->state->exception; - if (thisE != NULL) - { - thisE->freeEx(thisE); - recognizer->state->exception = NULL; - } + + { + // ml: 2013-11-05, added reset of old exceptions. + pANTLR3_EXCEPTION thisE = recognizer->state->exception; + if (thisE != NULL) + { + thisE->freeEx(thisE); + recognizer->state->exception = NULL; + } + } // Install a new following set // diff --git a/runtime/C/src/antlr3basetree.c b/runtime/C/src/antlr3basetree.c index f191f6fde..593f52b5d 100644 --- a/runtime/C/src/antlr3basetree.c +++ b/runtime/C/src/antlr3basetree.c @@ -214,9 +214,11 @@ addChild (pANTLR3_BASE_TREE tree, pANTLR3_BASE_TREE child) tree->createChildrenList(tree); } - ANTLR3_UINT32 count = tree->children->add(tree->children, child, (void (ANTLR3_CDECL *)(void *))child->free); - child->setChildIndex(child, count - 1); - child->setParent(child, tree); + { + ANTLR3_UINT32 count = tree->children->add(tree->children, child, (void (ANTLR3_CDECL *)(void *))child->free); + child->setChildIndex(child, count - 1); + child->setParent(child, tree); + } } } From f5d2f904d4e1624fa1b5f659f83ec4d6867db6f8 Mon Sep 17 00:00:00 2001 From: Ivan Brezina Date: Sun, 11 May 2014 19:46:25 +0200 Subject: [PATCH 02/53] Fix memory leak when using lexer rule label references. Inspired by bennyk. Since this patch uses std::unique_ptr the build now requires a compiler supporting at least some of C++11 features. --- runtime/Cpp/tests/Makefile | 2 +- .../org/antlr/codegen/templates/Cpp/Cpp.stg | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/runtime/Cpp/tests/Makefile b/runtime/Cpp/tests/Makefile index 1efad371e..b0336419c 100644 --- a/runtime/Cpp/tests/Makefile +++ b/runtime/Cpp/tests/Makefile @@ -15,7 +15,7 @@ STGS = $(wildcard ../../../tool/src/main/resources/org/antlr/codegen/templates/ INCLUDES= -I. -I../include/ -CFLAGS=-ggdb3 -O0 -fno-inline -Wall -Wno-unused-variable +CFLAGS=-ggdb3 -O0 -fno-inline -Wall -Wno-unused-variable -std=c++0x #CFLAGS=-ggdb3 -O3 TOBJS= utils.o diff --git a/tool/src/main/resources/org/antlr/codegen/templates/Cpp/Cpp.stg b/tool/src/main/resources/org/antlr/codegen/templates/Cpp/Cpp.stg index d94024b7d..25b8f6332 100755 --- a/tool/src/main/resources/org/antlr/codegen/templates/Cpp/Cpp.stg +++ b/tool/src/main/resources/org/antlr/codegen/templates/Cpp/Cpp.stg @@ -142,7 +142,7 @@ outputFile( LEXER, /* ----------------------------------------- * Include the ANTLR3 generated header file. */ -#include ".hpp" +#include ".hpp" #include \ @@ -151,6 +151,7 @@ outputFile( LEXER, // .hpp" }; separator="\n"> +#include \ /* ----------------------------------------- */ @@ -540,7 +541,7 @@ lexer( grammar, numRules, filterMode, superClass, - labelType="ImplTraits::CommonTokenType*") ::= << + labelType="ImplTraits::CommonTokenType") ::= << using namespace antlr3; @@ -1280,7 +1281,7 @@ lexerRuleLabelDefs() ::= << <[ruleDescriptor.tokenLabels, ruleDescriptor.tokenListLabels, ruleDescriptor.ruleLabels] - :{it | = NULL;}; separator="\n" + :{it |std::unique_ptr\<\> = NULL;}; separator="\n" > ;}; separator="\n"> <[ruleDescriptor.tokenListLabels, @@ -1689,7 +1690,7 @@ ANTLR_UINT32