How to register uses for declarations which are outside of the current file?

David Nolden david.nolden.kdevelop at art-master.de
Sun Mar 13 19:13:58 UTC 2011


2011/3/13 Sven Brauch <svenbrauch at googlemail.com>:
> Hey,
>
> thank you very much for your reply. That AliasDeclaration thing sounds
> like a very good solution for "from foo import bar".
> There's another case, however; for "import foo", you must actually
> create a new... container object or whatever which is called foo and
> contains all declarations from foo.py. Currently I'm doing this by
> creating a declaration called foo and assigning it the topContext of
> the file I want to import with setInternalContext(). How would you
> reference a declaration in that internal context?

Using setInternalContext for this is not safe, because the
relationship between a declaration and its internal context must be
unique (eg. declaration->internalContext()->owner() == declaration).

However, I think you can simply do this: Create a new declaration and
context named "bar" while importing (associated with each other
through setInternalContext()), and within that context, import the
context containing the actual declarations using
barContext->addImportedParentContext(fooBarContext).

Regarding the referencing of the declarations through "DeclarationId",
this is hard because they cannot be referenced by their path.
Generally, it would be best if this was somehow possible, because
otherwise, the whole symbol-table is somewhat useless. How does python
assign "global" IDs to its objects? Maybe you could just add
"namespace" contexts within each top-context, for example a "bar"
context around the declarations of the "bar" file.

Otherwise, the only solution I see is forcing every DeclarationId to
be "direct" for python declarations. This should be handled in
Declaration::id(), and we could add another 1-bit bool to
DeclarationData to hold this information (see
Declaration::setFinal(bool) as example).

Greetings, David




More information about the KDevelop-devel mailing list