summaryrefslogtreecommitdiffstats
path: root/src/dotparse.ypp
blob: f8e8960e669765af0e9f161214346a23551dfa97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* dot.y */

%{
#include <ntqdict.h>
#include <ntqptrstack.h>
#include <ntqlistview.h>
#include "calltreedlg.h"
#include "graphwidget.h"
#include "treewidget.h"
#include "encoder.h"

extern FILE* yyin;
int yylex();
void yyinit(CallTreeDlg*, FILE*, Encoder*);
void yyerror(const char*);

static TQMap<TQString, TQString> s_pMapAttr;
static TQStack<TQListViewItem> s_pParentStack;
static TQListView* s_pTree;

static GraphWidget* s_pGraph;
static TreeWidget* s_pCallTree;
static TreeWidget* s_pCallingTree;
static Encoder* s_pEncoder;

// Avoid compiler warnings
#define YYENABLE_NLS 0
#ifndef YYLTYPE_IS_TRIVIAL
#define YYLTYPE_IS_TRIVIAL 0
#endif
%}

%union {
	TQString* pText;
}

%token GRAPH DIGRAPH NODE NAME STRING NUMBER DIR_EDGE UNDIR_EDGE
%token CALL_TREE CALLING_TREE
%type <pText> NAME STRING NUMBER attr_val

%start file

%%

file
	: call_tree calling_tree graph

graph
	: graph_type NAME '{' graph_desc_list '}' { delete $2; }
	;

graph_type
	: GRAPH
	| DIGRAPH
	;

graph_desc_list
	:
	| graph_desc_entry graph_desc_list
	;

graph_desc_entry
	: def_node_attr
	| graph_attr
	| node_record
	| edge_record 
	;
	
def_node_attr
	: NODE attributes ';'
	;
	
graph_attr
	: GRAPH attributes ';'
		{
			if (s_pMapAttr.find("kscope_zoom") != s_pMapAttr.end())
				s_pGraph->setZoom(s_pMapAttr["kscope_zoom"].toDouble());
		}
	;
	
node_record
	: NAME attributes ';'
		{
			s_pGraph->addNode(*$1);
			delete $1;
			s_pMapAttr.clear();
		}
	;
	
edge_record
	: NAME edge_type NAME attributes ';'
		{
			GraphWidget::CallData cd;
			
			cd.m_sCaller = *$1;
			cd.m_sCallee = *$3;
			cd.m_sFile = s_pMapAttr["kscope_file"];
			cd.m_sLine = s_pMapAttr["kscope_line"];
			cd.m_sText = s_pEncoder->decode(s_pMapAttr["kscope_text"]);
			s_pGraph->addCall(cd);
			
			delete $1;
			delete $3;
			s_pMapAttr.clear();
		}
	;
	
edge_type
	: DIR_EDGE
	| UNDIR_EDGE
	;
	
attributes
	: 
	| '[' attr_list ']'
	;
	
attr_list
	:
	| non_empty_attr_list
	;
	
non_empty_attr_list
	: attr
	| attr ',' attr_list
	;
	
attr
	: NAME '=' attr_val
		{
			s_pMapAttr.insert(*$1, *$3);
			delete $1;
			delete $3;
		}
	;
	
attr_val
	: NAME
	| STRING
	| NUMBER
	;
	
call_tree
	: call_tree_prepare '{' root_node '}'
	;
	
call_tree_prepare
	: CALL_TREE { s_pTree = s_pCallTree; }
	;
	
calling_tree
	: calling_tree_prepare '{' root_node '}'
	;
	
calling_tree_prepare
	: CALLING_TREE { s_pTree = s_pCallingTree; }
	;

root_node
	: root_tree_node '{' child_list '}'
		{
			TQListViewItem* pItem;
			
			pItem = s_pParentStack.pop();
			if (pItem->firstChild() != NULL)
				pItem->setOpen(true);
		}
	;

root_tree_node
	: NAME
		{
			TQListViewItem* pItem;
			
			pItem = new TQListViewItem(s_pTree, *$1);
			s_pParentStack.push(pItem);
			delete $1;
		}
	;
	
child_list
	:
	| child_node child_list
	;
	
child_node
	: tree_node tree_attributes '{' child_list '}'
		{
			TQListViewItem* pItem;
			
			pItem = s_pParentStack.pop();
			if (pItem->firstChild() != NULL)
				pItem->setOpen(true);
		}
	;

tree_node
	: NAME
		{
			TQListViewItem* pItem;
			
			pItem = new TQListViewItem(s_pParentStack.top(), *$1);
			s_pParentStack.push(pItem);
			delete $1;
		}
	;

tree_attributes
	: attributes
		{
			TQListViewItem* pItem;
			
			pItem = s_pParentStack.top();
			pItem->setText(1, s_pMapAttr["kscope_file"]);
			pItem->setText(2, s_pMapAttr["kscope_line"]);
			pItem->setText(3, s_pEncoder->decode(s_pMapAttr["kscope_text"]));
		}
	;

%%

void yyinit(CallTreeDlg* pDlg, FILE* pFile, Encoder* pEnc)
{
	yyin = pFile;
	s_pCallTree = pDlg->m_pCalledWidget;
	s_pCallingTree = pDlg->m_pCallingWidget;
	s_pGraph = pDlg->m_pGraphWidget;
	s_pEncoder = pEnc;
}

void yyerror(const char* szError)
{
	fprintf(stderr, "%s\n", szError);
}