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

fix bugs 95673, 95768

This commit is contained in:
Andrew Niefer 2005-05-18 15:51:16 +00:00
parent fbee283243
commit 5c33d3d918
3 changed files with 101 additions and 37 deletions

View file

@ -4234,4 +4234,41 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPFunction strcmp = (ICPPFunction) col.getName(0).resolveBinding(); ICPPFunction strcmp = (ICPPFunction) col.getName(0).resolveBinding();
assertSame( strcmp, col.getName(4).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() );
}
} }

View file

@ -2438,28 +2438,30 @@ public class CPPSemantics {
//conversion operators //conversion operators
if( s instanceof ICPPInternalClassType ){ if( s instanceof ICPPInternalClassType ){
ICPPMethod [] ops = ((ICPPInternalClassType)s).getConversionOperators(); ICPPMethod [] ops = ((ICPPInternalClassType)s).getConversionOperators();
Cost [] costs = null; if( ops.length > 0 && !(ops[0] instanceof IProblemBinding) ){
for (int i = 0; i < ops.length; i++) { Cost [] costs = null;
cost = checkStandardConversionSequence( ops[i].getType().getReturnType(), target ); for (int i = 0; i < ops.length; i++) {
if( cost.rank != Cost.NO_MATCH_RANK ) cost = checkStandardConversionSequence( ops[i].getType().getReturnType(), target );
costs = (Cost[]) ArrayUtil.append( Cost.class, costs, cost ); 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( bestIsBest ){ if( costs != null ){
conversion = ops[ bestIdx ]; Cost best = costs[0];
conversionCost = best; 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;
}
} }
} }
} }

View file

@ -1674,22 +1674,47 @@ public class CPPVisitor {
} }
} else if( expression instanceof IASTBinaryExpression ){ } else if( expression instanceof IASTBinaryExpression ){
IASTBinaryExpression binary = (IASTBinaryExpression) expression; IASTBinaryExpression binary = (IASTBinaryExpression) expression;
IType type = getExpressionType( ((IASTBinaryExpression) expression).getOperand2() ); int op = binary.getOperator();
if( binary.getOperator() == ICPPASTBinaryExpression.op_pmarrow || IType result = null;
binary.getOperator() == ICPPASTBinaryExpression.op_pmdot ) switch( op ){
{ case IASTBinaryExpression.op_lessEqual:
if( type instanceof ICPPPointerToMemberType ){ case IASTBinaryExpression.op_lessThan:
try { case IASTBinaryExpression.op_greaterEqual:
return ((ICPPPointerToMemberType)type).getType(); case IASTBinaryExpression.op_greaterThan:
} catch ( DOMException e ) { case IASTBinaryExpression.op_logicalAnd:
return e.getProblem(); case IASTBinaryExpression.op_logicalOr:
} result = new CPPBasicType( ICPPBasicType.t_bool, 0 );
} break;
return new ProblemBinding( binary, IProblemBinding.SEMANTIC_INVALID_TYPE, new char[0] ); case IASTBinaryExpression.op_plus:
} else if( type instanceof CPPBasicType ){ case IASTBinaryExpression.op_minus:
((CPPBasicType)type).setValue( expression ); 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 ) else if( expression instanceof IASTUnaryExpression )
{ {
@ -1728,7 +1753,7 @@ public class CPPVisitor {
if( typeidExp.getOperator() == IASTTypeIdExpression.op_sizeof ){ if( typeidExp.getOperator() == IASTTypeIdExpression.op_sizeof ){
IScope scope = getContainingScope( typeidExp ); IScope scope = getContainingScope( typeidExp );
try { try {
IBinding [] bs = scope.find( "size_t" );//$NON-NLS-1$ IBinding [] bs = scope.find( SIZE_T );
if( bs.length > 0 && bs[0] instanceof IType ){ if( bs.length > 0 && bs[0] instanceof IType ){
return (IType) bs[0]; return (IType) bs[0];
} }