When to create Contexts (or: how does C++ do it)

Andreas Pakulat apaku at gmx.de
Mon Feb 11 00:05:56 UTC 2008


On 11.02.08 00:23:37, David Nolden wrote:
> On Sunday 10 February 2008 23:58:32 Andreas Pakulat wrote:
> > Hi,
> >
> > I'm looking at the visitFunctionDefinition/Declaration code in C++
> > contextbuilder and am wondering about something:
> >
> > What range does the created context cover? If I'm not completely wrong
> > there's only 1 context opened for a function definition, thats the one
> > for its content.
> >
> > If thats true: Why is there no context for the functions parameters?
> > Aren't that also declarations which would need a context? Or how is that
> > done?
> >
> > I'm mostly wondering because in the visitForStatement there's a separate
> > context for the init/end/step part, i.e. the actual looping conditions.
> > And of course the other one that covers the body of the for (importing
> > the first one)
> >
> > Andreas
> 
> Here's how it works in C++:
> For function-declarations, there is always one context created for the 
> parameters. That context has type DUContext::Function. If the 
> function-declaration has a body, another context is created for the body. 
> Such code-context always have type DUContext::Other. The body context then 
> imports the function-cotext, so the parameters are visible from within it.
> 
> Furthermore, in class function-definitions, the function parameter context 
> imports the class-context, so the content of the class is visible in that 
> context, as well as in the body.

Ok, makes sense, so I'm missing something.

> Maybe you just didn't see the place where the function-parameter contexts are 
> created? The AST walking stuff is sometimes really hard to follow.

Indeed. If I see this correctly the creation of the context for a
function is inside typebuilder.cpp in the visitDeclarator() method.
Which kind of makes sense as a function can be used as type in C++.

Hmm, actually thats true as well for Python...

So, just to make sure I didn't miss something, the visitor-hierarchy
used for context and declaration creation is:

ContextBuilder
|
Typebuilder
|
DeclarationBuilder

right?

Andreas

-- 
You will gain money by a speculation or lottery.




More information about the KDevelop-devel mailing list