Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Cpp/C target fixes #145

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f03d333
When you name your source files *.c, MSVC (2010) assumes it's compili…
ibre5041 Feb 7, 2014
f5d2f90
Fix memory leak when using lexer rule label references.
ibre5041 May 11, 2014
700d2df
Fix lexer labels onto EOF token
ibre5041 May 12, 2014
0c90ab8
All Token labels are declared as const*
ibre5041 Jun 20, 2013
c243a87
Fix to lexer label refs(array form)
ibre5041 May 12, 2014
670347a
Add test for lexer rule labels
ibre5041 May 12, 2014
0ef2d9f
lexer token names
ibre5041 Oct 7, 2013
5b60623
fix for filtering option
ibre5041 May 13, 2014
dd3e20a
fuzzy lexer test
ibre5041 May 14, 2014
9420200
use gnu make wildcards instead of shell ones
ibre5041 May 14, 2014
c93830e
remove executable flag from header files
ibre5041 May 15, 2014
e431dd4
Do not use EOF macro in generated code
ibre5041 May 30, 2014
9c9e336
Fix for MSVC. MSVC does not support const_expr
ibre5041 Jun 14, 2014
6a4485d
AST initial support (has memory leaks)
ibre5041 Jul 26, 2014
e35f17a
AST memory management
ibre5041 Jul 27, 2014
bec7e9c
AST tests
ibre5041 Jul 27, 2014
0b4952b
Memory leak fix.
ibre5041 Jul 27, 2014
508797d
avoid compiler warning
ibre5041 Jul 27, 2014
44ffe27
Fix dirty flag setting
ibre5041 Jul 28, 2014
0626d13
REWRITE_EARLY_EXCEPTION aka RewriteEarlyExitException
ibre5041 Jul 29, 2014
7f32b85
Performance improvement - do not alloc new instances of std::string i…
ibre5041 Aug 4, 2014
17dcc84
Debug print
ibre5041 Jul 27, 2014
3c713e3
nextNode nextTree fix
ibre5041 Jul 28, 2014
3b7cc8d
Segfault fix
ibre5041 Aug 4, 2014
470eff5
memory leak fix
ibre5041 Aug 13, 2014
c29d448
fix memory leaks when parse error-recovering/error-reporting
ibre5041 Aug 14, 2014
9ba24c5
remove preprecessor macros ANTLR_BEGIN_NAMESPACE/ANTLR_END_NAMESPACE
ibre5041 Aug 14, 2014
52eac3d
Cleanup
ibre5041 Aug 15, 2014
11b73bf
avoid various compiler warnings on various platforms
ibre5041 Aug 15, 2014
c28a3ef
Sync tests with latest changes
ibre5041 Aug 15, 2014
1ecc77e
Force all enum values (including EOF_TOKEN) to be unsigned
ibre5041 Aug 15, 2014
1e1405f
Linux compile fixes, older gcc support
ibre5041 Aug 15, 2014
fff2271
fix for BLOCK[$lc,"BLOCK"]
ibre5041 Aug 15, 2014
e33569b
CommonTree::getCharPositionInLine/getLine renamed and fixed
ibre5041 Aug 16, 2014
1e6ddad
Function name aligned
ibre5041 Aug 21, 2014
7365950
Function name aligned
ibre5041 Aug 21, 2014
bfa144c
AST construcition fixes - clone recursively
ibre5041 Aug 23, 2014
bdaf927
Reduce size of rule return class. Do not keep pointer onto parser in …
ibre5041 Aug 27, 2014
09e49a4
linux headers fix
ibre5041 Aug 28, 2015
b4839bf
fix test s005
ibre5041 Sep 4, 2015
545bc01
add TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType…
ibre5041 Sep 4, 2015
2ed5d99
Reduce size of rule return class. Do not keep pointer onto parser in …
ibre5041 Aug 27, 2014
9146932
Function names aligned
ibre5041 Aug 21, 2014
7af3cd8
AST construcition fixes - clone recursively
ibre5041 Aug 23, 2014
3552feb
test a005 - rewrites having predicates
ibre5041 Jul 29, 2014
14bd4a5
a006
ibre5041 Aug 13, 2014
c8eabb4
Merge branch 'master' of https://github.com/ibre5041/antlr3
ibre5041 Sep 6, 2015
8557bc6
missing create functions
ibre5041 Sep 6, 2015
b339647
Store additional information in Tokens member TokenUserDataType
ibre5041 Sep 17, 2015
5cdcf00
Store UserData in Tree node
ibre5041 Sep 27, 2015
e28a57c
display additional comments(enum value) in generated sources
ibre5041 Sep 27, 2015
2808ae9
test a009 treeAdaptor override example
ibre5041 Sep 30, 2015
a4d1928
allow overriden recover() method to emit a factored("hand make") token
ibre5041 Mar 31, 2016
45cc4eb
Do not segfault when getTokenName(index) is out of bounds (return <UN…
ibre5041 May 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions runtime/C/src/antlr3baserecognizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
8 changes: 5 additions & 3 deletions runtime/C/src/antlr3basetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
81 changes: 55 additions & 26 deletions runtime/Cpp/include/antlr3.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,62 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <string>
#include <cassert>
#include <cstddef> // ptrdiff_t
#include <cstdint> // uint32_t, ...
#include <cstdio> // stderr (TODO remove fprintf(stderr)
#include <cstdlib> // malloc, calloc
#include <cstring>

#include <algorithm>
#include <deque>
#include <exception>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <new>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#include "antlr3defs.hpp"

/* Pre declare the typedefs for all the interfaces, then
* they can be inter-dependant and we will let the linker
* sort it out for us.
*/
#include "antlr3interfaces.hpp"

// Include the unicode.org conversion library header.
//
#include "antlr3convertutf.hpp"

#include "antlr3errors.hpp"
#include "antlr3memory.hpp"

#include "antlr3defs.hpp"

#include "antlr3errors.hpp"
#include "antlr3memory.hpp"

#include "antlr3recognizersharedstate.hpp"
#include "antlr3baserecognizer.hpp"
#include "antlr3bitset.hpp"
#include "antlr3collections.hpp"
#include "antlr3commontoken.hpp"
#include "antlr3commontree.hpp"
#include "antlr3commontreeadaptor.hpp"
#include "antlr3cyclicdfa.hpp"
#include "antlr3debugeventlistener.hpp"
#include "antlr3exception.hpp"
#include "antlr3filestream.hpp"
#include "antlr3intstream.hpp"
#include "antlr3input.hpp"
#include "antlr3tokenstream.hpp"
#include "antlr3commontreenodestream.hpp"
#include "antlr3lexer.hpp"
#include "antlr3parser.hpp"
#include "antlr3rewritestreams.hpp"
#include "antlr3traits.hpp"
#include "antlr3treeparser.hpp"
#include "antlr3collections.hpp"
#include "antlr3recognizersharedstate.hpp"
#include "antlr3baserecognizer.hpp"
#include "antlr3bitset.hpp"
#include "antlr3commontoken.hpp"
#include "antlr3commontree.hpp"
#include "antlr3commontreeadaptor.hpp"
#include "antlr3cyclicdfa.hpp"
#include "antlr3debugeventlistener.hpp"
#include "antlr3exception.hpp"
#include "antlr3filestream.hpp"
#include "antlr3intstream.hpp"
#include "antlr3input.hpp"
#include "antlr3tokenstream.hpp"
#include "antlr3commontreenodestream.hpp"
#include "antlr3lexer.hpp"
#include "antlr3parser.hpp"
//#include "antlr3rewritestreams.hpp"
#include "antlr3rewriteruletokenstream.hpp"
#include "antlr3rewriterulesubtreestream.hpp"
#include "antlr3traits.hpp"
#include "antlr3treeparser.hpp"

#endif
4 changes: 2 additions & 2 deletions runtime/Cpp/include/antlr3.inl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

//static
ANTLR_INLINE void GenericStream::displayRecognitionError( const StringType& str )
{
fprintf(stderr, str.c_str() );
}

ANTLR_END_NAMESPACE()
}
7 changes: 2 additions & 5 deletions runtime/Cpp/include/antlr3baserecognizer.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "antlr3defs.hpp"
#include "antlr3collections.hpp"

ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

/** \brief Base tracking context structure for all types of
* recognizers.
Expand Down Expand Up @@ -501,7 +498,7 @@ class BaseRecognizer : public ImplTraits::AllocPolicyType

};

ANTLR_END_NAMESPACE()
}

#include "antlr3baserecognizer.inl"

Expand Down
29 changes: 15 additions & 14 deletions runtime/Cpp/include/antlr3baserecognizer.inl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

template< class ImplTraits, class StreamType >
BaseRecognizer<ImplTraits, StreamType>::BaseRecognizer(ANTLR_UINT32 sizeHint,
Expand Down Expand Up @@ -62,15 +62,16 @@ BaseRecognizer<ImplTraits, StreamType>::match(ANTLR_UINT32 ttype, BitsetListType
//
const UnitType* matchedSymbol = this->getCurrentInputSymbol(is);

if (is->_LA(1) == ttype)
{
//if (is->LA(1) == ttype)
if (matchedSymbol->get_type() == ttype)
{
// The token was the one we were told to expect
//
is->consume(); // Consume that token from the stream
m_state->set_errorRecovery(false); // Not in error recovery now (if we were)
m_state->set_failed(false); // The match was a success
return matchedSymbol; // We are done
}
}

// We did not find the expected token type, if we are backtracking then
// we just set the failed flag and return.
Expand Down Expand Up @@ -107,7 +108,7 @@ void BaseRecognizer<ImplTraits, StreamType>::matchAny()
template< class ImplTraits, class StreamType >
bool BaseRecognizer<ImplTraits, StreamType>::mismatchIsUnwantedToken(IntStreamType* is, ANTLR_UINT32 ttype)
{
ANTLR_UINT32 nextt = is->_LA(2);
ANTLR_UINT32 nextt = is->LA(2);

if (nextt == ttype)
{
Expand Down Expand Up @@ -172,7 +173,7 @@ bool BaseRecognizer<ImplTraits, StreamType>::mismatchIsMissingToken(IntStreamTyp
/// in follow set to indicate that the fall of the start symbol is
/// in the set (EOF can follow).
///
if ( followClone->isMember(is->_LA(1))
if ( followClone->isMember(is->LA(1))
|| followClone->isMember(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE)
)
{
Expand Down Expand Up @@ -579,7 +580,7 @@ bool BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedElement(Bitse
* is consistent, then we can "insert" that token by not throwing
* an exception and assuming that we saw it.
*/
if ( follow->isMember(is->_LA(1)) == true)
if ( follow->isMember(is->LA(1)) == true)
{
/* report the error, but don't cause any rules to abort and stuff
*/
Expand Down Expand Up @@ -612,14 +613,14 @@ void BaseRecognizer<ImplTraits, StreamType>::consumeUntil(ANTLR_UINT32 tokenTy

// What do have at the moment?
//
ANTLR_UINT32 ttype = is->_LA(1);
ANTLR_UINT32 ttype = is->LA(1);

// Start eating tokens until we get to the one we want.
//
while (ttype != ImplTraits::CommonTokenType::TOKEN_EOF && ttype != tokenType)
{
is->consume();
ttype = is->_LA(1);
ttype = is->LA(1);
}
}

Expand All @@ -632,14 +633,14 @@ void BaseRecognizer<ImplTraits, StreamType>::consumeUntilSet(BitsetType* set)

// What do have at the moment?
//
ttype = is->_LA(1);
ttype = is->LA(1);

// Start eating tokens until we get to one we want.
//
while (ttype != ImplTraits::CommonTokenType::TOKEN_EOF && set->isMember(ttype) == false)
{
is->consume();
ttype = is->_LA(1);
ttype = is->LA(1);
}

}
Expand Down Expand Up @@ -773,7 +774,7 @@ BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* ist
{
typedef typename ImplTraits::TokenStreamType TokenStreamType;
TokenStreamType* token_stream = static_cast<TokenStreamType*>(istream);
return token_stream->_LT(1);
return token_stream->LT(1);
}

template< class ImplTraits, class StreamType >
Expand All @@ -782,7 +783,7 @@ BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* ist
{
typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
TreeNodeStreamType* ctns = static_cast<TreeNodeStreamType*>(istream);
return ctns->_LT(1);
return ctns->LT(1);
}


Expand Down Expand Up @@ -916,4 +917,4 @@ BaseRecognizer<ImplTraits, StreamType>::~BaseRecognizer()



ANTLR_END_NAMESPACE()
}
6 changes: 2 additions & 4 deletions runtime/Cpp/include/antlr3bitset.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "antlr3defs.hpp"

ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

/** How many bits in the elements
*/
Expand Down Expand Up @@ -216,7 +214,7 @@ class Bitset : public ImplTraits::AllocPolicyType

};

ANTLR_END_NAMESPACE()
}

#include "antlr3bitset.inl"

Expand Down
4 changes: 2 additions & 2 deletions runtime/Cpp/include/antlr3bitset.inl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

template <class ImplTraits>
ANTLR_INLINE BitsetList<ImplTraits>::BitsetList()
Expand Down Expand Up @@ -489,4 +489,4 @@ Bitset<ImplTraits>* Bitset<ImplTraits>::BitsetFromList(const IntListType& list)
return bitset;
}

ANTLR_END_NAMESPACE()
}
6 changes: 2 additions & 4 deletions runtime/Cpp/include/antlr3collections.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "antlr3defs.hpp"

ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

/* -------------- TRIE Interfaces ---------------- */

Expand Down Expand Up @@ -276,7 +274,7 @@ class Topo : public ImplTraits::AllocPolicyType
~Topo();
};

ANTLR_END_NAMESPACE()
}

#include "antlr3collections.inl"

Expand Down
4 changes: 2 additions & 2 deletions runtime/Cpp/include/antlr3collections.inl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ANTLR_BEGIN_NAMESPACE()
namespace antlr3 {

template< class ImplTraits, class DataType >
ANTLR_INLINE TrieEntry<ImplTraits, DataType>::TrieEntry(const DataType& data, TrieEntry* next)
Expand Down Expand Up @@ -992,4 +992,4 @@ Topo<ImplTraits>::~Topo()
}


ANTLR_END_NAMESPACE()
}
Loading