Skip to content

Commit a668cb1

Browse files
authored
Merge pull request #3189 from masatake/make--fill-end-fields
Make: fill "end:" fields
2 parents 4680b01 + 3455534 commit a668cb1

File tree

7 files changed

+63
-27
lines changed

7 files changed

+63
-27
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--extras=+r
2-
--fields=+r
2+
--fields=+re

Units/parser-make.r/make.include.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $(wildcard *.h) input.mk /^include $(1) $* Z0 $(shell) $(wildcard *.h) $(SHELL)$
77
A input.mk /^include A$/;" I roles:included
88
B input.mk /^sinclude B$/;" I roles:optional
99
C input.mk /^-include C$/;" I roles:optional
10-
D input.mk /^define D$/;" m roles:def
10+
D input.mk /^define D$/;" m roles:def end:11
1111
F input.mk /^include F G H$/;" I roles:included
1212
G input.mk /^include F G H$/;" I roles:included
1313
H input.mk /^include F G H$/;" I roles:included
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--fields=+en
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all input.mak /^all: foo bar$/;" t
2-
bar input.mak /^foo bar: baz$/;" t
3-
baz input.mak /^baz:$/;" t
4-
foo input.mak /^foo bar: baz$/;" t
1+
all input.mak /^all: foo bar$/;" t line:2 end:3
2+
bar input.mak /^foo bar: baz$/;" t line:4 end:6
3+
baz input.mak /^baz:$/;" t line:7 end:8
4+
foo input.mak /^foo bar: baz$/;" t line:4 end:6

main/numarray.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
return current->count; \
7373
} \
7474
\
75+
extern bool prefix##ArrayIsEmpty (const prefix##Array *const current) \
76+
{ \
77+
return (prefix##ArrayCount(current) == 0); \
78+
} \
79+
\
7580
extern type prefix##ArrayItem (const prefix##Array *const current, const unsigned int indx) \
7681
{ \
7782
Assert (current != NULL); \

main/numarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
extern void prefix##ArrayCombine (prefix##Array *const current, prefix##Array *const from); \
2727
extern void prefix##ArrayClear (prefix##Array *const current); \
2828
extern unsigned int prefix##ArrayCount (const prefix##Array *const current); \
29+
extern bool prefix##ArrayIsEmpty(const prefix##Array *const current); \
2930
extern type prefix##ArrayItem (const prefix##Array *const current, const unsigned int indx); \
3031
extern type prefix##ArrayLast (const prefix##Array *const current); \
3132
extern void prefix##ArrayDelete (prefix##Array *const current); \

parsers/make.c

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include "make.h"
1919

20+
#include "entry.h"
2021
#include "kind.h"
22+
#include "numarray.h"
2123
#include "parse.h"
2224
#include "read.h"
2325
#include "routines.h"
@@ -106,12 +108,12 @@ static bool isSpecialTarget (vString *const name)
106108
return true;
107109
}
108110

109-
static void makeSimpleMakeTag (vString *const name, makeKind kind)
111+
static int makeSimpleMakeTag (vString *const name, makeKind kind)
110112
{
111113
if (!isLanguageEnabled (getInputLanguage ()))
112-
return;
114+
return CORK_NIL;
113115

114-
makeSimpleTag (name, kind);
116+
return makeSimpleTag (name, kind);
115117
}
116118

117119
static void makeSimpleMakeRefTag (const vString* const name, const int kind,
@@ -123,22 +125,23 @@ static void makeSimpleMakeRefTag (const vString* const name, const int kind,
123125
makeSimpleRefTag (name, kind, roleIndex);
124126
}
125127

126-
static void newTarget (vString *const name)
128+
static int newTarget (vString *const name)
127129
{
128130
/* Ignore GNU Make's "special targets". */
129131
if (isSpecialTarget (name))
130132
{
131-
return;
133+
return CORK_NIL;
132134
}
133-
makeSimpleMakeTag (name, K_TARGET);
135+
return makeSimpleMakeTag (name, K_TARGET);
134136
}
135137

136-
static void newMacro (vString *const name, bool with_define_directive, bool appending)
138+
static int newMacro (vString *const name, bool with_define_directive, bool appending)
137139
{
140+
int r = CORK_NIL;
138141
subparser *s;
139142

140143
if (!appending)
141-
makeSimpleMakeTag (name, K_MACRO);
144+
r = makeSimpleMakeTag (name, K_MACRO);
142145

143146
foreachSubparser(s, false)
144147
{
@@ -148,6 +151,8 @@ static void newMacro (vString *const name, bool with_define_directive, bool appe
148151
m->newMacroNotify (m, vStringValue(name), with_define_directive, appending);
149152
leaveSubparser();
150153
}
154+
155+
return r;
151156
}
152157

153158
static void valueFound (vString *const name)
@@ -206,13 +211,25 @@ static void readIdentifier (const int first, vString *const id)
206211
ungetcToInputFile (c);
207212
}
208213

214+
static void endTargets (intArray *targets, unsigned long lnum)
215+
{
216+
for (unsigned int i = 0; i < intArrayCount (targets); i++)
217+
{
218+
int cork_index = intArrayItem (targets, i);
219+
tagEntryInfo *e = getEntryInCorkQueue (cork_index);
220+
if (e)
221+
e->extensionFields.endLine = lnum;
222+
}
223+
intArrayClear (targets);
224+
}
225+
209226
static void findMakeTags (void)
210227
{
211228
stringList *identifiers = stringListNew ();
212229
bool newline = true;
213-
bool in_define = false;
230+
int current_macro = CORK_NIL;
214231
bool in_value = false;
215-
bool in_rule = false;
232+
intArray *current_targets = intArrayNew ();
216233
bool variable_possible = true;
217234
bool appending = false;
218235
int c;
@@ -226,21 +243,21 @@ static void findMakeTags (void)
226243
{
227244
if (newline)
228245
{
229-
if (in_rule)
246+
if (!intArrayIsEmpty (current_targets))
230247
{
231248
if (c == '\t' || (c = skipToNonWhite (c)) == '#')
232249
{
233250
skipLine (); /* skip rule or comment */
234251
c = nextChar ();
235252
}
236253
else if (c != '\n')
237-
in_rule = false;
254+
endTargets (current_targets, getInputLineNumber () - 1);
238255
}
239256
else if (in_value)
240257
in_value = false;
241258

242259
stringListClear (identifiers);
243-
variable_possible = (bool)(!in_rule);
260+
variable_possible = intArrayIsEmpty (current_targets);
244261
newline = false;
245262
}
246263
if (c == '\n')
@@ -271,9 +288,12 @@ static void findMakeTags (void)
271288
{
272289
unsigned int i;
273290
for (i = 0; i < stringListCount (identifiers); i++)
274-
newTarget (stringListItem (identifiers, i));
291+
{
292+
int r = newTarget (stringListItem (identifiers, i));
293+
if (r != CORK_NIL)
294+
intArrayAdd (current_targets, r);
295+
}
275296
stringListClear (identifiers);
276-
in_rule = true;
277297
}
278298
}
279299
else if (variable_possible && c == '=' &&
@@ -282,7 +302,7 @@ static void findMakeTags (void)
282302
newMacro (stringListItem (identifiers, 0), false, appending);
283303

284304
in_value = true;
285-
in_rule = false;
305+
endTargets (current_targets, getInputLineNumber () - 1);
286306
appending = false;
287307
}
288308
else if (variable_possible && isIdentifier (c))
@@ -296,13 +316,18 @@ static void findMakeTags (void)
296316

297317
if (stringListCount (identifiers) == 1)
298318
{
299-
if (in_define && ! strcmp (vStringValue (name), "endef"))
300-
in_define = false;
301-
else if (in_define)
319+
if ((current_macro != CORK_NIL) && ! strcmp (vStringValue (name), "endef"))
320+
{
321+
tagEntryInfo *e = getEntryInCorkQueue(current_macro);
322+
323+
current_macro = CORK_NIL;
324+
if (e)
325+
e->extensionFields.endLine = getInputLineNumber ();
326+
}
327+
else if (current_macro != CORK_NIL)
302328
skipLine ();
303329
else if (! strcmp (vStringValue (name), "define"))
304330
{
305-
in_define = true;
306331
c = skipToNonWhite (nextChar ());
307332
vStringClear (name);
308333
/* all remaining characters on the line are the name -- even spaces */
@@ -315,7 +340,7 @@ static void findMakeTags (void)
315340
ungetcToInputFile (c);
316341
vStringStripTrailing (name);
317342

318-
newMacro (name, true, false);
343+
current_macro = newMacro (name, true, false);
319344
}
320345
else if (! strcmp (vStringValue (name), "export"))
321346
stringListClear (identifiers);
@@ -357,6 +382,9 @@ static void findMakeTags (void)
357382
variable_possible = false;
358383
}
359384

385+
endTargets (current_targets, getInputLineNumber ());
386+
387+
intArrayDelete (current_targets);
360388
stringListDelete (identifiers);
361389
}
362390

@@ -376,5 +404,6 @@ extern parserDefinition* MakefileParser (void)
376404
def->extensions = extensions;
377405
def->aliases = aliases;
378406
def->parser = findMakeTags;
407+
def->useCork = CORK_QUEUE;
379408
return def;
380409
}

0 commit comments

Comments
 (0)