@@ -29,12 +29,16 @@ signature module MacroReportConfigSig<ResultType ResultElement> {
29
29
/* Create a message to describe this macro, using '$@' to describe an example `ResultElement`. */
30
30
string getMessageVariedResultInAllExpansions ( Macro m ) ;
31
31
32
- /*
32
+ /**
33
33
* Create a message to describe this macro expansion which produces a `ResultElement`, using '$@'
34
34
* to describe the relevant macro.
35
35
*/
36
-
37
36
string getMessageResultInIsolatedExpansion ( ResultElement element ) ;
37
+
38
+ /**
39
+ * Create a message to describe a `ResultElement` which is not generated by a macro expansion.
40
+ */
41
+ string getMessageNotInMacro ( ResultElement element ) ;
38
42
}
39
43
40
44
/**
@@ -88,7 +92,7 @@ signature module MacroReportConfigSig<ResultType ResultElement> {
88
92
* ## Generating Report Objects
89
93
*
90
94
* This module also can be used to more easily report issues across these cases, by implementing
91
- * `MacroReportConfigSig` and importing `DeduplicateMacroResults::Report::ReportResultInMacro `.
95
+ * `MacroReportConfigSig` and importing `DeduplicateMacroResults::Report::ReportResult `.
92
96
*
93
97
* ```
94
98
* module InvalidFooInMacroReportConfig implements MacroReportConfigSig<InvalidFoo> {
@@ -106,11 +110,15 @@ signature module MacroReportConfigSig<ResultType ResultElement> {
106
110
* string getMessageResultInIsolatedExpansion(InvalidFoo foo) {
107
111
* result = "Invocation of macro $@ has invalid foo '" + foo.getName() + "'."
108
112
* }
113
+ *
114
+ * string getMessageNotInMacro(ResultElement element) {
115
+ * result = "Invalid foo '" + element.getName() + "'."
116
+ * }
109
117
* }
110
118
*
111
119
* import DeduplicateFooInMacros::Report<InvalidFooInMacroReportConfig> as Report;
112
120
*
113
- * from Report::ReportResultInMacro report
121
+ * from Report::ReportResult report
114
122
* where not excluded(report.getPrimaryElement(), ...)
115
123
* select report.getPrimaryElement(), report.getMessage(), report.getOptionalPlaceholderLocation(),
116
124
* report.getOptionalPlaceholderMessage()
@@ -234,11 +242,10 @@ module DeduplicateMacroResults<
234
242
}
235
243
}
236
244
237
- /*
245
+ /**
238
246
* Convenience predicate to know when invalid macro expansions have been reported at their macro
239
247
* definition.
240
248
*/
241
-
242
249
private predicate reported ( Macro macro ) {
243
250
macro instanceof PrimaryMacroSameResultElementInAllInvocations or
244
251
macro instanceof PrimaryMacroDifferentResultElementInAllInvocations
@@ -248,7 +255,7 @@ module DeduplicateMacroResults<
248
255
* A macro invocation for which the target macro does not always produce a `ResultElement`, but
249
256
* this specific invocation of it does.
250
257
*
251
- * This is "primary" / most specific macro for these result elements. It will also does not match
258
+ * This is the "primary" / most specific macro for these result elements. It also does not match
252
259
* `MacroInvocation`s inside of a `MacroInvocation` of a `Macro` which always produces a
253
260
* `ResultElement`, indicating that the real problem lies with that other `Macro` instead of with
254
261
* this particular invocation.
@@ -274,10 +281,15 @@ module DeduplicateMacroResults<
274
281
* See the doc comment for the `DeduplicateMacroResults` module for more info.
275
282
*/
276
283
module Report< MacroReportConfigSig< ResultElement > ReportConfig> {
277
- newtype TReportResultInMacro =
284
+ newtype TReportResult =
278
285
TReportMacroResultWithSameName ( PrimaryMacroSameResultElementInAllInvocations def ) or
279
286
TReportMacroResultWithVariedName ( PrimaryMacroDifferentResultElementInAllInvocations def ) or
280
- TReportIsolatedMacroResult ( IsolatedMacroExpansionWithResultElement def )
287
+ TReportIsolatedMacroResult ( IsolatedMacroExpansionWithResultElement def ) or
288
+ TReportNotInMacro ( ResultElement def ) {
289
+ not exists ( ResultMacroExpansion macroExpansion |
290
+ macroExpansion .getResultElement ( ) = def
291
+ )
292
+ }
281
293
282
294
/**
283
295
* An instance of a `ResultElement` to be reported to a user.
@@ -291,7 +303,7 @@ module DeduplicateMacroResults<
291
303
* The values returned by these methods are configured by the `MacroReportConfigSig`
292
304
* signature parameter.
293
305
*/
294
- class ReportResultInMacro extends TReportResultInMacro {
306
+ class ReportResult extends TReportResult {
295
307
string toString ( ) { result = getMessage ( ) }
296
308
297
309
string getMessage ( ) {
@@ -310,6 +322,11 @@ module DeduplicateMacroResults<
310
322
this = TReportIsolatedMacroResult ( def ) and
311
323
result = ReportConfig:: getMessageResultInIsolatedExpansion ( def .getResultElement ( ) )
312
324
)
325
+ or
326
+ exists ( ResultElement def |
327
+ this = TReportNotInMacro ( def ) and
328
+ result = ReportConfig:: getMessageNotInMacro ( def )
329
+ )
313
330
}
314
331
315
332
Element getPrimaryElement ( ) {
@@ -318,6 +335,8 @@ module DeduplicateMacroResults<
318
335
this = TReportMacroResultWithVariedName ( result )
319
336
or
320
337
this = TReportIsolatedMacroResult ( result )
338
+ or
339
+ this = TReportNotInMacro ( result )
321
340
}
322
341
323
342
Location getOptionalPlaceholderLocation ( ) {
@@ -335,6 +354,11 @@ module DeduplicateMacroResults<
335
354
this = TReportIsolatedMacroResult ( def ) and
336
355
result = def .getMacro ( ) .getLocation ( )
337
356
)
357
+ or
358
+ exists ( ResultElement def |
359
+ this = TReportNotInMacro ( def ) and
360
+ result = def .getLocation ( )
361
+ )
338
362
}
339
363
340
364
string getOptionalPlaceholderMessage ( ) {
@@ -343,7 +367,10 @@ module DeduplicateMacroResults<
343
367
result = Config:: describe ( def .getExampleResultElement ( ) )
344
368
)
345
369
or
346
- this = TReportMacroResultWithSameName ( _) and
370
+ (
371
+ this = TReportMacroResultWithSameName ( _)
372
+ or this = TReportNotInMacro ( _)
373
+ ) and
347
374
result = "(ignored)"
348
375
or
349
376
this = TReportIsolatedMacroResult ( _) and
@@ -374,6 +401,12 @@ module DeduplicateMacroResults<
374
401
or
375
402
this = TReportIsolatedMacroResult ( result )
376
403
}
404
+
405
+ ResultElement getAResultElement ( ) {
406
+ result = getAResultMacroExpansion ( ) .getResultElement ( )
407
+ or
408
+ this = TReportNotInMacro ( result )
409
+ }
377
410
}
378
411
}
379
412
}
0 commit comments