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

Sven Brauch svenbrauch at googlemail.com
Mon Mar 14 16:13:40 UTC 2011


Hi,

I tried wrapping a context around every file, but for some reason that
screws up about everything. So if possible, I'd like to avoid that.
Could you maybe explain again which conditions must be met so a
declaration can be found by findDeclaration()? I tried opening a new
context when processing the import statement, then adding the imported
files top-context into that newly opened one (using
addImportedParentContext), but when doing a search for a declaration
from the added context it apparently still fails. Why?

Bye,
Sven

2011/3/13 Sven Brauch <svenbrauch at googlemail.com>:
> Hi,
>
> okay, I'll change the internalContext thing to what you proposed.
> Sound good and easy to do.
> And yes, I think it's a good idea to wrap every file in a module
> context. If I remember that correctly, that's
> also what Python itself does. It also shouldn't be difficult to implement.
> Did I understand that right: When parsing the file "foo", you would
> first create a Declaration
> (for the module "foo"), and then use the rest of the file as its
> internalContext()?
> That would be easy to import into other files then, I guess.
>
> "Global IDs" for objects...? I don't think there's something like that
> in python. There's no table of functions or such,
> when the code declaring the function is run, the function is created,
> and if some other code
> declares that function too, it's simply overwritten.
>
> Bye,
> Sven
>
> 2011/3/13 David Nolden <david.nolden.kdevelop at art-master.de>:
>> 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