Lines 32-42
Link Here
|
32 |
this.declarationEnd = sourceEnd; |
32 |
this.declarationEnd = sourceEnd; |
33 |
} |
33 |
} |
34 |
|
34 |
|
35 |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, |
35 |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { |
36 |
FlowInfo flowInfo) { |
|
|
37 |
// record variable initialization if any |
36 |
// record variable initialization if any |
38 |
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { |
37 |
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { |
39 |
bits |= IsLocalDeclarationReachable; // only set if actually reached |
38 |
bits |= ASTNode.IsLocalDeclarationReachable; // only set if actually reached |
40 |
} |
39 |
} |
41 |
if (this.initialization == null) { |
40 |
if (this.initialization == null) { |
42 |
return flowInfo; |
41 |
return flowInfo; |
Lines 46-51
Link Here
|
46 |
this.initialization |
45 |
this.initialization |
47 |
.analyseCode(currentScope, flowContext, flowInfo) |
46 |
.analyseCode(currentScope, flowContext, flowInfo) |
48 |
.unconditionalInits(); |
47 |
.unconditionalInits(); |
|
|
48 |
if (!flowInfo.isDefinitelyAssigned(this.binding)){// for local variable debug attributes |
49 |
this.bits |= FirstAssignmentToLocal; |
50 |
} else { |
51 |
this.bits &= ~FirstAssignmentToLocal; // int i = (i = 0); |
52 |
} |
49 |
flowInfo.markAsDefinitelyAssigned(binding); |
53 |
flowInfo.markAsDefinitelyAssigned(binding); |
50 |
if ((this.binding.type.tagBits & TagBits.IsBaseType) == 0) { |
54 |
if ((this.binding.type.tagBits & TagBits.IsBaseType) == 0) { |
51 |
switch(nullStatus) { |
55 |
switch(nullStatus) { |
Lines 89-137
Link Here
|
89 |
return; |
93 |
return; |
90 |
} |
94 |
} |
91 |
int pc = codeStream.position; |
95 |
int pc = codeStream.position; |
92 |
Constant inlinedValue; |
|
|
93 |
|
96 |
|
94 |
// something to initialize? |
97 |
// something to initialize? |
95 |
if (initialization != null) { |
98 |
generateInit: { |
96 |
// initialize to constant value? |
99 |
if (this.initialization == null) |
97 |
if ((inlinedValue = initialization.constant) != Constant.NotAConstant) { |
100 |
break generateInit; |
98 |
// forget initializing unused or final locals set to constant value (final ones are inlined) |
101 |
// forget initializing unused or final locals set to constant value (final ones are inlined) |
99 |
if (binding.resolvedPosition != -1) { // may need to preserve variable |
102 |
if (binding.resolvedPosition < 0) { |
100 |
int initPC = codeStream.position; |
103 |
if (initialization.constant != Constant.NotAConstant) |
101 |
codeStream.generateConstant(inlinedValue, initialization.implicitConversion); |
104 |
break generateInit; |
102 |
codeStream.recordPositionsFrom(initPC, initialization.sourceStart); |
|
|
103 |
codeStream.store(binding, false); |
104 |
binding.recordInitializationStartPC(codeStream.position); |
105 |
// codeStream.lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index |
106 |
// codeStream.lastInitStateIndexWhenAddingInits = -2; // reinitialize add index |
107 |
} |
108 |
} else { // initializing to non-constant value |
109 |
initialization.generateCode(currentScope, codeStream, true); |
110 |
// if binding unused generate then discard the value |
105 |
// if binding unused generate then discard the value |
111 |
if (binding.resolvedPosition != -1) { |
106 |
initialization.generateCode(currentScope, codeStream, false); |
112 |
// 26903, need extra cast to store null in array local var |
107 |
break generateInit; |
113 |
if (binding.type.isArrayType() |
108 |
} |
114 |
&& (initialization.resolvedType == TypeBinding.NULL // arrayLoc = null |
109 |
initialization.generateCode(currentScope, codeStream, true); |
115 |
|| ((initialization instanceof CastExpression) // arrayLoc = (type[])null |
110 |
// 26903, need extra cast to store null in array local var |
116 |
&& (((CastExpression)initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){ |
111 |
if (binding.type.isArrayType() |
117 |
codeStream.checkcast(binding.type); |
112 |
&& (initialization.resolvedType == TypeBinding.NULL // arrayLoc = null |
118 |
} |
113 |
|| ((initialization instanceof CastExpression) // arrayLoc = (type[])null |
119 |
codeStream.store(binding, false); |
114 |
&& (((CastExpression)initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){ |
120 |
if (binding.initializationCount == 0) { |
115 |
codeStream.checkcast(binding.type); |
121 |
/* Variable may have been initialized during the code initializing it |
116 |
} |
122 |
e.g. int i = (i = 1); |
117 |
codeStream.store(binding, false); |
123 |
*/ |
118 |
if ((this.bits & ASTNode.FirstAssignmentToLocal) != 0) { |
124 |
binding.recordInitializationStartPC(codeStream.position); |
119 |
/* Variable may have been initialized during the code initializing it |
125 |
// codeStream.lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index |
120 |
e.g. int i = (i = 1); |
126 |
// codeStream.lastInitStateIndexWhenAddingInits = -2; // reinitialize add index |
121 |
*/ |
127 |
} |
122 |
binding.recordInitializationStartPC(codeStream.position); |
128 |
} else { |
|
|
129 |
if ((binding.type == TypeBinding.LONG) || (binding.type == TypeBinding.DOUBLE)) { |
130 |
codeStream.pop2(); |
131 |
} else { |
132 |
codeStream.pop(); |
133 |
} |
134 |
} |
135 |
} |
123 |
} |
136 |
} |
124 |
} |
137 |
codeStream.recordPositionsFrom(pc, this.sourceStart); |
125 |
codeStream.recordPositionsFrom(pc, this.sourceStart); |