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();
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
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;
}
}
}
}

View file

@ -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];
}