On Sunday 02 March 2003 12:59 pm, Chris Pickett wrote:
I actually don't want to do anything if the variable has not been
initialized, except to increment the store counter for that variable. I
can't add code to initialize the variable before I test, because if I
did it might give a false silent store when really it's just the
initialization of a variable.
I think I understand what you mean. Here's how I would do that:
For each variable v in your program, add a boolean flag initialized_v as
variable.
For each local variable, add a statement at the beginning of its method that
sets initialized_v to false. For each field, add such a statement to the
constructor or initializer, before all other statements.
Add statements that set initialized_v to true wherever you find a statement
that defines v. You can then use initialized_v to do the test you described.
You may have to be careful with your Java compiler: I think Java compilers are
allowed to reuse local variables (which means that two variables in your Java
source might be one variable in the bytecode).
Yes, I just thought of the same thing :-) Except I'm not sure that the
code will verify because the vm might not be smart enough to detect that
it's been initialized on all paths even if protected by that flag (I
just had the same problem in the actual transformer, but in that case
it was okay to initialize the variables even if those initial values
would never be used). I'll try it and let you know (maybe not today).