Finding the class given a CPPASTBaseSpecifier [message #184613] |
Wed, 14 February 2007 08:05  |
Eclipse User |
|
|
|
Hello,
we are developing an application to export information from C++ code. I
therefore made a subclass of the CPPASTVisitor class.
I am stuck trying to export information regarding superclasses. When
visiting a class, I can get its superclasses (if any) by using the
method getBaseSpecifiers(). This returns me instances of class
CPPASTBaseSpecifier.
My problem is that I need to find the actual classes these specifiers
refer to, and I do not know how to go about it. In other words, how to
get to the class (a CPPASTCompositeTypeSpecifier) given a
CPPASTBaseSpecifier ?
Any help would be much appreciated...
--Roel Wuyts
|
|
|
|
|
|
|
Re: Finding the class given a CPPASTBaseSpecifier [message #184993 is a reply to message #184678] |
Fri, 16 February 2007 18:24  |
Eclipse User |
|
|
|
Tim,
I was thinking of something like this:
ICPPASTCompositeTypeSpecifier classSpecifier = getClassSpecifier();
ICPPASTBaseSpecifier[] bases = classSpecifier.getBaseSpecifiers();
for( int i = 0 ; i < bases.length; i++ ) {
IBinding binding = bases[i].getName().resolveBinding();
if( binding instanceof ICPPClassType)
{
IScope scope = ((ICPPClassType)binding).getCompositeScope();
IASTName name = scope.getScopeName();
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier)
{
//name.getParent() is the composite-type-spec that bases[i]
//refers to
}
}
}
Note that I haven't actually tried this, but if it works, then the savings are:
1) you don't need to getAllCompositeTypeSpecifierInTranslationUnit() ;
2) more importantly, you don't need to sp.getName().resolveBinding() on every
single composite-type-spec in the translation unit.
As well, this could use more error checking, resolveBinding() could return an
IProblemBinding which is also a ICPPClassType. getCompositeScope() could return
null.
-Andrew
Tim Wang wrote:
>> If you do need to get back to the composite-type-spec, try
>> classTypeBinding.getCompositeTypeScope().getScopeName(), that might get you
>> back to the IASTName in the composite-type-spec without having to resolve
>> all the other classes in the translation unit.
>
> I didn't quite catch up with you. Could you please give some sample code to
> show how to achieve this?
>
> "Andrew Niefer" <aniefer@ca.ibm.com>
> ??????:eqva7o$1l0$1@utils.eclipse.org...
>> The key point here is the
>> bases[i].getName().resolveBinding()
>>
>> I would hope the rest of this is not necessary since it is doing alot of
>> extra work.
>>
>> The resolveBinding on the name from the base specifier should return you a
>> ICPPClassType. That should hopefully give you all the information you
>> need without going back to the ICPPASTCompositeTypeSpecifier.
>>
>> If you do need to get back to the composite-type-spec, try
>> classTypeBinding.getCompositeTypeScope().getScopeName(), that might get
>> you back to the IASTName in the composite-type-spec without having to
>> resolve all the other classes in the translation unit.
>>
>> -Andrew
>>
>> Tim Wang wrote:
>>> ICPPASTCompositeTypeSpecifier classSpecifier = getClassSpecifier() ;
>>>
>>> List classList = getAllCompositeTypeSpecifierInTranslationUnit() ;
>>>
>>> ICPPASTBaseSpecifier[] bases = classSpecifier.getBaseSpecifiers() ;
>>>
>>> for( int i = 0 ; i < bases.length; i++ ) {
>>>
>>> for( Iterator it = classList.iterator() ; it.hasNext(); ) {
>>>
>>> ICPPASTCompositeTypeSpecifier sp =
>>> (ICPPASTCompositeTypeSpecifier)it.next() ;
>>> if(
>>> sp.getName().resolveBinding().equals(bases[i].getName().reso lveBinding())
>>> ) {
>>> // sp is a immediate base class of classSpecifier
>>> }
>>> }
>>> }
>>>
>>>
>>> "Roel Wuyts" <roel.wuyts@gmail.com>
>>> ??????:eqv1fa$lu3$1@utils.eclipse.org...
>>>> Hello,
>>>>
>>>> we are developing an application to export information from C++ code. I
>>>> therefore made a subclass of the CPPASTVisitor class.
>>>>
>>>> I am stuck trying to export information regarding superclasses. When
>>>> visiting a class, I can get its superclasses (if any) by using the
>>>> method getBaseSpecifiers(). This returns me instances of class
>>>> CPPASTBaseSpecifier.
>>>>
>>>> My problem is that I need to find the actual classes these specifiers
>>>> refer to, and I do not know how to go about it. In other words, how to
>>>> get to the class (a CPPASTCompositeTypeSpecifier) given a
>>>> CPPASTBaseSpecifier ?
>>>>
>>>> Any help would be much appreciated...
>>>>
>>>>
>>>> --Roel Wuyts
>
|
|
|
Powered by
FUDForum. Page generated in 0.04725 seconds