1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
/******************************************************************************
*
* Copyright (C) 2014 by M. Kreis
*
* 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.
*
*/
#include <qcstring.h>
#include <qfileinfo.h>
#include <qcstringlist.h>
#include "vhdljjparser.h"
#include "vhdlcode.h"
#include "vhdldocgen.h"
#include "message.h"
#include "config.h"
#include "doxygen.h"
#include "util.h"
#include "language.h"
#include "commentscan.h"
#include "index.h"
#include "definition.h"
#include "searchindex.h"
#include "outputlist.h"
#include "arguments.h"
#include "types.h"
#include "VhdlParserIF.h"
using namespace vhdl::parser;
using namespace std;
static ParserInterface *g_thisParser;
static QCString yyFileName;
static int yyLineNr = 1;
static int* lineParse;
static int iDocLine = -1;
static QCString inputString;
static Entry* gBlock = 0;
static Entry* previous = 0;
//-------------------------------------------------------
static Entry* oldEntry;
static bool varr=FALSE;
static QCString varName;
static QList<Entry> instFiles;
static QList<Entry> libUse;
static QList<Entry> lineEntry;
Entry* VhdlParser::currentCompound=0;
Entry* VhdlParser::tempEntry=0;
Entry* VhdlParser::lastEntity=0 ;
Entry* VhdlParser::lastCompound=0 ;
Entry* VhdlParser::current=0;
Entry* VhdlParser::current_root = 0;
QCString VhdlParser::compSpec;
QCString VhdlParser::currName;
QCString VhdlParser::confName;
QCString VhdlParser::genLabels;
QCString VhdlParser::lab;
QCString VhdlParser::forL;
int VhdlParser::param_sec = 0;
int VhdlParser::parse_sec=0;
int VhdlParser::currP=0;
int VhdlParser::levelCounter;
static QList<VhdlConfNode> configL;
static struct
{
QCString doc;
bool brief;
bool pending;
int iDocLine;
} str_doc;
static QCString strComment;
static int iCodeLen;
static const char *vhdlFileName = 0;
bool checkMultiComment(QCString& qcs,int line);
QList<Entry>* getEntryAtLine(const Entry* ce,int line);
//-------------------------------------
QList<VhdlConfNode>& getVhdlConfiguration() { return configL; }
QList<Entry>& getVhdlInstList() { return instFiles; }
Entry* getVhdlCompound()
{
if (VhdlParser::lastEntity) return VhdlParser::lastEntity;
if (VhdlParser::lastCompound) return VhdlParser::lastCompound;
return NULL;
}
bool isConstraintFile(const QCString &fileName,const QCString &ext)
{
return fileName.right(ext.length())==ext;
}
void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,Entry *root,
bool ,QStrList&)
{
g_thisParser=this;
bool inLine=false;
inputString=fileBuf;
// fprintf(stderr,"\n ============= %s\n ==========\n",fileBuf);
if (strlen(fileName)==0)
{
inLine=true;
}
yyFileName+=fileName;
bool xilinx_ucf=isConstraintFile(yyFileName,".ucf");
bool altera_qsf=isConstraintFile(yyFileName,".qsf");
// support XILINX(ucf) and ALTERA (qsf) file
if (xilinx_ucf)
{
VhdlDocGen::parseUCF(fileBuf,root,yyFileName,FALSE);
return;
}
if (altera_qsf)
{
VhdlDocGen::parseUCF(fileBuf,root,yyFileName,TRUE);
return;
}
libUse.setAutoDelete(true);
yyLineNr=1;
VhdlParser::current_root=root;
VhdlParser::lastCompound=0;
VhdlParser::lastEntity=0;
VhdlParser::currentCompound=0;
VhdlParser::lastEntity=0;
oldEntry = 0;
VhdlParser::current=new Entry();
VhdlParser::initEntry(VhdlParser::current);
groupEnterFile(fileName,yyLineNr);
vhdlFileName = fileName;
lineParse=new int[200]; // Dimitri: dangerous constant: should be bigger than largest token id in VhdlParserConstants.h
VhdlParserIF::parseVhdlfile(fileBuf,inLine);
delete VhdlParser::current;
VhdlParser::current=0;
if (!inLine)
VhdlParser::mapLibPackage(root);
delete[] lineParse;
yyFileName.resize(0);
libUse.clear();
VhdlDocGen::resetCodeVhdlParserState();
vhdlFileName = 0;
}
void VhdlParser::lineCount()
{
yyLineNr++;
}
void VhdlParser::lineCount(const char* text)
{
for (const char* c=text ; *c ; ++c )
{
yyLineNr += (*c == '\n') ;
}
}
void isVhdlDocPending()
{
if (!str_doc.pending) return;
str_doc.pending=FALSE;
oldEntry=0; // prevents endless recursion
iDocLine=str_doc.iDocLine;
VhdlParser::handleCommentBlock(str_doc.doc,str_doc.brief);
iDocLine=-1;
}
void VhdlParser::initEntry(Entry *e)
{
e->fileName = yyFileName;
e->lang = SrcLangExt_VHDL;
isVhdlDocPending();
initGroupInfo(e);
}
void VhdlParser::newEntry()
{
if (current->spec==VhdlDocGen::ENTITY ||
current->spec==VhdlDocGen::PACKAGE ||
current->spec==VhdlDocGen::ARCHITECTURE ||
current->spec==VhdlDocGen::PACKAGE_BODY)
{
current_root->addSubEntry(current);
}
else
{
if (lastCompound)
{
lastCompound->addSubEntry(current);
}
else
{
if (lastEntity)
{
lastEntity->addSubEntry(current);
}
else
{
current_root->addSubEntry(current);
}
}
}
previous = current;
current = new Entry ;
initEntry(current);
}
void VhdlParser::handleFlowComment(const char* doc)
{
lineCount(doc);
if (VhdlDocGen::getFlowMember())
{
QCString qcs(doc);
qcs=qcs.stripWhiteSpace();
qcs.stripPrefix("--#");
FlowChart::addFlowChart(FlowChart::COMMENT_NO,0,0,qcs.data());
}
}
void VhdlParser::handleCommentBlock(const char* doc1,bool brief)
{
int position=0;
QCString doc;
doc.append(doc1);
// fprintf(stderr,"\n %s",doc.data());
if (doc.isEmpty()) return;
if (checkMultiComment(doc,yyLineNr))
{
strComment.resize(0);
return;
}
VhdlDocGen::prepareComment(doc);
bool needsEntry=FALSE;
Protection protection=Public;
if (oldEntry==current)
{
//printf("\n find pending message < %s > at line: %d \n ",doc.data(),iDocLine);
str_doc.doc=doc;
str_doc.iDocLine=iDocLine;
str_doc.brief=brief;
str_doc.pending=TRUE;
return;
}
oldEntry=current;
if (brief)
{
current->briefLine = yyLineNr;
}
else
{
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,
doc, // text
yyFileName, // file
iDocLine, // line of block start
brief,
0,
FALSE,
protection,
position,
needsEntry
)
)
{
//printf("parseCommentBlock position=%d [%s]\n",position,doc.data()+position);
if (needsEntry) newEntry();
}
if (needsEntry)
{
if (varr)
{
varr=FALSE;
current->name=varName;
current->section=Entry::VARIABLEDOC_SEC;
varName="";
}
newEntry();
}
iDocLine=-1;
strComment.resize(0);
}
void VHDLLanguageScanner::parsePrototype(const char *text)
{
varName=text;
varr=TRUE;
}
void VhdlParser::addCompInst(const char *n, const char* instName, const char* comp,int iLine)
{
current->spec=VhdlDocGen::INSTANTIATION;
current->section=Entry::VARIABLE_SEC;
current->startLine=iLine;
current->bodyLine=iLine;
current->type=instName; // foo:instname e.g proto or work. proto(ttt)
current->exception=genLabels.lower(); // |arch|label1:label2...
current->name=n; // foo
if (lastCompound)
{
current->args=lastCompound->name; // architecture name
}
current->includeName=comp; // component/enity/configuration
int u=genLabels.find("|",1);
if (u>0)
{
current->write=genLabels.right(genLabels.length()-u);
current->read=genLabels.left(u);
}
//printf (" \n genlable: [%s] inst: [%s] name: [%s] %d\n",n,instName,comp,iLine);
if (lastCompound)
{
current->args=lastCompound->name;
if (true) // !findInstant(current->type))
{
initEntry(current);
instFiles.append(new Entry(*current));
}
Entry *temp=current; // hold current pointer (temp=oldEntry)
current=new Entry; // (oldEntry != current)
delete temp;
}
else
{
newEntry();
}
}
void VhdlParser::addVhdlType(const char *n,int startLine,int section,
uint64 spec,const char* args,const char* type,Protection prot)
{
QCString name(n);
if (isFuncProcProced() || VhdlDocGen::getFlowMember()) return;
if (parse_sec==GEN_SEC)
{
spec= VhdlDocGen::GENERIC;
}
QCStringList ql=QCStringList::split(",",name);
for (uint u=0;u<ql.count();u++)
{
current->name=ql[u];
current->startLine=startLine;
current->bodyLine=startLine;
current->section=section;
current->spec=spec;
current->fileName=yyFileName;
if (current->args.isEmpty())
{
current->args=args;
}
current->type=type;
current->protection=prot;
if (!lastCompound && (section==Entry::VARIABLE_SEC) && (spec == VhdlDocGen::USE || spec == VhdlDocGen::LIBRARY) )
{
libUse.append(new Entry(*current));
current->reset();
}
newEntry();
}
}
void VhdlParser::createFunction(const char *imp,uint64 spec,const char *fn)
{
QCString impure(imp);
QCString fname(fn);
current->spec=spec;
current->section=Entry::FUNCTION_SEC;
if (impure=="impure" || impure=="pure")
{
current->exception=impure;
}
if (parse_sec==GEN_SEC)
{
current->spec= VhdlDocGen::GENERIC;
current->section=Entry::FUNCTION_SEC;
}
if (currP==VhdlDocGen::PROCEDURE)
{
current->name=impure;
current->exception="";
}
else
{
current->name=fname;
}
if (spec==VhdlDocGen::PROCESS)
{
current->args=fname;
current->name=impure;
VhdlDocGen::deleteAllChars(current->args,' ');
if (!fname.isEmpty())
{
QCStringList q1=QCStringList::split(",",fname);
for (uint ii=0;ii<q1.count();ii++)
{
Argument *arg=new Argument;
arg->name=q1[ii];
current->argList->append(arg);
}
}
return;
}
}
bool VhdlParser::isFuncProcProced()
{
if (currP==VhdlDocGen::FUNCTION ||
currP==VhdlDocGen::PROCEDURE ||
currP==VhdlDocGen::PROCESS
)
{
return TRUE;
}
return FALSE;
}
void VhdlParser::pushLabel( QCString &label,QCString & val)
{
label+="|";
label+=val;
}
QCString VhdlParser::popLabel(QCString & q)
{
int i=q.findRev("|");
if (i<0) return "";
q = q.left(i);
return q;
}
void VhdlParser::addConfigureNode(const char* a,const char*b, bool,bool isLeaf,bool inlineConf)
{
VhdlConfNode* co=0;
QCString ent;
ent=a;
if (b)
{
ent=b;
}
int level=0;
if (!configL.isEmpty())
{
VhdlConfNode* vc=configL.getLast();
level=vc->level;
if (levelCounter==0)
{
pushLabel(forL,ent);
}
else if (level<levelCounter)
{
if (!isLeaf)
{
pushLabel(forL,ent);
}
}
else if (level>levelCounter)
{
forL=popLabel(forL);
}
}
else
{
pushLabel(forL,ent);
}
if (inlineConf)
{
confName=lastCompound->name;
}
//fprintf(stderr,"\n[%s %d %d]\n",forL.data(),levelCounter,level);
co=new VhdlConfNode(a,b,confName.lower().data(),forL.lower().data(),isLeaf);
if (inlineConf)
{
co->isInlineConf=TRUE;
}
configL.append(co);
}
void VhdlParser::addProto(const char *s1,const char *s2,const char *s3,
const char *s4,const char *s5,const char *s6)
{
(void)s5; // avoid unused warning
QCString name=s2;
QCStringList ql=QCStringList::split(",",name);
for (uint u=0;u<ql.count();u++)
{
Argument *arg=new Argument;
arg->name=ql[u];
if (s3)
{
arg->type=s3;
}
arg->type+=" ";
arg->type+=s4;
if (s6)
{
arg->type+=s6;
}
if (parse_sec==GEN_SEC && param_sec==0)
{
arg->defval="gen!";
}
if (parse_sec==PARAM_SEC)
{
// assert(false);
}
arg->defval+=s1;
arg->attrib="";//s6;
current->argList->append(arg);
current->args+=s2;
current->args+=",";
}
}
/*
* adds the library|use statements to the next class (entity|package|architecture|package body
* library ieee
* entity xxx
* .....
* library
* package
* enity zzz
* .....
* and so on..
*/
void VhdlParser::mapLibPackage( Entry* root)
{
QList<Entry> epp=libUse;
EntryListIterator eli(epp);
Entry *rt;
for (;(rt=eli.current());++eli)
{
if (addLibUseClause(rt->name))
{
Entry *current;
EntryListIterator eLib(*root->children());
bool bFound=FALSE;
for (eLib.toFirst();(current=eLib.current());++eLib)
{
if (VhdlDocGen::isVhdlClass(current))
{
if (current->startLine > rt->startLine)
{
bFound=TRUE;
current->addSubEntry(new Entry(*rt));
break;
}
}
}//for
if (!bFound)
{
root->addSubEntry(new Entry(*rt));
}
} //if
}// for
}//MapLib
bool VhdlParser::addLibUseClause(const QCString &type)
{
static bool showIEEESTD=Config_getBool(FORCE_LOCAL_INCLUDES);
if (showIEEESTD) // all standard packages and libraries will not be shown
{
if (type.lower().stripPrefix("ieee")) return FALSE;
if (type.lower().stripPrefix("std")) return FALSE;
}
return TRUE;
}
int VhdlParser::getLine()
{
return yyLineNr;
}
void VhdlParser::setLineParsed(int tok)
{
lineParse[tok]=yyLineNr;
}
int VhdlParser::getLine(int tok)
{
int val=lineParse[tok];
if (val<0) val=0;
//assert(val>=0 && val<=yyLineNr);
return val;
}
void VhdlParser::createFlow()
{
if (!VhdlDocGen::getFlowMember())
{
return;
}
QCString q,ret;
if (currP==VhdlDocGen::FUNCTION)
{
q=":function( ";
FlowChart::alignFuncProc(q,tempEntry->argList,true);
q+=")";
}
else if (currP==VhdlDocGen::PROCEDURE)
{
q=":procedure (";
FlowChart::alignFuncProc(q,tempEntry->argList,false);
q+=")";
}
else
{
q=":process( "+tempEntry->args;
q+=")";
}
q.prepend(VhdlDocGen::getFlowMember()->name().data());
FlowChart::addFlowChart(FlowChart::START_NO,q,0);
if (currP==VhdlDocGen::FUNCTION)
{
ret="end function ";
}
else if (currP==VhdlDocGen::PROCEDURE)
{
ret="end procedure";
}
else
{
ret="end process ";
}
FlowChart::addFlowChart(FlowChart::END_NO,ret,0);
// FlowChart::printFlowList();
FlowChart::writeFlowChart();
currP=0;
}
void VhdlParser::setMultCommentLine()
{
iDocLine=yyLineNr;
}
void VhdlParser::oneLineComment(QCString qcs)
{
int j=qcs.find("--!");
qcs=qcs.right(qcs.length()-3-j);
if (!checkMultiComment(qcs,iDocLine))
{
handleCommentBlock(qcs,TRUE);
}
}
bool checkMultiComment(QCString& qcs,int line)
{
QList<Entry> *pTemp=getEntryAtLine(VhdlParser::current_root,line);
if (pTemp->isEmpty()) return false;
VhdlDocGen::prepareComment(qcs);
while (!pTemp->isEmpty())
{
Entry *e=(Entry*)pTemp->getFirst();
e->briefLine=line;
e->brief+=qcs;
pTemp->removeFirst();
}
return true;
}
// returns the vhdl parsed types at line xxx
QList<Entry>* getEntryAtLine(const Entry* ce,int line)
{
EntryListIterator eli(*ce->children());
Entry *rt;
for (;(rt=eli.current());++eli)
{
if (rt->bodyLine==line)
{
lineEntry.insert(0,rt);
}
getEntryAtLine(rt,line);
}
return &lineEntry;
}
const char *getVhdlFileName(void)
{
return vhdlFileName;
}
|