Commit 36122e49 authored by Dimitri van Heesch's avatar Dimitri van Heesch

New VHDL parser implementation

parent 6a60477b
......@@ -17,6 +17,8 @@
/libmd5/Makefile.libmd5
/qtools/Makefile
/qtools/Makefile.qtools
/vhdlparser/Makefile
/vhdlparser/Makefile.vhdlparser
/src/Makefile.doxygen
/src/Makefile.libdoxycfg
/src/Makefile.libdoxygen
......
......@@ -21,6 +21,7 @@ clean: FORCE
- cd qtools ; $(MAKE) clean
- cd src ; $(MAKE) clean
- cd libmd5 ; $(MAKE) clean
- cd vhdlparser ; $(MAKE) clean
-cd addon/doxywizard ; $(MAKE) clean
-cd addon/doxysearch ; $(MAKE) clean
-cd addon/doxyapp ; $(MAKE) clean
......@@ -33,6 +34,7 @@ clean: FORCE
distclean: clean
-cd src ; $(MAKE) distclean
-cd libmd5 ; $(MAKE) distclean
-cd vhdlparser ; $(MAKE) distclean
-cd addon/doxywizard ; $(MAKE) distclean
-cd addon/doxysearch ; $(MAKE) distclean
-cd addon/doxyapp ; $(MAKE) distclean
......@@ -52,8 +54,9 @@ distclean: clean
-rm -f src/Makefile.doxygen src/Makefile.libdoxygen
-rm -f src/Makefile.libdoxycfg src/libdoxycfg.t src/libdoxygen.t
-rm -f libmd5/Makefile.libmd5
-rm -f vhdlparser/Makefile.vhdlparser
-rm -f .makeconfig .tmakeconfig
-rm -f src/doxygen.pro src/libdoxygen.pro qtools/qtools.pro src/libdoxycfg.pro libmd5/libmd5.pro
-rm -f src/doxygen.pro src/libdoxygen.pro qtools/qtools.pro src/libdoxycfg.pro libmd5/libmd5.pro vhdlparser/vhdlparser.pro
-rm -rf generated_src
-rm -f addon/doxywizard/doxywizard.pro
-rm -f VERSION
......@@ -95,7 +98,7 @@ docs: FORCE
pdf: docs
cd latex ; $(MAKE)
DISTFILES = Doxyfile libmd5 addon tmake doc examples bin lib objects testing \
DISTFILES = Doxyfile vhdlparser libmd5 addon tmake doc examples bin lib objects testing \
qtools src configure configure.bin Makefile.in Makefile.win_nmake.in \
Makefile.win_make.in INSTALL LANGUAGE.HOWTO LICENSE PLATFORMS \
VERSION README.md packages winbuild jquery
......
......@@ -868,7 +868,7 @@ INCLUDEPATH += $XAPIAN/include
EOF
fi
f_inmakefiles="Makefile.in qtools/Makefile.in src/Makefile.in examples/Makefile.in doc/Makefile.in addon/doxywizard/Makefile.in addon/doxmlparser/src/Makefile.in addon/doxmlparser/test/Makefile.in addon/doxmlparser/examples/metrics/Makefile.in libmd5/Makefile.in addon/doxyapp/Makefile.in addon/doxysearch/Makefile.in"
f_inmakefiles="Makefile.in qtools/Makefile.in src/Makefile.in examples/Makefile.in doc/Makefile.in addon/doxywizard/Makefile.in addon/doxmlparser/src/Makefile.in addon/doxmlparser/test/Makefile.in addon/doxmlparser/examples/metrics/Makefile.in libmd5/Makefile.in addon/doxyapp/Makefile.in addon/doxysearch/Makefile.in vhdlparser/Makefile.in"
for i in $f_inmakefiles ; do
SRC=$i
......@@ -893,7 +893,9 @@ EOF
echo "all: generated_src/doxygen/version.cpp $EXTRADEPS" >> $DST
echo " \$(MAKE) -C qtools" >> $DST
echo " \$(MAKE) -C libmd5" >> $DST
echo " \$(MAKE) -C vhdlparser" >> $DST
echo " \$(MAKE) -C src" >> $DST
if test $f_wizard = YES; then
echo " \$(MAKE) MAN1DIR=\$(MAN1DIR) -C addon/doxywizard" >> $DST
fi
......@@ -930,7 +932,7 @@ done
cat src/libdoxycfg.t.in | sed -e "s|%%FLEX%%|$f_flex|g" -e "s|%%BISON%%|$f_bison|g" -e "s|%%PYTHON%%|$f_python|g" > src/libdoxycfg.t
cat src/libdoxygen.t.in | sed -e "s|%%FLEX%%|$f_flex|g" -e "s|%%BISON%%|$f_bison|g" -e "s|%%PYTHON%%|$f_python|g" > src/libdoxygen.t
f_inprofiles="qtools/qtools.pro.in src/libdoxygen.pro.in src/libdoxycfg.pro.in src/doxygen.pro.in addon/doxywizard/doxywizard.pro.in addon/doxmlparser/src/doxmlparser.pro.in addon/doxmlparser/test/xmlparse.pro.in addon/doxmlparser/examples/metrics/metrics.pro.in libmd5/libmd5.pro.in addon/doxyapp/doxyapp.pro.in addon/doxysearch/doxysearch.pro.in addon/doxysearch/doxyindexer.pro.in"
f_inprofiles="qtools/qtools.pro.in src/libdoxygen.pro.in src/libdoxycfg.pro.in src/doxygen.pro.in addon/doxywizard/doxywizard.pro.in addon/doxmlparser/src/doxmlparser.pro.in addon/doxmlparser/test/xmlparse.pro.in addon/doxmlparser/examples/metrics/metrics.pro.in libmd5/libmd5.pro.in addon/doxyapp/doxyapp.pro.in addon/doxysearch/doxysearch.pro.in addon/doxysearch/doxyindexer.pro.in vhdlparser/vhdlparser.pro.in"
for i in $f_inprofiles ; do
SRC=$i
......
......@@ -2908,6 +2908,7 @@ void DocVhdlFlow::parse()
DBG(("DocVhdlFlow::parse() end\n"));
DocNode *n=g_nodeStack.pop();
ASSERT(n==this);
VhdlDocGen::createFlowChart(g_memberDef);
}
......
......@@ -79,7 +79,7 @@
#include "store.h"
#include "marshal.h"
#include "portable.h"
#include "vhdlscanner.h"
#include "vhdljjparser.h"
#include "vhdldocgen.h"
#include "eclipsehelp.h"
#include "cite.h"
......
......@@ -18,18 +18,18 @@ TEMPLATE = app.t
CONFIG = console warn_on $extraopts
HEADERS = doxygen.h
SOURCES = main.cpp
unix:LIBS += -L../lib -ldoxygen -ldoxycfg -lqtools -lmd5 -lpthread %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%%
unix:LIBS += -L../lib -ldoxygen -lvhdlparser -ldoxycfg -lqtools -lmd5 -lpthread %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%%
win32:INCLUDEPATH += .
win32-mingw:LIBS += -L../lib -ldoxygen -ldoxycfg -lqtools -lmd5 -lpthread -llibiconv -lole32 %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%%
win32-msvc:LIBS += qtools.lib md5.lib doxygen.lib doxycfg.lib shell32.lib iconv.lib
win32-mingw:LIBS += -L../lib -ldoxygen -ldoxycfg -lvhdlparser -lqtools -lmd5 -lpthread -llibiconv -lole32 %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%%
win32-msvc:LIBS += qtools.lib md5.lib doxygen.lib doxycfg.lib vhdlparser.lib shell32.lib iconv.lib
win32-msvc:TMAKE_LFLAGS += /LIBPATH:..\lib
win32-borland:LIBS += qtools.lib md5.lib doxygen.lib doxycfg.lib shell32.lib iconv.lib
win32-borland:LIBS += qtools.lib md5.lib doxygen.lib doxycfg.lib vhdlparser.lib shell32.lib iconv.lib
win32-borland:TMAKE_LFLAGS += -L..\lib -L$(BCB)\lib\psdk
win32:TMAKE_CXXFLAGS += -DQT_NODLL
win32-g++:LIBS = -L../lib -ldoxygen -ldoxycfg -lqtools -lmd5 -liconv -lpthread %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%% -Wl,--as-needed -lole32
win32-g++:LIBS = -L../lib -ldoxygen -ldoxycfg -lvhdlparser -lqtools -lmd5 -liconv -lpthread %%SQLITE3_LIBS%% %%LIBCLANG_LIBS%% -Wl,--as-needed -lole32
win32-g++:TMAKE_CXXFLAGS += -fno-exceptions -fno-rtti
DEPENDPATH += ../generated_src/doxygen
INCLUDEPATH += ../qtools ../libmd5 .
INCLUDEPATH += ../qtools ../libmd5 . ../vhdlparser
DESTDIR = ../bin
TARGET = doxygen
unix:TARGETDEPS = ../lib/libdoxygen.a ../lib/libdoxycfg.a
......
......@@ -1773,14 +1773,35 @@ void HtmlDocVisitor::visitPost(DocHtmlBlockQuote *b)
forceStartParagraph(b);
}
void HtmlDocVisitor::visitPre(DocVhdlFlow *)
void HtmlDocVisitor::visitPre(DocVhdlFlow *vf)
{
if (m_hide) return;
if (VhdlDocGen::getFlowMember()) // use VHDL flow chart creator
{
forceEndParagraph(vf);
QCString fname=FlowChart::convertNameToFileName();
m_t << "<p>";
m_t << "flowchart: " ; // TODO: translate me
m_t << "<a href=\"";
m_t << fname.data();
m_t << ".svg\">";
m_t << VhdlDocGen::getFlowMember()->name().data();
m_t << "</a>";
if (vf->hasCaption())
{
m_t << "<br />";
}
}
}
void HtmlDocVisitor::visitPost(DocVhdlFlow *)
void HtmlDocVisitor::visitPost(DocVhdlFlow *vf)
{
if (m_hide) return;
if (VhdlDocGen::getFlowMember()) // use VHDL flow chart creator
{
m_t << "</p>";
forceStartParagraph(vf);
}
}
void HtmlDocVisitor::visitPre(DocParBlock *)
......
......@@ -115,11 +115,12 @@ HEADERS = arguments.h \
version.h \
vhdlcode.h \
vhdldocgen.h \
vhdlscanner.h \
xmldocvisitor.h \
xmlgen.h \
docbookvisitor.h \
docbookgen.h \
vhdljjparser.h
SOURCES = arguments.cpp \
cite.cpp \
......@@ -198,10 +199,10 @@ SOURCES = arguments.cpp \
xmlgen.cpp \
docbookvisitor.cpp \
docbookgen.cpp \
../generated_src/doxygen/ce_parse.cpp \
vhdljjparser.cpp \
../generated_src/doxygen/ce_parse.cpp \
../generated_src/doxygen/constexp.cpp \
../generated_src/doxygen/vhdlcode.cpp \
../generated_src/doxygen/vhdlscanner.cpp \
../generated_src/doxygen/code.cpp \
../generated_src/doxygen/commentcnv.cpp \
../generated_src/doxygen/commentscan.cpp \
......@@ -215,13 +216,15 @@ SOURCES = arguments.cpp \
../generated_src/doxygen/tclscanner.cpp \
../generated_src/doxygen/fortrancode.cpp \
../generated_src/doxygen/fortranscanner.cpp \
../generated_src/doxygen/version.cpp
../generated_src/doxygen/version.cpp
win32:TMAKE_CXXFLAGS += -DQT_NODLL
win32-msvc:TMAKE_CXXFLAGS += -Zm200
win32-g++:TMAKE_CXXFLAGS += -fno-exceptions
linux-g++:TMAKE_CXXFLAGS += -fno-exceptions
INCLUDEPATH += ../generated_src/doxygen ../src ../qtools ../libmd5
INCLUDEPATH += ../generated_src/doxygen ../src ../qtools ../libmd5 ../vhdlparser
INCLUDEPATH += %%SQLITE3_INC%%
DEPENDPATH += ../generated_src/doxygen
win32:INCLUDEPATH += .
......
......@@ -111,8 +111,7 @@ sub GenerateLex {
$(YACC) -l -d -p ce_parsexpYY constexp.y -o \$(GENERATED_SRC)/ce_parse.c
-rm $(GENERATED_SRC)/ce_parse.c
#$ GenerateDep("\$(GENERATED_SRC)/vhdlscanner.cpp","vhdlscanner.l");
#$ GenerateLex("vhdlscanner",1);
TO_C_CMD=$(PYTHON) to_c_cmd.py < $< > $@
......
......@@ -37,7 +37,7 @@
#include "parserintf.h"
#include "marshal.h"
#include "objcache.h"
#include "vhdlscanner.h"
#include "vhdldocgen.h"
#include "arguments.h"
#include "memberlist.h"
......
......@@ -169,6 +169,7 @@ void OutputList::writeDoc(DocRoot *root,Definition *ctx,MemberDef *md)
// ctx?ctx->getDefFileExtension().data():"<null>");
if (og->isEnabled()) og->writeDoc(root,ctx,md);
}
VhdlDocGen::setFlowMember(0);
}
bool OutputList::parseText(const QCString &textStr)
......
......@@ -1576,6 +1576,8 @@ void parseVhdlCode(CodeOutputInterface &od,const char *className,const QCString
// g_args.resize(0);
g_parmName.resize(0);
g_parmType.resize(0);
if(!g_lexInit)
VhdlDocGen::init();
if (memberDef)
{
setParameterList(memberDef);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
/******************************************************************************
*
*
*
* Copyright (C) 1997-2014 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#ifndef VHDLSCANNER_H
#define VHDLSCANNER_H
#ifndef VHDLJJPARSER_H
#define VHDLJJPARSER_H
#include "parserintf.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <qarray.h>
#include <unistd.h>
#include <qfile.h>
#include <qdict.h>
#include "entry.h"
#include <string>
#include "memberlist.h"
#include "types.h"
#include "entry.h"
#include "vhdldocgen.h"
#include "qstringlist.h"
#include "vhdlcode.h"
#include "config.h"
enum { GEN_SEC=0x1, PARAM_SEC,CONTEXT_SEC,PROTECTED_SEC } ;
void parserVhdlfile(const char* inputBuffer);
class Entry;
class ClassSDict;
......@@ -38,7 +29,7 @@ class FileStorage;
class ClassDef;
class MemberDef;
class QStringList;
class VhdlConfNode;
/** \brief VHDL parser using state-based lexical scanning.
*
......@@ -55,7 +46,7 @@ class VHDLLanguageScanner : public ParserInterface
Entry *root,
bool sameTranslationUnit,
QStrList &filesInSameTranslationUnit);
bool needsPreprocessing(const QCString &extension);
void parseCode(CodeOutputInterface &codeOutIntf,
const char *scopeName,
const QCString &input,
......@@ -69,14 +60,39 @@ class VHDLLanguageScanner : public ParserInterface
MemberDef *memberDef=0,
bool showLineNumbers=TRUE,
Definition *searchCtx=0,
bool collectXRefs=TRUE
);
void resetCodeParserState();
void parsePrototype(const char *text);
bool collectXRefs=TRUE);
bool needsPreprocessing(const QCString &) { return TRUE; }
void resetCodeParserState() {}
void parsePrototype(const char *) {}
};
void vhdlscanFreeScanner();
class VhdlConfNode
{
public:
VhdlConfNode(const char* a,const char* b,const char* config,const char* cs,bool leaf)
{
arch=a; // architecture e.g. for iobuffer
arch=arch.lower();
binding=b; // binding e.g. use entiy work.xxx(bev)
binding=binding.lower();
confVhdl=config; // configuration foo is bar
compSpec=cs;
isInlineConf=false; // primary configuration?
isLeaf=leaf;
};
QCString confVhdl;
QCString arch;
QCString binding;
QCString compSpec;
int level;
bool isLeaf;
bool isInlineConf;
};
//---------------------------------------------------------------------------------
void vhdlscanFreeScanner();
QList<VhdlConfNode>& getVhdlConfiguration();
QList<Entry>& getVhdlInstList();
#endif
This diff is collapsed.
/* Generated By:JavaCC: Do not edit this line. CharStream.cc Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#include "CharStream.h"
namespace {
template <class T>
void ArrayCopy(T* src, int src_offset, T* dest, int dest_offset, int len) {
for (int i = 0; i < len; i++) {
dest[dest_offset + i] = src[src_offset + i];
}
}
class StringReaderStream : public ReaderStream {
public:
StringReaderStream(const JAVACC_STRING_TYPE& str) : str_(str), cur_(0), max_(str.size()) {}
virtual size_t read(JAVACC_CHAR_TYPE *bufptr, int offset, size_t len) {
size_t count = str_.copy(bufptr + offset, len > max_ ? max_ : len, cur_);
cur_ += count;
max_ -= count;
return count;
}
virtual ~StringReaderStream() {}
virtual bool endOfInput() {
return max_ == 0;
}
private:
const JAVACC_STRING_TYPE str_;
size_t cur_;
size_t max_;
};
}
namespace vhdl {
namespace parser {
void CharStream::ReInit(const JAVACC_STRING_TYPE& str, int startline,
int startcolumn, int buffersize) {
StringReaderStream *stream = new StringReaderStream(str);
ReInit(stream, startline, startcolumn, buffersize);
deleteStream = true;
}
void CharStream::ReInit(ReaderStream *input_stream, int startline,
int startcolumn, int buffersize) {
if (deleteStream) {
delete inputStream;
}
if (buffer != NULL) {
DeleteBuffers();
}
available = bufsize = buffersize;
buffer = new JAVACC_CHAR_TYPE[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
column = startcolumn - 1;
inputStream = input_stream;
line = startline;
prevCharIsLF = prevCharIsCR = false;
tokenBegin = inBuf = maxNextCharInd = 0;
bufpos = -1;
deleteStream = false;
}
void CharStream::DeleteBuffers() {
delete[] buffer;
delete[] bufline;
delete[] bufcolumn;
}
void CharStream::adjustBeginLineColumn(int newLine, int newCol) {
int start = tokenBegin;
int len;
if (bufpos >= tokenBegin) {
len = bufpos - tokenBegin + inBuf + 1;
} else {
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}
int i = 0, j = 0, k = 0;
int nextColDiff = 0, columnDiff = 0;
while (i < len && bufline[j = start % bufsize] ==
bufline[k = (start + 1) % bufsize]) {
bufline[j] = newLine;
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
bufcolumn[j] = newCol + columnDiff;
columnDiff = nextColDiff;
i++;
start++;
}
if (i < len) {
bufline[j] = newLine++;
bufcolumn[j] = newCol + columnDiff;
while (i++ < len) {
if (bufline[j = start % bufsize] != bufline[(start + 1) % bufsize])
bufline[j] = newLine++;
else
bufline[j] = newLine;
start++;
}
}
line = bufline[j];
column = bufcolumn[j];
}
void CharStream::ExpandBuff(bool wrapAround) {
JAVACC_CHAR_TYPE *newbuffer = new JAVACC_CHAR_TYPE[bufsize + 2048];
int *newbufline = new int[bufsize + 2048];
int *newbufcolumn = new int[bufsize + 2048];
if (wrapAround) {
ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
ArrayCopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
ArrayCopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
ArrayCopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufpos += (bufsize - tokenBegin);
} else {
ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufpos -= tokenBegin;
}
maxNextCharInd = bufpos;
DeleteBuffers();
buffer = newbuffer;
bufline = newbufline;
bufcolumn = newbufcolumn;
bufsize += 2048;
available = bufsize;
tokenBegin = 0;
}
void CharStream::FillBuff() {
if (maxNextCharInd == available) {
if (available == bufsize) {
if (tokenBegin > 2048) {
bufpos = maxNextCharInd = 0;
available = tokenBegin;
} else if (tokenBegin < 0) {
bufpos = maxNextCharInd = 0;
} else {
ExpandBuff(false);
}
} else if (available > tokenBegin) {
available = bufsize;
} else if ((tokenBegin - available) < 2048) {
ExpandBuff(true);
} else {
available = tokenBegin;
}
}
int i = inputStream->read(buffer, maxNextCharInd, available - maxNextCharInd);
if (i > 0) {
maxNextCharInd += i;
} else {
--bufpos;
backup(0);
if (tokenBegin == -1) {
tokenBegin = bufpos;
}
}
}
void CharStream::UpdateLineColumn(JAVACC_CHAR_TYPE c) {
column++;
if (prevCharIsLF) {
prevCharIsLF = false;
column = 1;
line++;
} else if (prevCharIsCR) {
prevCharIsCR = false;
if (c == '\n') {
prevCharIsLF = true;
} else {
column = 1;
line++;
}
}
switch (c) {
case '\r' :
prevCharIsCR = true;
break;
case '\n' :
prevCharIsLF = true;
break;
case '\t' :
column--;
column += (tabSize - (column % tabSize));
break;
default :
break;
}
bufline[bufpos] = line;
bufcolumn[bufpos] = column;
}
}
}
/* JavaCC - OriginalChecksum=e709b9ee1adf0fcb6b1c5e1641f10348 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. CharStream.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef CHARSTREAM_H
#define CHARSTREAM_H
#include "JavaCC.h"
#ifndef INITIAL_BUFFER_SIZE
#define INITIAL_BUFFER_SIZE 4096
#endif
namespace vhdl {
namespace parser {
/**
* This class describes a character stream that maintains line and
* column number positions of the characters. It also has the capability
* to backup the stream to some extent. An implementation of this
* class is used in the TokenManager implementation generated by
* JavaCCParser.
*
* All the methods except backup can be implemented in any fashion. backup
* needs to be implemented correctly for the correct operation of the lexer.
* Rest of the methods are all used to get information like line number,
* column number and the string that constitutes a token and are not used
* by the lexer. Hence their implementation won't affect the generated lexer's
* operation.
*/
class CharStream {
public:
void setTabSize(int i) { tabSize = i; }
int getTabSize(int) { return tabSize; }
virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
virtual bool getTrackLineColumn() { return trackLineColumn; }
virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
/**
* Backs up the input stream by amount steps. Lexer calls this method if it
* had already read some characters, but could not use them to match a
* (longer) token. So, they will be used again as the prefix of the next
* token and it is the implemetation's responsibility to do this right.
*/
virtual inline void backup(int amount) {
inBuf += amount;
bufpos -= amount;
if (bufpos < 0) {
bufpos += bufsize;
}
}
/**
* Returns the next character that marks the beginning of the next token.
* All characters must remain in the buffer between two successive calls
* to this method to implement backup correctly.
*/
virtual inline JAVACC_CHAR_TYPE BeginToken() {
tokenBegin = -1;
JAVACC_CHAR_TYPE c = readChar();
tokenBegin = bufpos;
return c;
}
/**
* Returns the next character from the selected input. The method
* of selecting the input is the responsibility of the class
* implementing this class.
*/
virtual inline JAVACC_CHAR_TYPE readChar() {
if (inBuf > 0) {
--inBuf;
++bufpos;
if (bufpos == bufsize) {
bufpos = 0;
}
return buffer[bufpos];
}
++bufpos;
if (bufpos >= maxNextCharInd) {
FillBuff();
}
JAVACC_CHAR_TYPE c = buffer[bufpos];
if (trackLineColumn) {
UpdateLineColumn(c);
}
return c;
}
virtual void ExpandBuff(bool wrapAround);
virtual void FillBuff();
/**
* Returns a string made up of characters from the marked token beginning
* to the current buffer position. Implementations can return
* anything that they want to. For example, for efficiency, one might decide
* to just return NULL, which is a valid implementation.
*/
virtual JAVACC_STRING_TYPE GetImage() {
if (bufpos >= tokenBegin)
return JAVACC_STRING_TYPE(buffer + tokenBegin, bufpos - tokenBegin + 1);
else
return JAVACC_STRING_TYPE(buffer + tokenBegin, bufsize - tokenBegin)
.append(buffer, bufpos + 1);
}
/**
* Returns an array of characters that make up the suffix of length 'len' for
* the currently matched token. This is used to build up the matched string
* for use in actions in the case of MORE. A simple and inefficient
* implementation of this is as follows :
*/
virtual JAVACC_STRING_TYPE GetSuffix(int len) {
if ((bufpos + 1) >= len) {
return JAVACC_STRING_TYPE(buffer + bufpos - len + 1, len);
}
return JAVACC_STRING_TYPE(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1)
.append(buffer, bufpos + 1);
}
/**
* The lexer calls this function to indicate that it is done with the stream
* and hence implementations can free any resources held by this class.
*/
virtual void DeleteBuffers();
virtual ~CharStream() {
if (deleteStream) {
delete inputStream;
}
DeleteBuffers();
}
bool endOfInput() {
return inBuf == 0 && bufpos + 1 >= maxNextCharInd &&
inputStream->endOfInput();
}
CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline,
int startcolumn, int buffersize) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, buffersize);
}
CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline, int startcolumn) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
}
CharStream(const JAVACC_STRING_TYPE& str, int startline,
int startcolumn, int buffersize) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(str, startline, startcolumn, buffersize);
}
CharStream(const JAVACC_STRING_TYPE& str, int startline, int startcolumn) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0) ,tabSize(8), trackLineColumn(true){
ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
}
CharStream(ReaderStream *input_stream, int startline,
int startcolumn, int) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
}
CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
}
CharStream(ReaderStream *input_stream) :
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
inBuf(0),tabSize(8), trackLineColumn(true) {
ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
}
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn,
int buffersize);
virtual void ReInit(ReaderStream *input_stream, int startline,
int startcolumn) {
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
}
virtual void ReInit(ReaderStream *input_stream) {
ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
}
virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
int startcolumn, int buffersize);
virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
int startcolumn) {
ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
}
virtual void adjustBeginLineColumn(int newLine, int newCol);
protected:
virtual void UpdateLineColumn(JAVACC_CHAR_TYPE c);
int *bufline;
int *bufcolumn;
ReaderStream *inputStream;
bool deleteStream;
JAVACC_CHAR_TYPE * buffer;
int bufpos;
int bufsize;
int tokenBegin;
int column;
int line;
bool prevCharIsCR ;
bool prevCharIsLF ;
int available;
int maxNextCharInd;
int inBuf ;
int tabSize ;
bool trackLineColumn;
};
}
}
#endif
/* JavaCC - OriginalChecksum=5eaf75ef6a2c7859369c80cf6fd037e0 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. ErrorHandler.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef ERRORHANDLER_H
#define ERRORHANDLER_H
#include <string>
#include "JavaCC.h"
#include "Token.h"
namespace vhdl {
namespace parser {
class VhdlParser;
class ErrorHandler {
protected:
int error_count;
public:
// Called when the parser encounters a different token when expecting to
// consume a specific kind of token.
// expectedKind - token kind that the parser was trying to consume.
// expectedToken - the image of the token - tokenImages[expectedKind].
// actual - the actual token that the parser got instead.
virtual void handleUnexpectedToken(int, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *) {
error_count++;
fprintf(stderr, "Expecting %s at: %d:%d but got %s\n", addUnicodeEscapes(expectedToken).c_str(), actual->beginLine, actual->beginColumn, addUnicodeEscapes(actual->image).c_str());
}
// Called when the parser cannot continue parsing.
// last - the last token successfully parsed.
// unexpected - the token at which the error occurs.
// production - the production in which this error occurrs.
virtual void handleParseError(Token *, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *) {
error_count++;
fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str());
}
virtual int getErrorCount() {
return error_count;
}
virtual ~ErrorHandler() {}
ErrorHandler() { error_count = 0; }
};
}
}
#endif
/* JavaCC - OriginalChecksum=282223c3bcb53b7ff385aed35944d185 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. JavaCC.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef __JAVACC_H
#define __JAVACC_H
#include <stdio.h>
#include <string>
#include <memory.h>
#include <assert.h>
#include <cstring>
#include "vhdlstring.h"
#ifndef JAVACC_CHAR_TYPE
#define JAVACC_CHAR_TYPE char
#endif
#ifndef JAVACC_STRING_TYPE
#define JAVACC_STRING_TYPE VhdlString
#endif
#define finally // TODO(Sreeni): Get rid of when we fix jjtree
#define JAVACC_SIMPLE_STRING VhdlString
JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str);
typedef JAVACC_STRING_TYPE StringBuffer;
typedef JAVACC_STRING_TYPE String;
// Abstraction on stream classes to read a block of data into a buffer.
class ReaderStream {
public:
// Read block of data into a buffer and return the actual number read.
virtual size_t read(JAVACC_CHAR_TYPE *, int, size_t) {
return 0;
}
virtual bool endOfInput() { return true; }
virtual ~ReaderStream() {}
};
const JAVACC_CHAR_TYPE EMPTY[] = { 0 };
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#endif
/* JavaCC - OriginalChecksum=775c677272b259e2a33aac80851ba9f1 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. JavaCC.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef __JAVACC_H
#define __JAVACC_H
#include <stdio.h>
#include <string>
#include <memory.h>
#include <assert.h>
#include <cstring>
#include "vhdlstring.h"
#ifndef JAVACC_CHAR_TYPE
#define JAVACC_CHAR_TYPE char
#endif
#ifndef JAVACC_STRING_TYPE
#define JAVACC_STRING_TYPE VhdlString
#endif
#define finally // TODO(Sreeni): Get rid of when we fix jjtree
#define JAVACC_SIMPLE_STRING VhdlString
JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str);
typedef JAVACC_STRING_TYPE StringBuffer;
typedef JAVACC_STRING_TYPE String;
// Abstraction on stream classes to read a block of data into a buffer.
class ReaderStream {
public:
// Read block of data into a buffer and return the actual number read.
virtual size_t read(JAVACC_CHAR_TYPE *, int, size_t) {
return 0;
}
virtual bool endOfInput() { return true; }
virtual ~ReaderStream() {}
};
const JAVACC_CHAR_TYPE EMPTY[] = { 0 };
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#endif
/* JavaCC - OriginalChecksum=775c677272b259e2a33aac80851ba9f1 (do not edit this line) */
#
#
#
# Copyright (C) 1997-2000 by Dimitri van Heesch.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation under the terms of the GNU General Public License is hereby
# granted. No representations are made about the suitability of this software
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
# Documents produced by Doxygen are derivative works derived from the
# input used in their production; they are not affected by this license.
#
all: Makefile.vhdlparser Makefile
$(MAKE) -f Makefile.vhdlparser $@
Makefile.vhdlparser: vhdlparser.pro
$(ENV) $(PERL) "$(TMAKE)" vhdlparser.pro >Makefile.vhdlparser
tmake:
$(ENV) $(PERL) "$(TMAKE)" vhdlparser.pro >Makefile.vhdlparser
clean: Makefile.vhdlparser
$(MAKE) -f Makefile.vhdlparser clean
regenerate:
$(RM) CharStream.cc CharStream.h ErrorHandler.h ParseException.cc ParseException.h \
Token.cc Token.h TokenManager.h TokenMgrError.cc TokenMgrError.h VhdlParser.cc VhdlParser.h \
VhdlParserConstants.h VhdlParserTokenManager.cc VhdlParserTokenManager.h \
JavaCC.h
javacc vhdlparser.jj
patch <vhdlparser.patch
$(CP) JavaCC.h.in JavaCC.h
distclean: clean
$(RM) Makefile vhdlparser.pro
FORCE:
/* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#include "ParseException.h"
namespace vhdl {
namespace parser {
/**
* This exception is thrown when parse errors are encountered.
* You can explicitly create objects of this exception type by
* calling the method generate_ParseException in the generated
* parser.
*
* You can modify this class to customize your error reporting
* mechanisms so long as you retain the fields.
*/
/**
* This constructor is used by the method "generate_ParseException"
* in the generated parser. Calling this constructor generates
* a new object of this type with the fields "currentToken",
* "expectedTokenSequences", and "tokenImage" set.
*/
ParseException::ParseException(Token currentTokenVal,
int** expectedTokenSequencesVal,
JAVACC_STRING_TYPE* tokenImageVal
)
{
initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal);
currentToken = currentTokenVal;
expectedTokenSequences = expectedTokenSequencesVal;
tokenImage = tokenImageVal;
}
/**
* The following constructors are for use by you for whatever
* purpose you can think of. Constructing the exception in this
* manner makes the exception behave in the normal way - i.e., as
* documented in the class "Throwable". The fields "errorToken",
* "expectedTokenSequences", and "tokenImage" do not contain
* relevant information. The JavaCC generated code does not use
* these constructors.
*/
ParseException::ParseException() {
}
/** Constructor with message. */
ParseException::ParseException(JAVACC_STRING_TYPE message) {
}
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
* followng this token will (therefore) be the first error token.
*/
Token currentToken;
/**
* Each entry in this array is an array of integers. Each array
* of integers represents a sequence of tokens (by their ordinal
* values) that is expected at this point of the parse.
*/
int** expectedTokenSequences;
/**
* This is a reference to the "tokenImage" array of the generated
* parser within which the parse error occurred. This array is
* defined in the generated ...Constants class.
*/
JAVACC_STRING_TYPE* tokenImage;
/**
* It uses "currentToken" and "expectedTokenSequences" to generate a parse
* error message and returns it. If this object has been created
* due to a parse error, and you do not catch it (it gets thrown
* from the parser) the correct error message
* gets displayed.
*/
JAVACC_STRING_TYPE ParseException::initialise(Token currentToken,
int** expectedTokenSequences,
JAVACC_STRING_TYPE* tokenImage) {
#if 0
//JAVACC_STRING_TYPE eol = System.getProperty("line.separator", "\n");
expected = new JAVACC_STRING_TYPE();
int maxSize = 0;
for (int i = 0; i < expectedTokenSequences.length; i++) {
if (maxSize < expectedTokenSequences[i].length) {
maxSize = expectedTokenSequences[i].length;
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
expected.append((JAVACC_CHAR_TYPE*)"...");
}
expected.append(eol).append(" ");
}
JAVACC_STRING_TYPE retval = (JAVACC_CHAR_TYPE*)"Encountered \"";
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) retval += (JAVACC_CHAR_TYPE*)" ";
if (tok.kind == 0) {
retval += tokenImage[0];
break;
}
retval += (JAVACC_CHAR_TYPE*)" " + tokenImage[tok.kind];
retval += (JAVACC_CHAR_TYPE*)" \"";
retval += add_escapes(tok.image);
retval += (JAVACC_CHAR_TYPE*)" \"";
tok = tok.next;
}
retval += (JAVACC_CHAR_TYPE*)"\" at line " + currentToken.next.beginLine + (JAVACC_CHAR_TYPE*)", column " + currentToken.next.beginColumn;
retval += (JAVACC_CHAR_TYPE*)"." + eol;
if (expectedTokenSequences.length == 1) {
retval += (JAVACC_CHAR_TYPE*)"Was expecting:" + eol + (JAVACC_CHAR_TYPE*)" ";
} else {
retval += (JAVACC_CHAR_TYPE*)"Was expecting one of:" + eol + (JAVACC_CHAR_TYPE*)" ";
}
retval += expected.toString();
return retval;
#endif
return (JAVACC_CHAR_TYPE*)"Parse exception";
}
/**
* The end of line JAVACC_STRING_TYPE for this machine.
*/
#define eol "\n"
/**
* Used to convert raw characters to their escaped version
* when these raw version cannot be used as part of an ASCII
* string literal.
*/
JAVACC_STRING_TYPE ParseException::add_escapes(JAVACC_STRING_TYPE str) {
/*
JAVACC_STRING_TYPE *retval = new JAVACC_STRING_TYPE();
JAVACC_CHAR_TYPE ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
JAVACC_STRING_TYPE s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
*/ return str;
}
}
}
/* JavaCC - OriginalChecksum=99d488e13335cf377284c90700f070ed (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. ParseException.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef _PARSE_EXCEPTION_H
#define _PARSE_EXCEPTION_H
#include "JavaCC.h"
#include "Token.h"
namespace vhdl {
namespace parser {
/**
* This exception is thrown when parse errors are encountered.
* You can explicitly create objects of this exception type by
* calling the method generateParseException in the generated
* parser.
*
* You can modify this class to customize your error reporting
* mechanisms so long as you retain the fields.
*/
class ParseException {
public:
/**
* This constructor is used by the method "generateParseException"
* in the generated parser. Calling this constructor generates
* a new object of this type with the fields "currentToken",
* "expectedTokenSequences", and "tokenImage" set.
*/
ParseException(Token currentTokenVal,
int** expectedTokenSequencesVal,
JAVACC_STRING_TYPE* tokenImageVal
);
/**
* The following constructors are for use by you for whatever
* purpose you can think of. Constructing the exception in this
* manner makes the exception behave in the normal way - i.e., as
* documented in the class "Throwable". The fields "errorToken",
* "expectedTokenSequences", and "tokenImage" do not contain
* relevant information. The JavaCC generated code does not use
* these constructors.
*/
ParseException();
/** Constructor with message. */
ParseException(JAVACC_STRING_TYPE message);
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
* followng this token will (therefore) be the first error token.
*/
Token currentToken;
/**
* Each entry in this array is an array of integers. Each array
* of integers represents a sequence of tokens (by their ordinal
* values) that is expected at this point of the parse.
*/
int** expectedTokenSequences;
/**
* This is a reference to the "tokenImage" array of the generated
* parser within which the parse error occurred. This array is
* defined in the generated ...Constants class.
*/
JAVACC_STRING_TYPE* tokenImage;
/**
* It uses "currentToken" and "expectedTokenSequences" to generate a parse
* error message and returns it. If this object has been created
* due to a parse error, and you do not catch it (it gets thrown
* from the parser) the correct error message
* gets displayed.
*/
private: JAVACC_STRING_TYPE initialise(Token currentToken,
int** expectedTokenSequences,
JAVACC_STRING_TYPE* tokenImage);
/**
* The end of line string for this machine.
*/
#define eol "\n"
/**
* Used to convert raw characters to their escaped version
* when these raw version cannot be used as part of an ASCII
* string literal.
*/
JAVACC_STRING_TYPE add_escapes(JAVACC_STRING_TYPE str);
};
}
}
#endif
/* JavaCC - OriginalChecksum=8c47c56fc2030f05b43e20cae6ca5d66 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. Token.cc Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true,TOKEN_INCLUDES=,TOKEN_EXTENDS= */
#include "Token.h"
namespace vhdl {
namespace parser {
/**
* Describes the input token stream.
*/
/**
* An optional attribute value of the Token.
* Tokens which are not used as syntactic sugar will often contain
* meaningful values that will be used later on by the compiler or
* interpreter. This attribute value is often different from the image.
* Any subclass of Token that actually wants to return a non-NULL value can
* override this method as appropriate.
*/
void * Token::getValue() {
return NULL;
}
/**
* No-argument constructor
*/
Token::Token() {
this->next = NULL;
this->specialToken = NULL;
}
/**
* Constructs a new token for the specified Image.
*/
Token::Token(int kind)
{
this->kind = kind;
this->next = NULL;
this->specialToken = NULL;
}
/**
* Constructs a new token for the specified Image and Kind.
*/
Token::Token(int kind, JAVACC_STRING_TYPE image)
{
this->kind = kind;
this->image = image;
this->next = NULL;
this->specialToken = NULL;
}
/**
* Returns the image.
*/
JAVACC_STRING_TYPE Token::toString()
{
return image;
}
/**
* Returns a new Token object, by default. However, if you want, you
* can create and return subclass objects based on the value of ofKind.
* Simply add the cases to the switch for all those special cases.
* For example, if you have a subclass of Token called IDToken that
* you want to create if ofKind is ID, simply add something like :
*
* case MyParserConstants.ID : return new IDToken(ofKind, image);
*
* to the following switch statement. Then you can cast matchedToken
* variable to the appropriate type and use sit in your lexical actions.
*/
Token *Token::newToken(int ofKind, JAVACC_STRING_TYPE image)
{
switch(ofKind)
{
default : return new Token(ofKind, image);
}
}
Token *Token::newToken(int ofKind)
{
return newToken(ofKind, JAVACC_STRING_TYPE((JAVACC_CHAR_TYPE*)""));
}
Token::~Token() {
if (specialToken) delete specialToken;
}
}
}
/* JavaCC - OriginalChecksum=9db9ca693072c4c37bb7cc933c0c5e35 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. Token.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true,TOKEN_INCLUDES=,TOKEN_EXTENDS= */
#ifndef TOKEN_H
#define TOKEN_H
#include "JavaCC.h"
namespace vhdl {
namespace parser {
/**
* Describes the input token stream.
*/
class Token
{
public:
/**
* An integer that describes the kind of this token. This numbering
* system is determined by JavaCCParser, and a table of these numbers is
* stored in the file ...Constants.java.
*/
int kind;
/** The line number of the first character of this Token. */
int beginLine;
/** The column number of the first character of this Token. */
int beginColumn;
/** The line number of the last character of this Token. */
int endLine;
/** The column number of the last character of this Token. */
int endColumn;
/**
* The string image of the token.
*/
JAVACC_STRING_TYPE image;
/**
* A reference to the next regular (non-special) token from the input
* stream. If this is the last token from the input stream, or if the
* token manager has not read tokens beyond this one, this field is
* set to NULL. This is true only if this token is also a regular
* token. Otherwise, see below for a description of the contents of
* this field.
*/
Token *next;
/**
* This field is used to access special tokens that occur prior to this
* token, but after the immediately preceding regular (non-special) token.
* If there are no such special tokens, this field is set to NULL.
* When there are more than one such special token, this field refers
* to the last of these special tokens, which in turn refers to the next
* previous special token through its specialToken field, and so on
* until the first special token (whose specialToke_ field is NULL).
* The next fields of special tokens refer to other special tokens that
* immediately follow it (without an intervening regular token). If there
* is no such token, this field is NULL.
*/
Token *specialToken;
/**
* An optional attribute value of the Token.
* Tokens which are not used as syntactic sugar will often contain
* meaningful values that will be used later on by the compiler or
* interpreter. This attribute value is often different from the image.
* Any subclass of Token that actually wants to return a non-NULL value can
* override this method as appropriate.
*/
void * getValue();
/**
* No-argument constructor
*/
Token();
/**
* Constructs a new token for the specified Image.
*/
Token(int kind);
/**
* Constructs a new token for the specified Image and Kind.
*/
Token(int kind, JAVACC_STRING_TYPE image);
/**
* Returns the image.
*/
JAVACC_STRING_TYPE toString();
public: virtual ~Token();
/**
* Returns a new Token void *, by default. However, if you want, you
* can create and return subclass objects based on the value of ofKind.
* Simply add the cases to the switch for all those special cases.
* For example, if you have a subclass of Token called IDToken that
* you want to create if ofKind is ID, simply add something like :
*
* case MyParserConstants.ID : return new IDToken(ofKind, image);
*
* to the following switch statement. Then you can cast matchedToken
* variable to the appropriate type and use sit in your lexical actions.
*/
static Token *newToken(int ofKind, JAVACC_STRING_TYPE image);
static Token *newToken(int ofKind);
};
}
}
#endif
/* JavaCC - OriginalChecksum=2f5eb1c937adc983dfa2008c4fe383a7 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. TokenManager.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef TOKENMANAGER_H
#define TOKENMANAGER_H
#include "JavaCC.h"
#include "Token.h"
namespace vhdl {
namespace parser {
/**
* An implementation for this interface is generated by
* JavaCCParser. The user is free to use any implementation
* of their choice.
*/
class TokenManager {
public:
/** This gets the next token from the input stream.
* A token of kind 0 (<EOF>) should be returned on EOF.
*/
public: virtual Token *getNextToken() = 0;
public: virtual ~TokenManager() { }
public: virtual void lexicalError() {
fprintf(stderr, "Lexical error encountered\n");
}
};
}
}
#endif
/* JavaCC - OriginalChecksum=d4725ee75465725057819b3b07fadaa7 (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.cc Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#include "TokenMgrError.h"
namespace vhdl {
namespace parser {
/**
* Returns a detailed message for the Error when it is thrown by the
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
* curJAVACC_CHAR_TYPE : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
JAVACC_STRING_TYPE TokenMgrError::LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar) {
#if 0
JAVACC_STRING_TYPE s;
stringstream<JAVACC_STRING_TYPE> ss;
ss << "Lexical error at line " << errorLine << " column " << errorColumn
<< ". Encountered: " << curChar << "(" << (int)curChar
<< ") after : \"" << errorAfter.c_str() << "\"";
return (JAVACC_STRING_TYPE)ss.rdbuf()->str();
#endif
return EMPTY;
}
/**
* You can also modify the body of this method to customize your error messages.
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
* of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
JAVACC_STRING_TYPE TokenMgrError::getMessage() {
return message;
}
/*
* Constructors of various flavors follow.
*/
/** No arg constructor. */
TokenMgrError::TokenMgrError() {
}
/** Constructor with message and reason. */
TokenMgrError::TokenMgrError(JAVACC_STRING_TYPE message, int reason) {
errorCode = reason;
}
/** Full Constructor. */
TokenMgrError::TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, int reason) {
message = LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar);
errorCode = reason;
}
}
}
// i < 16 - guaranteed
static char hexChar(int i) {
if (i < 10) {
return i - '0';
}
return 'a' + (i - 10);
}
/**
* Replaces unprintable characters by their escaped (or unicode escaped)
* equivalents in the given string
*/
JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str) {
JAVACC_SIMPLE_STRING retval;
for (size_t i = 0; i < str.size(); i++) {
JAVACC_CHAR_TYPE ch = str[i];
switch (ch)
{
case 0 :
retval += EMPTY[0];
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if (ch < 0xff) {
retval += ch;
continue;
}
retval.append("\\u");
retval += (hexChar(ch >> 12));
retval += (hexChar((ch & 0x0f00) >> 8));
retval += (hexChar((ch & 0x00f0) >> 4));
retval += (hexChar(ch & 0x000f));
continue;
}
}
return retval;
}
/* JavaCC - OriginalChecksum=7f80e3c4eac120168f5e81d4ddb72e4b (do not edit this line) */
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.h Version 6.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#ifndef _TOKENMGRERROR_H
#define _TOKENMGRERROR_H
#include "JavaCC.h"
namespace vhdl {
namespace parser {
enum LexerErrors {
/**
* Lexical error occurred.
*/
LEXICAL_ERROR = 0,
/**
* An attempt was made to create a second instance of a token manager.
*/
STATIC_LEXER_ERROR = 1,
/**
* Tried to change to an invalid lexical state.
*/
INVALID_LEXICAL_STATE = 2,
/**
* Detected (and bailed out of) an infinite loop in the token manager.
*/
LOOP_DETECTED = 3,
};
class TokenMgrError
{
public:
/*
* Ordinals for various reasons why an Error of this type can be thrown.
*/
/**
* Indicates the reason why the exception is thrown. It will have
* one of the above 4 values.
*/
int errorCode;
/**
* Returns a detailed message for the Error when it is thrown by the
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
* curchar : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
JAVACC_STRING_TYPE LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar);
private: JAVACC_STRING_TYPE message;
/**
* You can also modify the body of this method to customize your error messages.
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
* of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
JAVACC_STRING_TYPE getMessage() ;
/*
* Constructors of various flavors follow.
*/
/** No arg constructor. */
public: TokenMgrError() ;
/** Constructor with message and reason. */
public: TokenMgrError(JAVACC_STRING_TYPE message, int reason) ;
/** Full Constructor. */
public: TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, int reason) ;
};
}
}
#endif
/* JavaCC - OriginalChecksum=c7d825cb4d037b031ae43569d383f738 (do not edit this line) */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef VHDLPARSERERRORHANDLER_H
#define VHDLPARSERERRORHANDLER_H
#include <stdio.h>
#include <stdlib.h>
#include <exception>
#include "VhdlParser.h"
#include "ErrorHandler.h"
namespace vhdl { namespace parser {
class VhdlErrorHandler: public ErrorHandler
{
virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *parser)
{
fprintf(stderr,"\n\n syntax error at line: %d : %s\n", actual->beginLine,actual->image.data());
error_count++;
throw std::exception();
}
virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser)
{
fprintf(stderr,"\n\n unexpected token at line: %d %s\n", last->beginLine,unexpected->image.data());
error_count++;
throw std::exception();
}
virtual void handleOtherError(JAVACC_STRING_TYPE message, VhdlParser *parser)
{
fprintf(stderr, "\n\n unexpected error: %s\n", (char*)message.c_str());
error_count++;
throw std::exception();
}
};
}
}
#endif
#include "VhdlParserTokenManager.h"
#include "VhdlParserErrorHandler.hpp"
#include "VhdlParser.h"
#include "VhdlParserIF.h"
#include "CharStream.h"
using namespace vhdl::parser;
static VhdlParser * myParser;
void VhdlParserIF::parseVhdlfile(const char* inputBuffer,bool inLine)
{
JAVACC_STRING_TYPE s =inputBuffer;
CharStream *stream = new CharStream(s.c_str(), (int)s.size(), 1, 1);
VhdlParserTokenManager *tokenManager = new VhdlParserTokenManager(stream);
myParser=new VhdlParser(tokenManager);
VhdlErrorHandler *myErr=new VhdlErrorHandler();
myParser->setErrorHandler(myErr);
try
{
if(inLine)
{
myParser->parseInline();
}
else
{
myParser->design_file();
}
}
catch( std::exception &)
{
/* fprintf(stderr,"\n[%s]",e.what()); */
}
// fprintf(stderr,"\n\nparsed lines: %d\n",yyLineNr);
// fprintf(stderr,"\n\nerrors : %d\n\n",myErr->getErrorCount());
delete myParser;
}
void VhdlParser::error_skipto(int kind)
{
Token *op;
do
{
op=myParser->getToken(1);
if (op==0) break;
//fprintf(stderr,"\n %s",t->image.data());
} while (op->kind != kind);
myParser->hasError=false;
// The above loop consumes tokens all the way up to a token of
// "kind". We use a do-while loop rather than a while because the
// current token is the one immediately before the erroneous token
// (in our case the token immediately before what should have been
// "if"/"while".
}
#ifndef VHDLPARSERIF
#define VHDLPARSERIF
#include "VhdlParser.h"
class VhdlParserIF
{
public:
static void parseVhdlfile(const char* inputBuffer,bool inLine);
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
--- VhdlParser.h 2014-07-27 14:26:18.000000000 +0200
+++ VhdlParser.h.new 2014-07-27 14:23:22.000000000 +0200
@@ -6,6 +6,7 @@
#include "TokenManager.h"
#include "VhdlParserTokenManager.h"
#include "VhdlParser.h"
+#include "vhdljjparser.h"
#include "VhdlParserConstants.h"
#include "ErrorHandler.h"
TEMPLATE = lib
CONFIG = warn_on staticlib $extraopts
HEADERS = CharStream.h \
ErrorHandler.h \
JavaCC.h \
ParseException.h \
TokenManager.h \
Token.h \
vhdlstring.h \
VhdlParser.h \
VhdlParserConstants.h \
VhdlParserTokenManager.h \
TokenMgrError.h \
VhdlParserIF.h \
VhdlParserErrorHandler.hpp
SOURCES = CharStream.cc \
ParseException.cc \
Token.cc \
TokenMgrError.cc \
VhdlParser.cc \
VhdlParserTokenManager.cc \
VhdlParserIF.cpp
INCLUDEPATH = . ../src ../qtools generated_src/doxygen
#TMAKE_CXXFLAGS += -DQT_NO_CODECS -DQ T_LITE_UNICODE
#must enable -fexceptions because we have try catch blocks in VhdlParser.cc
TMAKE_CXXFLAGS +=-w -fexceptions -DQT_LITE_UNICODE
win32:TMAKE_CXXFLAGS += -fexceptions -DQT_NODLL
win32-g++:TMAKE_CXXFLAGS += -fexceptions -D__CYGWIN__ -DALL_STATIC
OBJECTS_DIR = ../objects/vhdlparser
DESTDIR = ../lib
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment