Doxygen
Loading...
Searching...
No Matches
FlowChart Class Reference

#include <src/vhdldocgen.h>

Collaboration diagram for FlowChart:

Public Types

enum  nodeTypes {
  IF_NO = 1<<1 , ELSIF_NO = 1<<2 , ELSE_NO = 1<<3 , CASE_NO = 1<<4 ,
  WHEN_NO = 1<<5 , EXIT_NO = 1<<6 , END_NO = 1<<7 , TEXT_NO = 1<<8 ,
  START_NO = 1<<9 , ENDIF_NO = 1<<10 , FOR_NO = 1<<11 , WHILE_NO = 1<<12 ,
  END_LOOP = 1<<13 , END_CASE = 1<<14 , VARIABLE_NO = 1<<15 , RETURN_NO = 1<<16 ,
  LOOP_NO = 1<<17 , NEXT_NO = 1<<18 , EMPTY_NO = 1<<19 , COMMENT_NO = 1<<20 ,
  BEGIN_NO = 1<<21
}

Public Member Functions

 FlowChart (int typ, const DString &t, const DString &ex, const DString &label=DString())

Static Public Member Functions

static void createSVG ()
static void startDot (TextStream &t)
static void endDot (TextStream &t)
static void codify (TextStream &t, const DString &str)
static void writeShape (TextStream &t, const FlowChart &fl)
static void writeEdge (TextStream &t, int fl_from, int fl_to, int i, bool bFrom=false, bool bTo=false)
static void writeEdge (TextStream &t, const FlowChart &fl_from, const FlowChart &fl_to, int i)
static void writeFlowLinks (TextStream &t)
static DString getNodeName (int n)
static void colTextNodes ()
static size_t getNextIfLink (const FlowChart &, size_t)
static size_t getNextNode (size_t index, int stamp)
static size_t findNode (size_t index, int stamp, int type)
static size_t findNode (size_t index, int type)
static size_t findNextLoop (size_t j, int stamp)
static size_t findPrevLoop (size_t j, int stamp, bool endif=false)
static size_t findLabel (size_t j, const DString &)
static void delFlowList ()
static const char * getNodeType (int c)
static void addFlowChart (int type, const DString &text, const DString &exp, const DString &label=DString())
static void moveToPrevLevel ()
static int getTimeStamp ()
static void writeFlowChart ()
static void alignFuncProc (DString &q, const ArgumentList &al, bool isFunc)
static DString convertNameToFileName ()
static void printNode (const FlowChart &n)
static void printFlowTree ()
static void buildCommentNodes (TextStream &t)
static void alignCommentNode (TextStream &t, DString com)
static void printUmlTree ()
static DString printPlantUmlNode (const FlowChart &flo, bool, bool)

Private Attributes

int id = 0
int stamp = 0
int type = 0
int line = 0
DString label
DString text
DString exp

Detailed Description

Definition at line 238 of file vhdldocgen.h.

Member Enumeration Documentation

◆ nodeTypes

Enumerator
IF_NO 
ELSIF_NO 
ELSE_NO 
CASE_NO 
WHEN_NO 
EXIT_NO 
END_NO 
TEXT_NO 
START_NO 
ENDIF_NO 
FOR_NO 
WHILE_NO 
END_LOOP 
END_CASE 
VARIABLE_NO 
RETURN_NO 
LOOP_NO 
NEXT_NO 
EMPTY_NO 
COMMENT_NO 
BEGIN_NO 

Definition at line 241 of file vhdldocgen.h.

241 {
242 IF_NO = 1<<1,
243 ELSIF_NO = 1<<2,
244 ELSE_NO = 1<<3,
245 CASE_NO = 1<<4,
246 WHEN_NO = 1<<5,
247 EXIT_NO = 1<<6,
248 END_NO = 1<<7,
249 TEXT_NO = 1<<8,
250 START_NO = 1<<9,
251 ENDIF_NO = 1<<10,
252 FOR_NO = 1<<11,
253 WHILE_NO = 1<<12,
254 END_LOOP = 1<<13,
255 END_CASE = 1<<14,
256 VARIABLE_NO = 1<<15,
257 RETURN_NO = 1<<16,
258 LOOP_NO = 1<<17,
259 NEXT_NO = 1<<18,
260 EMPTY_NO = 1<<19,
261 COMMENT_NO = 1<<20,
262 BEGIN_NO = 1<<21
263 };

Constructor & Destructor Documentation

◆ FlowChart()

FlowChart::FlowChart ( int typ,
const DString & t,
const DString & ex,
const DString & label = DString() )

Definition at line 2858 of file vhdldocgen.cpp.

2859{
2861
2862 if (typ & STARTL)
2863 {
2864 ifcounter++;
2865 }
2866
2867 text=t;
2868 exp=ex;
2869 type=typ;
2870 label=lab;
2871
2872 if (typ & (ELSE_NO | ELSIF_NO))
2873 {
2874 stamp--;
2875 }
2876
2877 if (typ & (START_NO | END_NO | VARIABLE_NO))
2878 {
2879 stamp=0;
2880 }
2881
2882 id=nodeCounter++;
2883}
DString text
Definition vhdldocgen.h:312
DString exp
Definition vhdldocgen.h:313
DString label
Definition vhdldocgen.h:311
static int nodeCounter
static int ifcounter
#define STARTL

References ELSE_NO, ELSIF_NO, END_NO, exp, ifcounter, label, nodeCounter, stamp, START_NO, STARTL, text, type, and VARIABLE_NO.

Referenced by addFlowChart(), buildCommentNodes(), colTextNodes(), findLabel(), findNextLoop(), findNode(), findPrevLoop(), getNextIfLink(), getNextNode(), getTimeStamp(), printNode(), printPlantUmlNode(), printUmlTree(), writeEdge(), writeFlowLinks(), and writeShape().

Member Function Documentation

◆ addFlowChart()

void FlowChart::addFlowChart ( int type,
const DString & text,
const DString & exp,
const DString & label = DString() )
static

Definition at line 2885 of file vhdldocgen.cpp.

2886{
2887 if (!VhdlDocGen::getFlowMember()) return;
2888
2889 DString typeString(text);
2890 DString expression(exp);
2891
2892
2893 if (!text.empty())
2894 {
2895 typeString=substitute(typeString,";","\n");
2896 }
2897
2898 if (!exp.empty())
2899 {
2900 expression=substitute(expression,"\"","\\\"");
2901 }
2902
2903 if (type & VARIABLE_NO)
2904 {
2905 // Ignore the empty section of the VHDL variable definition.
2906 // This is section between `process` and `begin` keywords, where any source text is missing, probably a bug in the VHDL source parser.
2907 if(text.empty()) return;
2908
2909 flowList.insert(flowList.begin(),FlowChart(type,typeString,expression,label));
2910 flowList.front().line=1; // TODO: use getLine(); of the parser
2911 }
2912 else if (type & START_NO)
2913 {
2914 flowList.insert(flowList.begin(),FlowChart(type,typeString,expression,label));
2915 flowList.front().line=1; // TODO: use getLine(); of the parser
2916 }
2917 else
2918 {
2919 flowList.emplace_back(type,typeString,expression,label);
2920 flowList.back().line=1; // TODO: use getLine(); of the parser
2921 }
2922}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
FlowChart(int typ, const DString &t, const DString &ex, const DString &label=DString())
static const MemberDef * getFlowMember()
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:476
std::vector< FlowChart > flowList

References DString::empty(), exp, FlowChart(), flowList, VhdlDocGen::getFlowMember(), label, START_NO, substitute(), text, type, and VARIABLE_NO.

Referenced by VHDLOutlineParser::createFlow(), findNode(), and VHDLOutlineParser::handleFlowComment().

◆ alignCommentNode()

void FlowChart::alignCommentNode ( TextStream & t,
DString com )
static

Definition at line 2715 of file vhdldocgen.cpp.

2716{
2717 size_t max=0;
2718 DString s;
2719 StringVector ql=split(com.str(),"\n");
2720 for (size_t j=0;j<ql.size();j++)
2721 {
2722 s=ql[j];
2723 if (max<s.length()) max=s.length();
2724 }
2725
2726 s=ql.back();
2727 int diff=static_cast<int>(max-s.length());
2728
2729 DString n;
2730 if (diff>0)
2731 {
2732 n.fill(' ',2*diff);
2733 n.append(".");
2734 s+=n;
2735 ql.pop_back();
2736 ql.push_back(s.str());
2737 }
2738
2739 for (size_t j=0;j<ql.size();j++)
2740 {
2741 s=ql[j];
2742 if (j<ql.size()-1)
2743 {
2744 s+="\n";
2745 }
2746 FlowChart::codify(t,s);
2747 }
2748}
DString & append(char c)
Definition dstring.h:478
DString fill(char c, int len=-1)
Fills a string with a predefined character.
Definition dstring.h:283
const std::string & str() const
Definition dstring.h:634
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:156
static void codify(TextStream &t, const DString &str)
std::vector< std::string > StringVector
Definition containers.h:33
StringVector split(const std::string &s, const std::string &delimiter)
split input string s by string delimiter delimiter.
Definition util.cpp:6662

References DString::append(), codify(), DString::fill(), DString::length(), split(), and DString::str().

Referenced by buildCommentNodes(), getTimeStamp(), and writeShape().

◆ alignFuncProc()

void FlowChart::alignFuncProc ( DString & q,
const ArgumentList & al,
bool isFunc )
static

Definition at line 3276 of file vhdldocgen.cpp.

3277{
3278 size_t index=al.size();
3279 if (index==0) return;
3280
3281 size_t len=q.length()+VhdlDocGen::getFlowMember()->name().length();
3282 DString prev,temp;
3283 prev.fill(' ',static_cast<int>(len)+1);
3284
3285 q+="\n";
3286 for (const Argument &arg : al)
3287 {
3288 DString attl=arg.defval+" ";
3289 attl+=arg.name+" ";
3290
3291 if (!isFunc)
3292 {
3293 attl+=arg.attrib+" ";
3294 }
3295 else
3296 {
3297 attl+=" in ";
3298 }
3299 attl+=arg.type;
3300 if (--index) attl+=",\n"; else attl+="\n";
3301
3302 attl.prepend(prev);
3303 temp+=attl;
3304 }
3305
3306 q+=temp;
3307}
size_t size() const
Definition arguments.h:100
DString & prepend(const char *s)
Definition dstring.h:504
virtual const DString & name() const =0

References DString::fill(), VhdlDocGen::getFlowMember(), DString::length(), Definition::name(), DString::prepend(), and ArgumentList::size().

Referenced by VHDLOutlineParser::createFlow(), and getTimeStamp().

◆ buildCommentNodes()

void FlowChart::buildCommentNodes ( TextStream & t)
static

Definition at line 2751 of file vhdldocgen.cpp.

2752{
2753 size_t size=flowList.size();
2754 bool begin=false;
2755
2756 if (size>0)
2757 {
2758 for (uint32_t j=0;j < size-1 ;j++)
2759 {
2760 FlowChart &fll = flowList[j];
2761 if (fll.type & COMMENT_NO)
2762 {
2763 FlowChart &to=flowList[j+1];
2764 if (to.type & COMMENT_NO)
2765 {
2766 to.label = fll.label+"\n"+to.label;
2767 flowList.erase(flowList.begin()+j);
2768 if (size>0) size--;
2769 if (j>0) j--;
2770 }
2771 }
2772 }// for
2773 }
2774
2775 for (size_t j=0;j <flowList.size() ;j++)
2776 {
2777 const FlowChart &fll=flowList[j];
2778
2779 if (fll.type & BEGIN_NO)
2780 {
2781 begin = true;
2782 continue;
2783 }
2784
2785 if (fll.type & COMMENT_NO)
2786 {
2787 const FlowChart *to = nullptr;
2788 if (!begin)
2789 {
2790 // comment between function/process .. begin is linked to start node
2791 to = &flowList[0];
2792 }
2793 else if (j>0 && flowList[j-1].line==fll.line)
2794 {
2795 to = &flowList[j-1];
2796 }
2797 else
2798 {
2799 to = &flowList[j+1];
2800 }
2801 t << getNodeName(fll.id);
2802 t << "[shape=none, label=<\n";
2803 t << "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\" >\n ";
2804 t << "<TR><TD BGCOLOR=\"";
2805 t << flowCol.comment;
2806 t << "\" > ";
2807
2809 t << " </TD></TR></TABLE>>];";
2810 writeEdge(t,fll.id,to->id,2);
2811 }
2812 }// for
2813
2814 // delete comment nodes;
2815 size=flowList.size();
2816 for (size_t j=0; j<size; j++)
2817 {
2818 FlowChart &fll=flowList[j];
2819 if (fll.type & (COMMENT_NO | BEGIN_NO))
2820 {
2821 size_t diff=FLOWLEN-(j+1);
2822
2823 if ((fll.type & COMMENT_NO) && diff > 1)
2824 {
2825 flowList[j+1].label = fll.label;
2826 }
2827
2828 flowList.erase(flowList.begin()+j);
2829
2830 if (size>0) size--;
2831 if (j>0) j--;
2832 }
2833 }// for;
2834}
DString & erase(size_t index=0, size_t count=npos)
Definition dstring.h:237
static void alignCommentNode(TextStream &t, DString com)
static void writeEdge(TextStream &t, int fl_from, int fl_to, int i, bool bFrom=false, bool bTo=false)
static DString getNodeName(int n)
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:170
#define FLOWLEN
static struct @262143045100337216022015277174266365223104043217 flowCol

References alignCommentNode(), begin(), BEGIN_NO, COMMENT_NO, FlowChart(), flowCol, FLOWLEN, flowList, getNodeName(), id, label, line, type, and writeEdge().

Referenced by getTimeStamp(), and writeFlowChart().

◆ codify()

void FlowChart::codify ( TextStream & t,
const DString & str )
static

Definition at line 2836 of file vhdldocgen.cpp.

2837{
2838 if (!str.empty())
2839 {
2840 const char *p=str.data();
2841 while (*p)
2842 {
2843 char c=*p++;
2844 switch(c)
2845 {
2846 case '<': t << "&lt;"; break;
2847 case '>': t << "&gt;"; break;
2848 case '&': t << "&amp;"; break;
2849 case '\'': t << "&#39;"; break;
2850 case '"': t << "&quot;"; break;
2851 case '\n': t <<"<BR ALIGN=\"LEFT\"/>"; break;
2852 default: t << c; break;
2853 }
2854 }
2855 }
2856}//codify
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:162

References DString::data(), and DString::empty().

Referenced by alignCommentNode().

◆ colTextNodes()

void FlowChart::colTextNodes ( )
static

Definition at line 2651 of file vhdldocgen.cpp.

2652{
2653 FlowChart *flno = nullptr;
2654 bool found=false;
2655 for (size_t j=0;j<flowList.size();j++)
2656 {
2657 FlowChart &flo = flowList[j];
2658 if (flo.type&TEXT_NO)
2659 {
2660 if (!found)
2661 {
2662 flno=&flo;
2663 }
2664 else
2665 {
2666 flno->text+=flo.text;
2667 flowList.erase(flowList.begin()+j);
2668 if (j>0) j=j-1;
2669 }
2670 found=true;
2671 }
2672 else
2673 {
2674 found=false;
2675 }
2676 }
2677
2678 // find if..endif without text
2679 // if..elseif without text
2680 if (!flowList.empty())
2681 {
2682 for (size_t j=0;j<flowList.size()-1;j++)
2683 {
2684 const FlowChart &flo = flowList[j];
2685 int kind = flo.type;
2686 if ( (kind & IFF) || (flo.type & ELSE_NO))
2687 {
2688 const FlowChart &ftemp = flowList[j+1];
2689 if (ftemp.type & EMPTY)
2690 {
2691 FlowChart fc(TEXT_NO,"empty ",DString());
2692 fc.stamp = flo.stamp;
2693 flowList.insert(flowList.begin()+j+1,fc);
2694 }
2695 }
2696 }
2697 }
2698
2699}// colTextNode
DString()=default
#define IFF
#define EMPTY

References DString::DString(), ELSE_NO, EMPTY, FlowChart(), flowList, IFF, stamp, text, TEXT_NO, and type.

Referenced by writeFlowChart().

◆ convertNameToFileName()

DString FlowChart::convertNameToFileName ( )
static

Definition at line 3013 of file vhdldocgen.cpp.

3014{
3015 return VhdlDocGen::getFlowMember()->name();
3016}

References VhdlDocGen::getFlowMember(), and Definition::name().

Referenced by createSVG(), getTimeStamp(), HtmlDocVisitor::operator()(), and printUmlTree().

◆ createSVG()

void FlowChart::createSVG ( )
static

Definition at line 3047 of file vhdldocgen.cpp.

3048{
3049 DString qcs("/");
3050 DString ov = Config_getString(HTML_OUTPUT);
3051
3053
3054 //const MemberDef *m=VhdlDocGen::getFlowMember();
3055 //if (m)
3056 // fprintf(stderr,"\n creating flowchart : %s %s in file %s \n",theTranslator->trVhdlType(m->getMemberSpecifiers(),true),qPrint(m->name()),qPrint(m->getFileDef()->name()));
3057
3058 DString dir=" -o \""+ov+qcs+"\"";
3059 ov+="/flow_design.dot";
3060
3061 DString vlargs="-Tsvg \""+ov+"\" "+dir ;
3062
3064 {
3065 err("could not create dot file\n");
3066 }
3067}
static DString verifiedDotPath
Definition doxygen.h:137
static DString convertNameToFileName()
#define Config_getString(name)
Definition config.h:32
#define err(fmt,...)
Definition message.h:127
int system(const DString &command, const DString &args, bool commandHasConsole=true)
Definition portable.cpp:105

References Config_getString, convertNameToFileName(), err, Portable::system(), and Doxygen::verifiedDotPath.

Referenced by writeFlowChart().

◆ delFlowList()

void FlowChart::delFlowList ( )
static

Definition at line 2708 of file vhdldocgen.cpp.

2709{
2710 ifcounter=0;
2711 nodeCounter=0;
2712 flowList.clear();
2713}

References flowList, ifcounter, and nodeCounter.

Referenced by findNode(), and writeFlowChart().

◆ endDot()

void FlowChart::endDot ( TextStream & t)
static

Definition at line 3077 of file vhdldocgen.cpp.

3078{
3079 t << " } \n";
3080}

Referenced by writeFlowChart().

◆ findLabel()

size_t FlowChart::findLabel ( size_t j,
const DString & label )
static

Definition at line 3349 of file vhdldocgen.cpp.

3350{
3351 for (size_t j=index;j>0;j--)
3352 {
3353 const FlowChart &flo = flowList[j];
3354 if ((flo.type & LOOP) && !flo.label.empty() && dstricmp(flo.label,label)==0)
3355 {
3356 return j;
3357 }
3358 }
3359 err("could not find label: '{}'\n",label);
3360 return 0;
3361}
int dstricmp(const char *s1, const char *s2)
Definition dstring.cpp:435
#define LOOP

References dstricmp(), DString::empty(), err, FlowChart(), flowList, label, LOOP, and type.

Referenced by findNode(), and writeFlowLinks().

◆ findNextLoop()

size_t FlowChart::findNextLoop ( size_t j,
int stamp )
static

Definition at line 3309 of file vhdldocgen.cpp.

3310{
3311 for (size_t j=index+1; j<flowList.size(); j++)
3312 {
3313 const FlowChart &flo = flowList[j];
3314 if (flo.stamp==stamp)
3315 {
3316 continue;
3317 }
3318 if (flo.type&END_LOOP)
3319 {
3320 return j;
3321 }
3322 }
3323 return flowList.size()-1;
3324}

References END_LOOP, FlowChart(), flowList, stamp, and type.

Referenced by findNode(), and writeFlowLinks().

◆ findNode() [1/2]

size_t FlowChart::findNode ( size_t index,
int stamp,
int type )
static

Definition at line 3363 of file vhdldocgen.cpp.

3364{
3365 for (size_t j=index+1; j<flowList.size(); j++)
3366 {
3367 const FlowChart &flo = flowList[j];
3368 if (flo.type==type && flo.stamp==stamp)
3369 {
3370 return j;
3371 }
3372 }
3373 return 0;
3374}// findNode

References FlowChart(), flowList, stamp, and type.

Referenced by getNextIfLink(), getNextNode(), and writeFlowLinks().

◆ findNode() [2/2]

size_t FlowChart::findNode ( size_t index,
int type )
static

◆ findPrevLoop()

size_t FlowChart::findPrevLoop ( size_t j,
int stamp,
bool endif = false )
static

Definition at line 3326 of file vhdldocgen.cpp.

3327{
3328 for (size_t j=index;j>0;j--)
3329 {
3330 const FlowChart &flo = flowList[j];
3331 if (flo.type & LOOP)
3332 {
3333 if (flo.stamp==stamp && endif)
3334 {
3335 return j;
3336 }
3337 else
3338 {
3339 if (flo.stamp<stamp)
3340 {
3341 return j;
3342 }
3343 }
3344 }
3345 }
3346 return flowList.size()-1;
3347}

References FlowChart(), flowList, LOOP, stamp, and type.

Referenced by findNode(), and writeFlowLinks().

◆ getNextIfLink()

size_t FlowChart::getNextIfLink ( const FlowChart & fl,
size_t index )
static

Definition at line 3417 of file vhdldocgen.cpp.

3418{
3419 int stamp=fl.stamp;
3420 size_t start = index+1;
3421 size_t endifNode = findNode(start,stamp,ENDIF_NO);
3422 size_t elseifNode = findNode(start,stamp,ELSIF_NO);
3423 size_t elseNode = findNode(start,stamp,ELSE_NO);
3424
3425 if (elseifNode>0 && elseifNode<endifNode)
3426 {
3427 return elseifNode;
3428 }
3429
3430 if (elseNode>0 && elseNode<endifNode)
3431 {
3432 return elseNode+1;
3433 }
3434
3435 stamp=flowList[endifNode].stamp;
3436 return getNextNode(endifNode,stamp);
3437}
static size_t getNextNode(size_t index, int stamp)
static size_t findNode(size_t index, int stamp, int type)

References ELSE_NO, ELSIF_NO, ENDIF_NO, findNode(), FlowChart(), flowList, getNextNode(), and stamp.

Referenced by writeFlowLinks().

◆ getNextNode()

size_t FlowChart::getNextNode ( size_t index,
int stamp )
static

Definition at line 3376 of file vhdldocgen.cpp.

3377{
3378 for (size_t j=index+1; j<flowList.size(); j++)
3379 {
3380 const FlowChart &flo = flowList[j];
3381 int kind = flo.type;
3382 int s = flo.stamp;
3383 if (s>stamp)
3384 {
3385 continue;
3386 }
3387 if (kind & ENDIF_NO)
3388 {
3389 if (s<stamp && stamp>0)
3390 {
3391 stamp--;
3392 continue;
3393 }
3394 }
3395 if (kind & (ELSE_NO | ELSIF_NO))
3396 {
3397 if (s<stamp && stamp>0)
3398 {
3399 stamp--;
3400 }
3401 j=findNode(j,stamp,ENDIF_NO);
3402 continue;
3403 }
3404 if (kind & WHEN_NO)
3405 {
3406 if (s<stamp && stamp>0)
3407 {
3408 stamp--;
3409 }
3410 return findNode(j,stamp-1,END_CASE);
3411 }
3412 return j;
3413 }
3414 return FLOWLEN;
3415}

References ELSE_NO, ELSIF_NO, END_CASE, ENDIF_NO, findNode(), FlowChart(), FLOWLEN, flowList, stamp, type, and WHEN_NO.

Referenced by getNextIfLink(), and writeFlowLinks().

◆ getNodeName()

DString FlowChart::getNodeName ( int n)
static

Definition at line 2701 of file vhdldocgen.cpp.

2702{
2703 DString node;
2704 node.setNum(n);
2705 return node.prepend("node");
2706}
DString & setNum(short n)
Definition dstring.h:541

References DString::prepend(), and DString::setNum().

Referenced by buildCommentNodes(), writeEdge(), writeEdge(), and writeShape().

◆ getNodeType()

const char * FlowChart::getNodeType ( int c)
static

Definition at line 3018 of file vhdldocgen.cpp.

3019{
3020 switch(c)
3021 {
3022 case IF_NO: return "if ";
3023 case ELSIF_NO: return "elsif ";
3024 case ELSE_NO: return "else ";
3025 case CASE_NO: return "case ";
3026 case WHEN_NO: return "when ";
3027 case EXIT_NO: return "exit ";
3028 case END_NO: return "end ";
3029 case TEXT_NO: return "text ";
3030 case START_NO: return "start ";
3031 case ENDIF_NO: return "endif ";
3032 case FOR_NO: return "for ";
3033 case WHILE_NO: return "while ";
3034 case END_LOOP: return "end_loop ";
3035 case END_CASE: return "end_case ";
3036 case VARIABLE_NO: return "variable_decl ";
3037 case RETURN_NO: return "return ";
3038 case LOOP_NO: return "infinite loop ";
3039 case NEXT_NO: return "next ";
3040 case COMMENT_NO: return "comment ";
3041 case EMPTY_NO: return "empty ";
3042 case BEGIN_NO: return "<begin> ";
3043 default: return "--failure--";
3044 }
3045}

References BEGIN_NO, CASE_NO, COMMENT_NO, ELSE_NO, ELSIF_NO, EMPTY_NO, END_CASE, END_LOOP, END_NO, ENDIF_NO, EXIT_NO, FOR_NO, IF_NO, LOOP_NO, NEXT_NO, RETURN_NO, START_NO, TEXT_NO, VARIABLE_NO, WHEN_NO, and WHILE_NO.

Referenced by findNode(), and printNode().

◆ getTimeStamp()

◆ moveToPrevLevel()

void FlowChart::moveToPrevLevel ( )
static

Definition at line 2924 of file vhdldocgen.cpp.

2925{
2926 if (!VhdlDocGen::getFlowMember()) return;
2927 ifcounter--;
2928}

References VhdlDocGen::getFlowMember(), and ifcounter.

Referenced by findNode().

◆ printFlowTree()

void FlowChart::printFlowTree ( )
static

Definition at line 2643 of file vhdldocgen.cpp.

2644{
2645 for (const auto &flowChart : flowList)
2646 {
2647 printNode(flowChart);
2648 }
2649}
static void printNode(const FlowChart &n)

References flowList, and printNode().

Referenced by getTimeStamp(), and writeFlowChart().

◆ printNode()

void FlowChart::printNode ( const FlowChart & n)
static

Definition at line 2583 of file vhdldocgen.cpp.

2584{
2585 DString ui="-";
2586 std::string q;
2587 std::string t;
2588
2589 ui.fill('-',255);
2590
2591 if (flo.type & STARTL)
2592 {
2593 if (flo.stamp>0)
2594 {
2595 q=ui.left(2*flo.stamp).str();
2596 }
2597 else
2598 {
2599 q=" ";
2600 }
2601 DString nn=flo.exp.stripWhiteSpace();
2602 printf("\nYES: %s%s[%d,%d]",qPrint(q),qPrint(nn),flo.stamp,flo.id);
2603 }
2604 else
2605 {
2606 if (flo.type & COMMENT_NO)
2607 {
2608 t=flo.label.str();
2609 }
2610 else
2611 {
2612 t=flo.text.str();
2613 }
2614 static const reg::Ex ep(R"(\s)");
2615 t = reg::replace(t,ep,std::string());
2616 if (t.empty())
2617 {
2618 t=" ";
2619 }
2620 if (flo.stamp>0)
2621 {
2622 q=ui.left(2*flo.stamp).str();
2623 }
2624 else
2625 {
2626 q=" ";
2627 }
2628 if (flo.type & EMPTNODE)
2629 {
2630 printf("\n NO: %s%s[%d,%d]",qPrint(q),FlowChart::getNodeType(flo.type),flo.stamp,flo.id);
2631 }
2632 else if (flo.type & COMMENT_NO)
2633 {
2634 printf("\n NO: %s%s[%d,%d]",qPrint(t),FlowChart::getNodeType(flo.type),flo.stamp,flo.id);
2635 }
2636 else
2637 {
2638 printf("\n NO: %s[%d,%d]",qPrint(t),flo.stamp,flo.id);
2639 }
2640 }
2641}
DString left(size_t len) const
Definition dstring.h:311
static const char * getNodeType(int c)
const char * qPrint(const char *s)
Definition dstring.h:769
std::string replace(std::string_view str, const Ex &re, std::string_view replacement)
Searching in a given input string for parts that match regular expression re and replaces those parts...
Definition regex.cpp:869
#define EMPTNODE

References COMMENT_NO, EMPTNODE, exp, DString::fill(), FlowChart(), getNodeType(), id, label, DString::left(), qPrint(), reg::replace(), stamp, STARTL, DString::str(), DString::stripWhiteSpace(), text, and type.

Referenced by getTimeStamp(), and printFlowTree().

◆ printPlantUmlNode()

DString FlowChart::printPlantUmlNode ( const FlowChart & flo,
bool ca,
bool endL )
static

Definition at line 2930 of file vhdldocgen.cpp.

2931{
2932 DString t;
2933 DString exp=flo.exp.stripWhiteSpace();
2934 DString text=flo.text.stripWhiteSpace();
2935 switch (flo.type)
2936 {
2937 case START_NO: t=":"+text+"|"; break;
2938 case IF_NO : t="\nif ("+exp+") then (yes)"; break;
2939 case ELSIF_NO: t="\nelseif ("+exp+") then (yes)"; break;
2940 case ELSE_NO: t="\nelse"; break;
2941 case CASE_NO: t="\n:"+exp+";"; break;
2942 case WHEN_NO: t="\n";
2943 if (!ca) t+="else";
2944 t+="if ("+exp+") then (yes)";
2945 break;
2946 case EXIT_NO: break;
2947 case END_NO: if (text.contains(" function")==0) t="\n:"+text+";";
2948 break;
2949 case TEXT_NO: t="\n:"+text+"]"; break;
2950 case ENDIF_NO: t="\nendif"; break;
2951 case FOR_NO: t="\nwhile ("+exp+") is (yes)"; break;
2952 case WHILE_NO: t="\nwhile ("+exp+") is (yes)"; break;
2953 case END_LOOP: t="\nendwhile"; break;
2954 case END_CASE: t="\nendif\n:end case;"; break;
2955 case VARIABLE_NO:t="\n:"+text+";"; break;
2956 case RETURN_NO: t="\n:"+text+";";
2957 if (!endL) t+="\nstop";
2958 break;
2959 case LOOP_NO: t="\nwhile (infinite loop)"; break;
2960 case NEXT_NO: break;
2961 case EMPTY_NO: break;
2962 case COMMENT_NO: t="\n note left \n "+flo.label+"\nend note \n"; break;
2963 case BEGIN_NO: t="\n:begin;"; break;
2964 default: assert(false); break;
2965 }
2966 return t;
2967}
int contains(char c, bool cs=true) const
Definition dstring.cpp:76
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:342

References BEGIN_NO, CASE_NO, COMMENT_NO, DString::contains(), ELSE_NO, ELSIF_NO, EMPTY_NO, END_CASE, END_LOOP, END_NO, ENDIF_NO, EXIT_NO, exp, FlowChart(), FOR_NO, IF_NO, label, LOOP_NO, NEXT_NO, RETURN_NO, START_NO, DString::stripWhiteSpace(), text, TEXT_NO, type, VARIABLE_NO, WHEN_NO, and WHILE_NO.

Referenced by getTimeStamp(), and printUmlTree().

◆ printUmlTree()

void FlowChart::printUmlTree ( )
static

Definition at line 2969 of file vhdldocgen.cpp.

2970{
2971 int caseCounter = 0;
2972 int whenCounter = 0;
2973
2974 DString qcs;
2975 size_t size=flowList.size();
2976 for (size_t j=0;j<size;j++)
2977 {
2978 bool endList = j==FLOWLEN;
2979 const FlowChart &flo = flowList[j];
2980 if (flo.type==CASE_NO)
2981 {
2982 caseCounter++;
2983 whenCounter=0;
2984 }
2985
2986 if (flo.type==END_CASE)
2987 {
2988 caseCounter--;
2989 }
2990
2991 bool ca = (caseCounter>0 && whenCounter==0);
2992
2993 qcs+=printPlantUmlNode(flo,ca,endList);
2994
2995 if (flo.type==WHEN_NO)
2996 {
2997 whenCounter++;
2998 }
2999
3000 }
3001 qcs+="\n";
3002
3003 DString htmlOutDir = Config_getString(HTML_OUTPUT);
3004
3005 DString n=convertNameToFileName();
3006 auto baseNameVector=PlantumlManager::instance().writePlantUMLSource(htmlOutDir,n,qcs,PlantumlManager::PUML_SVG,"uml",n,1,true);
3007 for (const auto &baseName: baseNameVector)
3008 {
3010 }
3011}
static DString printPlantUmlNode(const FlowChart &flo, bool, bool)
void generatePlantUMLOutput(const DString &baseName, const DString &outDir, OutputFormat format, bool toIndex)
Convert a PlantUML file to an image.
Definition plantuml.cpp:201
StringVector writePlantUMLSource(const DString &outDirArg, const DString &fileName, const DString &content, OutputFormat format, const DString &engine, const DString &srcFile, int srcLine, bool inlineCode)
Write a PlantUML compatible file.
Definition plantuml.cpp:31
static PlantumlManager & instance()
Definition plantuml.cpp:230

References CASE_NO, Config_getString, convertNameToFileName(), END_CASE, FlowChart(), FLOWLEN, flowList, PlantumlManager::generatePlantUMLOutput(), PlantumlManager::instance(), printPlantUmlNode(), PlantumlManager::PUML_SVG, type, WHEN_NO, and PlantumlManager::writePlantUMLSource().

Referenced by getTimeStamp(), and writeFlowChart().

◆ startDot()

void FlowChart::startDot ( TextStream & t)
static

Definition at line 3069 of file vhdldocgen.cpp.

3070{
3071 t << " digraph G { \n";
3072 t << "rankdir=TB \n";
3073 t << "concentrate=true\n";
3074 t << "stylesheet=\"doxygen.css\"\n";
3075}

Referenced by writeFlowChart().

◆ writeEdge() [1/2]

void FlowChart::writeEdge ( TextStream & t,
const FlowChart & fl_from,
const FlowChart & fl_to,
int i )
static

Definition at line 3229 of file vhdldocgen.cpp.

3230{
3231 bool b=fl_from.type & STARTL;
3232 bool c=fl_to.type & STARTL;
3233
3234#ifdef DEBUGFLOW
3235 DString s1(getNodeName(fl_from.id));
3236 DString s2(getNodeName(fl_to.id));
3237 auto it = g_keyMap.find(s1.str());
3238 auto it1 = g_keyMap.find(s2.str());
3239 // checks if the link is connected to a valid node
3240 assert(it!=g_keyMap.end());
3241 assert(it1!=g_keyMap.end());
3242#endif
3243
3244 writeEdge(t,fl_from.id,fl_to.id,i,b,c);
3245}

References FlowChart(), getNodeName(), id, STARTL, DString::str(), type, and writeEdge().

◆ writeEdge() [2/2]

void FlowChart::writeEdge ( TextStream & t,
int fl_from,
int fl_to,
int i,
bool bFrom = false,
bool bTo = false )
static

Definition at line 3247 of file vhdldocgen.cpp.

3248{
3249 DString label,col;
3250
3251 if (i==0)
3252 {
3253 col=flowCol.yesNodeLink;
3254 label="yes";
3255 }
3256 else if (i==1)
3257 {
3258 col=flowCol.noNodeLink;
3259 label="no";
3260 }
3261 else
3262 {
3263 col=flowCol.textNodeLink;
3264 label="";
3265 }
3266
3267 t << "edge [color=\""+col+"\",label=\""+label+"\"]\n";
3268 t << getNodeName(fl_from);
3269 if (bFrom) t << ":s";
3270 t << "->";
3271 t << getNodeName(fl_to);
3272 if (bTo) t << ":n";
3273 t << "\n";
3274}

References flowCol, getNodeName(), and label.

Referenced by buildCommentNodes(), writeEdge(), and writeFlowLinks().

◆ writeFlowChart()

void FlowChart::writeFlowChart ( )
static

Definition at line 3082 of file vhdldocgen.cpp.

3083{
3084 // assert(VhdlDocGen::flowMember);
3085
3086 DString ov = Config_getString(HTML_OUTPUT);
3087 DString fileName = ov+"/flow_design.dot";
3088 std::ofstream f = Portable::openOutputStream(fileName);
3089 if (!f.is_open())
3090 {
3091 err("Cannot open file {} for writing\n",fileName);
3092 return;
3093 }
3094 TextStream t(&f);
3095
3096 colTextNodes();
3097 // buildCommentNodes(t);
3098
3099#ifdef DEBUGFLOW
3100 printFlowTree();
3101#endif
3102
3103 if (!Config_getString(PLANTUML_JAR_PATH).empty())
3104 {
3105 printUmlTree();
3106 delFlowList();
3107 t.flush();
3108 f.close();
3109 return;
3110 }
3111
3112 startDot(t);
3114 for (const auto &fll : flowList)
3115 {
3116 writeShape(t,fll);
3117 }
3118 writeFlowLinks(t);
3119
3121 delFlowList();
3122 t.flush();
3123 f.close();
3125}// writeFlowChart
static void printFlowTree()
static void startDot(TextStream &t)
static void delFlowList()
static void colTextNodes()
static void createSVG()
static void writeShape(TextStream &t, const FlowChart &fl)
static void buildCommentNodes(TextStream &t)
static void printUmlTree()
static void writeFlowLinks(TextStream &t)
static void endDot(TextStream &t)
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:648

References buildCommentNodes(), colTextNodes(), Config_getString, createSVG(), delFlowList(), endDot(), err, flowList, TextStream::flush(), Portable::openOutputStream(), printFlowTree(), printUmlTree(), startDot(), writeFlowLinks(), and writeShape().

Referenced by VHDLOutlineParser::createFlow(), and getTimeStamp().

◆ writeFlowLinks()

void FlowChart::writeFlowLinks ( TextStream & t)
static

Definition at line 3439 of file vhdldocgen.cpp.

3440{
3441 size_t size=flowList.size();
3442 if (size<2) return;
3443
3444 // write start link
3445 writeEdge(t,flowList[0],flowList[1],2);
3446
3447 for (size_t j=0;j<size;j++)
3448 {
3449 const FlowChart &fll = flowList[j];
3450 int kind = fll.type;
3451 int stamp = fll.stamp;
3452 if (kind & EEND)
3453 {
3454 continue;
3455 }
3456
3457 if (kind & IFF)
3458 {
3459 writeEdge(t,fll,flowList[j+1],0);
3460 size_t z=getNextIfLink(fll,j);
3461 // assert(z>-1);
3462 writeEdge(t,fll,flowList[z],1);
3463 }
3464 else if (kind & LOOP_NO)
3465 {
3466 writeEdge(t,fll,flowList[j+1],2);
3467 continue;
3468 }
3469 else if (kind & (CASE_NO | FOR_NO | WHILE_NO))
3470 {
3471 if (kind & CASE_NO)
3472 {
3473 writeEdge(t,fll,flowList[j+1],2);
3474 continue;
3475 }
3476 else
3477 {
3478 writeEdge(t,fll,flowList[j+1],0);
3479 }
3480
3481 kind=END_LOOP;
3482 size_t z=findNode(j+1,fll.stamp,kind);
3483 z=getNextNode(z,flowList[z].stamp);
3484
3485 // assert(z>-1);
3486 writeEdge(t,fll,flowList[z],1);
3487 continue;
3488 }
3489 else if (kind & (TEXT_NO | VARIABLE_NO))
3490 {
3491 size_t z=getNextNode(j,stamp);
3492 writeEdge(t,fll,flowList[z],2);
3493 }
3494 else if (kind & WHEN_NO)
3495 {
3496 // default value
3497 if (dstricmp(fll.text.simplifyWhiteSpace(),"others")==0)
3498 {
3499 writeEdge(t,fll,flowList[j+1],2);
3500 continue;
3501 }
3502
3503
3504 writeEdge(t,fll,flowList[j+1],0);
3505 size_t u=findNode(j,stamp,WHEN_NO);
3506 size_t v=findNode(j,stamp-1,END_CASE);
3507
3508 if (u>0 && u<v)
3509 {
3510 writeEdge(t,fll,flowList[u],1);
3511 }
3512 else
3513 {
3514 writeEdge(t,fll,flowList[v],1);
3515 }
3516 }
3517 else if (kind & END_CASE)
3518 {
3519 size_t z=FlowChart::getNextNode(j,fll.stamp);
3520 writeEdge(t,fll,flowList[z],2);
3521 }
3522 else if (kind & END_LOOP)
3523 {
3524 size_t z=findPrevLoop(j,fll.stamp,true);
3525 writeEdge(t,fll,flowList[z],2);
3526 }
3527 else if (kind & RETURN_NO)
3528 {
3529 writeEdge(t,fll,flowList[size-1],2);
3530 }
3531 else if (kind & (EXIT_NO | NEXT_NO))
3532 {
3533 size_t z = 0;
3534 bool b = kind==NEXT_NO;
3535 if (!fll.exp.empty())
3536 {
3537 writeEdge(t,fll,flowList[j+1],1);
3538 }
3539 if (!fll.label.empty())
3540 {
3541 z=findLabel(j,fll.label);
3542 if (b)
3543 {
3544 writeEdge(t,fll,flowList[z],0);
3545 }
3546 else
3547 {
3549 z=getNextNode(z,flowList[z].stamp);
3550 writeEdge(t,fll,flowList[z],0);
3551 }
3552 continue;
3553 }
3554 else
3555 {
3556 if (b)
3557 {
3558 z=findPrevLoop(j,fll.stamp);
3559 writeEdge(t,fll,flowList[z],0);
3560 continue;
3561 }
3562 else
3563 {
3564 z =findNextLoop(j,fll.stamp-1);
3565 }
3566 z=getNextNode(z,flowList[z].stamp);
3567 }
3568 writeEdge(t,fll,flowList[z],0);
3569 }
3570 } //for
3571} //writeFlowLinks
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
Definition dstring.cpp:118
static size_t findNextLoop(size_t j, int stamp)
static size_t findPrevLoop(size_t j, int stamp, bool endif=false)
static size_t getNextIfLink(const FlowChart &, size_t)
static size_t findLabel(size_t j, const DString &)
#define EEND

References CASE_NO, dstricmp(), EEND, DString::empty(), END_CASE, END_LOOP, EXIT_NO, exp, findLabel(), findNextLoop(), findNode(), findPrevLoop(), FlowChart(), flowList, FOR_NO, getNextIfLink(), getNextNode(), IFF, label, LOOP_NO, NEXT_NO, RETURN_NO, DString::simplifyWhiteSpace(), stamp, text, TEXT_NO, type, VARIABLE_NO, WHEN_NO, WHILE_NO, and writeEdge().

Referenced by writeFlowChart().

◆ writeShape()

void FlowChart::writeShape ( TextStream & t,
const FlowChart & fl )
static

Definition at line 3127 of file vhdldocgen.cpp.

3128{
3129 if (fl.type & EEND) return;
3130 DString var;
3131 if (fl.type & LOOP)
3132 {
3133 var=" loop";
3134 }
3135 else if (fl.type & IFF)
3136 {
3137 var=" then";
3138 }
3139 else
3140 {
3141 var="";
3142 }
3143
3144 t << getNodeName(fl.id);
3145
3146#ifdef DEBUGFLOW
3147 DString qq(getNodeName(fl.id));
3148 g_keyMap.emplace(qq.str(),fl.id);
3149#endif
3150
3151 bool dec=(fl.type & DECLN);
3152 bool exit=(fl.type & EXITNEXT);
3153 if (exit && !fl.exp.empty())
3154 {
3155 dec=true;
3156 }
3157 if (dec)
3158 {
3159 DString exp=fl.exp;
3160 alignText(exp);
3161
3162 t << " [shape=diamond,style=filled,color=\"";
3163 t << flowCol.decisionNode;
3164 t << "\",label=\" ";
3165 DString kl;
3166 if (exit) kl=fl.text+" ";
3167
3168 if (!fl.label.empty())
3169 {
3170 kl+=fl.label+":"+exp+var;
3171 }
3172 else
3173 {
3174 kl+=exp+var;
3175 }
3176
3178 t << "\"]\n";
3179 }
3180 else if (fl.type & ENDCL)
3181 {
3182 DString val=fl.text;
3183 t << " [shape=ellipse ,label=\""+val+"\"]\n";
3184 }
3185 else if (fl.type & STARTFIN)
3186 {
3187 DString val=fl.text;
3188 t << "[shape=box , style=rounded label=<\n";
3189 t << "<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" >\n ";
3190 t << "<TR><TD BGCOLOR=\"";
3191 t<< flowCol.startEndNode;
3192 t<< "\"> ";
3194 t << " </TD></TR></TABLE>>];";
3195 }
3196 else
3197 {
3198 if (fl.text.empty()) return;
3199 bool isVar=(fl.type & FlowChart::VARIABLE_NO);
3200 DString q=fl.text;
3201
3202 if (exit)
3203 {
3204 q+=" "+fl.label;
3205 }
3206
3207 size_t z=q.rfind('\n');
3208
3209 if (z!=DString::npos && z==q.length()-1)
3210 {
3211 q=q.remove(z,2);
3212 }
3213 t << "[shape=none margin=0.1, label=<\n";
3214 t << "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\" >\n ";
3215 if (isVar)
3216 {
3217 t << "<TR><TD BGCOLOR=\"" << flowCol.varNode << "\" > ";
3218 }
3219 else
3220 {
3221 t << "<TR><TD BGCOLOR=\"" << flowCol.textNode << "\" > ";
3222 }
3224 t << " </TD></TR></TABLE>>];";
3225 }
3226}
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:249
DString & remove(size_t index, size_t len)
Definition dstring.h:524
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:183
static void alignText(DString &q)
#define ENDCL
#define DECLN
#define STARTFIN
#define EXITNEXT

References alignCommentNode(), alignText(), DECLN, EEND, DString::empty(), ENDCL, EXITNEXT, exp, FlowChart(), flowCol, getNodeName(), id, IFF, label, DString::length(), LOOP, DString::npos, DString::remove(), DString::rfind(), STARTFIN, DString::str(), text, type, and VARIABLE_NO.

Referenced by writeFlowChart().

Member Data Documentation

◆ exp

DString FlowChart::exp
private

◆ id

int FlowChart::id = 0
private

Definition at line 305 of file vhdldocgen.h.

Referenced by buildCommentNodes(), printNode(), writeEdge(), and writeShape().

◆ label

◆ line

int FlowChart::line = 0
private

Definition at line 309 of file vhdldocgen.h.

Referenced by buildCommentNodes().

◆ stamp

int FlowChart::stamp = 0
private

◆ text

DString FlowChart::text
private

◆ type


The documentation for this class was generated from the following files: