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:
parent
b4b565a872
commit
19836aa78b
2 changed files with 17 additions and 10 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,7 @@ 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;
|
||||||
|
if (fArguments != null) {
|
||||||
for (int i = 0; i < fArguments.length; i++) {
|
for (int i = 0; i < fArguments.length; i++) {
|
||||||
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, maxdepth, point);
|
||||||
if (arg != fArguments[i]) {
|
if (arg != fArguments[i]) {
|
||||||
|
@ -157,6 +158,7 @@ public class EvalTypeId extends CPPEvaluation {
|
||||||
args[i] = arg;
|
args[i] = arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);
|
IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point);
|
||||||
if (args == fArguments && type == fInputType)
|
if (args == fArguments && type == fInputType)
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Add table
Reference in a new issue