Doxygen
Loading...
Searching...
No Matches
vhdlcode.l
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15/******************************************************************************
16 * Parser for syntax highlighting and references for vhdl subset
17 * written by M. Kreis
18 * supports VHDL-87/93/2008
19 ******************************************************************************/
20%option never-interactive
21%option case-insensitive
22%option prefix="vhdlcodeYY"
23%option reentrant
24%option extra-type="struct vhdlcodeYY_state *"
25%top{
26#include <stdint.h>
27// forward declare yyscan_t to improve type safety
28#define YY_TYPEDEF_YY_SCANNER_T
29#define yyguts_t vhdlcodeYYguts_t
30struct yyguts_t;
yyguts_t * yyscan_t
Definition code.l:25
#define yyguts_t
Definition code.l:23
32}
33
34%{
35
36// own header
37#include "vhdlcode.h"
38
39// standard includes
40#include <memory>
41#include <string>
42#include <unordered_set>
43#include <vector>
44
45// other includes
46#include "classdef.h"
47#include "config.h"
48#include "debug.h"
49#include "doxygen.h"
50#include "filedef.h"
51#include "membername.h"
52#include "message.h"
53#include "outputlist.h"
54#include "regex.h"
55#include "searchindex.h"
56#include "stringutil.h"
57#include "tooltip.h"
58#include "util.h"
59#include "vhdldocgen.h"
60
61#define YY_NO_INPUT 1
62#define YY_NO_UNISTD_H 1
63
64// Toggle for some debugging info
65//#define DBG_CTX(x) fprintf x
66#define DBG_CTX(x) do { } while(0)
67
68
69/* -----------------------------------------------------------------
70 * statics
71 */
72
73// ----------------- <vhdl> ----------------------------------
74
76{
77 bool isFuncProto = false;
78 bool isComponent = false;
79 bool isPackageBody = false;
80 bool isProto = false;
83 std::unordered_set<std::string> vhdlKeyDict;
86 const MemberDef * vhdlMember = nullptr;
88
89 OutputCodeList * code = nullptr;
90 const char * inputString = nullptr; //!< the code fragment as text
91 int inputPosition = 0; //!< read offset during parsing
93 int inputLines = 0; //!< number of line in the code fragment
94 int yyLineNr = 0; //!< current line number
95 bool insideCodeLine = false;
96 const Definition *searchCtx = nullptr;
97
98 bool exampleBlock = false;
101
102 bool currArch = false;
103
104 std::unique_ptr<FileDef> exampleFileDef;
105 const FileDef * sourceFileDef = nullptr;
106 bool lineNumbers = false;
107 const Definition * currentDefinition = nullptr;
108 const MemberDef * currentMemberDef = nullptr;
110 const char * currentFontClass = nullptr;
113
114 bool lexInit = false;
115 int braceCount = 0;
117 std::vector<const Definition *> foldStack;
118};
119
120static void writeFont(yyscan_t yyscanner,const char *s,const DString &text,bool specialComment=false);
121static void generateMemLink(yyscan_t yyscanner,OutputCodeList &ol,DString &clName,DString& memberName);
122static bool writeColoredWord(yyscan_t yyscanner,DString& word );
123static void generateClassOrGlobalLink(yyscan_t yyscanner,OutputCodeList &ol,const DString &clName, bool typeOnly=false, const DString &curr_class=DString());
124static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor);
125static bool checkVhdlString(yyscan_t yyscanner,DString &name);
126static void addToSearchIndex(yyscan_t yyscanner,const DString &text);
127static void startCodeLine(yyscan_t yyscanner);
128static void endCodeLine(yyscan_t yyscanner);
129static void nextCodeLine(yyscan_t yyscanner);
130static void writeWord(yyscan_t yyscanner,const DString &word,const DString &curr_class=DString(),bool classLink=false);
131static void codifyLines(yyscan_t yyscanner,const DString &text,const DString &cl=DString(),bool classlink=false,bool comment=false);
132static void writeMultiLineCodeLink(yyscan_t yyscanner,OutputCodeList &ol,
133 const Definition *d,
134 const DString &text);
135static void generateFuncLink(yyscan_t yyscanner,OutputCodeList &ol,const MemberDef* mdef);
136static int countLines(yyscan_t yyscanner);
137static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment=false);
138static void endFontClass(yyscan_t yyscanner,bool specialComment=false);
139static void appStringLower(DString& qcs,const char* text);
140static void codifyMapLines(yyscan_t yyscanner,const DString &text);
141static void writeFuncProto(yyscan_t yyscanner);
142static void writeProcessProto(yyscan_t yyscanner);
143static int yyread(yyscan_t yyscanner,char *buf,int max_size);
144
145[[maybe_unused]] static const char *stateToString(int state);
146//-------------------------------------------------------------------
147
148
149#undef YY_INPUT
150#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
151
152// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
153static inline const char *getLexerFILE() {return __FILE__;}
154#include "doxygen_lex.h"
155
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
The common base class of all entity definitions found in the sources.
Definition definition.h:77
A model of a file symbol.
Definition filedef.h:97
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
Class representing a list of different code generators.
Definition outputlist.h:162
Class that manages the tooltips for a source file.
Definition tooltip.h:27
Web server based search engine.
Some helper functions for std::string.
bool insideCodeLine
Definition vhdlcode.l:95
DString PortMapComp
Definition vhdlcode.l:85
DString exampleName
Definition vhdlcode.l:99
const Definition * searchCtx
Definition vhdlcode.l:96
int yyLineNr
current line number
Definition vhdlcode.l:94
std::vector< const Definition * > foldStack
Definition vhdlcode.l:117
std::unique_ptr< FileDef > exampleFileDef
Definition vhdlcode.l:104
DString funcProto
Definition vhdlcode.l:87
const MemberDef * vhdlMember
Definition vhdlcode.l:86
DString prevString
Definition vhdlcode.l:81
OutputCodeList * code
Definition vhdlcode.l:89
TooltipManager tooltipManager
Definition vhdlcode.l:116
int lastCopyCommentContext
Definition vhdlcode.l:112
std::unordered_set< std::string > vhdlKeyDict
Definition vhdlcode.l:83
DString currClass
Definition vhdlcode.l:82
const Definition * currentDefinition
Definition vhdlcode.l:107
DString exampleFile
Definition vhdlcode.l:100
bool insideSpecialComment
Definition vhdlcode.l:111
int inputPosition
read offset during parsing
Definition vhdlcode.l:91
const FileDef * sourceFileDef
Definition vhdlcode.l:105
const MemberDef * currentMemberDef
Definition vhdlcode.l:108
const char * inputString
the code fragment as text
Definition vhdlcode.l:90
const char * currentFontClass
Definition vhdlcode.l:110
DString tempComp
Definition vhdlcode.l:84
DString fileName
Definition vhdlcode.l:92
bool includeCodeFragment
Definition vhdlcode.l:109
int inputLines
number of line in the code fragment
Definition vhdlcode.l:93
A bunch of utility functions.
static void endCodeLine(yyscan_t yyscanner)
Definition vhdlcode.l:1121
static void generateClassOrGlobalLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &clName, bool typeOnly=false, const DString &curr_class=DString())
Definition vhdlcode.l:1380
static void nextCodeLine(yyscan_t yyscanner)
Definition vhdlcode.l:1129
static void startCodeLine(yyscan_t yyscanner)
Definition vhdlcode.l:1053
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
Definition vhdlcode.l:953
static void appStringLower(DString &qcs, const char *text)
Definition vhdlcode.l:1503
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition vhdlcode.l:938
static int countLines(yyscan_t yyscanner)
Definition vhdlcode.l:1436
static const char * stateToString(int state)
static void generateFuncLink(yyscan_t yyscanner, OutputCodeList &ol, const MemberDef *mdef)
Definition vhdlcode.l:1327
static void codifyLines(yyscan_t yyscanner, const DString &text, const DString &cl=DString(), bool classlink=false, bool comment=false)
Definition vhdlcode.l:1241
static void codifyMapLines(yyscan_t yyscanner, const DString &text)
Definition vhdlcode.l:1511
static void addToSearchIndex(yyscan_t yyscanner, const DString &text)
Definition vhdlcode.l:1007
static void writeProcessProto(yyscan_t yyscanner)
Definition vhdlcode.l:1606
static bool writeColoredWord(yyscan_t yyscanner, DString &word)
Definition vhdlcode.l:1615
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
Definition vhdlcode.l:1472
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
Definition vhdlcode.l:1455
static void writeMultiLineCodeLink(yyscan_t yyscanner, OutputCodeList &ol, const Definition *d, const DString &text)
Definition vhdlcode.l:1287
static const char * getLexerFILE()
Definition vhdlcode.l:153
static void generateMemLink(yyscan_t yyscanner, OutputCodeList &ol, DString &clName, DString &memberName)
Definition vhdlcode.l:1343
static void writeFuncProto(yyscan_t yyscanner)
Definition vhdlcode.l:1569
static void writeFont(yyscan_t yyscanner, const char *s, const DString &text, bool specialComment=false)
Definition vhdlcode.l:1491
static void writeWord(yyscan_t yyscanner, const DString &word, const DString &curr_class=DString(), bool classLink=false)
Definition vhdlcode.l:1149
static bool checkVhdlString(yyscan_t yyscanner, DString &name)
Definition vhdlcode.l:969
156%}
157
158
159B [ \t]
160BN [ \t\n\r]
161STRING ["][^"\n]*["]
162NAME [a-z_A-Z][ a-z_A-Z0-9]*
163FUNCNAME [a-z_A-Z"][a-z_A-Z0-9+*"/=<>-]*
164ID "$"?[a-z_A-Z][a-z_A-Z0-9]*
165SPECSIGN [:;, +*&\/=<>'\t]*
166DIGITSS [0-9]+|[0-9]+("#")*[0-9_a-fA-F\+\.\-]+("#")*
167ALLTYPESMAP {B}*[_a-zA-Z0-9. ]+{BN}*
168ALLTYPESMAP1 {BN}*[_a-zA-Z0-9.() ]+{BN}*
169
170ARCHITECTURE ^{B}*("architecture"){BN}+{FUNCNAME}{BN}+("of"){BN}+{FUNCNAME}{BN}+("is")
171PROCESS ({BN}*{FUNCNAME}{BN}*[:]+{BN}*("process"){BN}*[(]*)|[^a-zA-Z]("process "|"process("){BN}*[ (]*|[^a-zA-Z]("process"){BN}+
172
173END1 {B}*("end "){BN}+("if"|"case"|"loop"|"generate"|"for")
174END2 [^a-zA-Z_]("end"){BN}*[;]
175END3 {BN}*[^a-zA-Z]("end"){BN}+{FUNCNAME}{BN}*[;]
176END4 {B}*("end"){BN}+"function"{BN}+{FUNCNAME}{BN}*[;]
177ENDEFUNC {END3}|{END4}|{END2}
178
179KEYWORD ("of"|"new"|"event"|"break"|"case"|"end"|"loop"|"else"|"for"|"goto"|"if"|"return"|"generate"|"is"|"while"|"in")
180TYPEKW ^{B}*("type"|"subtype"|"constant"|"attribute"|"signal"|"variable","alias","configuration")
181FUNC ^{B}*("function"|"procedure"){BN}*{FUNCNAME}{BN}*("(")
182
183ARITHOP "+"|"-"|"/"|"*"|"%"|"/="|":="
184ASSIGNOP "="|"*="|"/="|"%="|"+="|"-="|"<<="|">>="|"&="|"^="|"|="
185LOGICOP "=="|"!="|">"|"<"|">="|"<="|"&&"|"||"|"!"
186BITOP "&"|"|"|"^"|"<<"|">>"|"~"
187OPERATOR {ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}
188
189PORT {B}*("port"){BN}*("(")
190GENERIC {B}*("generic"){BN}*("(")
191
192BRACEOPEN [(]{1}
193BRACECLOSE [)]{1}
194
195TEXTT {B}*"--"[^\n]*
196
197MAPCOMPONENT1 ({ALLTYPESMAP}[:]{ALLTYPESMAP}{TEXTT}*{BN}+("port"|"generic"){BN}+("map"){BN}*("("){1})
198MAPCOMPONENT2 {BN}*("port"|"generic"){BN}+("map"){BN}*("("){1}
199MAPCOMPONENT3 ({ALLTYPESMAP}[:]{BN}*{ALLTYPESMAP1}{TEXTT}*{BN}+("port"|"generic"){BN}+("map"){BN}*("("){1})
200MAPCOMPONENT4 ({ALLTYPESMAP}[:]{BN}*("entity"|"component"|"configuration"){BN}+{ALLTYPESMAP1}{TEXTT}*{BN}*("port"|"generic"){BN}*("map"){BN}*("("){1})
201
202XILINX "INST"|"NET"|"PIN"|"BLKNM"|"BUFG"|"COLLAPSE"|"CPLD"|"COMPGRP"|"CONFIG"|"CONFIG_MODE"|"COOL_CLK"|"DATA_GATE"|"DCI_VALUE"|"DISABLE"|"DRIVE"|"DROP_SPEC"|"ENABLE"|"FAST"|"FEEDBACK"|"FILE"|"FLOAT"|"FROM-THRU-TO"|"FROM-TO"|"HBLKNM"|"HU_SET"|"INREG"|"IOB"|"IOBDELAY"|"IOSTANDARD"|"KEEP"|"KEEPER"|"LOC"|"LOCATE"|"LOCK_PINS"|"MAP"|"MAXDELAY"|"MAXPT"|"MAXSKEW"|"NODELAY"|"NOREDUCE"|"OFFSET"|"OPEN_DRAIN"|"OPT_EFFORT"|"OPTIMIZE"|"PERIOD"|"PIN"|"PRIORITY"|"PROHIBIT"|"PULLDOWN"|"PULLUP"|"PWR_MODE"|"REG"|"RLOC"|"RLOC_ORIGIN"|"RLOC_RANGE"|"SAVE NET"|"FLAG"|"SYSTEM_JITTER"|"TEMPERATURE"|"TIMEGRP"|"TIMESPEC"|"VOLTAGE"
203
204%option noyywrap
205%option nounput
206
207%x Bases
208%x ParseType
209%x ParseFuncProto
210%x ParseComponent
211%x ParsePackage
212%x ParseProcessProto
213%x ClassesName
214%x Map
215%x End
216%x CopyComment
217
219
220. {
221 BEGIN(Bases);
222 }
223
224<Map>{BRACEOPEN} {
225 yyextra->braceCount++;
226 writeFont(yyscanner,"vhdlchar",yytext);
227 BEGIN(Map);
228 }
229
230<Map>[^()\n,--]* { /* write and link a port map lines */
231 DString tt(yytext);
233 auto ql = split(tt.str(),"=>");
234 if (ql.size()>=2)
235 {
236 unsigned int index=0;
237 DString t1(ql[0]);
238 char cc=t1.at(index);
239 while (cc==' ' || cc=='\t')
240 {
241 char c2[2];
242 c2[0]=cc;
243 c2[1]=0;
244 yyextra->code->codify(c2);
245 index++;
246 if (index>=t1.size()) break;
247 cc=t1.at(index);
248 }
249
250 DString s1=t1;
251 s1=s1.stripWhiteSpace();
252
253 // if (!yyextra->PortMapComp.empty())
254 generateMemLink(yyscanner,*yyextra->code,yyextra->PortMapComp,s1);
255 while (index++<t1.size())
256 {
257 cc=t1.at(index);
258 if (cc==' ' || cc=='\t')
259 {
260 char c2[2];
261 c2[0]=cc;
262 c2[1]=0;
263 yyextra->code->codify(c2);
264 }
265 }
266 codifyLines(yyscanner,"=>");
267 index=0;
268 DString s2(ql[1]);
269 t1=s2;
270 cc=t1.at(index);
271 while (cc==' ' || cc=='\t')
272 {
273 char c2[2];
274 c2[0]=cc;
275 c2[1]=0;
276 yyextra->code->codify(c2);
277 index++;
278 if (index>=t1.size()) break;
279 cc=t1.at(index);
280 }
281 s2=s2.stripWhiteSpace();
282 if (!checkVhdlString(yyscanner,s2))
283 {
284 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,s2);
285 }
286 while (index++<t1.size())
287 {
288 if (t1.at(index)==' ')
289 {
290 yyextra->code->codify(" ");
291 }
292 }
293 }
294 else
295 {
296 codifyLines(yyscanner,yytext,yyextra->currClass);
297 }
298 BEGIN(Map);
299 }
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
static void deleteAllChars(DString &s, char c)
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
Definition stringutil.h:119
300
301<Map>"\n"|"," {
302 codifyLines(yyscanner,yytext);
303 BEGIN(Map);
304 }
305
306<Map>{BRACECLOSE} {
307 yyextra->braceCount--;
308 writeFont(yyscanner,"vhdlchar",yytext);
309 if (yyextra->braceCount==0)
310 {
311 BEGIN(Bases);
312 }
313 }
314
315<ParseFuncProto>{NAME} {
316 DString tmp(yytext);
317 tmp=tmp.stripWhiteSpace();
318 appStringLower(yyextra->prevString,yytext);
319 yyextra->vhdlKeyDict.insert(yyextra->prevString.str());
320 if (!writeColoredWord(yyscanner,tmp))
321 {
322 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,tmp);
323 }
324 BEGIN(Bases);
325 }
326
327<ParseType>{STRING} {
328 DString qcs(yytext);
331 if (VhdlDocGen::isNumber(qcs.str()))
332 {
333 writeFont(yyscanner,"vhdllogic",yytext);
334 }
335 else
336 {
337 writeFont(yyscanner,"keyword",yytext);
338 }
339 }
static bool isNumber(const std::string &s)
340
341<ParseType>"\n" {
342 yyextra->funcProto.append(yytext);
343 if (yyextra->isProto)
344 {
345 codifyLines(yyscanner,yytext);
346 }
347 BEGIN(ParseType);
348 }
349
350
351<ParseType>{TEXTT} {
352 yyextra->funcProto.append(yytext);
353 if (yyextra->isProto)
354 {
355 writeFont(yyscanner,"keyword",yytext);
356 }
357 BEGIN(ParseType);
358 }
359
360<ParseType>{ENDEFUNC} {
361 DString tt(yytext);
362 codifyLines(yyscanner,yytext,yyextra->currClass);
363 tt=tt.lower();
365 tt.stripWhiteSpace();
366 static const reg::Ex regg(R"(\s+)"); // any number of whitespace
367 auto ql = split(tt.str(),regg);
368 size_t index1=findIndex(ql,"if");
369 size_t index2=findIndex(ql,"case");
370 size_t index3=findIndex(ql,"loop");
371 size_t index4=findIndex(ql,"generate");
372 if (index1==std::string::npos &&
373 index2==std::string::npos &&
374 index3==std::string::npos &&
375 index4==std::string::npos)
376 {
377 BEGIN(Bases);
378 }
379 else
380 {
381 BEGIN(ParseType);
382 }
383 }
Class representing a regular expression.
Definition regex.h:39
size_t findIndex(const StringVector &sv, const std::string &s)
find the index of a string in a vector of strings, returns std::string::npos if the string could not ...
Definition stringutil.h:179
384
385<ParseType>{END1} {
386 codifyLines(yyscanner,yytext,yyextra->currClass);
387 yyextra->vhdlKeyDict.clear();
388 }
389
390<ParseType>^{B}*("begin "|"begin") {
391 codifyLines(yyscanner,yytext,yyextra->currClass);
392 yyextra->isFuncProto=false;
393 }
394
395<ParseType>{SPECSIGN} {
396 yyextra->funcProto.append(yytext);
397 if (yyextra->isProto)
398 {
399 codifyLines(yyscanner,yytext,yyextra->currClass);
400 }
401 }
402
403<ParseType>["_a-zA-Z0-9]* {
404 DString val(yytext);
405 yyextra->funcProto.append(yytext);
406 appStringLower(yyextra->prevString,yytext);
407
408 if (yyextra->isFuncProto && yyextra->braceCount==0)
409 {
410 yyextra->vhdlKeyDict.insert(yyextra->prevString.str());
411 }
412
413 if (yyextra->isProto)
414 {
415 if (!writeColoredWord(yyscanner,val))
416 {
417 if (!yyextra->isFuncProto &&
418 yyextra->vhdlKeyDict.find(yyextra->prevString.str())==yyextra->vhdlKeyDict.end())
419 {
420 val=val.stripWhiteSpace();
421 if (VhdlDocGen::isNumber(val.str()))
422 {
423 startFontClass(yyscanner,"vhdllogic");
424 codifyLines(yyscanner,yytext,yyextra->currClass);
425 endFontClass(yyscanner);
426 }
427 else
428 {
429 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,val);
430 }
431 }
432 else
433 {
434 codifyLines(yyscanner,yytext,yyextra->currClass);
435 }
436 }
437 }
438 BEGIN(ParseType);
439 }
440
441<ParseType>{BRACEOPEN} {
442 yyextra->braceCount++;
443 yyextra->funcProto+='(';
444 if (yyextra->isProto)
445 {
446 writeFont(yyscanner,"vhdlchar",yytext);
447 }
448 BEGIN(ParseType);
449 }
450
451<ParseType>{BRACECLOSE} {
452 yyextra->braceCount--;
453 yyextra->funcProto+=')';
454 if (yyextra->isProto)
455 {
456 writeFont(yyscanner,"vhdlchar",yytext);
457 }
458 if (yyextra->braceCount==0 && !yyextra->isProto)// && !yyextra->isPackageBody)
459 {
460 yyextra->isProto=true;
461 appStringLower(yyextra->prevString,yytext);
462 writeFuncProto(yyscanner);
463 BEGIN(Bases);
464 }
465 if (yyextra->isPackageBody)
466 {
467 BEGIN(ParseType);
468 }
469 }
470
471
472<ClassesName>{FUNCNAME} {
473 appStringLower(yyextra->prevString,yytext);
474 yyextra->currClass.clear();
475 yyextra->currClass.append(yytext);
476 yyextra->currClass=yyextra->currClass.stripWhiteSpace();
477
478 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
479 BEGIN(Bases);
480 }
481
482
483<ParseComponent>{BRACEOPEN} {
484 yyextra->braceCount++;
485 yyextra->code->codify(yytext);
486 }
487
488
489<ParseComponent>{BRACECLOSE} {
490 yyextra->braceCount--;
491 yyextra->code->codify(yytext);
492 if (yyextra->braceCount==0 && !yyextra->isComponent)
493 {
494 yyextra->tempComp.clear();
495 BEGIN(Bases);
496 }
497 else
498 {
499 BEGIN(ParseComponent);
500 }
501 }
502
503<ParseComponent>{B}*"-" {
504 if (strlen(yytext)>=2) // found text ?
505 {
506 writeFont(yyscanner,"keyword",yytext);
507 }
508 else
509 {
510 writeFont(yyscanner,"vhdlchar",yytext);
511 }
512 }
513
514<ParseComponent>{SPECSIGN} {
515 codifyLines(yyscanner,yytext);
516 }
517
518
519
520<ParseComponent>"\n"|" " {
521 codifyLines(yyscanner,yytext);
522 }
523
524<ParseComponent>{DIGITSS} {
525 startFontClass(yyscanner,"vhdllogic");
526 codifyLines(yyscanner,yytext);
527 endFontClass(yyscanner);
528 }
529
530<ParseComponent>{PORT} {
531 codifyLines(yyscanner,yytext);
532 yyextra->braceCount=1;
533 yyextra->isComponent=false;
534 }
535
536<ParseComponent>{GENERIC} {
537 codifyLines(yyscanner,yytext);
538 yyextra->braceCount=1;
539 }
540
541<ParseComponent>[_a-zA_Z][_a-zA-Z0-9]* {
542 DString temp(yytext);
543 appStringLower(yyextra->prevString,yytext);
544 if (!checkVhdlString(yyscanner,temp))
545 {
546 if (!writeColoredWord(yyscanner,yyextra->prevString))
547 {
548 generateMemLink(yyscanner,*yyextra->code,yyextra->tempComp,temp);
549 }
550 }
551 }
552
553<ParseComponent>{STRING} {
554 DString temp(yytext);
555 if (!checkVhdlString(yyscanner,temp))
556 {
557 codifyLines(yyscanner,yytext);
558 }
559 }
560
561
562<ParseProcessProto>[^()]* {
563 yyextra->funcProto.append(yytext);
564 }
565
566
567
568<ParseProcessProto>{BRACEOPEN} {
569 yyextra->funcProto.append(yytext);
570 yyextra->braceCount++;
571 }
572
573<ParseProcessProto>{BRACECLOSE} {
574 yyextra->funcProto.append(yytext);
575 yyextra->braceCount--;
576 if (yyextra->braceCount==0)
577 {
578 writeProcessProto(yyscanner);
579 BEGIN(Bases);
580 }
581 }
582
583<ParsePackage>[^:;]* { //found package
584 StringVector strl=split(yytext,".");
585 if (strl.size()>2)
586 {
587 DString s1 = strl[0];
588 DString s2 = strl[1];
589 DString s3 = strl[2];
590 s1.append(".");
591 s3.prepend(".");
592 codifyLines(yyscanner,s1,yyextra->currClass);
594 if (cd)
595 {
596 generateClassOrGlobalLink(yyscanner,*yyextra->code,s2);
597 }
598 else
599 {
600 codifyLines(yyscanner,s2);
601 }
602 codifyLines(yyscanner,s3);
603 }
604 else
605 {
606 writeFont(yyscanner,"keywordflow",yytext);
607 }
608 BEGIN(Bases);
609 }
A abstract class representing of a compound symbol.
Definition classdef.h:100
DString & append(char c)
Definition dstring.h:489
DString & prepend(const char *s)
Definition dstring.h:515
static ClassDef * getPackageName(const DString &name)
std::vector< std::string > StringVector
Definition containers.h:33
610
611<Bases>{MAPCOMPONENT1}|{MAPCOMPONENT2}|{MAPCOMPONENT3}|{MAPCOMPONENT4} { // found port or generic map
612 DString tt(yytext);
613 size_t j=tt.find('.');
614
615 if (j!=DString::npos && j>0)
616 {
617 DString left=tt.left(j+1);
618 codifyLines(yyscanner,left);
619 tt=tt.mid(j+1);
620 left=VhdlDocGen::getIndexWord(tt,0);
621 if (!left.empty())
622 {
623 j=left.find('(');
624 if (j!=DString::npos)
625 {
626 DString name=left.left(j);
627 generateClassOrGlobalLink(yyscanner,*yyextra->code,name);
628 yyextra->PortMapComp=name;
629 name=tt.mid(name.length());
630 codifyLines(yyscanner,name);
631 }
632 else
633 {
634 generateClassOrGlobalLink(yyscanner,*yyextra->code,left);
635 tt.stripPrefix(left);
636
637 yyextra->PortMapComp=left;
638 codifyLines(yyscanner,tt);
639 }
640 }
641 }
642 else
643 {
644 if (tt.contains(':',false))
645 {
646 codifyMapLines(yyscanner,tt);
647 }
648 else
649 {
650 codifyLines(yyscanner,tt);
651 }
652 }
653 yyextra->braceCount=1;
654 BEGIN(Map);
655 }
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString left(size_t len) const
Definition dstring.h:306
static DString getIndexWord(const DString &, int index)
const char * name(int level)
Definition latexgen.h:368
656
657<Bases>^{B}*("component"){BN}+{FUNCNAME} { // found component
658 appStringLower(yyextra->prevString,yytext);
659 DString temp=VhdlDocGen::getIndexWord(yytext,1);
660 temp=temp.stripWhiteSpace();
662 yyextra->tempComp=temp;
663 codifyLines(yyscanner,yytext,temp,true);
664 yyextra->braceCount=0;
665 yyextra->isComponent=true;
666 BEGIN(ParseComponent);
667 }
668
669
670
671<Bases>{ARCHITECTURE} { // found architecture
672 yyextra->PortMapComp.clear();
673 DString temp = VhdlDocGen::getIndexWord(yytext,3);
674 yyextra->currArch = true;
675 temp+="::";
676 temp+=VhdlDocGen::getIndexWord(yytext,1);
677 yyextra->currClass=temp;
679 codifyLines(yyscanner,yytext,temp,true);
680 yyextra->isPackageBody=false;
681 }
682
683
684<Bases>^{B}*("package "){BN}*("body"){BN}*{FUNCNAME} { // found package body
685 DString ss(yytext);
686 DString temp=VhdlDocGen::getIndexWord(yytext,2);
687 StringVector ql=split(yytext,temp.str());
688 DString ll = ql[0];
689 codifyLines(yyscanner,ll,yyextra->currClass);
690 temp=temp.stripWhiteSpace();
691 temp.prepend("_");
692 generateClassOrGlobalLink(yyscanner,*yyextra->code,temp);
693 yyextra->currClass.clear();
694 yyextra->currClass=temp;
695 yyextra->isProto=false;
696 yyextra->isPackageBody=true;
697 }
const std::string & str() const
Definition dstring.h:645
698
699<Bases>{PROCESS} { // found process
700 yyextra->isFuncProto=true;
701 yyextra->funcProto.clear();
702 yyextra->funcProto.append(yytext);
703 yyextra->vhdlKeyDict.clear();
704 appStringLower(yyextra->prevString,yytext);
705 if (yyextra->prevString.contains('('))
706 {
707 yyextra->braceCount=1;
708 BEGIN(ParseProcessProto);
709 }
710 else
711 {
712 writeProcessProto(yyscanner);
713 }
714 }
715
716<Bases>("end"){BN}+("process") { // end of process
717 yyextra->isFuncProto=false;
718 codifyLines(yyscanner,yytext);
719 BEGIN(Bases);
720 }
721
722
723<Bases>^{B}*("begin "|"begin") {
724 yyextra->isFuncProto=false;
725 writeFont(yyscanner,"vhdlkeyword",yytext);
726 }
727
728<Bases>^{B}*("use"|"library"){BN}+ { //found package or library
729 writeFont(yyscanner,"vhdlkeyword",yytext);
730 BEGIN(ParsePackage);
731 }
732
733
734<Bases>^{B}*("use"){BN}+("configuration")[^\n]* {
735 codifyLines(yyscanner,yytext);
736 }
737
738<Bases>{FUNC} { // found function|procedure
739 yyextra->vhdlKeyDict.clear();
740 yyextra->funcProto.clear();
741 yyextra->isProto=false;
742 yyextra->funcProto.append(yytext);
743 yyextra->braceCount=1;
744 BEGIN(ParseType);
745 }
746
747<Bases>^{B}*("entity"|"package"){BN}+ {
748 appStringLower(yyextra->prevString,yytext);
749 writeFont(yyscanner,"keywordflow",yytext);
750 yyextra->isPackageBody=false;
751 BEGIN(ClassesName);
752 }
753
754<Bases>"end"{BN}+"architecture"{BN}+{FUNCNAME} {
755 codifyLines(yyscanner,yytext,yyextra->currClass,true);
756 yyextra->currArch = false;
757 }
758<Bases>"end"{BN}+{FUNCNAME} {
759 if (yyextra->currArch)
760 {
761 codifyLines(yyscanner,yytext,yyextra->currClass,true);
762 yyextra->currArch = false;
763 }
764 else
765 {
766 REJECT;
767 }
768 }
769<Bases>"end" {
770 appStringLower(yyextra->prevString,yytext);
771 DString temp(yytext);
772 temp=temp.stripWhiteSpace();
773
774 writeColoredWord(yyscanner,temp);
775 BEGIN(End);
776 }
777<End>{ID} {
778 appStringLower(yyextra->prevString,yytext);
779 DString temp(yytext);
780 temp=temp.stripWhiteSpace();
781
782 if (!writeColoredWord(yyscanner,temp))
783 {
784 generateClassOrGlobalLink(yyscanner,*yyextra->code,temp);
785 }
786 }
787<End>";" {
788 codifyLines(yyscanner,yytext);
789 BEGIN(Bases);
790 }
791<Bases>{KEYWORD} { // found keyword
792 DString qcs(yytext);
793 if (!writeColoredWord(yyscanner,qcs))
794 {
795 startFontClass(yyscanner,"vhdlchar");
796 yyextra->code->codify(yytext);
797 endFontClass(yyscanner);
798 }
799 }
800
801
802<Bases>{ID} {
803 appStringLower(yyextra->prevString,yytext);
804 DString temp(yytext);
805 temp=temp.stripWhiteSpace();
806
807 if (!writeColoredWord(yyscanner,temp))
808 {
809 startFontClass(yyscanner,"vhdlchar");
810 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,temp);
811 endFontClass(yyscanner);
812 }
813 }
814
815<Bases,ParseComponent>{DIGITSS} {
816 startFontClass(yyscanner,"vhdllogic");
817 codifyLines(yyscanner,yytext);
818 endFontClass(yyscanner);
819 }
820
821<Bases>^{B}*("use"){BN}+("entity"|"component")[^\n]* {
822 codifyLines(yyscanner,yytext,yyextra->currClass,true);
823 }
824
825
826<Bases>{TYPEKW} {
827 codifyLines(yyscanner,yytext);
828 if (yyextra->isFuncProto)
829 {
830 BEGIN(ParseFuncProto);
831 }
832 else
833 {
834 BEGIN(Bases);
835 }
836 }
837
838<Bases>{OPERATOR} {
839 startFontClass(yyscanner,"vhdlchar");
840 yyextra->code->codify(yytext);
841 endFontClass(yyscanner);
842 }
843
844<Bases>","|"."|":"|"'"|"("|")" {
845 startFontClass(yyscanner,"vhdlchar");
846 yyextra->code->codify(yytext);
847 endFontClass(yyscanner);
848 }
849
850<Bases>{STRING} {
851 DString qcs(yytext);
854
855 if (VhdlDocGen::isNumber(qcs.str()))
856 {
857 writeFont(yyscanner,"vhdllogic",yytext);
858 }
859 else
860 {
861 writeFont(yyscanner,"keyword",yytext);
862 }
863 }
864
865<Bases>{B}*"#"[^\n]* {
866 writeFont(yyscanner,"keyword",yytext);
867 }
868
869<Bases>^{B}*{XILINX}/[^a-zA-Z0-9_] {
870 writeWord(yyscanner,yytext);
871 //codifyLines(yyscanner,yytext,yyextra->currClass,true);
872 }
873
874<Bases>^{B}*"set_"[^\n]* {
875 writeWord(yyscanner,yytext);
876 }
877
878<*>\n {
879 codifyLines(yyscanner,yytext);
880 BEGIN(Bases);
881 }
882
883<*>[\x80-\xFF]* { // keep utf8 characters together...
884 yyextra->code->codify(yytext);
885 }
886<*>. {
887 yyextra->code->codify(yytext);
888 }
889
890
891<*>\n?"--!"[^\n]*/\n{B}*"--!" { // found special multi-line comment on its own line
892 if (YY_START!=CopyComment)
893 {
894 startFontClass(yyscanner,"comment",true);
895 yyextra->lastCopyCommentContext=YY_START;
896 BEGIN(CopyComment);
897 }
898 codifyLines(yyscanner,yytext,DString(),false,true);
899 }
900<*>\n{TEXTT} { // found normal or special comment on its own line
901 DString text(yytext);
902 size_t i=text.find("--");
903 bool isSpecialComment = i!=DString::npos && yytext[i+2]=='!';
904 if (isSpecialComment && YY_START!=CopyComment)
905 {
906 startFontClass(yyscanner,"comment",true);
907 }
908 codifyLines(yyscanner,text,DString(),false,true);
909 if (isSpecialComment)
910 {
911 endFontClass(yyscanner,true);
912 }
913 if (YY_START==CopyComment)
914 {
915 BEGIN(yyextra->lastCopyCommentContext);
916 }
917 }
918<*>{TEXTT} { // found normal or special comment after something
919 DString text(yytext);
920 size_t i=text.find("--");
921 bool isSpecialComment = i!=DString::npos && yytext[i+2]=='!';
922 if (isSpecialComment)
923 {
924 startFontClass(yyscanner,"comment",true);
925 }
926 codifyLines(yyscanner,yytext,DString(),false,true);
927 if (isSpecialComment)
928 {
929 endFontClass(yyscanner,true);
930 }
931 }
932
933%%
934
935/*@ ----------------------------------------------------------------------------
936 */
937
938static int yyread(yyscan_t yyscanner,char *buf,int max_size)
939{
940 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
941 int inputPosition = yyextra->inputPosition;
942 const char *s = yyextra->inputString + inputPosition;
943 int c=0;
944 while( c < max_size && *s)
945 {
946 *buf++ = *s++;
947 c++;
948 }
949 yyextra->inputPosition += c;
950 return c;
951}
952
953static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor)
954{
955 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
956 if (Doxygen::searchIndex.enabled())
957 {
958 if (yyextra->searchCtx)
959 {
960 Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),false);
961 }
962 else
963 {
964 Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,true);
965 }
966 }
967}
968
969static bool checkVhdlString(yyscan_t yyscanner,DString &name)
970{
971 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
972 if (name.empty()) return false;
973
974 size_t len=name.length();
975 if (len>2 && name.at(0)=='"' && name.at(len-1)=='"')
976 {
977 DString inside = name.mid(1,len-2);
978 static const reg::Ex regg(R"(\s+)"); // any number of whitespace
979 auto qrl=split(inside.str(),regg);
980 if (!qrl.empty() && VhdlDocGen::isNumber(qrl[0]))
981 {
982 yyextra->code->codify("\"");
983 startFontClass(yyscanner,"vhdllogic");
984 yyextra->code->codify(inside);
985 endFontClass(yyscanner);
986 yyextra->code->codify("\"");
987 }
988 else
989 {
990 startFontClass(yyscanner,"keyword");
991 yyextra->code->codify(name);
992 endFontClass(yyscanner);
993 }
994 return true;
995 }
996
997 if (VhdlDocGen::isNumber(name.str()))
998 {
999 startFontClass(yyscanner,"vhdllogic");
1000 yyextra->code->codify(name);
1001 endFontClass(yyscanner);
1002 return true;
1003 }
1004 return false;
1005}
1006
1007static void addToSearchIndex(yyscan_t /*yyscanner*/,const DString &text)
1008{
1009 if (Doxygen::searchIndex.enabled())
1010 {
1011 Doxygen::searchIndex.addWord(text,false);
1012 }
1013}
1014
1015static void codeFolding(yyscan_t yyscanner,const Definition *d)
1016{
1017 // TODO: the VHDL parse doesn't seem to record startLine and endBodyLine for many of the constructs, preventing folding from working.
1018 if (Config_getBool(HTML_CODE_FOLDING))
1019 {
1020 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1021 while (!yyextra->foldStack.empty())
1022 {
1023 const Definition *dd = yyextra->foldStack.back();
1024 if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
1025 {
1026 yyextra->code->endFold();
1027 //printf("%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
1028 yyextra->foldStack.pop_back();
1029 }
1030 else
1031 {
1032 break;
1033 }
1034 }
1035 if (d)
1036 {
1037 int startLine = d->getStartDefLine();
1038 int endLine = d->getEndBodyLine();
1039 if (endLine!=-1 && startLine!=endLine && (yyextra->foldStack.empty() || yyextra->foldStack.back()->getEndBodyLine()!=startLine))
1040 {
1041 //printf("%d: start codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->name()),d->getStartDefLine(),d->getEndBodyLine());
1042 yyextra->code->startFold(yyextra->yyLineNr,"","");
1043 yyextra->foldStack.push_back(d);
1044 }
1045 }
1046 }
1047}
1048
1049/*! start a new line of code, inserting a line number if yyextra->sourceFileDef
1050 * is true. If a definition starts at the current line, then the line
1051 * number is linked to the documentation of that definition.
1052 */
1053static void startCodeLine(yyscan_t yyscanner)
1054{
1055 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1056 //if (yyextra->currentFontClass) { yyextra->code->endFontClass(); }
1057 if (yyextra->sourceFileDef && yyextra->lineNumbers)
1058 {
1059 //DString lineNumber,lineAnchor;
1060 //lineNumber.sprintf("%05d",yyextra->yyLineNr);
1061 //lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
1062 // if ((yyextra->yyLineNr % 500) == 0)
1063 // fprintf(stderr,"\n starting Line %d:",yyextra->yyLineNr);
1064 const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
1065 //printf("startCodeLine %d d=%s\n", yyextra->yyLineNr,qPrint(d ? d->name()) : "<null>");
1066 if (!yyextra->includeCodeFragment && d)
1067 {
1068 yyextra->currentDefinition = d;
1069 yyextra->currentMemberDef = yyextra->sourceFileDef->getSourceMember(yyextra->yyLineNr);
1070 if (!yyextra->tempComp.empty() && yyextra->currentMemberDef )
1071 {
1072 //ClassDef *cf=VhdlDocGen::getClass(yyextra->tempComp);
1073 DString nn=yyextra->currentMemberDef->name();
1074 const MemberDef* mdeff=VhdlDocGen::findMember(yyextra->tempComp,nn);
1075 if (mdeff)
1076 {
1077 yyextra->currentMemberDef=mdeff;
1078 }
1079 }
1080
1081 DString lineAnchor;
1082 lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
1083 if (yyextra->currentMemberDef)
1084 {
1085 codeFolding(yyscanner,yyextra->currentMemberDef);
1086 yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
1087 yyextra->currentMemberDef->getOutputFileBase(),
1088 yyextra->currentMemberDef->anchor(),yyextra->yyLineNr,
1089 !yyextra->includeCodeFragment);
1090 setCurrentDoc(yyscanner,lineAnchor);
1091 }
1092 else if (d->isLinkableInProject())
1093 {
1094 codeFolding(yyscanner,yyextra->currentMemberDef);
1095 yyextra->code->writeLineNumber(d->getReference(),
1096 d->getOutputFileBase(),
1097 DString(),yyextra->yyLineNr,
1098 !yyextra->includeCodeFragment);
1099 setCurrentDoc(yyscanner,lineAnchor);
1100 }
1101 else
1102 {
1103 codeFolding(yyscanner,nullptr);
1104 }
1105 }
1106 else
1107 {
1108 codeFolding(yyscanner,nullptr);
1109 yyextra->code->writeLineNumber(DString(),DString(),DString(),yyextra->yyLineNr,
1110 !yyextra->includeCodeFragment);
1111 }
1112 }
1113 yyextra->code->startCodeLine(yyextra->yyLineNr);
1114 yyextra->insideCodeLine=true;
1115 if (yyextra->currentFontClass)
1116 {
1117 yyextra->code->startFontClass(yyextra->currentFontClass);
1118 }
1119}
1120
1121static void endCodeLine(yyscan_t yyscanner)
1122{
1123 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1124 endFontClass(yyscanner);
1125 yyextra->code->endCodeLine();
1126 yyextra->insideCodeLine=false;
1127}
1128
1129static void nextCodeLine(yyscan_t yyscanner)
1130{
1131 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1132 if (yyextra->insideCodeLine)
1133 {
1134 endCodeLine(yyscanner); // </div>
1135 }
1136 const char *fc = yyextra->currentFontClass;
1137 if (yyextra->yyLineNr<yyextra->inputLines)
1138 {
1139 yyextra->currentFontClass = fc;
1140 startCodeLine(yyscanner); //<div>
1141 }
1142}
1143
1144/*! writes a word to the output.
1145 * If curr_class is defined, the word belongs to a class
1146 * and will be linked.
1147 */
1148
1149static void writeWord(yyscan_t yyscanner,const DString &word,const DString &curr_class,bool classLink)
1150{
1151 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1152 bool found=false;
1153 DString temp;
1154 DString tclass(curr_class);
1155 DString ttt(word);
1156 if (ttt.empty()) return;
1157 for (unsigned int j=0;j<ttt.length();j++)
1158 {
1159 char c=ttt.at(j);
1160 if (c==' '|| c==',' || c==';' || c==':' || c=='(' || c==')' || c=='\r' || c=='\t' || c=='.')
1161 {
1162 if (found)
1163 {
1164 if (!writeColoredWord(yyscanner,temp)) // is it a keyword ?
1165 {
1166 //if (VhdlDocGen::findKeyWord(temp))
1167 // writeFont(yyscanner,"vhdlkeyword",temp);
1168 //printf("writeWord: %s\n",qPrint(temp));
1169 if (!tclass.empty())
1170 {
1171 if (!classLink)
1172 {
1173 generateMemLink(yyscanner,*yyextra->code,tclass,temp);
1174 }
1175 else
1176 {
1177 generateClassOrGlobalLink(yyscanner,*yyextra->code,temp,false,curr_class);
1178 }
1179 }
1180 else
1181 {
1182 if (!checkVhdlString(yyscanner,temp))
1183 {
1184 yyextra->code->codify(temp);
1185 }
1186 }
1187 }
1188 temp.clear();
1189 found=false;
1190 }
1191
1192 char cc[2];
1193 cc[0]=c;
1194 cc[1]=0;
1195 yyextra->code->codify(cc);
1196 }
1197 else
1198 {
1199 found=true;
1200 temp+=c;
1201 }
1202 } // for
1203
1204 if (!temp.empty())
1205 {
1206 if (!writeColoredWord(yyscanner,temp))
1207 {
1208 if (!tclass.empty())
1209 {
1210 if (!classLink)
1211 {
1212 generateMemLink(yyscanner,*yyextra->code,tclass,temp); // generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,left);
1213 }
1214 else
1215 {
1216 generateClassOrGlobalLink(yyscanner,*yyextra->code,temp,false,curr_class);
1217 }
1218 }
1219 else
1220 {
1221 DString qc(temp);
1222 if (VhdlDocGen::isNumber(qc.str()))
1223 {
1224 startFontClass(yyscanner,"vhdllogic");
1225 yyextra->code->codify(temp);
1226 endFontClass(yyscanner);
1227 }
1228 else
1229 {
1230 yyextra->code->codify(temp);
1231 }
1232 }
1233 }
1234 }
1235}// writeWord
1236
1237
1238/*! write a code fragment 'text' that may span multiple lines, inserting
1239 * line numbers for each line.
1240 */
1241static void codifyLines(yyscan_t yyscanner,const DString &text,const DString &cl,bool classlink,bool comment)
1242{
1243 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1244 if (text.empty()) return;
1245 //printf("codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,text);
1246 const char *p=text.data(),*sp=p;
1247 char c;
1248 bool done=false;
1249 while (!done)
1250 {
1251 sp=p;
1252 while ((c=*p++) && c!='\n') {}
1253 if (c=='\n')
1254 {
1255 yyextra->yyLineNr++;
1256 DString line = sp;
1257 line = line.left((int)(p-sp)-1);
1258 if (comment)
1259 {
1260 writeFont(yyscanner,"comment",line);
1261 }
1262 else
1263 {
1264 writeWord(yyscanner,line,cl,classlink);
1265 }
1266 nextCodeLine(yyscanner);
1267 }
1268 else
1269 {
1270 if (comment)
1271 {
1272 writeFont(yyscanner,"comment",sp);
1273 }
1274 else
1275 {
1276 writeWord(yyscanner,sp,cl,classlink);
1277 }
1278 done=true;
1279 }
1280 }
1281}
1282
1283/*! writes a link to a fragment \a text that may span multiple lines, inserting
1284 * line numbers for each line. If \a text contains newlines, the link will be
1285 * split into multiple links with the same destination, one for each line.
1286 */
1288 const Definition *d,
1289 const DString &text)
1290{
1291 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1292 if (text.empty()) return;
1293 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
1294 yyextra->tooltipManager.addTooltip(d);
1295 DString ref = d->getReference();
1296 DString file = d->getOutputFileBase();
1297 DString anchor = d->anchor();
1298 DString tooltip;
1299 if (!sourceTooltips) // fall back to simple "title" tooltips
1300 {
1301 tooltip = d->briefDescriptionAsTooltip();
1302 }
1303 bool done=false;
1304 const char *p=text.data();
1305 while (!done)
1306 {
1307 const char *sp=p;
1308 char c;
1309 while ((c=*p++) && c!='\n') {}
1310 if (c=='\n')
1311 {
1312 yyextra->yyLineNr++;
1313 // printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
1314 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,DString(sp,p-sp-1),tooltip);
1315 nextCodeLine(yyscanner);
1316 }
1317 else
1318 {
1319 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,sp,tooltip);
1320 done=true;
1321 }
1322 }
1323}
1324
1325/*! writes a link to a function or procedure
1326 */
1327static void generateFuncLink(yyscan_t yyscanner,OutputCodeList &ol,const MemberDef* mdef)
1328{
1329 //printf("generateFuncLink(FuncName=%s)\n",qPrint(mdef->name()));
1330 DString memberName=mdef->name();
1331
1332 if (mdef->isLinkable()) // is it a linkable class
1333 {
1334 writeMultiLineCodeLink(yyscanner,ol,mdef,mdef->name());
1335 addToSearchIndex(yyscanner,memberName);
1336 return;
1337 }
1338 codifyLines(yyscanner,memberName);
1339 addToSearchIndex(yyscanner,memberName);
1340} // generateFuncLink
1341
1342
1343static void generateMemLink(yyscan_t yyscanner,OutputCodeList &ol,DString &clName,DString& memberName)
1344{
1345 if (memberName.empty()) return;
1346 if (clName.empty())
1347 {
1348 codifyLines(yyscanner,memberName);
1349
1350 return;
1351 }
1352
1353 DString className=clName;
1354
1355 //MemberDef *comp=nullptr;
1356 //bool isLocal=false;
1357
1358 const MemberDef *md=VhdlDocGen::findMember(className,memberName);
1359 ClassDef *po=VhdlDocGen::getClass(className);
1360
1361 if (md==nullptr && po && (VhdlDocGen::VhdlClasses)po->protection()==VhdlDocGen::PACKBODYCLASS)
1362 {
1363 DString temp=className;//.stripPrefix("_");
1364 temp.stripPrefix("_");
1365 md=VhdlDocGen::findMember(temp,memberName);
1366 }
1367
1368 if (md && md->isLinkable()) // is it a linkable class
1369 {
1370 writeMultiLineCodeLink(yyscanner,ol,md,memberName);
1371 addToSearchIndex(yyscanner,memberName);
1372 return;
1373 }
1374 // nothing found, just write out the word
1375 codifyLines(yyscanner,memberName);
1376 addToSearchIndex(yyscanner,memberName);
1377}// generateMemLink
1378
1379
1381 const DString &clName, bool /*typeOnly*/, const DString &curr_class)
1382{
1383 DString className=clName;
1384
1385 if (className.empty()) return;
1386
1387 ClassDef *cd=nullptr;
1388 //MemberDef *md=nullptr;
1389 //bool isLocal=false;
1390 className.stripPrefix("_");
1391 cd = getClass(className);
1392 if (!cd && !curr_class.empty())
1393 {
1394 DString cls = curr_class;
1395 DString suffix = "::";
1396 suffix+=clName;
1397 if (cls.right(suffix.length())==suffix)
1398 {
1399 cd = getClass(curr_class);
1400 }
1401 }
1402
1403 while (cd)
1404 {
1405 //className.stripPrefix("_");
1406 DString temp(clName);
1407 temp.stripPrefix("_");
1408 if (cd && cd->isLinkable()) // is it a linkable class
1409 {
1410 //if ((VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::ARCHITECTURECLASS)
1411 //{
1412 // temp=VhdlDocGen::getClassName(cd);
1413 //}
1414 writeMultiLineCodeLink(yyscanner,ol,cd,temp);
1415 addToSearchIndex(yyscanner,className);
1416 return;
1417 }
1418 Definition *d = cd->getOuterScope();
1420 {
1421 cd = toClassDef(d);
1422 }
1423 else
1424 {
1425 cd = nullptr;
1426 }
1427 }
1428
1429 // nothing found, just write out the word
1430 codifyLines(yyscanner,clName);
1431 addToSearchIndex(yyscanner,clName);
1432}// generateClasss or global link
1433
1434
1435/*! counts the number of lines in the input */
1436static int countLines(yyscan_t yyscanner)
1437{
1438 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1439 const char *p=yyextra->inputString;
1440 char c;
1441 int count=1;
1442 while ((c=*p))
1443 {
1444 p++ ;
1445 if (c=='\n') count++;
1446 }
1447 if (p>yyextra->inputString && *(p-1)!='\n')
1448 { // last line does not end with a \n, so we add an extra
1449 // line and explicitly terminate the line after parsing.
1450 count++;
1451 }
1452 return count;
1453}
1454
1455static void endFontClass(yyscan_t yyscanner,bool specialComment)
1456{
1457 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1458 //printf("endFontClass: specialComment=%d insideSpecialComment=%d\n",
1459 // specialComment,yyextra->insideSpecialComment);
1460 if (yyextra->currentFontClass)
1461 {
1462 yyextra->code->endFontClass();
1463 yyextra->currentFontClass=0;
1464 }
1465 if (specialComment && yyextra->insideSpecialComment)
1466 {
1467 yyextra->code->endSpecialComment();
1468 yyextra->insideSpecialComment=false;
1469 }
1470}
1471
1472static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment)
1473{
1474 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1475 if (s==nullptr) return;
1476 //printf("startFontClass(%s): specialComment=%d insideSpecialComment=%d\n",s,
1477 // specialComment,yyextra->insideSpecialComment);
1478 if (specialComment)
1479 {
1480 yyextra->code->startSpecialComment();
1481 yyextra->insideSpecialComment = true;
1482 }
1483 if (dstrcmp(yyextra->currentFontClass,s)!=0)
1484 {
1485 endFontClass(yyscanner);
1486 yyextra->code->startFontClass(s);
1487 yyextra->currentFontClass=s;
1488 }
1489}
1490
1491static void writeFont(yyscan_t yyscanner,const char *s,const DString &text,bool specialComment)
1492{
1493 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1494 if (s==nullptr || text.empty()) return;
1495 //printf("writeFont(yyscanner,%d,\"%s\")\n",yyextra->yyLineNr,text);
1496 startFontClass(yyscanner,s,specialComment);
1497 yyextra->code->codify(text);
1498 endFontClass(yyscanner,specialComment);
1499}
1500
1501//----------------------------------------------------------------------------
1502
1503static void appStringLower(DString& qcs,const char* text)
1504{
1505 qcs.clear();
1506 qcs.append(text);
1507 qcs=qcs.stripWhiteSpace();
1508}
1509
1510/* writes and links a port map statement */
1511static void codifyMapLines(yyscan_t yyscanner,const DString &text)
1512{
1513 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1514 if (text.empty()) return;
1515 DString temp;
1516 //bool dot=false;
1517 int wordCounter=0;
1518 DString ctemp;
1519 //printf("codifyMapLines(%d,\"%s\")\n",yyextra->yyLineNr,qPrint(text));
1520 const char *p=text.data();
1521 char c;
1522 bool done=false;
1523 while (!done)
1524 {
1525 //sp=p;
1526 while ((c=*p++) && c!='\n' && c!=':' && c != ' ' && c != '(' && c!='\0' && c!='\t')
1527 {
1528 if (c!=0x9)
1529 temp+=c;
1530 }
1531 if (c=='\0') return;
1532 if (!temp.empty()) wordCounter++;
1533
1534 if (!temp.empty())
1535 {
1536 // different kinds of component instantiations
1537 // xxx:yyy (generic/port) map(
1538 // xxx:(entity/component/configuration) yyy (generic/port) map(
1539 // xxx: entity yyy(zzz) (generic/port) map(
1540 if (wordCounter==2 || wordCounter==3)
1541 {
1542 DString q=temp.lower(); // consider (upper/lower) cases
1543 if (q=="entity" || q=="component" || q=="configuration" || q=="port" || q=="generic")
1544 {
1545 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,temp);
1546 }
1547 else
1548 {
1549 yyextra->PortMapComp=temp;
1550 generateClassOrGlobalLink(yyscanner,*yyextra->code,temp);
1551 }
1552 }
1553 else
1554 {
1555 generateMemLink(yyscanner,*yyextra->code,yyextra->currClass,temp);
1556 }
1557 }
1558 ctemp.fill(c,1);
1559 codifyLines(yyscanner,ctemp);
1560 ctemp.clear();
1561 temp.clear();
1562 }//while
1563}//codifyMapLines
1564
1565/*
1566* writes a function|procedure prototype and links the function|procedure name
1567*/
1568
1569static void writeFuncProto(yyscan_t yyscanner)
1570{
1571 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1572 DString name,ret;
1573 VhdlDocGen::parseFuncProto(yyextra->funcProto,name,ret,false);
1574
1575 if (name.empty())
1576 {
1577 codifyLines(yyscanner,yyextra->funcProto,yyextra->currClass);
1578 return;
1579 }
1580 StringVector qlist=split(yyextra->funcProto.str(),name.str());
1581 DString temp(qlist[0]);
1582 codifyLines(yyscanner,temp,yyextra->currClass);
1583 yyextra->funcProto.stripPrefix(temp);
1584 temp.clear();
1585 temp=yyextra->currClass;
1586 if (yyextra->isPackageBody)
1587 {
1588 temp.stripPrefix("_");// _{package body name}
1589 }
1590 const MemberDef *mdef=VhdlDocGen::findFunction(name,temp);
1591
1592 if (mdef)
1593 {
1594 generateFuncLink(yyscanner,*yyextra->code,mdef);
1595 yyextra->funcProto.stripPrefix(name);
1596 codifyLines(yyscanner,yyextra->funcProto,yyextra->currClass);
1597 }
1598 else
1599 {
1600 codifyLines(yyscanner,yyextra->funcProto,yyextra->currClass);
1601 }
1602}// writeFuncProto
1603
1604/* writes a process prototype to the output */
1605
1606static void writeProcessProto(yyscan_t yyscanner)
1607{
1608 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1609 codifyLines(yyscanner,yyextra->funcProto,yyextra->currClass);
1610 yyextra->vhdlKeyDict.clear();
1611}// writeProcessProto
1612
1613/* writes a keyword */
1614
1615static bool writeColoredWord(yyscan_t yyscanner,DString& word )
1616{
1617 DString qcs=word.lower();
1618 const char *ss=VhdlDocGen::findKeyWord(qcs);
1619 if (ss)
1620 {
1621 writeFont(yyscanner,ss,word);
1622 return true;
1623 }
1624 return false;
1625}
1626
1627//-----------------------------------------------------------------------------------
1628
1634
1636{
1637 vhdlcodeYYlex_init_extra(&p->state,&p->yyscanner);
1638#ifdef FLEX_DEBUG
1639 vhdlcodeYYset_debug(Debug::isFlagSet(Debug::Lex_vhdlcode)?1:0,p->yyscanner);
1640#endif
1642}
1643
1645{
1646 vhdlcodeYYlex_destroy(p->yyscanner);
1647}
1648
1650{
1651 p->state.vhdlKeyDict.clear();
1652}
1653
1655 const DString &/* className */,
1656 const DString &s,
1657 SrcLangExt,
1658 bool stripCodeComments,
1659 const CodeParserOptions &options
1660 )
1661{
1662 yyscan_t yyscanner = p->yyscanner;
1663 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1664 //printf("***parseCode() exBlock=%d exName=%s fd=%p\n",exBlock,exName,fd);
1665 if (s.empty()) return;
1666 DebugLex debugLex(Debug::Lex_vhdlcode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()): nullptr);
1667 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
1668 if (options.memberDef())
1669 {
1670 const ClassDef *dd=options.memberDef()->getClassDef();
1671 if (dd) yyextra->currClass = dd->name();
1672 }
1673 od.stripCodeComments(stripCodeComments);
1675 yyextra->code = &od;
1676 yyextra->inputString = s.data();
1677 yyextra->inputPosition = 0;
1678 yyextra->currentFontClass = nullptr;
1679 yyextra->insideCodeLine = false;
1680 yyextra->searchCtx = options.searchCtx();
1681 yyextra->insideSpecialComment = false;
1682 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
1683 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
1684 yyextra->foldStack.clear();
1685
1686 // yyextra->theCallContext.clear();
1687 yyextra->exampleBlock = options.isExample();
1688 yyextra->exampleName = options.exampleName();
1689 yyextra->sourceFileDef = options.fileDef();
1690 yyextra->lineNumbers = options.fileDef() && options.showLineNumbers();
1691 if (options.isExample() && options.fileDef()==nullptr)
1692 {
1693 // create a dummy filedef for the example
1694 yyextra->exampleFileDef = createFileDef("",options.exampleName());
1695 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1696 }
1697 if (yyextra->sourceFileDef)
1698 {
1699 setCurrentDoc(yyscanner,"l00001");
1700 }
1701 yyextra->currentDefinition = nullptr;
1702 yyextra->currentMemberDef = nullptr;
1703 yyextra->vhdlMember = nullptr;
1704 if (!yyextra->exampleName.empty())
1705 {
1706 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example");
1707 }
1708 yyextra->includeCodeFragment = options.inlineFragment();
1709 startCodeLine(yyscanner);
1710 if (!yyextra->lexInit)
1711 {
1713 yyextra->lexInit=true;
1714 }
1715 vhdlcodeYYrestart( nullptr, yyscanner );
1716 BEGIN( Bases );
1717 vhdlcodeYYlex(yyscanner);
1718 if (yyextra->insideCodeLine)
1719 {
1720 endCodeLine(yyscanner);
1721 }
1722 if (Config_getBool(HTML_CODE_FOLDING))
1723 {
1724 while (!yyextra->foldStack.empty())
1725 {
1726 yyextra->code->endFold();
1727 yyextra->foldStack.pop_back();
1728 }
1729 }
1730 if (yyextra->exampleFileDef)
1731 {
1732 // delete the temporary file definition used for this example
1733 yyextra->exampleFileDef.reset();
1734 yyextra->sourceFileDef = nullptr;
1735 }
1736
1737 // write the tooltips
1738 yyextra->tooltipManager.writeTooltips(od);
1739}
1740
1741#include "vhdlcode.l.h"
virtual Protection protection() const =0
Return the protection level (Public,Protected,Private) in which this compound was found.
void clear()
Definition dstring.h:214
DString fill(char c, size_t len)
Fills a string with a predefined character.
Definition dstring.h:278
DString lower() const
Definition dstring.h:326
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString right(size_t len) const
Definition dstring.h:311
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
bool stripPrefix(const DString &prefix)
Definition dstring.h:290
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
@ Lex_vhdlcode
Definition debug.h:71
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
virtual int getEndBodyLine() const =0
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual bool isLinkableInProject() const =0
virtual DString anchor() const =0
virtual int getStartDefLine() const =0
virtual DString getReference() const =0
virtual CodeSymbolType codeSymbolType() const =0
virtual Definition * getOuterScope() const =0
virtual DString getOutputFileBase() const =0
static SearchIndexIntf searchIndex
Definition doxygen.h:117
virtual DString fileName() const =0
virtual const ClassDef * getClassDef() const =0
void writeCodeLink(CodeSymbolType type, const DString &ref, const DString &file, const DString &anchor, const DString &name, const DString &tooltip)
Definition outputlist.h:247
void stripCodeComments(bool b)
Definition outputlist.h:235
void addWord(const DString &word, bool hiPriority)
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
void resetCodeParserState() override
Resets the state of the code parser.
Definition vhdlcode.l:1649
void parseCode(OutputCodeList &codeOutIntf, const DString &scopeName, const DString &input, SrcLangExt lang, bool stripCodeComments, const CodeParserOptions &options) override
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
Definition vhdlcode.l:1654
~VHDLCodeParser() override
Definition vhdlcode.l:1644
std::unique_ptr< Private > p
Definition vhdlcode.h:39
static const char * findKeyWord(const DString &word)
static const MemberDef * findFunction(const DString &name, const DString &package)
static void parseFuncProto(const DString &text, DString &name, DString &ret, bool doc=false)
static const MemberDef * findMember(const DString &className, const DString &memName)
static void init()
static ClassDef * getClass(const DString &name)
ClassDef * getClass(const DString &n)
ClassDef * toClassDef(Definition *d)
#define Config_getBool(name)
Definition config.h:33
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50
const char * qPrint(const char *s)
Definition dstring.h:783
std::unique_ptr< FileDef > createFileDef(const DString &p, const DString &n, const DString &ref, const DString &dn)
Definition filedef.cpp:270
Definition dstring.h:913
Options to configure the code parser.
Definition parserintf.h:77
bool isExample() const
Definition parserintf.h:80
const Definition * searchCtx() const
Definition parserintf.h:88
DString exampleName() const
Definition parserintf.h:81
const FileDef * fileDef() const
Definition parserintf.h:82
int endLine() const
Definition parserintf.h:84
const MemberDef * memberDef() const
Definition parserintf.h:86
bool showLineNumbers() const
Definition parserintf.h:87
bool inlineFragment() const
Definition parserintf.h:85
int startLine() const
Definition parserintf.h:83
vhdlcodeYY_state state
Definition vhdlcode.l:1632
SrcLangExt
Definition types.h:207
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2995
static void codeFolding(yyscan_t yyscanner, const Definition *d)
Definition vhdlcode.l:1015