Bug 159595 - PDOM missing function/variable annotations
Summary: PDOM missing function/variable annotations
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.0 M5   Edit
Assignee: Chris Recoskie CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on: 160692
Blocks:
  Show dependency tree
 
Reported: 2006-10-03 10:47 EDT by Jason Montojo CLA
Modified: 2008-06-20 10:41 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (108.38 KB, patch)
2006-10-11 16:06 EDT, Jason Montojo CLA
no flags Details | Diff
Updated patch (98.56 KB, patch)
2006-10-12 13:08 EDT, Jason Montojo CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Montojo CLA 2006-10-03 10:47:26 EDT
The PDOM currently doesn't store:
    - visibility: public, protected, private
    - storage class: auto, static, extern, mutable, register
    - other annotations inline, const, volatile
    - whether a function accepts varargs

A side effect of this can be seen during content assist, where all methods of Class1 appear public:

class Class1 {
	void f();
public:
	void g();
};

int main() {
	Class1 c;
	c.<invoke content assist here>


Since most of these annotations are boolean flags (except visibility), we could store all these annotations as a bit vector in the database.  2 bits would be enough for visibility, and 9 bits for the other flags, leaving 5 bits for future use.

Thoughts?
Comment 1 Andrew Niefer CLA 2006-10-03 11:13:53 EDT
The private methods showing up in content assist are unrelated to the contents of the PDOM.  Neither the IASTName.resolvePrefix nor the DOMCompletionContributor are filtering the results based on visibility.
Comment 2 Markus Schorn CLA 2006-10-03 12:14:14 EDT
I think storing these properties makes a lot of sense. For implementing the type hierarchy, some of this will be necessary.
Comment 3 Chris Recoskie CLA 2006-10-03 13:13:09 EDT
Jason is going to take a look at this if there are no objections.
Comment 4 Jason Montojo CLA 2006-10-03 13:27:30 EDT
To enable full support for these flags, I'd need to add the bit vector to the following classes:

 - PDOMCField
 - PDOMCFunction
 - PDOMCPPField
 - PDOMCPPFunction
 - PDOMCPPMethod
 - PDOMCPPVariable
 - PDOMCVariable
 - PDOMCPPParameter
 - PDOMPointerType
 - PDOMQualifierType

These classes would share code for storing/retrieving the individual flags.  Their common ancestor is PDOMBinding, but it doesn't seem like a natural place for putting the new code (or is it?).

Another alternative would be to have a utility class with static methods for packing/unpacking the bit fields; but this approach isn't very object oriented.

Does anyone have any preferences about where the new code should live?  Right now, I'm tempted to put it in PDOMBinding.
Comment 5 Doug Schaefer CLA 2006-10-03 15:13:16 EDT
Be careful not to make the PDOM bigger than it has to be. It's already too big. Put new information where it needs to be. If that means duplicating code, then do so while cursing Java's lack of multiple inheritance. I'm getting quite good at it myself. :)
Comment 6 Jason Montojo CLA 2006-10-03 15:39:57 EDT
Thanks for the feedback.  I'm trying as much as possible to minimize the space impact these changes will have.

I analyzed which flags/modifiers apply to which DOM nodes.  isMutable, isDestructor, and isVirtual and visibility (2 bits) only apply to C++ nodes (5 bits total), while the other flags apply to both C and C++ (8 bits total).  So the record sizes of these nodes will grow by 1 byte:

PDOMPointerType
PDOMQualifierType
PDOMCField
PDOMCVariable
PDOMCFunction

... and the sizes of these will grow by 2 bytes:

PDOMCPPVariable
PDOMCPPParameter
PDOMCPPField
PDOMCPPFunction
PDOMCPPMethod

Since space is allocated in the PDOM 16 bytes at a time (if I remember correctly), these changes will only increase the space usage of PDOMCPPFunction
and PDOMCPPMethod.  These nodes currently sit at 16 bytes per record, and they'll increase to 18 bytes (which means 32 bytes per record on disk).

All the other affected nodes are below the 16 byte border.
Comment 7 Jason Montojo CLA 2006-10-03 15:44:34 EDT
Doug, I'm seeing what you mean now about multiple inheritance.  Oh, how I loathe myself for succumbing to Ctrl-V :)
Comment 8 Jason Montojo CLA 2006-10-03 16:10:12 EDT
Hmm... is there a particular reason why PDOMCPPParameter extends PDOMNamedNode instead of PDOMCPPBinding?

I'd prefer to have it extend PDOMCPPBinding so I could reuse some code.  Any objections?
Comment 9 Jason Montojo CLA 2006-10-03 16:17:23 EDT
I think I see why the hierarchy is like that.  PDOMBinding stores declarations, definitions, and references.  Storing that for PDOMCPPParameters too would really bloat the PDOM.  Hmm...
Comment 10 Jason Montojo CLA 2006-10-11 16:06:26 EDT
Created attachment 51801 [details]
Proposed patch

This patch adds CV-qualifiers, storage class specifiers (where allowed by the ISO C/C++ specs) and function/method annotation (takesVarArgs, isDestructor, isVirtual, isInline, isMutable) to the PDOM.
Comment 11 Andrew Ferguson CLA 2006-10-12 05:48:51 EDT
looks good to me :)

one thing though - the overloading tests are giving false positives as they are testing for a single binding for a group of overloaded function/methods. We should have a binding per entity. 

just so you are aware - I've got a fix for the this (156504), and some related unit tests (which don't overlap significantly), but will hold off until this patch is committed as I'll move to using the convenience methods you've added to PDOMTestBase
   https://bugs.eclipse.org/bugs/show_bug.cgi?id=156504

also, I'm still seeing multiple non-deterministic failures due to the remaining race condition (this only happens without the suggested patch). I'm wondering why no one else is seeing these - I'm running under Win2k, so this might be the difference
   https://bugs.eclipse.org/bugs/show_bug.cgi?id=157992
Comment 12 Chris Recoskie CLA 2006-10-12 09:10:14 EDT
I'm going to commit this.  Question:  should we do this for just 4.0 or the 3.1.x branch as well?  I think we're getting borderline with respect to what is a fix versus an enhancement with all of this indexer work.
Comment 13 Jason Montojo CLA 2006-10-12 10:07:42 EDT
I have to rework the patch to incorporate Markus' new API changes.  I'll have a new one ready to go Very Soon(tm) :)
Comment 14 Jason Montojo CLA 2006-10-12 10:11:46 EDT
I'll pull out the misleading overload tests too.  The references/declarations/definitions shouldn't be counted the way I was counting them.
Comment 15 Doug Schaefer CLA 2006-10-12 11:05:54 EDT
Yeah, just do this in HEAD. This is a pretty significant change and I don't think CDT 3.1.2 needs that kind of churn.
Comment 16 Jason Montojo CLA 2006-10-12 13:08:33 EDT
Created attachment 51873 [details]
Updated patch

The (operator/function) overloading tests I'm withholding account for the 10k difference between this patch and the previous one.
Comment 17 Markus Schorn CLA 2006-10-13 04:44:45 EDT
Chris, although this is assigned to you, I have commited the patch because I have another one that makes changes to the PDOM tests. I hope that's ok for you.

Jason, I have integrated the failing tests with the regular ones. The advantage of that is, that you only have to remove the leading underscore to make a regular test case out of them. Please have a look whether this works for you.
Comment 18 Jason Montojo CLA 2006-10-13 09:11:50 EDT
Markus: Thanks very much.  I originally had the failing test cases set to "fail" when the behaviour they test is fixed.  That way, we'd get a reminder to update the test cases.  Anyway, it's fine the way it is now.  We'll just have to remember to remove the underscores once type information gets stored in the PDOM.
Comment 19 Chris Recoskie CLA 2006-10-13 09:15:00 EDT
(In reply to comment #17)
> Chris, although this is assigned to you, I have commited the patch because I
> have another one that makes changes to the PDOM tests. I hope that's ok for
> you.

No problem.  I'll mark this as fixed.
Comment 20 Markus Schorn CLA 2006-10-13 09:45:18 EDT
(In reply to comment #18)
> Markus: Thanks very much.  I originally had the failing test cases set to
> "fail" when the behaviour they test is fixed.  That way, we'd get a reminder > to update the test cases.  

That is still the case, the tests with the leading underscore are run and checked for failure. The method BasicTestCase.suite(Class clazz) does the magic.