How does C++ support create class declarations?

David Nolden zwabel at googlemail.com
Sun Feb 17 23:06:29 UTC 2008


On Sunday 17 February 2008 23:18:17 Andreas Pakulat wrote:
> Hi,
>
> seems I'm still missing a piece here. Looking at C++ highlighting code I
> see this:
>
> if( dec->context()->scopeIdentifier().isEmpty() )
> {
>    type = GlobalVariableType;
> }...
> and I'm wondering why that isn't empty. For Python scopeIdentifier is
> empty, although qualifiedIdentifier of the declaration returns something
> meaningful. I really must be missing something here. Currently what I do
> is:
>
> openContext( astnode, DUContext::Class, identifierForName(
> astnode->className ) );
> addImportedContext();
> openDefinition( astnode->className, astnode );
> ...
>
> which gives me a context with scopeIdentifier "Bar" (using the
> includeClasses option) and a declaration with qualifiedIdentifier
> "Bar::".
>
> So what am I doing wrong, that my declarations context returns "" for
> scopeIdentifier() while obviously that from C++ doesn't. Or is it
> correct in C++ to get a GlobalVariableType for a class Foo {};?
>
> Andreas

I think you are confusing internalContext() and context(). context() is the 
context that surrounds a declaration, so for a global declaration "class Foo 
{};" the context is empty. The context you are creating for the class-content 
should have the same localScopeIdentifier as the class, which in your case 
is "Bar", and should be attached to the Declaration 
using "Declaration::setInternalContext". Then you can get the declaration 
from the context through "DUContext::owner()".

Hope this helped.

Greetings, David




More information about the KDevelop-devel mailing list