geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dependency.c
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) 2016, Red Hat, Inc.
4 * Copyright (c) 2016, Masatake YAMATO
5 *
6 * Author: Masatake YAMATO <yamato@redhat.com>
7 *
8 * This source code is released for free distribution under the terms of the
9 * GNU General Public License version 2 or (at your option) any later version.
10 *
11 */
12
13#include "general.h" /* must always come first */
14
15#include "debug.h"
16#include "dependency.h"
17#include "options.h"
18#include "parse_p.h"
19#include "read.h"
20#include "read_p.h"
21#include "routines.h"
22#include "subparser.h"
23#include "subparser_p.h"
24#include "xtag.h"
25
26#include <string.h>
27
29 slaveParser *slaveParsers; /* The parsers on this list must be initialized when
30 this parser is initialized. */
34};
35
37 parserDefinition *const master,
38 struct slaveControlBlock *masterSCB,
39 struct kindControlBlock *masterKCB,
40 parserDefinition *const slave,
41 struct kindControlBlock *slaveKCB,
42 void *data)
43{
44 if (dtype == DEPTYPE_KIND_OWNER)
45 linkKindDependency (masterKCB, slaveKCB);
46 else if (dtype == DEPTYPE_SUBPARSER)
47 {
49
50 s->type = dtype;
51 s->id = slave->id;
52 s->data = data;
53
54 s->next = masterSCB->slaveParsers;
55 masterSCB->slaveParsers = s;
56 }
57}
58
60{
63}
64
65
67{
68 struct slaveControlBlock *cb;
69
70 cb = xMalloc (1, struct slaveControlBlock);
71 cb->slaveParsers = NULL;
74 cb->owner = parser->id;
75
76 return cb;
77}
78
80{
81 eFree (cb);
82}
83
85 struct slaveControlBlock *cb)
86{
87 unsigned int i;
88 slaveParser *sp;
89
90 /* Initialize slaves */
91 sp = cb->slaveParsers;
92 while (sp != NULL)
93 {
94 if (sp->type == DEPTYPE_SUBPARSER)
95 {
96 subparser *sub;
97
98 sub = (subparser *)sp->data;
99 sub->slaveParser = sp;
100 }
101
102 if (sp->type == DEPTYPE_KIND_OWNER
103 || (sp->type == DEPTYPE_SUBPARSER &&
104 (((subparser *)sp->data)->direction & SUBPARSER_BASE_RUNS_SUB)))
105 {
106 initializeParser (sp->id);
107 if (sp->type == DEPTYPE_SUBPARSER
109 {
110 subparser *subparser = sp->data;
112 }
113 }
114 sp = sp->next;
115 }
116
117 /* Initialize masters that act as base parsers. */
118 for (i = 0; i < parser->dependencyCount; i++)
119 {
120 parserDependency *d = parser->dependencies + i;
121 if (d->type == DEPTYPE_SUBPARSER &&
122 ((subparser *)(d->data))->direction & SUBPARSER_SUB_RUNS_BASE)
123 {
124 langType baseParser;
125 baseParser = getNamedLanguage (d->upperParser, 0);
126 Assert (baseParser != LANG_IGNORE);
127 initializeParser (baseParser);
128 }
129 }
130}
131
133 struct slaveControlBlock *cb)
134{
135 while (cb->slaveParsers)
136 {
137 slaveParser *sp = cb->slaveParsers;
138 cb->slaveParsers = sp->next;
139 sp->next = NULL;
140 eFree (sp);
141 }
142}
143
144extern void notifyInputStart (void)
145{
146 subparser *s;
147
148 foreachSubparser(s, false)
149 {
152
153 if (s->inputStart)
154 {
156 s->inputStart (s);
158 }
159 }
160}
161
162extern void notifyInputEnd (void)
163{
164 subparser *s;
165
166 foreachSubparser(s, false)
167 {
168 if (s->inputEnd)
169 {
171 s->inputEnd (s);
173 }
174
177 }
178}
179
180extern void notifyMakeTagEntry (const tagEntryInfo *tag, int corkIndex)
181{
182 subparser *s;
183
184 foreachSubparser(s, false)
185 {
186 if (s->makeTagEntryNotify)
187 {
189 s->makeTagEntryNotify (s, tag, corkIndex);
191 }
192 }
193}
194
196{
197 return s->slaveParser->id;
198}
199
200extern void chooseExclusiveSubparser (subparser *s, void *data)
201{
203 {
207 verbose ("%s is chosen as exclusive subparser\n",
210 }
211}
212
213extern subparser *getFirstSubparser(struct slaveControlBlock *controlBlock)
214{
215 if (controlBlock)
216 return controlBlock->subparsersInUse;
217 return NULL;
218}
219
220extern void useDefaultSubparsers (struct slaveControlBlock *controlBlock)
221{
222 controlBlock->subparsersInUse = controlBlock->subparsersDefault;
223}
224
225extern void useSpecifiedSubparser (struct slaveControlBlock *controlBlock, subparser *s)
226{
228 controlBlock->subparsersInUse = s;
229}
230
231extern void setupSubparsersInUse (struct slaveControlBlock *controlBlock)
232{
233 if (!controlBlock->subparsersInUse)
234 useDefaultSubparsers(controlBlock);
235}
236
238{
239 subparser *tmp;
240 subparser *s = NULL;
241
242 tmp = controlBlock->subparsersInUse;
243 controlBlock->subparsersInUse = NULL;
244
245 if (tmp && tmp->schedulingBaseparserExplicitly)
246 {
248 s = tmp;
249 }
250
251 if (s)
252 return s;
253
254 while (tmp)
255 {
257 {
258 s = tmp;
259 }
260 tmp = tmp->next;
261 }
262
263 return s;
264}
265
266
267static int subparserDepth;
268
270{
273}
274
275extern void leaveSubparser(void)
276{
277 popLanguage ();
279}
280
281extern bool doesSubparserRun (void)
282{
284 return false;
285 return subparserDepth;
286}
287
289{
290 if (scb)
291 return scb->slaveParsers;
292 return NULL;
293}
294
296{
297 return colprintTableNew ("L:NAME", "L:BASEPARSER", "L:DIRECTIONS", NULL);
298}
299
301 struct slaveControlBlock *scb)
302{
303 slaveParser *tmp;
304
305 pushLanguage (scb->owner);
307 {
308 struct colprintLine *line = colprintTableGetNewLine(table);
309
312
313 const char *direction;
314 switch (((subparser *)tmp->data)->direction)
315 {
317 direction = "base => sub {shared}";
318 break;
320 direction = "base <= sub {dedicated}";
321 break;
323 direction = "base <> sub {bidirectional}";
324 break;
325 default:
326 direction = "UNKNOWN(INTERNAL BUG)";
327 break;
328 }
330 }
331 popLanguage ();
332}
333
334static int subparserColprintCompareLines (struct colprintLine *a , struct colprintLine *b)
335{
336 const char *a_name = colprintLineGetColumn (a, 0);
337 const char *b_name = colprintLineGetColumn (b, 0);
338
339 int r;
340 r = strcmp (a_name, b_name);
341 if (r != 0)
342 return r;
343
344 const char *a_baseparser = colprintLineGetColumn (a, 1);
345 const char *b_baseparser = colprintLineGetColumn (b, 1);
346
347 return strcmp(a_baseparser, b_baseparser);
348}
349
351 bool withListHeader, bool machinable, FILE *fp)
352{
354 colprintTablePrint (table, 0, withListHeader, machinable, fp);
355}
void colprintLineAppendColumnCString(struct colprintLine *line, const char *column)
Definition: colprint.c:254
void colprintTableSort(struct colprintTable *table, int(*compareFn)(struct colprintLine *, struct colprintLine *))
Definition: colprint.c:235
struct colprintLine * colprintTableGetNewLine(struct colprintTable *table)
Definition: colprint.c:240
struct colprintTable * colprintTableNew(const char *columnHeader,...)
Definition: colprint.c:73
void colprintTablePrint(struct colprintTable *table, unsigned int startFrom, bool withHeader, bool machinable, FILE *fp)
Definition: colprint.c:227
const char * colprintLineGetColumn(struct colprintLine *line, unsigned int column)
Definition: colprint.c:285
#define Assert(c)
Definition: debug.h:47
slaveParser * getFirstSlaveParser(struct slaveControlBlock *scb)
Definition: dependency.c:288
static int subparserDepth
Definition: dependency.c:267
void useSpecifiedSubparser(struct slaveControlBlock *controlBlock, subparser *s)
Definition: dependency.c:225
void useDefaultSubparsers(struct slaveControlBlock *controlBlock)
Definition: dependency.c:220
static void attachSubparser(struct slaveControlBlock *base_sb, subparser *subparser)
Definition: dependency.c:59
void notifyInputStart(void)
Definition: dependency.c:144
subparser * teardownSubparsersInUse(struct slaveControlBlock *controlBlock)
Definition: dependency.c:237
void notifyMakeTagEntry(const tagEntryInfo *tag, int corkIndex)
Definition: dependency.c:180
struct colprintTable * subparserColprintTableNew(void)
Definition: dependency.c:295
struct slaveControlBlock * allocSlaveControlBlock(parserDefinition *parser)
Definition: dependency.c:66
void subparserColprintTablePrint(struct colprintTable *table, bool withListHeader, bool machinable, FILE *fp)
Definition: dependency.c:350
langType getSubparserLanguage(subparser *s)
Definition: dependency.c:195
void linkDependencyAtInitializeParsing(depType dtype, parserDefinition *const master, struct slaveControlBlock *masterSCB, struct kindControlBlock *masterKCB, parserDefinition *const slave, struct kindControlBlock *slaveKCB, void *data)
Definition: dependency.c:36
void enterSubparser(subparser *subparser)
Definition: dependency.c:269
void subparserColprintAddSubparsers(struct colprintTable *table, struct slaveControlBlock *scb)
Definition: dependency.c:300
bool doesSubparserRun(void)
Definition: dependency.c:281
void notifyInputEnd(void)
Definition: dependency.c:162
void setupSubparsersInUse(struct slaveControlBlock *controlBlock)
Definition: dependency.c:231
void finalizeDependencies(parserDefinition *parser, struct slaveControlBlock *cb)
Definition: dependency.c:132
subparser * getFirstSubparser(struct slaveControlBlock *controlBlock)
Definition: dependency.c:213
static int subparserColprintCompareLines(struct colprintLine *a, struct colprintLine *b)
Definition: dependency.c:334
void freeSlaveControlBlock(struct slaveControlBlock *cb)
Definition: dependency.c:79
void initializeDependencies(parserDefinition *parser, struct slaveControlBlock *cb)
Definition: dependency.c:84
void leaveSubparser(void)
Definition: dependency.c:275
void chooseExclusiveSubparser(subparser *s, void *data)
Definition: dependency.c:200
@ DEPTYPE_KIND_OWNER
Definition: dependency.h:27
@ DEPTYPE_SUBPARSER
Definition: dependency.h:28
enum eDepType depType
#define foreachSlaveParser(VAR)
Definition: dependency_p.h:27
vString * line
Definition: geany_cobol.c:133
void linkKindDependency(struct kindControlBlock *masterKCB, struct kindControlBlock *slaveKCB)
Definition: kind.c:343
void verbose(const char *const format,...)
Definition: options.c:655
langType getNamedLanguage(const char *const name, size_t len)
Definition: parse.c:406
const char * getLanguageName(const langType language)
Definition: parse.c:284
void notifyLanguageRegexInputStart(langType language)
Definition: parse.c:3732
void initializeParser(langType lang)
Definition: parse.c:1850
void notifyLanguageRegexInputEnd(langType language)
Definition: parse.c:3737
#define LANG_IGNORE
Definition: parse.h:27
#define NULL
Definition: rbtree.h:150
langType getInputLanguage(void)
Definition: read.c:196
langType getLanguageForBaseParser(void)
Definition: read.c:1164
langType popLanguage(void)
Definition: read.c:1159
void pushLanguage(const langType language)
Definition: read.c:1154
void eFree(void *const ptr)
Definition: routines.c:252
#define xMalloc(n, Type)
Definition: routines.h:23
langType id
Definition: parse.h:120
parserDependency * dependencies
Definition: parse.h:103
unsigned int dependencyCount
Definition: parse.h:104
const char * upperParser
Definition: dependency.h:34
void * data
Definition: dependency.h:41
langType id
Definition: dependency.h:40
depType type
Definition: dependency.h:39
slaveParser * next
Definition: dependency.h:42
void(* makeTagEntryNotify)(subparser *s, const tagEntryInfo *tag, int corkIndex)
Definition: subparser.h:50
void(* inputStart)(subparser *s)
Definition: subparser.h:47
slaveParser * slaveParser
Definition: subparser.h:39
bool chosenAsExclusiveSubparser
Definition: subparser.h:42
void(* exclusiveSubparserChosenNotify)(subparser *s, void *data)
Definition: subparser.h:49
bool schedulingBaseparserExplicitly
Definition: subparser.h:41
void(* inputEnd)(subparser *s)
Definition: subparser.h:48
subparser * next
Definition: subparser.h:40
subparser * subparsersInUse
Definition: dependency.c:32
langType owner
Definition: dependency.c:33
slaveParser * slaveParsers
Definition: dependency.c:29
subparser * subparsersDefault
Definition: dependency.c:31
#define foreachSubparser(VAR, INCLUDING_NONE_CRAFTED_PARSER)
Definition: subparser.h:23
@ SUBPARSER_BASE_RUNS_SUB
Definition: subparser.h:32
@ SUBPARSER_SUB_RUNS_BASE
Definition: subparser.h:33
@ SUBPARSER_BI_DIRECTION
Definition: subparser.h:34
struct sSubparser subparser
Definition: types.h:37
int langType
Definition: types.h:13
bool isXtagEnabled(xtagType type)
Definition: xtag.c:235
@ XTAG_SUBPARSER
Definition: xtag.h:35