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

Fixed f.p. for c++ lazy evaluation hacks

This commit is contained in:
Alena Laskavaia 2010-05-11 03:01:00 +00:00
parent 6d88bba776
commit fe3d182f42
2 changed files with 13 additions and 6 deletions

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
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.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
@ -85,6 +86,10 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
case IASTBinaryExpression.op_shiftLeftAssign: case IASTBinaryExpression.op_shiftLeftAssign:
case IASTBinaryExpression.op_shiftRightAssign: case IASTBinaryExpression.op_shiftRightAssign:
return false; return false;
case IASTBinaryExpression.op_logicalOr:
case IASTBinaryExpression.op_logicalAnd:
return hasNoEffect(binExpr.getOperand1())
&& hasNoEffect(binExpr.getOperand2());
} }
if (binExpr instanceof CPPASTBinaryExpression) { if (binExpr instanceof CPPASTBinaryExpression) {
// unfortunately ICPPASTBinaryExpression does not have // unfortunately ICPPASTBinaryExpression does not have
@ -95,9 +100,8 @@ public class StatementHasNoEffectChecker extends AbstractIndexAstChecker {
return false; return false;
IType expressionType = binExpr.getOperand1() IType expressionType = binExpr.getOperand1()
.getExpressionType(); .getExpressionType();
if (!(expressionType instanceof IBasicType)) { if (!(expressionType instanceof IBasicType || expressionType instanceof ICPPBasicType)) {
return false; // must be overloaded but parser could not return false; // must be overloaded but parser could not find it
// find it
} }
} }
return true; return true;

View file

@ -113,11 +113,14 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkNoErrors(); checkNoErrors();
} }
// main() { // void main() {
// a = foo(1) || a = foo(2); // bool a;
// class c {};
// c z;
// (a = z.foo(1)) || (a = z.foo(2));
// } // }
public void testLazyEvalHack() { public void testLazyEvalHack() {
loadCodeAndRun(getAboveComment()); loadCodeAndRunCpp(getAboveComment());
checkNoErrors(); checkNoErrors();
} }
} }