1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 265779. Fix and test case.

This commit is contained in:
Sergey Prigogin 2009-02-23 02:35:20 +00:00
parent 540907f410
commit a056ab0381
2 changed files with 39 additions and 26 deletions

View file

@ -6816,4 +6816,13 @@ public class AST2CPPTests extends AST2BaseTest {
ba.assertProblem("mprc(&X::m)", 4); ba.assertProblem("mprc(&X::m)", 4);
} }
// void f(int x);
//
// void test(int* p) {
// f(!p);
// }
public void testTypeOfNotExpression_265779() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ba.assertNonProblem("f(!p)", 1);
}
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -29,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
@ -43,18 +45,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
/** /**
* Unary expression in c++ * Unary expression in c++
*/ */
public class CPPASTUnaryExpression extends ASTNode implements public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpression, IASTAmbiguityParent {
ICPPASTUnaryExpression, IASTAmbiguityParent {
private int op; private int op;
private IASTExpression operand; private IASTExpression operand;
public CPPASTUnaryExpression() { public CPPASTUnaryExpression() {
} }
public CPPASTUnaryExpression(int operator, IASTExpression operand) { public CPPASTUnaryExpression(int operator, IASTExpression operand) {
this.op = operator; op = operator;
setOperand(operand); setOperand(operand);
} }
@ -68,9 +67,9 @@ public class CPPASTUnaryExpression extends ASTNode implements
return op; return op;
} }
public void setOperator(int value) { public void setOperator(int operator) {
assertNotFrozen(); assertNotFrozen();
this.op = value; op = operator;
} }
public IASTExpression getOperand() { public IASTExpression getOperand() {
@ -87,21 +86,21 @@ public class CPPASTUnaryExpression extends ASTNode implements
} }
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitExpressions ){ if (action.shouldVisitExpressions) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default : break;
} }
} }
if( operand != null ) if( !operand.accept( action ) ) return false; if (operand != null && !operand.accept(action)) return false;
if( action.shouldVisitExpressions ){ if (action.shouldVisitExpressions) {
switch( action.leave( this ) ){ switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP: return true;
default : break; default : break;
} }
} }
@ -109,12 +108,11 @@ public class CPPASTUnaryExpression extends ASTNode implements
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == operand ) { if (child == operand) {
other.setPropertyInParent( child.getPropertyInParent() ); other.setPropertyInParent(child.getPropertyInParent());
other.setParent( child.getParent() ); other.setParent(child.getParent());
operand = (IASTExpression) other; operand = (IASTExpression) other;
} }
} }
public IType getExpressionType() { public IType getExpressionType() {
@ -124,6 +122,8 @@ public class CPPASTUnaryExpression extends ASTNode implements
return CPPVisitor.get_SIZE_T(this); return CPPVisitor.get_SIZE_T(this);
case IASTUnaryExpression.op_typeid: case IASTUnaryExpression.op_typeid:
return CPPVisitor.get_type_info(this); return CPPVisitor.get_type_info(this);
case IASTUnaryExpression.op_not:
return new CPPBasicType(ICPPBasicType.t_bool, 0);
} }
final IASTExpression operand = getOperand(); final IASTExpression operand = getOperand();
@ -147,12 +147,14 @@ public class CPPASTUnaryExpression extends ASTNode implements
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
return new ProblemBinding(this, IProblemBinding.SEMANTIC_INVALID_TYPE, this.getRawSignature().toCharArray()); return new ProblemBinding(this, IProblemBinding.SEMANTIC_INVALID_TYPE,
this.getRawSignature().toCharArray());
} }
if (op == IASTUnaryExpression.op_amper) { if (op == IASTUnaryExpression.op_amper) {
IASTNode child= operand; IASTNode child= operand;
boolean inParenthesis= false; boolean inParenthesis= false;
while (child instanceof IASTUnaryExpression && ((IASTUnaryExpression) child).getOperator() == IASTUnaryExpression.op_bracketedPrimary) { while (child instanceof IASTUnaryExpression &&
((IASTUnaryExpression) child).getOperator() == IASTUnaryExpression.op_bracketedPrimary) {
child= ((IASTUnaryExpression) child).getOperand(); child= ((IASTUnaryExpression) child).getOperand();
inParenthesis= true; inParenthesis= true;
} }
@ -165,9 +167,11 @@ public class CPPASTUnaryExpression extends ASTNode implements
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
if (!member.isStatic()) { if (!member.isStatic()) {
if (!inParenthesis) { if (!inParenthesis) {
return new CPPPointerToMemberType(member.getType(), member.getClassOwner(), false, false); return new CPPPointerToMemberType(member.getType(), member.getClassOwner(),
false, false);
} else if (member instanceof IFunction) { } else if (member instanceof IFunction) {
return new ProblemBinding(operand, IProblemBinding.SEMANTIC_INVALID_TYPE, operand.getRawSignature().toCharArray()); return new ProblemBinding(operand, IProblemBinding.SEMANTIC_INVALID_TYPE,
operand.getRawSignature().toCharArray());
} }
} }
} }