How to differenciate a call to a function from a referencing its address?

View: New views
15 Messages — Rating Filter:   Alert me  

How to differenciate a call to a function from a referencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Let's assume I have a function F().
In the program it can be referenced in this way

void B
{
  void * addr = F; // or &F;
}

How can I differenciate this from the real call to F() using index or AST?

Let's assume I have an IIndexName for B.
I can get the list of enclosed names:

IIndexName funcB = ...
IIndexName[] refs = funcB.getEnclosedNames();
for(IIndexName ref: refs)
{
  IBinding refBinding = index.findBinding(ref);
  if( refBinding instanceof IFunction )
  {
     // How to know that ref is not call?
  }
}

Dmitry
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

RE: How to differenciate a call to a function from areferencing its address?

by Schorn, Markus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Currently you cannot tell the difference. If this is important for you,
please
raise an enhancement request on bugzilla.

Markus.

> -----Original Message-----
> From: cdt-dev-bounces@...
> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> Sent: Wednesday, October 01, 2008 3:59 PM
> To: cdt-dev@...
> Subject: [cdt-dev] How to differenciate a call to a function
> from areferencing its address?
> Importance: Low
>
> Hi,
>
> Let's assume I have a function F().
> In the program it can be referenced in this way
>
> void B
> {
>   void * addr = F; // or &F;
> }
>
> How can I differenciate this from the real call to F() using
> index or AST?
>
> Let's assume I have an IIndexName for B.
> I can get the list of enclosed names:
>
> IIndexName funcB = ...
> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
> ref: refs) {
>   IBinding refBinding = index.findBinding(ref);
>   if( refBinding instanceof IFunction )
>   {
>      // How to know that ref is not call?
>   }
> }
>
> Dmitry
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Re: How to differenciate a call to a function from areferencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it also not possible with AST?
What if F have some arguments? Can I know what actual arguments were
passed to a function?

2008/10/1 Schorn, Markus <Markus.Schorn@...>:

> Currently you cannot tell the difference. If this is important for you,
> please
> raise an enhancement request on bugzilla.
>
> Markus.
>
>> -----Original Message-----
>> From: cdt-dev-bounces@...
>> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> Sent: Wednesday, October 01, 2008 3:59 PM
>> To: cdt-dev@...
>> Subject: [cdt-dev] How to differenciate a call to a function
>> from areferencing its address?
>> Importance: Low
>>
>> Hi,
>>
>> Let's assume I have a function F().
>> In the program it can be referenced in this way
>>
>> void B
>> {
>>   void * addr = F; // or &F;
>> }
>>
>> How can I differenciate this from the real call to F() using
>> index or AST?
>>
>> Let's assume I have an IIndexName for B.
>> I can get the list of enclosed names:
>>
>> IIndexName funcB = ...
>> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
>> ref: refs) {
>>   IBinding refBinding = index.findBinding(ref);
>>   if( refBinding instanceof IFunction )
>>   {
>>      // How to know that ref is not call?
>>   }
>> }
>>
>> Dmitry
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

RE: How to differenciate a call to a function fromareferencing its address?

by Schorn, Markus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The AST contains the entire information. In one case you'd be looking at
a function-call expression (IASTFunctionCallExpression), in the other
there would not be one. You can find the function-call by looking at the
parents of the IASTName, which is the reference to the function. The
arguments are then available via
IASTTFunctionCallExpression.getParameterExpression(). This method should
correctly be called getArgumentExpression().

Markus.

> -----Original Message-----
> From: cdt-dev-bounces@...
> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> Sent: Wednesday, October 01, 2008 5:25 PM
> To: CDT General developers list.
> Subject: Re: [cdt-dev] How to differenciate a call to a
> function fromareferencing its address?
> Importance: Low
>
> Is it also not possible with AST?
> What if F have some arguments? Can I know what actual
> arguments were passed to a function?
>
> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> > Currently you cannot tell the difference. If this is important for
> > you, please raise an enhancement request on bugzilla.
> >
> > Markus.
> >
> >> -----Original Message-----
> >> From: cdt-dev-bounces@...
> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> Sent: Wednesday, October 01, 2008 3:59 PM
> >> To: cdt-dev@...
> >> Subject: [cdt-dev] How to differenciate a call to a function from
> >> areferencing its address?
> >> Importance: Low
> >>
> >> Hi,
> >>
> >> Let's assume I have a function F().
> >> In the program it can be referenced in this way
> >>
> >> void B
> >> {
> >>   void * addr = F; // or &F;
> >> }
> >>
> >> How can I differenciate this from the real call to F()
> using index or
> >> AST?
> >>
> >> Let's assume I have an IIndexName for B.
> >> I can get the list of enclosed names:
> >>
> >> IIndexName funcB = ...
> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
> >> ref: refs) {
> >>   IBinding refBinding = index.findBinding(ref);
> >>   if( refBinding instanceof IFunction )
> >>   {
> >>      // How to know that ref is not call?
> >>   }
> >> }
> >>
> >> Dmitry
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Re: How to differenciate a call to a function fromareferencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

One more question about IASTTFunctionCallExpression.
I cannot figure out how to deal with the arguments of the macro which
is a function-style macro.

struct myStruct
{
  void (*funcPtr)(int v1, intv2);
}

#define NUMBER 10

#define Func( p, v1, v2 ) p->funcPtr(v1, v2)

int main
{
  Func( 5, NUMBER);
}

I'm getting a IASTTFunctionCallExpression for a Func call in main().
Now I need to realize that argument 2 is a macro with name NUMBER.

With IASTTFunctionCallExpression.getParameterExpression() I can get a
list of parameters with values 5 and 10.
With IASTTFunctionCallExpression.getNodeLocations() I can get
IASTMacroExpansionLocation and its nested macros.
In this case, I will get one nested macro (ASTMacroReferenceName in
fact) for NUMBER.

The question is: how to map this ASTMacroReferenceName to a second (or
any other) argument?


2008/10/1 Schorn, Markus <Markus.Schorn@...>:

> The AST contains the entire information. In one case you'd be looking at
> a function-call expression (IASTFunctionCallExpression), in the other
> there would not be one. You can find the function-call by looking at the
> parents of the IASTName, which is the reference to the function. The
> arguments are then available via
> IASTTFunctionCallExpression.getParameterExpression(). This method should
> correctly be called getArgumentExpression().
>
> Markus.
>
>> -----Original Message-----
>> From: cdt-dev-bounces@...
>> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> Sent: Wednesday, October 01, 2008 5:25 PM
>> To: CDT General developers list.
>> Subject: Re: [cdt-dev] How to differenciate a call to a
>> function fromareferencing its address?
>> Importance: Low
>>
>> Is it also not possible with AST?
>> What if F have some arguments? Can I know what actual
>> arguments were passed to a function?
>>
>> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
>> > Currently you cannot tell the difference. If this is important for
>> > you, please raise an enhancement request on bugzilla.
>> >
>> > Markus.
>> >
>> >> -----Original Message-----
>> >> From: cdt-dev-bounces@...
>> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> >> Sent: Wednesday, October 01, 2008 3:59 PM
>> >> To: cdt-dev@...
>> >> Subject: [cdt-dev] How to differenciate a call to a function from
>> >> areferencing its address?
>> >> Importance: Low
>> >>
>> >> Hi,
>> >>
>> >> Let's assume I have a function F().
>> >> In the program it can be referenced in this way
>> >>
>> >> void B
>> >> {
>> >>   void * addr = F; // or &F;
>> >> }
>> >>
>> >> How can I differenciate this from the real call to F()
>> using index or
>> >> AST?
>> >>
>> >> Let's assume I have an IIndexName for B.
>> >> I can get the list of enclosed names:
>> >>
>> >> IIndexName funcB = ...
>> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
>> >> ref: refs) {
>> >>   IBinding refBinding = index.findBinding(ref);
>> >>   if( refBinding instanceof IFunction )
>> >>   {
>> >>      // How to know that ref is not call?
>> >>   }
>> >> }
>> >>
>> >> Dmitry
>> _______________________________________________
>> cdt-dev mailing list
>> cdt-dev@...
>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

RE: How to differenciate a call to a functionfromareferencing its address?

by Schorn, Markus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am uncertain whether I understand your question. When you use
the macro twice, there will simply be a second reference
to the macro.
Markus.

> -----Original Message-----
> From: cdt-dev-bounces@...
> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> Sent: Wednesday, October 15, 2008 11:11 AM
> To: CDT General developers list.
> Subject: Re: [cdt-dev] How to differenciate a call to a
> functionfromareferencing its address?
> Importance: Low
>
> Hi,
>
> One more question about IASTTFunctionCallExpression.
> I cannot figure out how to deal with the arguments of the
> macro which is a function-style macro.
>
> struct myStruct
> {
>   void (*funcPtr)(int v1, intv2);
> }
>
> #define NUMBER 10
>
> #define Func( p, v1, v2 ) p->funcPtr(v1, v2)
>
> int main
> {
>   Func( 5, NUMBER);
> }
>
> I'm getting a IASTTFunctionCallExpression for a Func call in main().
> Now I need to realize that argument 2 is a macro with name NUMBER.
>
> With IASTTFunctionCallExpression.getParameterExpression() I
> can get a list of parameters with values 5 and 10.
> With IASTTFunctionCallExpression.getNodeLocations() I can get
> IASTMacroExpansionLocation and its nested macros.
> In this case, I will get one nested macro (ASTMacroReferenceName in
> fact) for NUMBER.
>
> The question is: how to map this ASTMacroReferenceName to a
> second (or any other) argument?
>
>
> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> > The AST contains the entire information. In one case you'd
> be looking
> > at a function-call expression (IASTFunctionCallExpression), in the
> > other there would not be one. You can find the function-call by
> > looking at the parents of the IASTName, which is the
> reference to the
> > function. The arguments are then available via
> > IASTTFunctionCallExpression.getParameterExpression(). This method
> > should correctly be called getArgumentExpression().
> >
> > Markus.
> >
> >> -----Original Message-----
> >> From: cdt-dev-bounces@...
> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> Sent: Wednesday, October 01, 2008 5:25 PM
> >> To: CDT General developers list.
> >> Subject: Re: [cdt-dev] How to differenciate a call to a function
> >> fromareferencing its address?
> >> Importance: Low
> >>
> >> Is it also not possible with AST?
> >> What if F have some arguments? Can I know what actual
> arguments were
> >> passed to a function?
> >>
> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> >> > Currently you cannot tell the difference. If this is
> important for
> >> > you, please raise an enhancement request on bugzilla.
> >> >
> >> > Markus.
> >> >
> >> >> -----Original Message-----
> >> >> From: cdt-dev-bounces@...
> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> >> Sent: Wednesday, October 01, 2008 3:59 PM
> >> >> To: cdt-dev@...
> >> >> Subject: [cdt-dev] How to differenciate a call to a
> function from
> >> >> areferencing its address?
> >> >> Importance: Low
> >> >>
> >> >> Hi,
> >> >>
> >> >> Let's assume I have a function F().
> >> >> In the program it can be referenced in this way
> >> >>
> >> >> void B
> >> >> {
> >> >>   void * addr = F; // or &F;
> >> >> }
> >> >>
> >> >> How can I differenciate this from the real call to F()
> >> using index or
> >> >> AST?
> >> >>
> >> >> Let's assume I have an IIndexName for B.
> >> >> I can get the list of enclosed names:
> >> >>
> >> >> IIndexName funcB = ...
> >> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
> >> >> ref: refs) {
> >> >>   IBinding refBinding = index.findBinding(ref);
> >> >>   if( refBinding instanceof IFunction )
> >> >>   {
> >> >>      // How to know that ref is not call?
> >> >>   }
> >> >> }
> >> >>
> >> >> Dmitry
> >> _______________________________________________
> >> cdt-dev mailing list
> >> cdt-dev@...
> >> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@...
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Re: How to differenciate a call to a functionfromareferencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need to find out that the second argument of a expression Func( 5,
NUMBER) was NUMBER which is a macro.
I cannot figure out how to do this with AST.

2008/10/15 Schorn, Markus <Markus.Schorn@...>:

> I am uncertain whether I understand your question. When you use
> the macro twice, there will simply be a second reference
> to the macro.
> Markus.
>
>> -----Original Message-----
>> From: cdt-dev-bounces@...
>> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> Sent: Wednesday, October 15, 2008 11:11 AM
>> To: CDT General developers list.
>> Subject: Re: [cdt-dev] How to differenciate a call to a
>> functionfromareferencing its address?
>> Importance: Low
>>
>> Hi,
>>
>> One more question about IASTTFunctionCallExpression.
>> I cannot figure out how to deal with the arguments of the
>> macro which is a function-style macro.
>>
>> struct myStruct
>> {
>>   void (*funcPtr)(int v1, intv2);
>> }
>>
>> #define NUMBER 10
>>
>> #define Func( p, v1, v2 ) p->funcPtr(v1, v2)
>>
>> int main
>> {
>>   Func( 5, NUMBER);
>> }
>>
>> I'm getting a IASTTFunctionCallExpression for a Func call in main().
>> Now I need to realize that argument 2 is a macro with name NUMBER.
>>
>> With IASTTFunctionCallExpression.getParameterExpression() I
>> can get a list of parameters with values 5 and 10.
>> With IASTTFunctionCallExpression.getNodeLocations() I can get
>> IASTMacroExpansionLocation and its nested macros.
>> In this case, I will get one nested macro (ASTMacroReferenceName in
>> fact) for NUMBER.
>>
>> The question is: how to map this ASTMacroReferenceName to a
>> second (or any other) argument?
>>
>>
>> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
>> > The AST contains the entire information. In one case you'd
>> be looking
>> > at a function-call expression (IASTFunctionCallExpression), in the
>> > other there would not be one. You can find the function-call by
>> > looking at the parents of the IASTName, which is the
>> reference to the
>> > function. The arguments are then available via
>> > IASTTFunctionCallExpression.getParameterExpression(). This method
>> > should correctly be called getArgumentExpression().
>> >
>> > Markus.
>> >
>> >> -----Original Message-----
>> >> From: cdt-dev-bounces@...
>> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> >> Sent: Wednesday, October 01, 2008 5:25 PM
>> >> To: CDT General developers list.
>> >> Subject: Re: [cdt-dev] How to differenciate a call to a function
>> >> fromareferencing its address?
>> >> Importance: Low
>> >>
>> >> Is it also not possible with AST?
>> >> What if F have some arguments? Can I know what actual
>> arguments were
>> >> passed to a function?
>> >>
>> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
>> >> > Currently you cannot tell the difference. If this is
>> important for
>> >> > you, please raise an enhancement request on bugzilla.
>> >> >
>> >> > Markus.
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: cdt-dev-bounces@...
>> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> >> >> Sent: Wednesday, October 01, 2008 3:59 PM
>> >> >> To: cdt-dev@...
>> >> >> Subject: [cdt-dev] How to differenciate a call to a
>> function from
>> >> >> areferencing its address?
>> >> >> Importance: Low
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> Let's assume I have a function F().
>> >> >> In the program it can be referenced in this way
>> >> >>
>> >> >> void B
>> >> >> {
>> >> >>   void * addr = F; // or &F;
>> >> >> }
>> >> >>
>> >> >> How can I differenciate this from the real call to F()
>> >> using index or
>> >> >> AST?
>> >> >>
>> >> >> Let's assume I have an IIndexName for B.
>> >> >> I can get the list of enclosed names:
>> >> >>
>> >> >> IIndexName funcB = ...
>> >> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
>> >> >> ref: refs) {
>> >> >>   IBinding refBinding = index.findBinding(ref);
>> >> >>   if( refBinding instanceof IFunction )
>> >> >>   {
>> >> >>      // How to know that ref is not call?
>> >> >>   }
>> >> >> }
>> >> >>
>> >> >> Dmitry
>> >> _______________________________________________
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

RE: How to differenciate a call to afunctionfromareferencing its address?

by Schorn, Markus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Func(5, NUMBER) is not an expression, it is a macro-expansion.
The arguments to a macro-expansion are sequences of tokens. These
token-sequences can be used in different ways. The may or may not
be subject for recursive expansion.

Example:
#define USE(x, y) x + x##y + y
#define A 1
#define B 2
USE(A, B);  // expands to 1 + AB + 2

If you have a nested macro expansion (as 'NUMBER' is in your example)
you can ask for the image-location of this macro reference
(IASTName.getImageLocation()) which will tell you where the nested
expansion comes from (in your case it will be an image-location with
kind==ARGUMENT_TO_MACRO_EXPANSION).

Markus.

> -----Original Message-----
> From: cdt-dev-bounces@...
> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> Sent: Wednesday, October 15, 2008 11:42 AM
> To: CDT General developers list.
> Subject: Re: [cdt-dev] How to differenciate a call to
> afunctionfromareferencing its address?
> Importance: Low
>
> I need to find out that the second argument of a expression Func( 5,
> NUMBER) was NUMBER which is a macro.
> I cannot figure out how to do this with AST.
>
> 2008/10/15 Schorn, Markus <Markus.Schorn@...>:
> > I am uncertain whether I understand your question. When you use the
> > macro twice, there will simply be a second reference to the macro.
> > Markus.
> >
> >> -----Original Message-----
> >> From: cdt-dev-bounces@...
> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> Sent: Wednesday, October 15, 2008 11:11 AM
> >> To: CDT General developers list.
> >> Subject: Re: [cdt-dev] How to differenciate a call to a
> >> functionfromareferencing its address?
> >> Importance: Low
> >>
> >> Hi,
> >>
> >> One more question about IASTTFunctionCallExpression.
> >> I cannot figure out how to deal with the arguments of the
> macro which
> >> is a function-style macro.
> >>
> >> struct myStruct
> >> {
> >>   void (*funcPtr)(int v1, intv2);
> >> }
> >>
> >> #define NUMBER 10
> >>
> >> #define Func( p, v1, v2 ) p->funcPtr(v1, v2)
> >>
> >> int main
> >> {
> >>   Func( 5, NUMBER);
> >> }
> >>
> >> I'm getting a IASTTFunctionCallExpression for a Func call
> in main().
> >> Now I need to realize that argument 2 is a macro with name NUMBER.
> >>
> >> With IASTTFunctionCallExpression.getParameterExpression()
> I can get a
> >> list of parameters with values 5 and 10.
> >> With IASTTFunctionCallExpression.getNodeLocations() I can get
> >> IASTMacroExpansionLocation and its nested macros.
> >> In this case, I will get one nested macro (ASTMacroReferenceName in
> >> fact) for NUMBER.
> >>
> >> The question is: how to map this ASTMacroReferenceName to a second
> >> (or any other) argument?
> >>
> >>
> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> >> > The AST contains the entire information. In one case you'd
> >> be looking
> >> > at a function-call expression
> (IASTFunctionCallExpression), in the
> >> > other there would not be one. You can find the function-call by
> >> > looking at the parents of the IASTName, which is the
> >> reference to the
> >> > function. The arguments are then available via
> >> > IASTTFunctionCallExpression.getParameterExpression().
> This method
> >> > should correctly be called getArgumentExpression().
> >> >
> >> > Markus.
> >> >
> >> >> -----Original Message-----
> >> >> From: cdt-dev-bounces@...
> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> >> Sent: Wednesday, October 01, 2008 5:25 PM
> >> >> To: CDT General developers list.
> >> >> Subject: Re: [cdt-dev] How to differenciate a call to a
> function
> >> >> fromareferencing its address?
> >> >> Importance: Low
> >> >>
> >> >> Is it also not possible with AST?
> >> >> What if F have some arguments? Can I know what actual
> >> arguments were
> >> >> passed to a function?
> >> >>
> >> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> >> >> > Currently you cannot tell the difference. If this is
> >> important for
> >> >> > you, please raise an enhancement request on bugzilla.
> >> >> >
> >> >> > Markus.
> >> >> >
> >> >> >> -----Original Message-----
> >> >> >> From: cdt-dev-bounces@...
> >> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry
> >> >> >> Smirnov
> >> >> >> Sent: Wednesday, October 01, 2008 3:59 PM
> >> >> >> To: cdt-dev@...
> >> >> >> Subject: [cdt-dev] How to differenciate a call to a
> >> function from
> >> >> >> areferencing its address?
> >> >> >> Importance: Low
> >> >> >>
> >> >> >> Hi,
> >> >> >>
> >> >> >> Let's assume I have a function F().
> >> >> >> In the program it can be referenced in this way
> >> >> >>
> >> >> >> void B
> >> >> >> {
> >> >> >>   void * addr = F; // or &F;
> >> >> >> }
> >> >> >>
> >> >> >> How can I differenciate this from the real call to F()
> >> >> using index or
> >> >> >> AST?
> >> >> >>
> >> >> >> Let's assume I have an IIndexName for B.
> >> >> >> I can get the list of enclosed names:
> >> >> >>
> >> >> >> IIndexName funcB = ...
> >> >> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
> >> >> >> ref: refs) {
> >> >> >>   IBinding refBinding = index.findBinding(ref);
> >> >> >>   if( refBinding instanceof IFunction )
> >> >> >>   {
> >> >> >>      // How to know that ref is not call?
> >> >> >>   }
> >> >> >> }
> >> >> >>
> >> >> >> Dmitry
> >> >> _______________________________________________
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Re: How to differenciate a call to afunctionfromareferencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, it is simple. Thanks.
But how can I know that NUMBER was second and not first argument for
macro expansion?



2008/10/15 Schorn, Markus <Markus.Schorn@...>:

> Func(5, NUMBER) is not an expression, it is a macro-expansion.
> The arguments to a macro-expansion are sequences of tokens. These
> token-sequences can be used in different ways. The may or may not
> be subject for recursive expansion.
>
> Example:
> #define USE(x, y) x + x##y + y
> #define A 1
> #define B 2
> USE(A, B);  // expands to 1 + AB + 2
>
> If you have a nested macro expansion (as 'NUMBER' is in your example)
> you can ask for the image-location of this macro reference
> (IASTName.getImageLocation()) which will tell you where the nested
> expansion comes from (in your case it will be an image-location with
> kind==ARGUMENT_TO_MACRO_EXPANSION).
>
> Markus.
>
>> -----Original Message-----
>> From: cdt-dev-bounces@...
>> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> Sent: Wednesday, October 15, 2008 11:42 AM
>> To: CDT General developers list.
>> Subject: Re: [cdt-dev] How to differenciate a call to
>> afunctionfromareferencing its address?
>> Importance: Low
>>
>> I need to find out that the second argument of a expression Func( 5,
>> NUMBER) was NUMBER which is a macro.
>> I cannot figure out how to do this with AST.
>>
>> 2008/10/15 Schorn, Markus <Markus.Schorn@...>:
>> > I am uncertain whether I understand your question. When you use the
>> > macro twice, there will simply be a second reference to the macro.
>> > Markus.
>> >
>> >> -----Original Message-----
>> >> From: cdt-dev-bounces@...
>> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> >> Sent: Wednesday, October 15, 2008 11:11 AM
>> >> To: CDT General developers list.
>> >> Subject: Re: [cdt-dev] How to differenciate a call to a
>> >> functionfromareferencing its address?
>> >> Importance: Low
>> >>
>> >> Hi,
>> >>
>> >> One more question about IASTTFunctionCallExpression.
>> >> I cannot figure out how to deal with the arguments of the
>> macro which
>> >> is a function-style macro.
>> >>
>> >> struct myStruct
>> >> {
>> >>   void (*funcPtr)(int v1, intv2);
>> >> }
>> >>
>> >> #define NUMBER 10
>> >>
>> >> #define Func( p, v1, v2 ) p->funcPtr(v1, v2)
>> >>
>> >> int main
>> >> {
>> >>   Func( 5, NUMBER);
>> >> }
>> >>
>> >> I'm getting a IASTTFunctionCallExpression for a Func call
>> in main().
>> >> Now I need to realize that argument 2 is a macro with name NUMBER.
>> >>
>> >> With IASTTFunctionCallExpression.getParameterExpression()
>> I can get a
>> >> list of parameters with values 5 and 10.
>> >> With IASTTFunctionCallExpression.getNodeLocations() I can get
>> >> IASTMacroExpansionLocation and its nested macros.
>> >> In this case, I will get one nested macro (ASTMacroReferenceName in
>> >> fact) for NUMBER.
>> >>
>> >> The question is: how to map this ASTMacroReferenceName to a second
>> >> (or any other) argument?
>> >>
>> >>
>> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
>> >> > The AST contains the entire information. In one case you'd
>> >> be looking
>> >> > at a function-call expression
>> (IASTFunctionCallExpression), in the
>> >> > other there would not be one. You can find the function-call by
>> >> > looking at the parents of the IASTName, which is the
>> >> reference to the
>> >> > function. The arguments are then available via
>> >> > IASTTFunctionCallExpression.getParameterExpression().
>> This method
>> >> > should correctly be called getArgumentExpression().
>> >> >
>> >> > Markus.
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: cdt-dev-bounces@...
>> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
>> >> >> Sent: Wednesday, October 01, 2008 5:25 PM
>> >> >> To: CDT General developers list.
>> >> >> Subject: Re: [cdt-dev] How to differenciate a call to a
>> function
>> >> >> fromareferencing its address?
>> >> >> Importance: Low
>> >> >>
>> >> >> Is it also not possible with AST?
>> >> >> What if F have some arguments? Can I know what actual
>> >> arguments were
>> >> >> passed to a function?
>> >> >>
>> >> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
>> >> >> > Currently you cannot tell the difference. If this is
>> >> important for
>> >> >> > you, please raise an enhancement request on bugzilla.
>> >> >> >
>> >> >> > Markus.
>> >> >> >
>> >> >> >> -----Original Message-----
>> >> >> >> From: cdt-dev-bounces@...
>> >> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry
>> >> >> >> Smirnov
>> >> >> >> Sent: Wednesday, October 01, 2008 3:59 PM
>> >> >> >> To: cdt-dev@...
>> >> >> >> Subject: [cdt-dev] How to differenciate a call to a
>> >> function from
>> >> >> >> areferencing its address?
>> >> >> >> Importance: Low
>> >> >> >>
>> >> >> >> Hi,
>> >> >> >>
>> >> >> >> Let's assume I have a function F().
>> >> >> >> In the program it can be referenced in this way
>> >> >> >>
>> >> >> >> void B
>> >> >> >> {
>> >> >> >>   void * addr = F; // or &F;
>> >> >> >> }
>> >> >> >>
>> >> >> >> How can I differenciate this from the real call to F()
>> >> >> using index or
>> >> >> >> AST?
>> >> >> >>
>> >> >> >> Let's assume I have an IIndexName for B.
>> >> >> >> I can get the list of enclosed names:
>> >> >> >>
>> >> >> >> IIndexName funcB = ...
>> >> >> >> IIndexName[] refs = funcB.getEnclosedNames(); for(IIndexName
>> >> >> >> ref: refs) {
>> >> >> >>   IBinding refBinding = index.findBinding(ref);
>> >> >> >>   if( refBinding instanceof IFunction )
>> >> >> >>   {
>> >> >> >>      // How to know that ref is not call?
>> >> >> >>   }
>> >> >> >> }
>> >> >> >>
>> >> >> >> Dmitry
>> >> >> _______________________________________________
>> _______________________________________________
>> cdt-dev mailing list
>> cdt-dev@...
>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

RE: How to differenciate a call toafunctionfromareferencing its address?

by Schorn, Markus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The AST does not directly provide this information. All you can find
out is the file-location of the argument (the image-location is a
file-location).
Markus.

> -----Original Message-----
> From: cdt-dev-bounces@...
> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> Sent: Wednesday, October 15, 2008 2:33 PM
> To: CDT General developers list.
> Subject: Re: [cdt-dev] How to differenciate a call
> toafunctionfromareferencing its address?
> Importance: Low
>
> Ok, it is simple. Thanks.
> But how can I know that NUMBER was second and not first
> argument for macro expansion?
>
>
>
> 2008/10/15 Schorn, Markus <Markus.Schorn@...>:
> > Func(5, NUMBER) is not an expression, it is a macro-expansion.
> > The arguments to a macro-expansion are sequences of tokens. These
> > token-sequences can be used in different ways. The may or
> may not be
> > subject for recursive expansion.
> >
> > Example:
> > #define USE(x, y) x + x##y + y
> > #define A 1
> > #define B 2
> > USE(A, B);  // expands to 1 + AB + 2
> >
> > If you have a nested macro expansion (as 'NUMBER' is in
> your example)
> > you can ask for the image-location of this macro reference
> > (IASTName.getImageLocation()) which will tell you where the nested
> > expansion comes from (in your case it will be an
> image-location with
> > kind==ARGUMENT_TO_MACRO_EXPANSION).
> >
> > Markus.
> >
> >> -----Original Message-----
> >> From: cdt-dev-bounces@...
> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> Sent: Wednesday, October 15, 2008 11:42 AM
> >> To: CDT General developers list.
> >> Subject: Re: [cdt-dev] How to differenciate a call to
> >> afunctionfromareferencing its address?
> >> Importance: Low
> >>
> >> I need to find out that the second argument of a
> expression Func( 5,
> >> NUMBER) was NUMBER which is a macro.
> >> I cannot figure out how to do this with AST.
> >>
> >> 2008/10/15 Schorn, Markus <Markus.Schorn@...>:
> >> > I am uncertain whether I understand your question. When
> you use the
> >> > macro twice, there will simply be a second reference to
> the macro.
> >> > Markus.
> >> >
> >> >> -----Original Message-----
> >> >> From: cdt-dev-bounces@...
> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry Smirnov
> >> >> Sent: Wednesday, October 15, 2008 11:11 AM
> >> >> To: CDT General developers list.
> >> >> Subject: Re: [cdt-dev] How to differenciate a call to a
> >> >> functionfromareferencing its address?
> >> >> Importance: Low
> >> >>
> >> >> Hi,
> >> >>
> >> >> One more question about IASTTFunctionCallExpression.
> >> >> I cannot figure out how to deal with the arguments of the
> >> macro which
> >> >> is a function-style macro.
> >> >>
> >> >> struct myStruct
> >> >> {
> >> >>   void (*funcPtr)(int v1, intv2);
> >> >> }
> >> >>
> >> >> #define NUMBER 10
> >> >>
> >> >> #define Func( p, v1, v2 ) p->funcPtr(v1, v2)
> >> >>
> >> >> int main
> >> >> {
> >> >>   Func( 5, NUMBER);
> >> >> }
> >> >>
> >> >> I'm getting a IASTTFunctionCallExpression for a Func call
> >> in main().
> >> >> Now I need to realize that argument 2 is a macro with
> name NUMBER.
> >> >>
> >> >> With IASTTFunctionCallExpression.getParameterExpression()
> >> I can get a
> >> >> list of parameters with values 5 and 10.
> >> >> With IASTTFunctionCallExpression.getNodeLocations() I can get
> >> >> IASTMacroExpansionLocation and its nested macros.
> >> >> In this case, I will get one nested macro
> (ASTMacroReferenceName
> >> >> in
> >> >> fact) for NUMBER.
> >> >>
> >> >> The question is: how to map this ASTMacroReferenceName
> to a second
> >> >> (or any other) argument?
> >> >>
> >> >>
> >> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> >> >> > The AST contains the entire information. In one case you'd
> >> >> be looking
> >> >> > at a function-call expression
> >> (IASTFunctionCallExpression), in the
> >> >> > other there would not be one. You can find the
> function-call by
> >> >> > looking at the parents of the IASTName, which is the
> >> >> reference to the
> >> >> > function. The arguments are then available via
> >> >> > IASTTFunctionCallExpression.getParameterExpression().
> >> This method
> >> >> > should correctly be called getArgumentExpression().
> >> >> >
> >> >> > Markus.
> >> >> >
> >> >> >> -----Original Message-----
> >> >> >> From: cdt-dev-bounces@...
> >> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry
> >> >> >> Smirnov
> >> >> >> Sent: Wednesday, October 01, 2008 5:25 PM
> >> >> >> To: CDT General developers list.
> >> >> >> Subject: Re: [cdt-dev] How to differenciate a call to a
> >> function
> >> >> >> fromareferencing its address?
> >> >> >> Importance: Low
> >> >> >>
> >> >> >> Is it also not possible with AST?
> >> >> >> What if F have some arguments? Can I know what actual
> >> >> arguments were
> >> >> >> passed to a function?
> >> >> >>
> >> >> >> 2008/10/1 Schorn, Markus <Markus.Schorn@...>:
> >> >> >> > Currently you cannot tell the difference. If this is
> >> >> important for
> >> >> >> > you, please raise an enhancement request on bugzilla.
> >> >> >> >
> >> >> >> > Markus.
> >> >> >> >
> >> >> >> >> -----Original Message-----
> >> >> >> >> From: cdt-dev-bounces@...
> >> >> >> >> [mailto:cdt-dev-bounces@...] On Behalf Of Dmitry
> >> >> >> >> Smirnov
> >> >> >> >> Sent: Wednesday, October 01, 2008 3:59 PM
> >> >> >> >> To: cdt-dev@...
> >> >> >> >> Subject: [cdt-dev] How to differenciate a call to a
> >> >> function from
> >> >> >> >> areferencing its address?
> >> >> >> >> Importance: Low
> >> >> >> >>
> >> >> >> >> Hi,
> >> >> >> >>
> >> >> >> >> Let's assume I have a function F().
> >> >> >> >> In the program it can be referenced in this way
> >> >> >> >>
> >> >> >> >> void B
> >> >> >> >> {
> >> >> >> >>   void * addr = F; // or &F; }
> >> >> >> >>
> >> >> >> >> How can I differenciate this from the real call to F()
> >> >> >> using index or
> >> >> >> >> AST?
> >> >> >> >>
> >> >> >> >> Let's assume I have an IIndexName for B.
> >> >> >> >> I can get the list of enclosed names:
> >> >> >> >>
> >> >> >> >> IIndexName funcB = ...
> >> >> >> >> IIndexName[] refs = funcB.getEnclosedNames();
> for(IIndexName
> >> >> >> >> ref: refs) {
> >> >> >> >>   IBinding refBinding = index.findBinding(ref);
> >> >> >> >>   if( refBinding instanceof IFunction )
> >> >> >> >>   {
> >> >> >> >>      // How to know that ref is not call?
> >> >> >> >>   }
> >> >> >> >> }
> >> >> >> >>
> >> >> >> >> Dmitry
> >> >> >> _______________________________________________
> >> _______________________________________________
> >> cdt-dev mailing list
> >> cdt-dev@...
> >> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@...
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@...
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
_______________________________________________
cdt-dev mailing list
cdt-dev@...
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Re: How to differenciate a call toafunctionfromareferencing its address?

by Dmitry Smirnov-3 :: Rate this Message:

Reply to Author