Skip to main content

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

I actually want to know if a particular node was created as the result of a particular macro's expansion. I.e., Instead of getting all expansions of the target macro (as shown in this code sample), I would like to find out if my IASTNode, referenced my target macro.

Oh, perhaps you mean that I can get all the references, and then use #getImageLocation on each to see if it is contained within the #getImageLocation of the IASTName of my target node?

-Andrew

On 13-01-29 01:43 AM, Schorn, Markus wrote:
If you are looking for references of a macro you can simply use :

IASTPreprocessorMacroDefinition macroDef= ...
IBinding macro = macroDef.getName().resolveBinding();
IASTName[] references= IASTTranslationUnit.getReferences(macro);

Markus.

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Andrew Eidsness
Sent: Mon, 28. 01. 2013 22:52
To: cdt-dev@xxxxxxxxxxx
Subject: [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
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top