Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Finding the class given a CPPASTBaseSpecifier
Finding the class given a CPPASTBaseSpecifier [message #184613] Wed, 14 February 2007 08:05 Go to next message
Eclipse UserFriend
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 #184621 is a reply to message #184613] Wed, 14 February 2007 08:50 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Finding the class given a CPPASTBaseSpecifier [message #184664 is a reply to message #184621] Wed, 14 February 2007 10:35 Go to previous messageGo to next message
Eclipse UserFriend
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
>
>
Re: Finding the class given a CPPASTBaseSpecifier [message #184678 is a reply to message #184664] Wed, 14 February 2007 19:36 Go to previous messageGo to next message
Eclipse UserFriend
>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
>>
Re: Finding the class given a CPPASTBaseSpecifier [message #184820 is a reply to message #184621] Thu, 15 February 2007 15:32 Go to previous messageGo to next message
Eclipse UserFriend
Thanks a lot! Comparing the resolved bindings is indeed what I needed.

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
>
>
Re: Finding the class given a CPPASTBaseSpecifier [message #184993 is a reply to message #184678] Fri, 16 February 2007 18:24 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:Bring back "Open Declaration" please!
Next Topic:Error while installing CDT 4 on Solaris
Goto Forum:
  


Current Time: Thu Jun 12 03:58:42 EDT 2025

Powered by FUDForum. Page generated in 0.04725 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top