1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Fixed VariableReadWriteFlagsTest.testFieldAccess.

This commit is contained in:
Sergey Prigogin 2012-02-07 20:02:53 -08:00
parent 104a413f12
commit f0be3d2a6b
2 changed files with 33 additions and 23 deletions

View file

@ -68,14 +68,14 @@ public class VariableReadWriteFlagsTest extends AST2BaseTest {
return buf.toString();
}
}
public VariableReadWriteFlagsTest() {
}
public VariableReadWriteFlagsTest(String name) {
super(name);
}
public static TestSuite suite() {
return suite(VariableReadWriteFlagsTest.class);
}
@ -113,11 +113,11 @@ public class VariableReadWriteFlagsTest extends AST2BaseTest {
// A a;
// a.x = 1;
// };
public void _testFieldAccess() throws Exception {
public void testFieldAccess() throws Exception {
AssertionHelper a = getCPPAssertionHelper();
a.assertReadWriteFlags("a.", WRITE);
}
// struct A { int x; };
//
// void test(A* a) {
@ -127,7 +127,21 @@ public class VariableReadWriteFlagsTest extends AST2BaseTest {
AssertionHelper a = getCPPAssertionHelper();
a.assertReadWriteFlags("a->", READ);
}
// void f(int* x);
// void g(const int* x);
//
// void test() {
// int a, b;
// f(&a);
// g(&b);
// };
public void testExplicitArgument() throws Exception {
AssertionHelper a = getCPPAssertionHelper();
a.assertReadWriteFlags("a)", READ | WRITE);
a.assertReadWriteFlags("b)", READ);
}
// struct A {
// void m1();
// void m2() const;
@ -138,7 +152,7 @@ public class VariableReadWriteFlagsTest extends AST2BaseTest {
// a.m1();
// a.m2();
// };
public void _testMethodCall() throws Exception {
public void _testImplicitArgument() throws Exception {
AssertionHelper a = getCPPAssertionHelper();
a.assertReadWriteFlags("a.m1", READ | WRITE);
a.assertReadWriteFlags("a.m2", READ);

View file

@ -105,9 +105,19 @@ public abstract class VariableReadWriteFlags {
}
protected int rwInExpression(IASTExpression expr, IASTNode node, int indirection) {
if (expr instanceof IASTIdExpression) {
return rwAnyNode(expr, indirection);
}
if (expr instanceof IASTBinaryExpression) {
return rwInBinaryExpression(node, (IASTBinaryExpression) expr, indirection);
}
if (expr instanceof IASTFieldReference) {
if (node.getPropertyInParent() != IASTFieldReference.FIELD_OWNER ||
!((IASTFieldReference) expr).isPointerDereference()) {
return rwAnyNode(expr, indirection);
}
return READ;
}
if (expr instanceof IASTCastExpression) { // must be ahead of unary
return rwAnyNode(expr, indirection);
}
@ -134,25 +144,12 @@ public abstract class VariableReadWriteFlags {
}
return 0;
}
if (expr instanceof IASTFieldReference) {
if (node.getPropertyInParent() == IASTFieldReference.FIELD_NAME) {
return rwAnyNode(expr, indirection);
}
// if (node.getPropertyInParent() == IASTFieldReference.FIELD_OWNER &&
// !((IASTFieldReference) expr).isPointerDereference()) {
// return rwAnyNode(expr, indirection);
// }
return READ;
}
if (expr instanceof IASTFunctionCallExpression) {
if (node.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
return READ;
}
return rwArgumentForFunctionCall((IASTFunctionCallExpression) expr, node, indirection);
}
if (expr instanceof IASTIdExpression) {
return rwAnyNode(expr, indirection);
}
if (expr instanceof IASTProblemExpression) {
return READ | WRITE;
}
@ -181,7 +178,6 @@ public abstract class VariableReadWriteFlags {
return READ | WRITE; // fallback
}
protected int rwArgumentForFunctionCall(IFunctionType type, int parameterIdx, int indirection) {
IType[] ptypes= type.getParameterTypes();
if (ptypes != null && ptypes.length > parameterIdx) {
@ -249,11 +245,11 @@ public abstract class VariableReadWriteFlags {
return rwAnyNode(expr, indirection);
case IASTUnaryExpression.op_amper:
return rwAnyNode(expr, indirection+1);
return rwAnyNode(expr, indirection + 1);
case IASTUnaryExpression.op_star:
if (indirection > 0) {
return rwAnyNode(expr, indirection-1);
return rwAnyNode(expr, indirection - 1);
}
return READ;