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

186736: fix some operator-overloading issues

This commit is contained in:
Andrew Ferguson 2007-05-16 07:28:00 +00:00
parent 8aa0195243
commit 69f76d62ff
3 changed files with 36 additions and 7 deletions

View file

@ -3728,7 +3728,7 @@ public class AST2Tests extends AST2BaseTest {
// int c = (*a).method(); // Problem: method
// }
// };
public void _test186736() throws Exception {
public void test186736() throws Exception {
StringBuffer buffer = getContents(1)[0];
IASTTranslationUnit tu= parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP);
CNameCollector col = new CNameCollector();
@ -3776,7 +3776,7 @@ public class AST2Tests extends AST2BaseTest {
// int b2 = a2->method(); // Problem: method
// }
// };
public void _test186736_variant1() throws Exception {
public void test186736_variant1() throws Exception {
StringBuffer buffer = getContents(1)[0];
IASTTranslationUnit tu= parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP);
CNameCollector col = new CNameCollector();

View file

@ -87,6 +87,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
@ -359,12 +360,26 @@ public class CPPSemantics {
tempName = (IASTName) tempName.getParent();
ASTNodeProperty prop = tempName.getPropertyInParent();
if( prop == IASTFieldReference.FIELD_NAME ||
if( (prop == STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTUnaryExpression) ) {
ICPPASTUnaryExpression unaryExp = (ICPPASTUnaryExpression) tempName.getParent();
IASTExpression oprd= unaryExp.getOperand();
return CPPVisitor.getExpressionType(oprd);
} else if( prop == IASTFieldReference.FIELD_NAME ||
(prop == STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTFieldReference) )
{
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempName.getParent();
implied = CPPVisitor.getExpressionType( fieldRef.getFieldOwner() );
if( fieldRef.isPointerDereference() && implied instanceof IPointerType ){
IType ultimateImplied= getUltimateType(implied, true);
if( prop != STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() && ultimateImplied instanceof ICPPClassType) {
ICPPFunction operator= findOperator(fieldRef, (ICPPClassType) ultimateImplied);
try {
if(operator!=null) {
implied= operator.getType().getReturnType();
}
} catch(DOMException de) {
return de.getProblem();
}
} else if( fieldRef.isPointerDereference() && implied instanceof IPointerType ){
try {
implied = ((IPointerType)implied).getType();
} catch ( DOMException e ) {
@ -3278,7 +3293,12 @@ public class CPPSemantics {
astName.setPropertyInParent( STRING_LOOKUP_PROPERTY );
LookupData data = null;
if( exp instanceof IASTArraySubscriptExpression ){
if( exp instanceof IASTUnaryExpression) {
astName.setName( ICPPASTOperatorName.OPERATOR_STAR );
data = new LookupData( astName );
data.forceQualified = true;
data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else if( exp instanceof IASTArraySubscriptExpression ){
astName.setName( ICPPASTOperatorName.OPERATOR_BRACKET );
data = new LookupData( astName );
data.forceQualified = true;

View file

@ -863,8 +863,7 @@ public class CPPVisitor {
IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner();
IType type = getExpressionType( owner );
if( ((ICPPASTFieldReference)parent).isPointerDereference() ){
while( type instanceof ITypedef )
type = ((ITypedef)type).getType();
type= CPPSemantics.getUltimateType(type, true);
if( type instanceof ICPPClassType ){
ICPPFunction op = CPPSemantics.findOperator( (IASTFieldReference)parent, (ICPPClassType) type );
if( op != null ){
@ -1865,6 +1864,16 @@ public class CPPVisitor {
break;
}
}
if( op == IASTUnaryExpression.op_star && type instanceof ICPPClassType) {
try {
ICPPFunction operator= CPPSemantics.findOperator(expression, (ICPPClassType) type);
if(operator!=null) {
return operator.getType().getReturnType();
}
} catch(DOMException de) {
return de.getProblem();
}
}
if( op == IASTUnaryExpression.op_star && (type instanceof IPointerType || type instanceof IArrayType) ){
try {
return ((ITypeContainer)type).getType();