mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55:24 +02:00
Fixed an NPE.
Change-Id: I1a1e00b50eefdea775c7d0487250cb62850cf0ec
This commit is contained in:
parent
d8c56b9226
commit
77a506b6b8
1 changed files with 23 additions and 17 deletions
|
@ -36,6 +36,10 @@ public final class CompositeValue implements IValue {
|
||||||
|
|
||||||
public CompositeValue(ICPPEvaluation evaluation, ICPPEvaluation[] values) {
|
public CompositeValue(ICPPEvaluation evaluation, ICPPEvaluation[] values) {
|
||||||
this.evaluation = evaluation;
|
this.evaluation = evaluation;
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
if (values[i] == null)
|
||||||
|
values[i] = EvalFixed.INCOMPLETE;
|
||||||
|
}
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ public final class CompositeValue implements IValue {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation getSubValue(final int index) {
|
public ICPPEvaluation getSubValue(final int index) {
|
||||||
return rangeIsValid(index) && values[index] != null ? values[index] : EvalFixed.INCOMPLETE;
|
return rangeIsValid(index) ? values[index] : EvalFixed.INCOMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean rangeIsValid(int index) {
|
private boolean rangeIsValid(int index) {
|
||||||
|
@ -89,9 +93,10 @@ public final class CompositeValue implements IValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IValue create(EvalInitList initList) {
|
public static IValue create(EvalInitList initList) {
|
||||||
ICPPEvaluation[] values = new ICPPEvaluation[initList.getClauses().length];
|
ICPPEvaluation[] clauses = initList.getClauses();
|
||||||
for (int i = 0; i < initList.getClauses().length; i++) {
|
ICPPEvaluation[] values = new ICPPEvaluation[clauses.length];
|
||||||
ICPPEvaluation eval = initList.getClauses()[i];
|
for (int i = 0; i < clauses.length; i++) {
|
||||||
|
ICPPEvaluation eval = clauses[i];
|
||||||
values[i] = new EvalFixed(eval.getType(null), eval.getValueCategory(null), eval.getValue(null));
|
values[i] = new EvalFixed(eval.getType(null), eval.getValueCategory(null), eval.getValue(null));
|
||||||
}
|
}
|
||||||
return new CompositeValue(initList, values);
|
return new CompositeValue(initList, values);
|
||||||
|
@ -141,9 +146,10 @@ public final class CompositeValue implements IValue {
|
||||||
public static IValue create(EvalInitList initList, ICompositeType type) {
|
public static IValue create(EvalInitList initList, ICompositeType type) {
|
||||||
IField[] fields = type.getFields();
|
IField[] fields = type.getFields();
|
||||||
ICPPEvaluation[] values = new ICPPEvaluation[fields.length];
|
ICPPEvaluation[] values = new ICPPEvaluation[fields.length];
|
||||||
|
ICPPEvaluation[] clauses = initList.getClauses();
|
||||||
for (int i = 0; i < fields.length; i++) {
|
for (int i = 0; i < fields.length; i++) {
|
||||||
IField field = fields[i];
|
IField field = fields[i];
|
||||||
ICPPEvaluation eval = initList.getClauses()[i];
|
ICPPEvaluation eval = clauses[i];
|
||||||
IType fieldType = field.getType();
|
IType fieldType = field.getType();
|
||||||
IValue value = getValue(fieldType, eval);
|
IValue value = getValue(fieldType, eval);
|
||||||
values[i] = new EvalFixed(fieldType, eval.getValueCategory(null), value);
|
values[i] = new EvalFixed(fieldType, eval.getValueCategory(null), value);
|
||||||
|
@ -214,24 +220,20 @@ public final class CompositeValue implements IValue {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSubValue(int position, ICPPEvaluation newValue) {
|
public void setSubValue(int position, ICPPEvaluation newValue) {
|
||||||
values[position] = newValue;
|
values[position] = newValue == null ? EvalFixed.INCOMPLETE : newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("["); //$NON-NLS-1$
|
builder.append('[');
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
if (values[i] != null) {
|
if (i != 0) {
|
||||||
|
builder.append(',').append(' ');
|
||||||
|
}
|
||||||
builder.append(values[i].toString());
|
builder.append(values[i].toString());
|
||||||
} else {
|
|
||||||
builder.append("<null>"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
if (i != values.length-1) {
|
builder.append(']');
|
||||||
builder.append(", "); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.append("]"); //$NON-NLS-1$
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,9 +242,13 @@ public final class CompositeValue implements IValue {
|
||||||
ICPPEvaluation[] newValues = new ICPPEvaluation[values.length];
|
ICPPEvaluation[] newValues = new ICPPEvaluation[values.length];
|
||||||
for (int i = 0; i < newValues.length; i++) {
|
for (int i = 0; i < newValues.length; i++) {
|
||||||
ICPPEvaluation eval = values[i];
|
ICPPEvaluation eval = values[i];
|
||||||
|
if (eval == EvalFixed.INCOMPLETE) {
|
||||||
|
newValues[i] = eval;
|
||||||
|
} else {
|
||||||
IValue newValue = eval.getValue(null).clone();
|
IValue newValue = eval.getValue(null).clone();
|
||||||
newValues[i] = new EvalFixed(eval.getType(null), eval.getValueCategory(null), newValue);
|
newValues[i] = new EvalFixed(eval.getType(null), eval.getValueCategory(null), newValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return new CompositeValue(evaluation, newValues);
|
return new CompositeValue(evaluation, newValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue