Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] empty AST macro expansions

I'm trying to use the AST to discover whether a specific macro was used to create a particular node in the AST. I'm calling IASTNode.getNodeLocations and looking for instances of IASTMacroExpansionLocation that reference the target macro.

This works if the macro expands to a real value, but does not work when the expansion is to nothing. E.g., expansions of the first macro are found, expansions of the second are not:

	#define FOUND     found
	#define NOT_FOUND

The reason for the difference is the implementation of LocationCtxContainer.collectLocations.

In both cases, the LocationCtxMacroExpansion is present in the fChildren list. However, in the NOT_FOUND case, the child's fSequenceNumber is the same as childEndSequenceNumber (since length is 0).

Approximately:

	if (sequenceNumber < child.fSequenceNumber) {
	// ...
[159]		sequenceNumber= child.fSequenceNumber;
	}

	// ...
[164]	if (sequenceNumber < childEndSequenceNumber) {
		child.collectLocations( // ...

The loop's counter, sequenceNumber, is advanced (on line 159), which is before the check to see if the child is within the target range (on line 164).

The questions that I have are:

1) Is there a better way to do what I want? The expansion that I'm looking for is stored in the node's fChildren list, maybe there is a different way to access it?

2) Is this a bug or a feature? :-) Is there other code that depends on empty expansions being removed from the result?

If it is a bug, then I could submit a patch to fix it.  My first ideas are:
a) empty expansions should be given a sequenceLength of 1 when the LocationCtxMacroExpansion is created, or

b) the sequenceNumber counter should not be incremented until the child is fully processed.

-Andrew


Back to the top