When to create Contexts (or: how does C++ do it)
zwabel at googlemail.com
Sun Feb 10 23:23:37 UTC 2008
On Sunday 10 February 2008 23:58:32 Andreas Pakulat wrote:
> 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
> 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)
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.
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.
More information about the KDevelop-devel