Skip to content

Commit

Permalink
Bug 758495 - Bug in VHDL parser + other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri van Heesch committed Dec 20, 2015
1 parent da09bff commit 4bef277
Show file tree
Hide file tree
Showing 12 changed files with 807 additions and 684 deletions.
139 changes: 120 additions & 19 deletions src/vhdldocgen.cpp
Expand Up @@ -27,10 +27,7 @@
#include <qcstring.h>
#include <qfileinfo.h>
#include <qstringlist.h>

//#ifdef DEBUGFLOW
#include <qmap.h>
//#endif

/* --------------------------------------------------------------- */

Expand All @@ -47,7 +44,6 @@
#include "searchindex.h"
#include "outputlist.h"
#include "parserintf.h"

#include "layout.h"
#include "arguments.h"
#include "portable.h"
Expand All @@ -59,11 +55,12 @@
#include "filename.h"
#include "membergroup.h"
#include "memberdef.h"

#include "plantuml.h"
#include "vhdljjparser.h"
#include "VhdlParser.h"

#include "vhdlcode.h"
#include "plantuml.h"
//#define DEBUGFLOW
#define theTranslator_vhdlType VhdlDocGen::trVhdlType

static QDict<QCString> g_vhdlKeyDict0(17,FALSE);
Expand Down Expand Up @@ -95,7 +92,7 @@ void VhdlDocGen::setFlowMember( const MemberDef* mem)
flowMember=mem;
}

const MemberDef* VhdlDocGen::getFlowMember()
const MemberDef* VhdlDocGen::getFlowMember()
{
return flowMember;
}
Expand Down Expand Up @@ -2266,10 +2263,11 @@ void VhdlDocGen::writeVHDLDeclaration(MemberDef* mdef,OutputList &ol,
ol.endMemberItem();
if (!mdef->briefDescription().isEmpty() && Config_getBool("BRIEF_MEMBER_DESC") /* && !annMemb */)
{
ol.startMemberDescription(mdef->anchor());
QCString s=mdef->briefDescription();
ol.startMemberDescription(mdef->anchor());
ol.generateDoc(mdef->briefFile(),mdef->briefLine(),
mdef->getOuterScope()?mdef->getOuterScope():d,
mdef,mdef->briefDescription(),TRUE,FALSE,0,TRUE,FALSE);
mdef,s.data(),TRUE,FALSE,0,TRUE,FALSE);
if (detailsVisible)
{
ol.pushGeneratorState();
Expand Down Expand Up @@ -2610,7 +2608,7 @@ void VhdlDocGen::writeSource(MemberDef *mdef,OutputList& ol,QCString & cname)
codeFragment, // input
SrcLangExt_VHDL, // lang
FALSE, // isExample
0, // exampleName
0, // exampleName
mdef->getFileDef(), // fileDef
mdef->getStartBodyLine(), // startLine
mdef->getEndBodyLine(), // endLine
Expand Down Expand Up @@ -3559,7 +3557,7 @@ void FlowChart::printNode(const FlowChart* flo)
}
else
{
printf("\n NO: %s%s[%d,%d]",q.data(),t.data(),flo->stamp,flo->id);
printf("\n NO: %s[%d,%d]",t.data(),flo->stamp,flo->id);
}
}
}
Expand Down Expand Up @@ -3745,8 +3743,13 @@ void FlowChart::buildCommentNodes(FTextStream & t)
FlowChart *fll=flowList.at(j);
if (fll->type & (COMMENT_NO | BEGIN_NO))
{
int diff=FLOWLEN-(j+1);
flowList.remove(j);
delete fll;

if ((fll->type & COMMENT_NO) && diff > 1)
flowList.at(j+1)->label=fll->label;

delete fll;
fll=0;
size--;
if (j>0) j--;
Expand Down Expand Up @@ -3841,7 +3844,6 @@ void FlowChart::addFlowChart(int type,const char* text,const char* exp, const ch
{
flowList.append(fl);
}

}

void FlowChart::moveToPrevLevel()
Expand All @@ -3850,23 +3852,108 @@ void FlowChart::moveToPrevLevel()
ifcounter--;
}

QCString FlowChart::printPlantUmlNode(const FlowChart *flo,bool ca,bool endL)
{
QCString t;
QCString exp=flo->exp.stripWhiteSpace();
QCString text=flo->text.stripWhiteSpace();
switch (flo->type)
{
case START_NO: t=":"+text+"|"; break;
case IF_NO : t="\nif ("+exp+") then (yes)"; break;
case ELSIF_NO: t="\nelseif ("+exp+") then (yes)"; break;
case ELSE_NO: t="\nelse"; break;
case CASE_NO: t="\n:"+exp+";"; break;
case WHEN_NO: t="\n";
if (!ca) t+="else";
t+="if ("+exp+") then (yes)";
break;
case EXIT_NO: break;
case END_NO: if (text.contains(" function")==0) t="\n:"+text+";";
break;
case TEXT_NO: t="\n:"+text+"]"; break;
case ENDIF_NO: t="\nendif"; break;
case FOR_NO: t="\nwhile ("+exp+") is (yes)"; break;
case WHILE_NO: t="\nwhile ("+exp+") is (yes)"; break;
case END_LOOP: t="\nendwhile"; break;
case END_CASE: t="\nendif\n:end case;"; break;
case VARIABLE_NO:t="\n:"+text+";"; break;
case RETURN_NO: t="\n:"+text+";";
if (!endL) t+="\nstop";
break;
case LOOP_NO: t="\nwhile (infinite loop)"; break;
case NEXT_NO: break;
case EMPTY_NO: break;
case COMMENT_NO: t="\n note left \n "+flo->label+"\nend note \n"; break;
case BEGIN_NO: t="\n:begin;"; break;
default: assert(false); break;
}
return t;
}

void FlowChart::printUmlTree()
{
int caseCounter = 0;
int whenCounter = 0;

QCString qcs;
uint size=flowList.count();
bool endList;
for (uint j=0;j<size;j++)
{
endList=j==FLOWLEN;
FlowChart *flo=flowList.at(j);
if (flo->type==CASE_NO)
{
caseCounter++;
whenCounter=0;
}

if (flo->type==END_CASE)
{
caseCounter--;
}

bool ca = (caseCounter>0 && whenCounter==0);

qcs+=printPlantUmlNode(flo,ca,endList);

if (flo->type==WHEN_NO)
{
whenCounter++;
}

}
qcs+="\n";

QCString & outDir = Config_getString("OUTPUT_DIRECTORY");
QCString & htmlOutDir = Config_getString("HTML_OUTPUT");

QCString n=convertNameToFileName();
QCString tmp=htmlOutDir;
n=writePlantUMLSource(tmp,n,qcs);
generatePlantUMLOutput(n.data(),tmp.data(),PUML_SVG);
}

QCString FlowChart::convertNameToFileName()
{
static QRegExp exp ("[^][a-z_A-Z0-9]");
QCString temp,qcs;
const MemberDef* md=VhdlDocGen::getFlowMember();

temp.sprintf("%p",md);
// temp.sprintf("%p",md);
qcs=md->name();

#if 0
if (qcs.find(exp,0)>=0)
{
qcs.prepend("Z");
qcs=qcs.replace(exp,"_");
}
#endif

return qcs+temp;
//QCString tt= qcs;VhdlDocGen::getRecordNumber();
return qcs;
}

const char* FlowChart::getNodeType(int c)
Expand All @@ -3889,7 +3976,7 @@ const char* FlowChart::getNodeType(int c)
case END_CASE: return "end_case ";
case VARIABLE_NO: return "variable_decl ";
case RETURN_NO: return "return ";
case LOOP_NO: return "infinte loop ";
case LOOP_NO: return "infinite loop ";
case NEXT_NO: return "next ";
case COMMENT_NO: return "comment ";
case EMPTY_NO: return "empty ";
Expand Down Expand Up @@ -3949,14 +4036,23 @@ void FlowChart::writeFlowChart()
}

colTextNodes();
// buildCommentNodes(t);

#ifdef DEBUGFLOW
printFlowTree();
printFlowTree();
#endif
const MemberDef *p=VhdlDocGen::getFlowMember();

if (p->isStatic())
{
printUmlTree();
delFlowList();
f.close();
return;
}

startDot(t);
buildCommentNodes(t);

uint size=flowList.count();

for (uint j=0;j <size ;j++)
Expand Down Expand Up @@ -4458,4 +4554,9 @@ parseVhdlCode(codeOutIntf,

);

}





}// class
3 changes: 3 additions & 0 deletions src/vhdldocgen.h
Expand Up @@ -326,6 +326,9 @@ class FlowChart
static void buildCommentNodes(FTextStream &t);
static void alignCommentNode(FTextStream &t,QCString com);

static void printUmlTree();
static QCString printPlantUmlNode(const FlowChart *flo,bool,bool);

static QList<FlowChart> flowList;

FlowChart(int typ,const char* t,const char* ex,const char* label=0);
Expand Down
17 changes: 16 additions & 1 deletion src/vhdljjparser.cpp
Expand Up @@ -164,6 +164,9 @@ void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,En
g_thisParser=this;
bool inLine=false;
inputString=fileBuf;

// fprintf(stderr,"\n ============= %s\n ==========\n",fileBuf);

if (strlen(fileName)==0)
{
inLine=true;
Expand Down Expand Up @@ -291,6 +294,8 @@ bool checkInlineCode(QCString & doc)

void VhdlParser::handleFlowComment(const char* doc)
{
lineCount(doc);

if (VhdlDocGen::getFlowMember())
{
QCString qcs(doc);
Expand All @@ -305,7 +310,9 @@ void VhdlParser::handleCommentBlock(const char* doc1,bool brief)
{
int position=0;
static bool isIn;
QCString doc(doc1);
QCString doc;
doc.append(doc1);
// fprintf(stderr,"\n %s",doc.data());
if (doc.isEmpty()) return;

if (checkMultiComment(doc,yyLineNr))
Expand Down Expand Up @@ -359,6 +366,14 @@ void VhdlParser::handleCommentBlock(const char* doc1,bool brief)
current->docLine = yyLineNr;
}
// printf("parseCommentBlock file<%s>\n [%s]\n at line [%d] \n ",yyFileName.data(),doc.data(),iDocLine);

int j=doc.find("[plant]");
if (j>=0)
{
doc=doc.remove(j,7);
current->stat=true;
}

while (parseCommentBlock(
g_thisParser,
current,
Expand Down
34 changes: 25 additions & 9 deletions vhdlparser/CharStream.h
Expand Up @@ -30,13 +30,29 @@ namespace parser {
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; }
int getTabSize(int i) { return tabSize; }
private:
int getBufcolumn(int pos) {
if (trackLineColumn && pos>=0) {
return bufcolumn[pos];
} else {
return -1;
}
}
int getBufline(int pos) {
if (trackLineColumn && pos>=0) {
return bufline[pos];
} else {
return -1;
}
}
public:
virtual int getColumn() { return getBufcolumn(bufpos); }
virtual int getLine() { return getBufline(bufpos); }
virtual int getEndColumn() { return getBufcolumn(bufpos); }
virtual int getEndLine() { return getBufline(bufpos); }
virtual int getBeginColumn() { return getBufcolumn(tokenBegin); }
virtual int getBeginLine() { return getBufline(tokenBegin); }

virtual bool getTrackLineColumn() { return trackLineColumn; }
virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
Expand Down Expand Up @@ -179,7 +195,7 @@ class CharStream {
}

CharStream(ReaderStream *input_stream, int startline,
int startcolumn, int) :
int startcolumn, int buffersize) :
bufline(NULL), bufcolumn(NULL), buffer(NULL), bufpos(0), bufsize(0),
tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
Expand Down Expand Up @@ -248,4 +264,4 @@ class CharStream {
}
}
#endif
/* JavaCC - OriginalChecksum=89f4cb30f0d3487ee809cca18a2924f2 (do not edit this line) */
/* JavaCC - OriginalChecksum=3f0e693d1617236429891c8c95713d73 (do not edit this line) */

0 comments on commit 4bef277

Please sign in to comment.