From 5c33d3d9183f6decec40245e6714326b8575216e Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Wed, 18 May 2005 15:51:16 +0000 Subject: [PATCH] fix bugs 95673, 95768 --- .../core/parser/tests/ast2/AST2CPPTests.java | 37 ++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 44 +++++++------- .../core/dom/parser/cpp/CPPVisitor.java | 57 +++++++++++++------ 3 files changed, 101 insertions(+), 37 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 48f3b858495..a63004d48f3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -4234,4 +4234,41 @@ public class AST2CPPTests extends AST2BaseTest { ICPPFunction strcmp = (ICPPFunction) col.getName(0).resolveBinding(); assertSame( strcmp, col.getName(4).resolveBinding() ); } + + public void testBug95673() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("class Other; \n"); //$NON-NLS-1$ + buffer.append("class Base { \n"); //$NON-NLS-1$ + buffer.append(" public: Base( Other * ); \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + buffer.append("class Sub : public Base { \n"); //$NON-NLS-1$ + buffer.append(" public: Sub( Other * ); \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + buffer.append("Sub::Sub( Other * b ) : Base(b) {} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + ICPPConstructor ctor = (ICPPConstructor) col.getName(2).resolveBinding(); + assertSame( ctor, col.getName(15).resolveBinding() ); + } + + public void testBug95768() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("void mem( void *, const void * ); \n"); //$NON-NLS-1$ + buffer.append("void f() { \n"); //$NON-NLS-1$ + buffer.append(" char *x; int offset; \n"); //$NON-NLS-1$ + buffer.append(" mem( x, \"FUNC\" ); \n"); //$NON-NLS-1$ + buffer.append(" mem( x + offset, \"FUNC2\" ); \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + ICPPFunction mem = (ICPPFunction) col.getName(0).resolveBinding(); + assertSame( mem, col.getName(6).resolveBinding() ); + assertSame( mem, col.getName(8).resolveBinding() ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 62a44664bdb..4249cb815c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -2438,28 +2438,30 @@ public class CPPSemantics { //conversion operators if( s instanceof ICPPInternalClassType ){ ICPPMethod [] ops = ((ICPPInternalClassType)s).getConversionOperators(); - Cost [] costs = null; - for (int i = 0; i < ops.length; i++) { - cost = checkStandardConversionSequence( ops[i].getType().getReturnType(), target ); - if( cost.rank != Cost.NO_MATCH_RANK ) - costs = (Cost[]) ArrayUtil.append( Cost.class, costs, cost ); - } - if( costs != null ){ - Cost best = costs[0]; - boolean bestIsBest = true; - int bestIdx = 0; - for (int i = 1; i < costs.length && costs[i] != null; i++) { - int comp = best.compare( costs[i] ); - if( comp == 0 ) - bestIsBest = false; - else if( comp > 0 ){ - best = costs[ bestIdx = i ]; - bestIsBest = true; - } + if( ops.length > 0 && !(ops[0] instanceof IProblemBinding) ){ + Cost [] costs = null; + for (int i = 0; i < ops.length; i++) { + cost = checkStandardConversionSequence( ops[i].getType().getReturnType(), target ); + if( cost.rank != Cost.NO_MATCH_RANK ) + costs = (Cost[]) ArrayUtil.append( Cost.class, costs, cost ); } - if( bestIsBest ){ - conversion = ops[ bestIdx ]; - conversionCost = best; + if( costs != null ){ + Cost best = costs[0]; + boolean bestIsBest = true; + int bestIdx = 0; + for (int i = 1; i < costs.length && costs[i] != null; i++) { + int comp = best.compare( costs[i] ); + if( comp == 0 ) + bestIsBest = false; + else if( comp > 0 ){ + best = costs[ bestIdx = i ]; + bestIsBest = true; + } + } + if( bestIsBest ){ + conversion = ops[ bestIdx ]; + conversionCost = best; + } } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index be7775caea0..8cf21cdd3bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -1674,22 +1674,47 @@ public class CPPVisitor { } } else if( expression instanceof IASTBinaryExpression ){ IASTBinaryExpression binary = (IASTBinaryExpression) expression; - IType type = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); - if( binary.getOperator() == ICPPASTBinaryExpression.op_pmarrow || - binary.getOperator() == ICPPASTBinaryExpression.op_pmdot ) - { - if( type instanceof ICPPPointerToMemberType ){ - try { - return ((ICPPPointerToMemberType)type).getType(); - } catch ( DOMException e ) { - return e.getProblem(); - } - } - return new ProblemBinding( binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0] ); - } else if( type instanceof CPPBasicType ){ - ((CPPBasicType)type).setValue( expression ); + int op = binary.getOperator(); + IType result = null; + switch( op ){ + case IASTBinaryExpression.op_lessEqual: + case IASTBinaryExpression.op_lessThan: + case IASTBinaryExpression.op_greaterEqual: + case IASTBinaryExpression.op_greaterThan: + case IASTBinaryExpression.op_logicalAnd: + case IASTBinaryExpression.op_logicalOr: + result = new CPPBasicType( ICPPBasicType.t_bool, 0 ); + break; + case IASTBinaryExpression.op_plus: + case IASTBinaryExpression.op_minus: + IType t = getExpressionType( ((IASTBinaryExpression) expression).getOperand1() ); + if( t instanceof IPointerType ) + result = t; + else{ + result = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); + } + break; + case ICPPASTBinaryExpression.op_pmarrow: + case ICPPASTBinaryExpression.op_pmdot: + IType type = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); + if( type instanceof ICPPPointerToMemberType ){ + try { + result = ((ICPPPointerToMemberType)type).getType(); + } catch ( DOMException e ) { + result = e.getProblem(); + } + } else { + result = new ProblemBinding( binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0] ); + } + break; + default: + result = getExpressionType( ((IASTBinaryExpression) expression).getOperand1() ); + } + + if( result instanceof CPPBasicType ){ + ((CPPBasicType)result).setValue( expression ); } - return type; + return result; } else if( expression instanceof IASTUnaryExpression ) { @@ -1728,7 +1753,7 @@ public class CPPVisitor { if( typeidExp.getOperator() == IASTTypeIdExpression.op_sizeof ){ IScope scope = getContainingScope( typeidExp ); try { - IBinding [] bs = scope.find( "size_t" );//$NON-NLS-1$ + IBinding [] bs = scope.find( SIZE_T ); if( bs.length > 0 && bs[0] instanceof IType ){ return (IType) bs[0]; }