class store revisited
Bernd Gehrmann
Bernd-Gehrmann at gmx.de
Sun May 12 22:10:05 UTC 2002
The class store still has several issues. ClassStore::removeWithReferences()
doesn't work for namespaced classes. For example, if you add something like
"namespace Foo {" at the beginning of a file and a parse happens, all the
classes from that file will appear in that namespace (as expected). But even
if you close the namespace or remove the added string again, the classes will
never disappear again from the classview. Then there is the problem that the
namespace mode of the classview doesn't show the global namespace. This
is because there is no object in the class store representing the global name-
space, and therefore this is non-trivial to implement. A related problem is
that the persistence implementation is wrong in a subtle way: it stores each
namespaced class twice. Worse, if it reloads those classes, they cause memory
leaks.
All these problem are actually closely related in the classstore
implementation and I think I have a clear picture how to solve them. The
main problem is ClassStore::globalContainer which misuses the type
ParsedScopeContainer but is used as a general container for classes etc.
with a different ownership policy than those. I'm sure that few people
understand the hack in ParsedScopeContainer::clear() at all; it has certainly
cost me some time :-)
My plan is as follows:
- There is an object globalScope which represents the global namespace
- *each* class is owned by a namespace object (or a class, for nested
classes). Namespaced classes are in the respective ParsedScopeContainer,
global classes are in globalScope
- additionally, the ClassStore has the variables
QMap<QString, ParsedClassContainer*> allClasses;
QMap<QString, ParsedScopeContainer*> allScopes;
These map from the scoped class name (e.g. "KParts.Part" to the class
object, namespace, resp.). These QMaps are simply a convenient away
to find a class from its name or to get a list of all classes. They are
*not* involved in allocating or deallocating them.
- storing the class store in a file is done by storing globalScope.
It pulls everything into the file recursively.
- restoring the class store from a file is done in two steps: First
globalScope is restored. Then the maps allClasses and allScopes
are created by recursing through the namespace hierarchy.
This has a number of advantages:
- memory management is trivial. Since each class is owned by another
class or a namespace, it is deallocated together with it. There is no
difference between global and namespaced classes.
- fixing the namespace mode of the classview is trivial. It happens
automatically :-)
- the hack ParsedScopeContainer::clear() goes away.
- ParsedScopeContainer::_useFullPath goes away.
- structure easier to understand
- It's more difficult to produce bugs ;-)
I believe that these changes do not need any api changes, so e.g. the
classview code should be mostly unaffected. Neverthess I'd suggest to commit
any modified code before I start :-)
Bernd.
More information about the KDevelop-devel
mailing list