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've found another problem which I think is similar to this one. I've raised 401696 to track, but would appreciate it if someone could tell me if it actually isn't a bug. If not then I'll find a different way to do what I'm trying to accomplish.

In this case the empty expansion is lost when it is at the start of the declarator, e.g. in,

	#define X
	#define Y void
	Y X void func1() {}
	X Y void func2() {}

Calling IASTNode.getNodeLocations on the node for func1 will return two macro expansions, but calling it for func2 will return only one.

Stepping through the code for the problem case, it looks like the expansion for X is not being associated with the node at all. I guess that is because there isn't a way to distinguish from this case:

	Y X void func1() {} X
	  Y void func2() {}

?

-Andrew

On 13-01-29 10:42 AM, Andrew Eidsness wrote:
I've raised 339394, I'll add a sample of the problem soon.

Thanks,
-Andrew

On 13-01-29 10:03 AM, Schorn, Markus wrote:
Hi Andrew,
I think you are right, IASTNode.getNodeLocations() should return the
macro expansion, even if it expands to the empty token. Please file a
bug containing a code-snippet that illustrates the problem. I will
look into the issue.
Markus.

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Andrew Eidsness
Sent: Tue, 29. 01. 2013 13:02
To: CDT General developers list.
Subject: 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

_______________________________________________
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