mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +02:00
Fixed a ClassCastException.
Change-Id: Ib221d863650b5174f00e25e9dc9ff30c5870047f
This commit is contained in:
parent
0b6dfff78c
commit
aca869c045
2 changed files with 52 additions and 47 deletions
|
@ -265,9 +265,9 @@ public class CPPVariable extends PlatformObject implements ICPPInternalVariable
|
|||
}
|
||||
|
||||
/**
|
||||
* Return an evaluation representing the variable's initialization.
|
||||
* Returns an evaluation representing the variable's initialization.
|
||||
*
|
||||
* If the variable has no initializer, null is returned.
|
||||
* If the variable has no initializer, {@code null} is returned.
|
||||
*/
|
||||
public ICPPEvaluation getInitializerEvaluation() {
|
||||
ICPPASTDeclarator declarator = (ICPPASTDeclarator) findDeclarator();
|
||||
|
@ -297,7 +297,7 @@ public class CPPVariable extends PlatformObject implements ICPPInternalVariable
|
|||
|
||||
private static ICPPConstructor getImplicitlyCalledCtor(ICPPASTDeclarator declarator) {
|
||||
IBinding ctor = CPPSemantics.findImplicitlyCalledConstructor(declarator);
|
||||
if (ctor != null && !EvalUtil.isCompilerGeneratedCtor(ctor)) {
|
||||
if (ctor instanceof ICPPConstructor && !EvalUtil.isCompilerGeneratedCtor(ctor)) {
|
||||
return (ICPPConstructor) ctor;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -3421,60 +3421,65 @@ public class CPPSemantics {
|
|||
return getNestedType(((IPointerType) type).getType(), TDEF | REF | CVTYPE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructor called by a declarator, or {@code null} if no constructor is called.
|
||||
*/
|
||||
public static IBinding findImplicitlyCalledConstructor(final ICPPASTDeclarator declarator) {
|
||||
if (declarator.getNestedDeclarator() != null)
|
||||
return null;
|
||||
IASTDeclarator dtor= ASTQueries.findOutermostDeclarator(declarator);
|
||||
IASTNode parent = dtor.getParent();
|
||||
if (parent instanceof IASTSimpleDeclaration) {
|
||||
final IASTInitializer initializer = dtor.getInitializer();
|
||||
/**
|
||||
* Returns constructor called by a declarator, or {@code null} if no constructor is called.
|
||||
*/
|
||||
public static IBinding findImplicitlyCalledConstructor(final ICPPASTDeclarator declarator) {
|
||||
if (declarator.getNestedDeclarator() != null)
|
||||
return null;
|
||||
IASTDeclarator dtor= ASTQueries.findOutermostDeclarator(declarator);
|
||||
IASTNode parent = dtor.getParent();
|
||||
if (parent instanceof IASTSimpleDeclaration) {
|
||||
final IASTInitializer initializer = dtor.getInitializer();
|
||||
if (initializer == null) {
|
||||
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier();
|
||||
parent = parent.getParent();
|
||||
if (parent instanceof IASTCompositeTypeSpecifier ||
|
||||
declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) {
|
||||
// No initialization is performed for class members and extern declarations
|
||||
// without an initializer.
|
||||
return null;
|
||||
}
|
||||
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier();
|
||||
parent = parent.getParent();
|
||||
if (parent instanceof IASTCompositeTypeSpecifier ||
|
||||
declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) {
|
||||
// No initialization is performed for class members and extern declarations
|
||||
// without an initializer.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return findImplicitlyCalledConstructor(declarator.getName(), initializer);
|
||||
return findImplicitlyCalledConstructor(declarator.getName(), initializer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructor called by a class member initializer in a constructor initializer chain.
|
||||
* Returns {@code null} if no constructor is called.
|
||||
*/
|
||||
public static IBinding findImplicitlyCalledConstructor(ICPPASTConstructorChainInitializer initializer) {
|
||||
return findImplicitlyCalledConstructor(initializer.getMemberInitializerId(), initializer.getInitializer());
|
||||
}
|
||||
/**
|
||||
* Returns constructor called by a class member initializer in a constructor initializer chain.
|
||||
* Returns {@code null} if no constructor is called. Returns a {@link IProblemBinding} if the called
|
||||
* constructor cannot be uniquely resolved.
|
||||
*/
|
||||
public static IBinding findImplicitlyCalledConstructor(ICPPASTConstructorChainInitializer initializer) {
|
||||
return findImplicitlyCalledConstructor(initializer.getMemberInitializerId(), initializer.getInitializer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructor called by a variable declarator or an initializer in a constructor
|
||||
* initializer chain. Returns {@code null} if no constructor is called.
|
||||
*/
|
||||
private static IBinding findImplicitlyCalledConstructor(IASTName name, IASTInitializer initializer) {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (!(binding instanceof ICPPVariable))
|
||||
return null;
|
||||
/**
|
||||
* Returns constructor called by a variable declarator or an initializer in a constructor
|
||||
* initializer chain. Returns {@code null} if no constructor is called.
|
||||
*/
|
||||
private static IBinding findImplicitlyCalledConstructor(IASTName name, IASTInitializer initializer) {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (!(binding instanceof ICPPVariable))
|
||||
return null;
|
||||
|
||||
IType type = ((ICPPVariable) binding).getType();
|
||||
IType type = ((ICPPVariable) binding).getType();
|
||||
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE);
|
||||
if (!(type instanceof ICPPClassType))
|
||||
return null;
|
||||
if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem)
|
||||
return null;
|
||||
if (!(type instanceof ICPPClassType))
|
||||
return null;
|
||||
if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem)
|
||||
return null;
|
||||
|
||||
return findImplicitlyCalledConstructor((ICPPClassType) type, initializer, name);
|
||||
}
|
||||
return findImplicitlyCalledConstructor((ICPPClassType) type, initializer, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor implicitly called by the given expression, or {@code null} if there is no
|
||||
* constructor call, or a {@link IProblemBinding} if the called constructor cannot be uniquely resolved.
|
||||
*/
|
||||
public static IBinding findImplicitlyCalledConstructor(ICPPASTNewExpression expr) {
|
||||
IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE);
|
||||
if (!(type instanceof IPointerType))
|
||||
|
|
Loading…
Add table
Reference in a new issue