Closed Bug 551286 Opened 14 years ago Closed 14 years ago

A per function "Final" keyword for C++ code

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: MikeK, Assigned: jdm)

References

Details

Attachments

(1 file, 1 obsolete file)

Sometimes we have virtual functions (from interfaces) that have their final implementation in some class, it is currently not possible to prevent these from being overridden by child classes.

It has been proposed that the "virtual" could be removed, that would mean a new version of the NS_IMETHOD prefix, and some people might fail to realize that what they think is the overriding version isn't actually overriding anything...
While I think this is a good thing, it wouldn't make any sense to remove the `virtual`. Once a method is virtual, it's always virtual.
Just another reason to abandon that solution ;)
First pass at this.  For every function member of a class, all matching ancestor functions are checked for NS_FINAL annotations.
Assignee: nobody → josh
Attachment #431604 - Flags: review?
Attachment #431604 - Flags: review? → review?(tglek)
Needs tests... see xpcom/tests/static-checker for many examples.
Flags: in-testsuite?
Comment on attachment 431604 [details] [diff] [review]
Analysis pass for overriding functions marked NS_FINAL

Josh,
This is pretty good but needs testcases. Your choice of hooking at process_function level rather than process_decl is interesting, it might be more efficient.
Please add the functionality to final.js from bug 425454 instead of adding a new file.


>diff --git a/xpcom/analysis/final-function.js b/xpcom/analysis/final-function.js
>+function ancestorTypes(c)
>+{
>+  ancestors = Array();
>+  for each (let base in c.bases) {
>+      ancestors.concat(ancestorTypes(base.type));
>+      ancestors.push(base.type);
>+  }
>+  return ancestors;
>+}

This is much neater with yield, see http://hg.mozilla.org/mozilla-central/file/c04fe347f85d/xpcom/analysis/override.js

Thanks for the quick patch
Attachment #431604 - Flags: review?(tglek) → review-
(In reply to comment #5)
> >+function ancestorTypes(c)
> >+{
> >+  ancestors = Array();

This is cool stuff, great to see this kind of analysis emerge.

Agree on using a generator, but I wanted to leave a tiny drive-by nit about preferring [] to Array() or new Array(). Less spoofable or (to be fair) monkey-patchable, because [] uses the original value of the Array property of the global object, and more optimizable (and optimized in practice).

/be
Now integrated with the existing NS_FINAL pass, and 100% more tests.
Attachment #431604 - Attachment is obsolete: true
Attachment #431826 - Flags: review?(tglek)
Comment on attachment 431826 [details] [diff] [review]
Analysis pass for overriding functions marked NS_FINAL v2

nice!
Attachment #431826 - Flags: review?(tglek) → review+
Keywords: checkin-needed
http://hg.mozilla.org/mozilla-central/rev/f07fe9c3a1a7
Status: NEW → RESOLVED
Closed: 14 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: