How does C++ support create class declarations?

Andreas Pakulat apaku at gmx.de
Mon Feb 18 18:47:16 UTC 2008


On 18.02.08 00:06:29, David Nolden wrote:
> 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()".

Ok, now I'm totally confused I think :) Or rather classes work quite
differently from functions, I guess...

Maybe some example is better, lets take this:

class Bar:
  pass

I've got the following DUChain:
kdevelop(14055)/kdevelop (python support) Python::DumpChain::dump: "" New Context  "" [ (0, 0)  ->  (23, 0) ]   top-context
kdevelop(14055)/kdevelop (python support) Python::DumpChain::dump: "  " New Context  "Bar" [ (0, 0)  ->  (2, 1) ]
kdevelop(14055)/kdevelop (python support) Python::DumpChain::dump: "    " Declaration:  "<notype> "  [ "Bar::" ]   0x844ef20 (internal ctx 0x0 ) [ (0, 6)  ->  (0, 9) ] ,  defined,  0 use(s)

i.e. there's a Context with localScopeIdentifier "Bar" and inside that
the class declaration and following that would be the body statements.

Or should the Declaration be in the top context and there should be a
context just for the body with the localScopeIdentifier "Bar"?

Andreas

-- 
Hope that the day after you die is a nice day.




More information about the KDevelop-devel mailing list