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
117119static 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
153158static 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+
209226static 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