Closed
Bug 510212
Opened 16 years ago
Closed 12 years ago
New .hasDefaults property does not seem to work
Categories
(Developer Infrastructure :: Source Code Analysis, defect)
Tracking
(Not tracked)
RESOLVED
WONTFIX
People
(Reporter: dnovillo, Unassigned)
Details
Attachments
(3 files)
|
1.18 KB,
application/x-javascript
|
Details | |
|
1.92 KB,
patch
|
Details | Diff | Splinter Review | |
|
1.47 KB,
patch
|
Details | Diff | Splinter Review |
I have been trying to get at the .hasDefault property for functions, but I can't seem to see it. For this test case:
int foo(int y, long x=42);
int X;
int bar(void)
{
foo(X);
foo(X,X);
}
The attached script does not show hasDefault where I was expecting it (in the params for foo).
| Reporter | ||
Comment 1•16 years ago
|
||
Updated•16 years ago
|
Assignee: tglek → dwitte
Comment 2•16 years ago
|
||
The problem is that dehydra_convertAttachFunctionType(), which adds the default properties (to the decl.type.hasDefault array), gets called once. dehydra_moveDefaults(), which moves those defaults to each parameter in decl.parameters, gets called 3 times... and it removes decl.type.hasDefault when it's done.
I'm guessing that somehow decl.parameters gets overwritten between one of those 3 calls, and hasDefault gets lost. Taras, any ideas?
Comment 3•16 years ago
|
||
(In reply to comment #2)
> I'm guessing that somehow decl.parameters gets overwritten between one of those
> 3 calls, and hasDefault gets lost. Taras, any ideas?
I doubt it's getting overwritten. The problem is that I decided to make decl objects(also known as variables) to be distinct in every use. It seemed like a good idea so one could add attributes, delete stuff, etc without worrying, but now I'm not sure anyone actually benefits from that.
So what i think you are seeing is that the function decl is being used in another context, it steals the defaults array and the next time decls are being created the defaults array is gone.
I think for now the fix is to not destructively move the defaults. In the longer run it probably makes sense to make decls 1:1 with gcc decls just like types are.
Comment 4•16 years ago
|
||
Ok - will whip up a patch.
Comment 5•16 years ago
|
||
Hides the old hasDefaults property, so it won't show up under enumeration in js. Best we can do for now.
This doesn't do anything for function calls, I'll do that separately.
Attachment #394600 -
Flags: review?(tglek)
| Reporter | ||
Comment 6•16 years ago
|
||
This patch makes dehydra recognize arguments using default values. The way it does it is a bit wonky. Particularly how I get to the argument that dehydra_fcallDoArgs builds. What would be a better way to access the object that has just been added to the array of arguments?
The real problem with this approach is that it's not really sufficient to distinguish all uses of default values. The main problem is that the parser never tells us that a CALL_EXPR is using a default value.
When the parser builds a call expression, it checks what arguments are
used by default and if the user didn't specify and argument it puts
the default value in the call. However, it never marks that
replacement, so by the time we see the call expression in dehydra, the
call 'foo()' has been replaced with 'foo(42)' and there is no
indication that '42' has been injected by the parser.
What I've done is inspect the function prototype. If the argument I'm
examining is the same expression as the default argument, then I mark
that argument with the .hasDefault property (meaning that the argument
has the default value). However, this does not necessarily mean that
the user called 'foo()', they could've called 'foo(42)'.
A definitive solution for this involves changing the parser, but at the moment this is not something I can do easily.
Is this acceptable for now?
I now need to figure out how to deal with default arguments in template instantiation.
Comment 7•16 years ago
|
||
(In reply to comment #6)
> Is this acceptable for now?
yes, nice hack. You really need to add testcases, it's really easy, just name your file test/test_*.js and specify some details about it in a comment on top of the file.
Comment 8•16 years ago
|
||
Comment on attachment 394600 [details] [diff] [review]
make hasDefault hidden, v1 (checked in)
Checked in per bug 512887.
Attachment #394600 -
Attachment description: make hasDefault hidden, v1 → make hasDefault hidden, v1 (checked in)
Attachment #394600 -
Flags: review?(tglek)
Comment 9•14 years ago
|
||
Reassigning to nobody. If anyone wants to work on this, feel free!
Assignee: dwitte → nobody
Comment 10•12 years ago
|
||
Dehydra and treehydra are no longer maintained by Mozilla.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
Updated•7 years ago
|
Product: Core → Firefox Build System
Updated•3 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•