Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Finding ICPPClassType for this from the AST

>> Is there a way to find the ICPPClassType of this from the AST in all of the following cases?
>>
>> |class T
>> {
>> void callee();
>> void caller()
>> {
>> this->callee(); // case 1
>> callee(); // case 2
>> T::callee(); // case 3
>> }
>> };|
>>
>> I have the ICPPASTFunctionCallExpression and I’m trying to get the ICPPClassType of this to implement a Content
>> Assistant and a Codan checker.
>>
>
> For case 1, the name of the function call is an 
ICPPASTFieldReference, so I can use the result of getFieldOwner to get 
T.
>>
>> For cases 2 and 3, /if/ the node is a valid function call then I can use ICPPASTExpression.getEvaluation() to get an
>> EvalMemberAccess and then use the owner type to get T.
>>
>> However, I want to use this code as part of a Content Assistant and if the complete function call has not yet been
>> entered, then getEvaluation returns a Problem instead of the EvalMemberAccess. For the same reason, I can’t get the
>> IBinding from the index.
>
> Just as an update.
>
> I'm able to get to the ICPPClassType by navigating parents of the expression to the function definition and then using
> the name of the declarator.

Do you mean "class definition" rather than "function definition"? If so, that is
what I was going to suggest for case 2, though I think you can do it more easily 
by calling CPPVisitor.getContainingScope() for the name, and then walking up 
to parent scopes until you find a class scope.

For case 3, I think you want to get the name 'T' and get the binding for it to
get the class type. Alternatively, if getEvaluation() doesn't return an
EvalMemberAccess, it probably returns an EvalID (off the top of my head,
I haven't checked), and the class should be the EvalID's "name owner".

Regards,
Nate 		 	   		  

Back to the top