Skip to content

Commit 4bef277

Browse files
author
Dimitri van Heesch
committed
Bug 758495 - Bug in VHDL parser + other fixes
1 parent da09bff commit 4bef277

12 files changed

+807
-684
lines changed

src/vhdldocgen.cpp

+120-19
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
#include <qcstring.h>
2828
#include <qfileinfo.h>
2929
#include <qstringlist.h>
30-
31-
//#ifdef DEBUGFLOW
3230
#include <qmap.h>
33-
//#endif
3431

3532
/* --------------------------------------------------------------- */
3633

@@ -47,7 +44,6 @@
4744
#include "searchindex.h"
4845
#include "outputlist.h"
4946
#include "parserintf.h"
50-
5147
#include "layout.h"
5248
#include "arguments.h"
5349
#include "portable.h"
@@ -59,11 +55,12 @@
5955
#include "filename.h"
6056
#include "membergroup.h"
6157
#include "memberdef.h"
62-
58+
#include "plantuml.h"
6359
#include "vhdljjparser.h"
6460
#include "VhdlParser.h"
65-
6661
#include "vhdlcode.h"
62+
#include "plantuml.h"
63+
//#define DEBUGFLOW
6764
#define theTranslator_vhdlType VhdlDocGen::trVhdlType
6865

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

98-
const MemberDef* VhdlDocGen::getFlowMember()
95+
const MemberDef* VhdlDocGen::getFlowMember()
9996
{
10097
return flowMember;
10198
}
@@ -2266,10 +2263,11 @@ void VhdlDocGen::writeVHDLDeclaration(MemberDef* mdef,OutputList &ol,
22662263
ol.endMemberItem();
22672264
if (!mdef->briefDescription().isEmpty() && Config_getBool("BRIEF_MEMBER_DESC") /* && !annMemb */)
22682265
{
2269-
ol.startMemberDescription(mdef->anchor());
2266+
QCString s=mdef->briefDescription();
2267+
ol.startMemberDescription(mdef->anchor());
22702268
ol.generateDoc(mdef->briefFile(),mdef->briefLine(),
22712269
mdef->getOuterScope()?mdef->getOuterScope():d,
2272-
mdef,mdef->briefDescription(),TRUE,FALSE,0,TRUE,FALSE);
2270+
mdef,s.data(),TRUE,FALSE,0,TRUE,FALSE);
22732271
if (detailsVisible)
22742272
{
22752273
ol.pushGeneratorState();
@@ -2610,7 +2608,7 @@ void VhdlDocGen::writeSource(MemberDef *mdef,OutputList& ol,QCString & cname)
26102608
codeFragment, // input
26112609
SrcLangExt_VHDL, // lang
26122610
FALSE, // isExample
2613-
0, // exampleName
2611+
0, // exampleName
26142612
mdef->getFileDef(), // fileDef
26152613
mdef->getStartBodyLine(), // startLine
26162614
mdef->getEndBodyLine(), // endLine
@@ -3559,7 +3557,7 @@ void FlowChart::printNode(const FlowChart* flo)
35593557
}
35603558
else
35613559
{
3562-
printf("\n NO: %s%s[%d,%d]",q.data(),t.data(),flo->stamp,flo->id);
3560+
printf("\n NO: %s[%d,%d]",t.data(),flo->stamp,flo->id);
35633561
}
35643562
}
35653563
}
@@ -3745,8 +3743,13 @@ void FlowChart::buildCommentNodes(FTextStream & t)
37453743
FlowChart *fll=flowList.at(j);
37463744
if (fll->type & (COMMENT_NO | BEGIN_NO))
37473745
{
3746+
int diff=FLOWLEN-(j+1);
37483747
flowList.remove(j);
3749-
delete fll;
3748+
3749+
if ((fll->type & COMMENT_NO) && diff > 1)
3750+
flowList.at(j+1)->label=fll->label;
3751+
3752+
delete fll;
37503753
fll=0;
37513754
size--;
37523755
if (j>0) j--;
@@ -3841,7 +3844,6 @@ void FlowChart::addFlowChart(int type,const char* text,const char* exp, const ch
38413844
{
38423845
flowList.append(fl);
38433846
}
3844-
38453847
}
38463848

38473849
void FlowChart::moveToPrevLevel()
@@ -3850,23 +3852,108 @@ void FlowChart::moveToPrevLevel()
38503852
ifcounter--;
38513853
}
38523854

3855+
QCString FlowChart::printPlantUmlNode(const FlowChart *flo,bool ca,bool endL)
3856+
{
3857+
QCString t;
3858+
QCString exp=flo->exp.stripWhiteSpace();
3859+
QCString text=flo->text.stripWhiteSpace();
3860+
switch (flo->type)
3861+
{
3862+
case START_NO: t=":"+text+"|"; break;
3863+
case IF_NO : t="\nif ("+exp+") then (yes)"; break;
3864+
case ELSIF_NO: t="\nelseif ("+exp+") then (yes)"; break;
3865+
case ELSE_NO: t="\nelse"; break;
3866+
case CASE_NO: t="\n:"+exp+";"; break;
3867+
case WHEN_NO: t="\n";
3868+
if (!ca) t+="else";
3869+
t+="if ("+exp+") then (yes)";
3870+
break;
3871+
case EXIT_NO: break;
3872+
case END_NO: if (text.contains(" function")==0) t="\n:"+text+";";
3873+
break;
3874+
case TEXT_NO: t="\n:"+text+"]"; break;
3875+
case ENDIF_NO: t="\nendif"; break;
3876+
case FOR_NO: t="\nwhile ("+exp+") is (yes)"; break;
3877+
case WHILE_NO: t="\nwhile ("+exp+") is (yes)"; break;
3878+
case END_LOOP: t="\nendwhile"; break;
3879+
case END_CASE: t="\nendif\n:end case;"; break;
3880+
case VARIABLE_NO:t="\n:"+text+";"; break;
3881+
case RETURN_NO: t="\n:"+text+";";
3882+
if (!endL) t+="\nstop";
3883+
break;
3884+
case LOOP_NO: t="\nwhile (infinite loop)"; break;
3885+
case NEXT_NO: break;
3886+
case EMPTY_NO: break;
3887+
case COMMENT_NO: t="\n note left \n "+flo->label+"\nend note \n"; break;
3888+
case BEGIN_NO: t="\n:begin;"; break;
3889+
default: assert(false); break;
3890+
}
3891+
return t;
3892+
}
3893+
3894+
void FlowChart::printUmlTree()
3895+
{
3896+
int caseCounter = 0;
3897+
int whenCounter = 0;
3898+
3899+
QCString qcs;
3900+
uint size=flowList.count();
3901+
bool endList;
3902+
for (uint j=0;j<size;j++)
3903+
{
3904+
endList=j==FLOWLEN;
3905+
FlowChart *flo=flowList.at(j);
3906+
if (flo->type==CASE_NO)
3907+
{
3908+
caseCounter++;
3909+
whenCounter=0;
3910+
}
3911+
3912+
if (flo->type==END_CASE)
3913+
{
3914+
caseCounter--;
3915+
}
3916+
3917+
bool ca = (caseCounter>0 && whenCounter==0);
3918+
3919+
qcs+=printPlantUmlNode(flo,ca,endList);
3920+
3921+
if (flo->type==WHEN_NO)
3922+
{
3923+
whenCounter++;
3924+
}
3925+
3926+
}
3927+
qcs+="\n";
3928+
3929+
QCString & outDir = Config_getString("OUTPUT_DIRECTORY");
3930+
QCString & htmlOutDir = Config_getString("HTML_OUTPUT");
3931+
3932+
QCString n=convertNameToFileName();
3933+
QCString tmp=htmlOutDir;
3934+
n=writePlantUMLSource(tmp,n,qcs);
3935+
generatePlantUMLOutput(n.data(),tmp.data(),PUML_SVG);
3936+
}
38533937

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

3860-
temp.sprintf("%p",md);
3944+
// temp.sprintf("%p",md);
38613945
qcs=md->name();
38623946

3947+
#if 0
38633948
if (qcs.find(exp,0)>=0)
38643949
{
38653950
qcs.prepend("Z");
38663951
qcs=qcs.replace(exp,"_");
38673952
}
3953+
#endif
38683954

3869-
return qcs+temp;
3955+
//QCString tt= qcs;VhdlDocGen::getRecordNumber();
3956+
return qcs;
38703957
}
38713958

38723959
const char* FlowChart::getNodeType(int c)
@@ -3889,7 +3976,7 @@ const char* FlowChart::getNodeType(int c)
38893976
case END_CASE: return "end_case ";
38903977
case VARIABLE_NO: return "variable_decl ";
38913978
case RETURN_NO: return "return ";
3892-
case LOOP_NO: return "infinte loop ";
3979+
case LOOP_NO: return "infinite loop ";
38933980
case NEXT_NO: return "next ";
38943981
case COMMENT_NO: return "comment ";
38953982
case EMPTY_NO: return "empty ";
@@ -3949,14 +4036,23 @@ void FlowChart::writeFlowChart()
39494036
}
39504037

39514038
colTextNodes();
4039+
// buildCommentNodes(t);
39524040

39534041
#ifdef DEBUGFLOW
3954-
printFlowTree();
4042+
printFlowTree();
39554043
#endif
4044+
const MemberDef *p=VhdlDocGen::getFlowMember();
4045+
4046+
if (p->isStatic())
4047+
{
4048+
printUmlTree();
4049+
delFlowList();
4050+
f.close();
4051+
return;
4052+
}
39564053

39574054
startDot(t);
39584055
buildCommentNodes(t);
3959-
39604056
uint size=flowList.count();
39614057

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

44594555
);
44604556

4461-
}
4557+
4558+
4559+
4560+
4561+
4562+
}// class

src/vhdldocgen.h

+3
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ class FlowChart
326326
static void buildCommentNodes(FTextStream &t);
327327
static void alignCommentNode(FTextStream &t,QCString com);
328328

329+
static void printUmlTree();
330+
static QCString printPlantUmlNode(const FlowChart *flo,bool,bool);
331+
329332
static QList<FlowChart> flowList;
330333

331334
FlowChart(int typ,const char* t,const char* ex,const char* label=0);

src/vhdljjparser.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,En
164164
g_thisParser=this;
165165
bool inLine=false;
166166
inputString=fileBuf;
167+
168+
// fprintf(stderr,"\n ============= %s\n ==========\n",fileBuf);
169+
167170
if (strlen(fileName)==0)
168171
{
169172
inLine=true;
@@ -291,6 +294,8 @@ bool checkInlineCode(QCString & doc)
291294

292295
void VhdlParser::handleFlowComment(const char* doc)
293296
{
297+
lineCount(doc);
298+
294299
if (VhdlDocGen::getFlowMember())
295300
{
296301
QCString qcs(doc);
@@ -305,7 +310,9 @@ void VhdlParser::handleCommentBlock(const char* doc1,bool brief)
305310
{
306311
int position=0;
307312
static bool isIn;
308-
QCString doc(doc1);
313+
QCString doc;
314+
doc.append(doc1);
315+
// fprintf(stderr,"\n %s",doc.data());
309316
if (doc.isEmpty()) return;
310317

311318
if (checkMultiComment(doc,yyLineNr))
@@ -359,6 +366,14 @@ void VhdlParser::handleCommentBlock(const char* doc1,bool brief)
359366
current->docLine = yyLineNr;
360367
}
361368
// printf("parseCommentBlock file<%s>\n [%s]\n at line [%d] \n ",yyFileName.data(),doc.data(),iDocLine);
369+
370+
int j=doc.find("[plant]");
371+
if (j>=0)
372+
{
373+
doc=doc.remove(j,7);
374+
current->stat=true;
375+
}
376+
362377
while (parseCommentBlock(
363378
g_thisParser,
364379
current,

vhdlparser/CharStream.h

+25-9
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,29 @@ namespace parser {
3030
class CharStream {
3131
public:
3232
void setTabSize(int i) { tabSize = i; }
33-
int getTabSize(int) { return tabSize; }
34-
virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
35-
virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
36-
virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
37-
virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
38-
virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
39-
virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
33+
int getTabSize(int i) { return tabSize; }
34+
private:
35+
int getBufcolumn(int pos) {
36+
if (trackLineColumn && pos>=0) {
37+
return bufcolumn[pos];
38+
} else {
39+
return -1;
40+
}
41+
}
42+
int getBufline(int pos) {
43+
if (trackLineColumn && pos>=0) {
44+
return bufline[pos];
45+
} else {
46+
return -1;
47+
}
48+
}
49+
public:
50+
virtual int getColumn() { return getBufcolumn(bufpos); }
51+
virtual int getLine() { return getBufline(bufpos); }
52+
virtual int getEndColumn() { return getBufcolumn(bufpos); }
53+
virtual int getEndLine() { return getBufline(bufpos); }
54+
virtual int getBeginColumn() { return getBufcolumn(tokenBegin); }
55+
virtual int getBeginLine() { return getBufline(tokenBegin); }
4056

4157
virtual bool getTrackLineColumn() { return trackLineColumn; }
4258
virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
@@ -179,7 +195,7 @@ class CharStream {
179195
}
180196

181197
CharStream(ReaderStream *input_stream, int startline,
182-
int startcolumn, int) :
198+
int startcolumn, int buffersize) :
183199
bufline(NULL), bufcolumn(NULL), buffer(NULL), bufpos(0), bufsize(0),
184200
tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
185201
available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
@@ -248,4 +264,4 @@ class CharStream {
248264
}
249265
}
250266
#endif
251-
/* JavaCC - OriginalChecksum=89f4cb30f0d3487ee809cca18a2924f2 (do not edit this line) */
267+
/* JavaCC - OriginalChecksum=3f0e693d1617236429891c8c95713d73 (do not edit this line) */

0 commit comments

Comments
 (0)