mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
- types of conditional, new & delete expressions
- handle typedefs in conversions for bug 96655
This commit is contained in:
parent
8206cea697
commit
353cad011a
3 changed files with 44 additions and 3 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||||
|
@ -752,6 +753,13 @@ public class CVisitor {
|
||||||
if( st instanceof IASTExpressionStatement )
|
if( st instanceof IASTExpressionStatement )
|
||||||
return getExpressionType( ((IASTExpressionStatement)st).getExpression() );
|
return getExpressionType( ((IASTExpressionStatement)st).getExpression() );
|
||||||
}
|
}
|
||||||
|
} else if( expression instanceof IASTConditionalExpression ){
|
||||||
|
IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
|
||||||
|
IType t2 = getExpressionType( conditional.getPositiveResultExpression() );
|
||||||
|
IType t3 = getExpressionType( conditional.getNegativeResultExpression() );
|
||||||
|
if( t3 instanceof IPointerType || t2 == null )
|
||||||
|
return t3;
|
||||||
|
return t2;
|
||||||
}
|
}
|
||||||
} catch( DOMException e ){
|
} catch( DOMException e ){
|
||||||
return e.getProblem();
|
return e.getProblem();
|
||||||
|
|
|
@ -2737,7 +2737,10 @@ public class CPPSemantics {
|
||||||
IType sPrev = src;
|
IType sPrev = src;
|
||||||
while( sPrev instanceof ITypeContainer ){
|
while( sPrev instanceof ITypeContainer ){
|
||||||
IType next = ((ITypeContainer)sPrev).getType();
|
IType next = ((ITypeContainer)sPrev).getType();
|
||||||
if( next == s || (next instanceof IQualifierType && ((IQualifierType)next).getType() == s ) )
|
while( next instanceof IQualifierType || next instanceof ITypedef ){
|
||||||
|
next = ((ITypeContainer)next).getType();
|
||||||
|
}
|
||||||
|
if( next == s )
|
||||||
break;
|
break;
|
||||||
sPrev = next;
|
sPrev = next;
|
||||||
}
|
}
|
||||||
|
@ -2757,7 +2760,10 @@ public class CPPSemantics {
|
||||||
IType tPrev = trg;
|
IType tPrev = trg;
|
||||||
while( tPrev instanceof ITypeContainer ){
|
while( tPrev instanceof ITypeContainer ){
|
||||||
IType next = ((ITypeContainer)tPrev).getType();
|
IType next = ((ITypeContainer)tPrev).getType();
|
||||||
if( next == t || (next instanceof IQualifierType && ((IQualifierType)next).getType() == t ) )
|
while( next instanceof IQualifierType || next instanceof ITypedef ){
|
||||||
|
next = ((ITypeContainer)next).getType();
|
||||||
|
}
|
||||||
|
if( next == t )
|
||||||
break;
|
break;
|
||||||
tPrev = next;
|
tPrev = next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||||
|
@ -83,6 +84,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||||
|
@ -91,6 +93,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
|
@ -1552,7 +1555,15 @@ public class CPPVisitor {
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
if( binding instanceof IType )
|
if( binding instanceof IType )
|
||||||
type = (IType) binding;
|
type = (IType) binding;
|
||||||
else if( binding instanceof ICPPTemplateNonTypeParameter ){
|
else if( binding instanceof ICPPConstructor ){
|
||||||
|
try {
|
||||||
|
ICPPClassScope scope = (ICPPClassScope) binding.getScope();
|
||||||
|
type = scope.getClassType();
|
||||||
|
type = new CPPPointerType( type );
|
||||||
|
} catch (DOMException e) {
|
||||||
|
type = e.getProblem();
|
||||||
|
}
|
||||||
|
} else if( binding instanceof ICPPTemplateNonTypeParameter ){
|
||||||
//TODO workaround... is there anything better?
|
//TODO workaround... is there anything better?
|
||||||
try {
|
try {
|
||||||
type = ((ICPPTemplateNonTypeParameter)binding).getType();
|
type = ((ICPPTemplateNonTypeParameter)binding).getType();
|
||||||
|
@ -1817,6 +1828,22 @@ public class CPPVisitor {
|
||||||
if( st instanceof IASTExpressionStatement )
|
if( st instanceof IASTExpressionStatement )
|
||||||
return getExpressionType( ((IASTExpressionStatement)st).getExpression() );
|
return getExpressionType( ((IASTExpressionStatement)st).getExpression() );
|
||||||
}
|
}
|
||||||
|
} else if( expression instanceof IASTConditionalExpression ){
|
||||||
|
IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
|
||||||
|
IType t2 = getExpressionType( conditional.getPositiveResultExpression() );
|
||||||
|
IType t3 = getExpressionType( conditional.getNegativeResultExpression() );
|
||||||
|
if( t3 instanceof IPointerType || t2 == null )
|
||||||
|
return t3;
|
||||||
|
return t2;
|
||||||
|
} else if( expression instanceof ICPPASTDeleteExpression ){
|
||||||
|
return CPPSemantics.VOID_TYPE;
|
||||||
|
} else if( expression instanceof ICPPASTTypenameExpression ){
|
||||||
|
IBinding binding = ((ICPPASTTypenameExpression)expression).getName().resolveBinding();
|
||||||
|
if( binding instanceof IType )
|
||||||
|
return (IType) binding;
|
||||||
|
} else if( expression instanceof ICPPASTNewExpression ) {
|
||||||
|
ICPPASTNewExpression newExp = (ICPPASTNewExpression) expression;
|
||||||
|
return createType( newExp.getTypeId() );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue