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
137138static 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+
213226static 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