Skip to content

Commit 3455534

Browse files
committed
Make: fill end: fields for targets
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 090f0bb commit 3455534

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed
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

parsers/make.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "entry.h"
2121
#include "kind.h"
22+
#include "numarray.h"
2223
#include "parse.h"
2324
#include "read.h"
2425
#include "routines.h"
@@ -124,14 +125,14 @@ static void makeSimpleMakeRefTag (const vString* const name, const int kind,
124125
makeSimpleRefTag (name, kind, roleIndex);
125126
}
126127

127-
static void newTarget (vString *const name)
128+
static int newTarget (vString *const name)
128129
{
129130
/* Ignore GNU Make's "special targets". */
130131
if (isSpecialTarget (name))
131132
{
132-
return;
133+
return CORK_NIL;
133134
}
134-
makeSimpleMakeTag (name, K_TARGET);
135+
return makeSimpleMakeTag (name, K_TARGET);
135136
}
136137

137138
static int newMacro (vString *const name, bool with_define_directive, bool appending)
@@ -210,13 +211,25 @@ static void readIdentifier (const int first, vString *const id)
210211
ungetcToInputFile (c);
211212
}
212213

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+
213226
static void findMakeTags (void)
214227
{
215228
stringList *identifiers = stringListNew ();
216229
bool newline = true;
217230
int current_macro = CORK_NIL;
218231
bool in_value = false;
219-
bool in_rule = false;
232+
intArray *current_targets = intArrayNew ();
220233
bool variable_possible = true;
221234
bool appending = false;
222235
int c;
@@ -230,21 +243,21 @@ static void findMakeTags (void)
230243
{
231244
if (newline)
232245
{
233-
if (in_rule)
246+
if (!intArrayIsEmpty (current_targets))
234247
{
235248
if (c == '\t' || (c = skipToNonWhite (c)) == '#')
236249
{
237250
skipLine (); /* skip rule or comment */
238251
c = nextChar ();
239252
}
240253
else if (c != '\n')
241-
in_rule = false;
254+
endTargets (current_targets, getInputLineNumber () - 1);
242255
}
243256
else if (in_value)
244257
in_value = false;
245258

246259
stringListClear (identifiers);
247-
variable_possible = (bool)(!in_rule);
260+
variable_possible = intArrayIsEmpty (current_targets);
248261
newline = false;
249262
}
250263
if (c == '\n')
@@ -275,9 +288,12 @@ static void findMakeTags (void)
275288
{
276289
unsigned int i;
277290
for (i = 0; i < stringListCount (identifiers); i++)
278-
newTarget (stringListItem (identifiers, i));
291+
{
292+
int r = newTarget (stringListItem (identifiers, i));
293+
if (r != CORK_NIL)
294+
intArrayAdd (current_targets, r);
295+
}
279296
stringListClear (identifiers);
280-
in_rule = true;
281297
}
282298
}
283299
else if (variable_possible && c == '=' &&
@@ -286,7 +302,7 @@ static void findMakeTags (void)
286302
newMacro (stringListItem (identifiers, 0), false, appending);
287303

288304
in_value = true;
289-
in_rule = false;
305+
endTargets (current_targets, getInputLineNumber () - 1);
290306
appending = false;
291307
}
292308
else if (variable_possible && isIdentifier (c))
@@ -366,6 +382,9 @@ static void findMakeTags (void)
366382
variable_possible = false;
367383
}
368384

385+
endTargets (current_targets, getInputLineNumber ());
386+
387+
intArrayDelete (current_targets);
369388
stringListDelete (identifiers);
370389
}
371390

0 commit comments

Comments
 (0)