diff options
author | Sergey Prigogin | 2012-02-08 04:02:53 +0000 |
---|---|---|
committer | Sergey Prigogin | 2012-02-08 04:02:53 +0000 |
commit | f0be3d2a6bffc796b4cab976963031add4d97a21 (patch) | |
tree | d897753cf6a2c9c559a822a5caaf19fc9f668db0 | |
parent | 104a413f124b4b8f0362cf71ba5c0b2a982318ab (diff) | |
download | org.eclipse.cdt-f0be3d2a6bffc796b4cab976963031add4d97a21.tar.gz org.eclipse.cdt-f0be3d2a6bffc796b4cab976963031add4d97a21.tar.xz org.eclipse.cdt-f0be3d2a6bffc796b4cab976963031add4d97a21.zip |
Fixed VariableReadWriteFlagsTest.testFieldAccess.
2 files changed, 33 insertions, 23 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java index 0ee39a109a9..de6ed76f3be 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java index 396c470c61d..6f2c0a4342e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java @@ -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; |