1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 299911. Fixed NPE and an unsafe method call.

This commit is contained in:
Sergey Prigogin 2012-08-08 20:41:26 -07:00
parent f122365484
commit 19fe2beaa4
2 changed files with 17 additions and 10 deletions

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
/** /**
@ -70,6 +71,8 @@ public class SizeofCalculator {
public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_long_double;
public final SizeAndAlignment sizeof_complex_long_double; public final SizeAndAlignment sizeof_complex_long_double;
private final IASTTranslationUnit ast;
/** /**
* Returns the default instance of sizeof calculator. The default instance is not aware * Returns the default instance of sizeof calculator. The default instance is not aware
* of the parser configuration and can only calculate sizes that are the same across all * of the parser configuration and can only calculate sizes that are the same across all
@ -80,6 +83,7 @@ public class SizeofCalculator {
} }
public SizeofCalculator(IASTTranslationUnit ast) { public SizeofCalculator(IASTTranslationUnit ast) {
this.ast = ast;
int maxAlignment = 32; int maxAlignment = 32;
Map<String, String> sizeofMacros = new HashMap<String, String>(); Map<String, String> sizeofMacros = new HashMap<String, String>();
for (IASTPreprocessorMacroDefinition macro : ast.getBuiltinMacroDefinitions()) { for (IASTPreprocessorMacroDefinition macro : ast.getBuiltinMacroDefinitions()) {
@ -131,6 +135,7 @@ public class SizeofCalculator {
sizeof_complex_double = null; sizeof_complex_double = null;
sizeof_long_double = null; sizeof_long_double = null;
sizeof_complex_long_double = null; sizeof_complex_long_double = null;
ast = null;
} }
/** /**
@ -246,7 +251,7 @@ public class SizeofCalculator {
IField[] fields; IField[] fields;
if (type instanceof ICPPClassType) { if (type instanceof ICPPClassType) {
ICPPClassType classType = (ICPPClassType) type; ICPPClassType classType = (ICPPClassType) type;
for (ICPPBase base : classType.getBases()) { for (ICPPBase base : ClassTypeHelper.getBases(classType, ast)) {
if (base.isVirtual()) if (base.isVirtual())
return null; // Don't know how to calculate size when there are virtual bases. return null; // Don't know how to calculate size when there are virtual bases.
IBinding baseClass = base.getBaseClass(); IBinding baseClass = base.getBaseClass();
@ -258,14 +263,14 @@ public class SizeofCalculator {
size += info.alignment - (size - 1) % info.alignment - 1 + info.size; size += info.alignment - (size - 1) % info.alignment - 1 + info.size;
if (maxAlignment < info.alignment) if (maxAlignment < info.alignment)
maxAlignment = info.alignment; maxAlignment = info.alignment;
for (ICPPMethod method : classType.getDeclaredMethods()) { for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, ast)) {
if (method.isVirtual()) { if (method.isVirtual()) {
// Don't know how to calculate size when there are virtual functions. // Don't know how to calculate size when there are virtual functions.
return null; return null;
} }
} }
} }
fields = classType.getDeclaredFields(); fields = ClassTypeHelper.getDeclaredFields(classType, ast);
} else { } else {
fields = type.getFields(); fields = type.getFields();
} }

View file

@ -147,14 +147,16 @@ public class EvalTypeId extends CPPEvaluation {
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) { ICPPClassSpecialization within, int maxdepth, IASTNode point) {
ICPPEvaluation[] args = fArguments; ICPPEvaluation[] args = fArguments;
for (int i = 0; i < fArguments.length; i++) { if (fArguments != null) {
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point); for (int i = 0; i < fArguments.length; i++) {
if (arg != fArguments[i]) { ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
if (args == fArguments) { if (arg != fArguments[i]) {
args = new ICPPEvaluation[fArguments.length]; if (args == fArguments) {
System.arraycopy(fArguments, 0, args, 0, fArguments.length); args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
} }
args[i] = arg;
} }
} }
IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);