Re: [CEDET-devel] support for aliases through using statements
Brought to you by:
zappo
From: Eric M. L. <er...@si...> - 2009-08-29 02:23:38
|
On Fri, 2009-08-28 at 18:13 +0200, David Engster wrote: > Eric M. Ludlam <er...@si...> writes: > > Thus, if you look in this method: > > > > (defmethod semanticdb-typecache-file-tags ((table semanticdb-table)) > > "Update the typecache for TABLE, and return the file-tags. > > File-tags are those that belong to this file only, and excludes > > all included files." > > (let* (;(idx (semanticdb-get-table-index table)) > > (cache (semanticdb-get-typecache table)) > > ) > > > > ;; Make sure our file-tags list is up to date. > > (when (not (oref cache filestream)) > > (let ((tags (semantic-find-tags-by-class 'type table))) > > (when tags > > (setq tags (semanticdb-typecache-safe-tag-list tags table)) > > (oset cache filestream (semanticdb-typecache-merge-streams tags > > nil))))) > > > > ;; Return our cache. > > (oref cache filestream) > > )) > > > > you see the function call `semantic-find-tags-by-class' which is applied > > to the tags in the specified buffer's tags table (derived from the > > sematnicdb table.) My first guess for augmenting this is to add an > > override method like `semanticdb-typecache-find-tags-for-typecache', > > whose default implementation is as written above. > > I'm confused. :-) > > Where should this new override > semanticdb-typecache-find-tags-for-typecache be called? > > > Then, in C/C++, it would also do that line, but also scan through that > > list looking for things to convert into some sort of alias tag. These > > alias tags would then be used in the completion engine in the simplified > > way that typedefs are. (cross fingers.) > > This would still need a dereferencer, right? And this one would still > have to look for TYPE in the aliased namespace? (Which could also be an > alias.) > > I'm not sure if that really would be faster, but maybe I'm just not > understanding it. > > To (hopefully) make things clearer, here's what my code does. Let's take > > namespace foo { > using namespace bar; > } > > When you ask for 'foo::TYPE': > > 1) Find namespace 'foo' (which can be scattered over several files) > 2) Search for all 'using' statements in that namespace. > -> We find 'using namespace bar;' > 3) Go to step 0), but this time search for 'bar::TYPE' > 4) If we find nothing take next 'using' statement. > > -> Do until TYPE is found, or until there are no more using statements. > > If I knew beforehand that 'foo' is an alias for 'bar', I could the skip > the search for using statements, but isn't that pretty fast? I don't > know. I would think that searching for TYPE in the namespace is what > really could be slow, but I don't see how to avoid that. > > BTW, couldn't I create these metatypes also in the dereferencer, after > step 2? Then I would only search for using statements the first time a > type is looked up in an aliased namespace. Hi David, I think I may be missing something from my understanding of the problem. Let me try and sum-up my previous email in a different way. I'm starting with the premise that we want to avoid the searches in a dereferencer. I'm sure the thing you wrote works fine, I'm just optimizing here. In fact, I'm only trying to optimize a single line, which was a global search across all tables. A search is basically a linear scan of all the tags. Not a big deal with small projects. More problematic for a large number of tables. The typecache happens to be a tool that already performs a linear scan of all the tags across all tables, but it tackles the problem via divide/concur/cache mechanism, which makes it faster. The question is then, can we leave special tags behind in the typecache during the scan? I'm not entirely sure after reading your mail. I was hoping something like a typedef could be left behind while building the cache. We would then need a dereferencer for the metatag, but that dereferencer would look just like the typedef one which has no searches in it. The trick is that if you find one of your special namespace entries, it would leave behind something with a name that matches what would be searched for. This tag would be found, and then the dereferences would just return a new name of whatever it referenced. What makes me uncertain if this will work now is that this only works for a fully qualified type. If I understand the problem right, your aliases are for names in the middle of a fully qualified name. As such, I think I may change my mind on a possible solution. Perhaps the typecache instead collect an alias table. The dereferencer could then just scan the table, instead of scanning the entire universe. Perhaps a simple alias table is needed for both the typecache, and the scope. I'm not sure how it all works out. Or perhaps this is a premature optimization, and I'm just speculating. Using ELP in the past has usually been the best thing. You could do before/after runs of the unit test suite, and see what the delta is. That would be easy. Thanks Eric |