1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Bug 328528: Read/write flags in initializers.

This commit is contained in:
Markus Schorn 2011-07-01 10:42:46 +02:00
parent 268b294717
commit 24c4f8f836
4 changed files with 215 additions and 112 deletions

View file

@ -67,9 +67,9 @@ public class IndexNamesTests extends BaseTestCase {
return fCProject.getProject(); return fCProject.getProject();
} }
protected StringBuffer[] getContentsForTest(int blocks) throws IOException { public String getComment() throws IOException {
return TestSourceReader.getContentsForTest( return TestSourceReader.getContentsForTest(
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), blocks); CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1)[0].toString();
} }
protected IFile createFile(IContainer container, String fileName, String contents) throws Exception { protected IFile createFile(IContainer container, String fileName, String contents) throws Exception {
@ -102,7 +102,7 @@ public class IndexNamesTests extends BaseTestCase {
// }; // };
public void testNestingWithFunction() throws Exception { public void testNestingWithFunction() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getComment();
IFile file= createFile(getProject().getProject(), "test.cpp", content); IFile file= createFile(getProject().getProject(), "test.cpp", content);
waitUntilFileIsIndexed(file, 4000); waitUntilFileIsIndexed(file, 4000);
@ -161,7 +161,7 @@ public class IndexNamesTests extends BaseTestCase {
// }; // };
public void testNestingWithMethod() throws Exception { public void testNestingWithMethod() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getComment();
IFile file= createFile(getProject().getProject(), "test.cpp", content); IFile file= createFile(getProject().getProject(), "test.cpp", content);
waitUntilFileIsIndexed(file, 4000); waitUntilFileIsIndexed(file, 4000);
@ -257,7 +257,7 @@ public class IndexNamesTests extends BaseTestCase {
// } // }
public void testCouldBePolymorphicMethodCall_Bug156691() throws Exception { public void testCouldBePolymorphicMethodCall_Bug156691() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getComment();
IFile file= createFile(getProject().getProject(), "test.cpp", content); IFile file= createFile(getProject().getProject(), "test.cpp", content);
waitUntilFileIsIndexed(file, 4000); waitUntilFileIsIndexed(file, 4000);
@ -315,7 +315,7 @@ public class IndexNamesTests extends BaseTestCase {
// } // }
public void testReadWriteFlagsC() throws Exception { public void testReadWriteFlagsC() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getComment();
IFile file= createFile(getProject().getProject(), "test.c", content); IFile file= createFile(getProject().getProject(), "test.c", content);
waitUntilFileIsIndexed(file, 4000); waitUntilFileIsIndexed(file, 4000);
@ -329,16 +329,15 @@ public class IndexNamesTests extends BaseTestCase {
IIndexFile ifile= fIndex.getFile(linkageID, IndexLocationFactory.getWorkspaceIFL(file)); IIndexFile ifile= fIndex.getFile(linkageID, IndexLocationFactory.getWorkspaceIFL(file));
IIndexName[] names= ifile.findNames(0, Integer.MAX_VALUE); IIndexName[] names= ifile.findNames(0, Integer.MAX_VALUE);
int j= 0; int j= 0;
for (int i = 0; i < names.length; i++) { for (IIndexName indexName : names) {
IIndexName indexName = names[i];
final String name = indexName.toString(); final String name = indexName.toString();
final char c0= name.length() > 0 ? name.charAt(0) : 0; final char c0= name.length() > 0 ? name.charAt(0) : 0;
if ((c0 == '_' || c0 == 'r' || c0 == 'w') && indexName.isReference()) { if ((c0 == '_' || c0 == 'r' || c0 == 'w') && indexName.isReference()) {
boolean isRead= name.charAt(0) == 'r' || name.charAt(0) == 'u'; boolean isRead= name.charAt(0) == 'r';
boolean isWrite= name.charAt(isRead ? 1 : 0) == 'w' || name.charAt(0) == 'u'; boolean isWrite= c0 == 'w' || (isRead && name.length() > 1 && name.charAt(1) == 'w');
String msg= "i=" + i + ", " + name + ":"; String msg= name + "(j=" + j + "):";
assertEquals(msg, isRead, indexName.isReadAccess()); assertEquals("Read access for " + msg, isRead, indexName.isReadAccess());
assertEquals(msg, isWrite, indexName.isWriteAccess()); assertEquals("Write access for " + msg, isWrite, indexName.isWriteAccess());
j++; j++;
} }
else { else {
@ -352,50 +351,99 @@ public class IndexNamesTests extends BaseTestCase {
} }
} }
// int _i, ri, wi, rwi, rfind, ui; // int _i, ri, wi, rwi;
// int* rp; int* wp; int* rwp; int* up; // int* rp; int* wp; int* rwp;
// int* const rpc= 0; // int* const rpc= 0;
// const int * const rcpc= 0; // const int * const rcpc= 0;
// const int* cip= &ri; // const int* rwcp= &ri;
// int* bla= &rwi; // void fi(int);
// void fi(int); // void fp(int*);
// void fp(int*); // void fr(int&);
// void fr(int&); // void fcp(const int*);
// void fcp(const int*); // void fcr(const int&);
// void fcr(const int&); // void fpp(int**);
// void fpp(int**); // void fpr(int*&);
// void fpr(int*&); // void fcpp(int const**);
// void fcpp(int const**); // void fcpr(int const*&);
// void fcpr(int const*&); // void fpcp(int *const*);
// void fpcp(int *const*); // void fpcr(int *const&);
// void fpcr(int *const&); // void fcpcp(int const *const*);
// void fcpcp(int const *const*); // void fcpcr(int const *const&);
// void fcpcr(int const *const&);
//
// int test() { // int test() {
// _i; // _i;
// wi= ri, _i, _i; // expr-list // wi= ri, _i, _i; // expr-list
// rwi %= ri; // assignment // rwi %= ri; // assignment
// ri ? _i : _i; // conditional // ri ? _i : _i; // conditional
// (ri ? wi : wi)= ri; // conditional // (ri ? wi : wi)= ri; // conditional
// if (ri) _i; // if (ri) _i;
// for(wi=1; ri>ri; rwi++) _i; // for(wi=1; ri>ri; rwi++) _i;
// do {_i;} while (ri); // do {_i;} while (ri);
// while(ri) {_i;}; // while(ri) {_i;};
// switch(ri) {case ri: _i;}; // switch(ri) {case ri: _i;};
// fi(ri); fp(&rwi); fcp(&ri); // fi(ri); fp(&rwi); fcp(&ri);
// fi(*rp); fp(rp); fcp(rp); fpp(&rwp); fcpp(&up); fpcp(&rpc); fcpcp(&rcpc); // fi(*rp); fp(rp); fcp(rp); fpp(&rwp); fcpp(&rwcp); fpcp(&rpc); fcpcp(&rcpc);
// fr(rwi); fcr(ri); fpr(&ui); // fr(rwi); fcr(ri);
// fcpr(&ui); fpcr(&rwi); fcpcr(&ri); // fpcr(&rwi); fcpcr(&ri);
// fpr(rwp); fcpr(up); fpcr(rp); fcpcr(rp); // fpr(rwp); fcpr(rwcp); fpcr(rp); fcpcr(rp);
// return ri; // return ri;
// } // }
public void testReadWriteFlagsCpp() throws Exception { public void testReadWriteFlagsCpp() throws Exception {
waitForIndexer(); waitForIndexer();
String content= getContentsForTest(1)[0].toString(); String content= getComment();
IFile file= createFile(getProject().getProject(), "test.cpp", content); IFile file= createFile(getProject().getProject(), "test.cpp", content);
waitUntilFileIsIndexed(file, 4000); waitUntilFileIsIndexed(file, 4000);
checkReadWriteFlags(file, ILinkage.CPP_LINKAGE_ID, 47); checkReadWriteFlags(file, ILinkage.CPP_LINKAGE_ID, 48);
}
// int _i, ri, wi, rwi;
// void f(int&, int);
// void g(int, int&);
// void test() {
// f(rwi, ri);
// g(ri, rwi);
// }
public void testRWInSecondArg() throws Exception {
waitForIndexer();
String content= getComment();
IFile file= createFile(getProject().getProject(), "testRWInSecondArg.cpp", content);
waitUntilFileIsIndexed(file, 4000);
checkReadWriteFlags(file, ILinkage.CPP_LINKAGE_ID, 4);
}
// struct A {
// A(int p) {}
// };
// int r;
// A a(r); // Should be read-access
// void test() {
// A b(r); // Should be read-access
// }
public void testRWInConstructorCall_328528() throws Exception {
waitForIndexer();
String content= getComment();
IFile file= createFile(getProject().getProject(), "testRWInConstructorCall.cpp", content);
waitUntilFileIsIndexed(file, 4000);
checkReadWriteFlags(file, ILinkage.CPP_LINKAGE_ID, 2);
}
// struct A {
// A(int p) {}
// };
// int r;
// int a[2] = {0, r}; // Should be read-access
// void test() {
// int b[2] = {0, r}; // Should be read-access
// }
public void testRWInArrayInitializer_328528() throws Exception {
waitForIndexer();
String content= getComment();
IFile file= createFile(getProject().getProject(), "testRWInArrayInitializer.cpp", content);
waitUntilFileIsIndexed(file, 4000);
checkReadWriteFlags(file, ILinkage.CPP_LINKAGE_ID, 2);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -28,6 +28,8 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@ -37,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -58,23 +61,22 @@ public abstract class VariableReadWriteFlags {
} }
protected int rwAnyNode(IASTNode node, int indirection) { protected int rwAnyNode(IASTNode node, int indirection) {
final IASTNode parent= node.getParent(); final IASTNode parent = node.getParent();
if (parent instanceof IASTExpression) { if (parent instanceof IASTExpression) {
return rwInExpression(node, (IASTExpression) parent, indirection); return rwInExpression((IASTExpression) parent, node, indirection);
} else if (parent instanceof IASTStatement) {
return rwInStatement((IASTStatement) parent, node, indirection);
} else if (parent instanceof IASTEqualsInitializer) {
return rwInEqualsInitializer((IASTEqualsInitializer) parent, indirection);
} else if (parent instanceof IASTArrayModifier) {
return READ; // dimension
} else if (parent instanceof IASTInitializerList) {
return rwInInitializerList((IASTInitializerList) parent, indirection);
} }
else if (parent instanceof IASTStatement) { return READ | WRITE; // fallback
return rwInStatement(node, (IASTStatement) parent, indirection);
}
else if (parent instanceof IASTEqualsInitializer) {
return rwInInitializerExpression(indirection, parent);
}
else if (parent instanceof IASTArrayModifier) {
return READ; // dimension
}
return READ | WRITE; // fallback
} }
protected int rwInInitializerExpression(int indirection, IASTNode parent) { protected int rwInEqualsInitializer(IASTEqualsInitializer parent, int indirection) {
IASTNode grand= parent.getParent(); IASTNode grand= parent.getParent();
if (grand instanceof IASTDeclarator) { if (grand instanceof IASTDeclarator) {
IBinding binding= ((IASTDeclarator) grand).getName().getBinding(); IBinding binding= ((IASTDeclarator) grand).getName().getBinding();
@ -85,7 +87,24 @@ public abstract class VariableReadWriteFlags {
return READ | WRITE; // fallback return READ | WRITE; // fallback
} }
protected int rwInExpression(IASTNode node, IASTExpression expr, int indirection) { protected int rwInInitializerList(IASTInitializerList parent, int indirection) {
IASTNode grand= parent.getParent();
if (grand instanceof IASTEqualsInitializer) {
IASTNode grandGrand= grand.getParent();
if (grandGrand instanceof IASTDeclarator) {
IBinding binding= ((IASTDeclarator) grandGrand).getName().resolveBinding();
if (binding instanceof IVariable) {
IType type= ((IVariable) binding).getType();
if (type instanceof IArrayType) {
return rwAssignmentToType(type, indirection);
}
}
}
}
return READ | WRITE; // fallback
}
protected int rwInExpression(IASTExpression expr, IASTNode node, int indirection) {
if (expr instanceof IASTBinaryExpression) { if (expr instanceof IASTBinaryExpression) {
return rwInBinaryExpression(node, (IASTBinaryExpression) expr, indirection); return rwInBinaryExpression(node, (IASTBinaryExpression) expr, indirection);
} }
@ -108,14 +127,8 @@ public abstract class VariableReadWriteFlags {
return rwAnyNode(expr, indirection); return rwAnyNode(expr, indirection);
} }
if (expr instanceof IASTExpressionList) { if (expr instanceof IASTExpressionList) {
final IASTExpressionList exprList = (IASTExpressionList)expr; // Only the first expression is passed on.
final IASTNode grand= expr.getParent(); final IASTExpression[] expressions = ((IASTExpressionList) expr).getExpressions();
if (grand instanceof IASTFunctionCallExpression && expr.getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) {
final IASTFunctionCallExpression funcCall = (IASTFunctionCallExpression) grand;
return rwArgumentForFunctionCall(node, exprList, funcCall, indirection);
}
// only the first expression is passed on.
final IASTExpression[] expressions = exprList.getExpressions();
if (expressions.length > 0 && expressions[0] == node) { if (expressions.length > 0 && expressions[0] == node) {
return rwAnyNode(expr, indirection); return rwAnyNode(expr, indirection);
} }
@ -131,7 +144,7 @@ public abstract class VariableReadWriteFlags {
if (node.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { if (node.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
return READ; return READ;
} }
return rwArgumentForFunctionCall((IASTFunctionCallExpression) expr, 0, indirection); return rwArgumentForFunctionCall((IASTFunctionCallExpression) expr, node, indirection);
} }
if (expr instanceof IASTIdExpression) { if (expr instanceof IASTIdExpression) {
return rwAnyNode(expr, indirection); return rwAnyNode(expr, indirection);
@ -143,37 +156,38 @@ public abstract class VariableReadWriteFlags {
return 0; return 0;
} }
return READ | WRITE; // fall back return READ | WRITE; // fall back
} }
protected int rwArgumentForFunctionCall(IASTNode node, final IASTExpressionList exprList, protected int rwArgumentForFunctionCall(final IASTFunctionCallExpression funcCall, IASTNode argument, int indirection) {
final IASTFunctionCallExpression funcCall, int indirection) { final IASTInitializerClause[] args = funcCall.getArguments();
final IASTExpression[] expressions = exprList.getExpressions(); for (int i = 0; i < args.length; i++) {
for (int i = 0; i < expressions.length; i++) { if (args[i] == argument) {
if (expressions[i] == node) { final IASTExpression functionNameExpression = funcCall.getFunctionNameExpression();
return rwArgumentForFunctionCall(funcCall, i, indirection); if (functionNameExpression != null) {
} final IType type= functionNameExpression.getExpressionType();
} if (type instanceof IFunctionType) {
return READ | WRITE;// fallback return rwArgumentForFunctionCall((IFunctionType) type, i, indirection);
} }
protected int rwArgumentForFunctionCall(final IASTFunctionCallExpression func, int parameterIdx, int indirection) {
final IASTExpression functionNameExpression = func.getFunctionNameExpression();
if (functionNameExpression != null) {
final IType type= functionNameExpression.getExpressionType();
if (type instanceof IFunctionType) {
IType[] ptypes= ((IFunctionType) type).getParameterTypes();
if (ptypes != null && ptypes.length > parameterIdx) {
return rwAssignmentToType(ptypes[parameterIdx], indirection);
} }
break;
} }
} }
return READ | WRITE; // fallback return READ | WRITE; // fallback
}
protected int rwArgumentForFunctionCall(IFunctionType type, int parameterIdx, int indirection) {
IType[] ptypes= type.getParameterTypes();
if (ptypes != null && ptypes.length > parameterIdx) {
return rwAssignmentToType(ptypes[parameterIdx], indirection);
}
return READ | WRITE; // Fallback
} }
protected abstract int rwAssignmentToType(IType type, int indirection); protected abstract int rwAssignmentToType(IType type, int indirection);
protected int rwInStatement(IASTNode node, IASTStatement stmt, int indirection) { protected int rwInStatement(IASTStatement stmt, IASTNode node, int indirection) {
if (stmt instanceof IASTCaseStatement) { if (stmt instanceof IASTCaseStatement) {
if (node.getPropertyInParent() == IASTCaseStatement.EXPRESSION) { if (node.getPropertyInParent() == IASTCaseStatement.EXPRESSION) {
return READ; return READ;
@ -314,6 +328,6 @@ public abstract class VariableReadWriteFlags {
} }
return READ; return READ;
} }
return READ; // fallback return READ; // fallback
} }
} }

View file

@ -10,8 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -45,35 +45,27 @@ public final class CVariableReadWriteFlags extends VariableReadWriteFlags {
} }
@Override @Override
protected int rwInExpression(IASTNode node, IASTExpression expr, int indirection) { protected int rwInExpression(IASTExpression expr, IASTNode node, int indirection) {
if (expr instanceof ICASTTypeIdInitializerExpression) { if (expr instanceof ICASTTypeIdInitializerExpression) {
return 0; return 0;
} }
return super.rwInExpression(node, expr, indirection); return super.rwInExpression(expr, node, indirection);
} }
@Override @Override
protected int rwInInitializerExpression(int indirection, IASTNode parent) { protected int rwInEqualsInitializer(IASTEqualsInitializer parent, int indirection) {
if (indirection == 0) { if (indirection == 0) {
return READ; return READ;
} }
return super.rwInInitializerExpression(indirection, parent); return super.rwInEqualsInitializer(parent, indirection);
} }
@Override @Override
protected int rwArgumentForFunctionCall(IASTFunctionCallExpression func, int parameterIdx,int indirection) { protected int rwArgumentForFunctionCall(IASTFunctionCallExpression funcCall, IASTNode argument, int indirection) {
if (indirection == 0) { if (indirection == 0) {
return READ; return READ;
} }
return super.rwArgumentForFunctionCall(func, parameterIdx, indirection); return super.rwArgumentForFunctionCall(funcCall, argument, indirection);
}
@Override
protected int rwArgumentForFunctionCall(IASTNode node, IASTExpressionList exprList, IASTFunctionCallExpression funcCall, int indirection) {
if (indirection == 0) {
return READ;
}
return super.rwArgumentForFunctionCall(node, exprList, funcCall, indirection);
} }
@Override @Override

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,16 +7,24 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Patrick Hofer - [Bug 328528]
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
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.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.VariableReadWriteFlags; import org.eclipse.cdt.internal.core.dom.parser.VariableReadWriteFlags;
@ -34,6 +42,47 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
return INSTANCE.rwAnyNode(variable, 0); return INSTANCE.rwAnyNode(variable, 0);
} }
@Override
protected int rwAnyNode(IASTNode node, int indirection) {
final IASTNode parent = node.getParent();
if (parent instanceof ICPPASTConstructorInitializer) {
return rwInCtorInitializer(node, indirection, (ICPPASTConstructorInitializer) parent);
}
return super.rwAnyNode(node, indirection);
}
private int rwInCtorInitializer(IASTNode node, int indirection, ICPPASTConstructorInitializer parent) {
IASTNode grand= parent.getParent();
if (grand instanceof IASTDeclarator) {
// Look for a constructor being called.
if (grand instanceof IASTImplicitNameOwner) {
IASTImplicitName[] names = ((IASTImplicitNameOwner) grand).getImplicitNames();
for (IASTImplicitName in : names) {
IBinding b= in.resolveBinding();
if (b instanceof ICPPConstructor) {
final ICPPConstructor ctor = (ICPPConstructor) b;
int idx= 0;
for (IASTNode child : parent.getArguments()) {
if (child == node) {
return rwArgumentForFunctionCall(ctor.getType(), idx, indirection);
}
idx++;
}
}
}
}
// Allow for initialization of primitive types.
if (parent.getArguments().length == 1) {
IBinding binding= ((IASTDeclarator) grand).getName().getBinding();
if (binding instanceof IVariable) {
IType type= ((IVariable) binding).getType();
return rwAssignmentToType(type, indirection);
}
}
}
return READ | WRITE; // fallback
}
@Override @Override
protected int rwInUnaryExpression(IASTNode node, IASTUnaryExpression expr, int indirection) { protected int rwInUnaryExpression(IASTNode node, IASTUnaryExpression expr, int indirection) {
switch (expr.getOperator()) { switch (expr.getOperator()) {