mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 21:35:40 +02:00
More testcases and a fix for 186123, information stored with bindings not updated.
This commit is contained in:
parent
128f34e967
commit
8d8572bbcb
3 changed files with 158 additions and 11 deletions
|
@ -20,6 +20,8 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
@ -588,4 +590,124 @@ public class IndexUpdateTests extends IndexTestBase {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct myType {
|
||||||
|
// int a;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// union myType {
|
||||||
|
// int a;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// typedef int myType;
|
||||||
|
|
||||||
|
// enum myType {};
|
||||||
|
public void testChangingTypePlainC() throws Exception {
|
||||||
|
setupFile(4, false);
|
||||||
|
IBinding binding;
|
||||||
|
ICompositeType ct;
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ICompositeType);
|
||||||
|
ct = (ICompositeType) binding;
|
||||||
|
assertTrue(ct.getKey() == ICompositeType.k_struct);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ICompositeType);
|
||||||
|
ct = (ICompositeType) binding;
|
||||||
|
assertTrue(ct.getKey() == ICompositeType.k_union);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ITypedef);
|
||||||
|
ITypedef td = (ITypedef) binding;
|
||||||
|
assertEquals(INT, ASTTypeUtil.getType(td.getType()));
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof IEnumeration);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// class myType {
|
||||||
|
// int a;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// struct myType {
|
||||||
|
// int a;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// union myType {
|
||||||
|
// int a;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// typedef int myType;
|
||||||
|
|
||||||
|
// enum myType {};
|
||||||
|
public void testChangingTypeCPP() throws Exception {
|
||||||
|
setupFile(4, true);
|
||||||
|
IBinding binding;
|
||||||
|
ICompositeType ct;
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ICompositeType);
|
||||||
|
ct = (ICompositeType) binding;
|
||||||
|
assertTrue(ct.getKey() == ICompositeType.k_struct);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ICompositeType);
|
||||||
|
ct = (ICompositeType) binding;
|
||||||
|
assertTrue(ct.getKey() == ICompositeType.k_union);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof ITypedef);
|
||||||
|
ITypedef td = (ITypedef) binding;
|
||||||
|
assertEquals(INT, ASTTypeUtil.getType(td.getType()));
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFile();
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
binding = findBinding("myType");
|
||||||
|
assertTrue(binding instanceof IEnumeration);
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -54,18 +55,30 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
|
||||||
|
|
||||||
public PDOMCStructure(PDOM pdom, PDOMNode parent, ICompositeType compType) throws CoreException {
|
public PDOMCStructure(PDOM pdom, PDOMNode parent, ICompositeType compType) throws CoreException {
|
||||||
super(pdom, parent, compType.getNameCharArray());
|
super(pdom, parent, compType.getNameCharArray());
|
||||||
|
setKind(compType);
|
||||||
// linked list is initialized by malloc zeroing allocated storage
|
// linked list is initialized by malloc zeroing allocated storage
|
||||||
try {
|
|
||||||
pdom.getDB().putByte(record + KEY, (byte) compType.getKey());
|
|
||||||
} catch (DOMException e) {
|
|
||||||
throw new CoreException(Util.createStatus(e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMCStructure(PDOM pdom, int record) {
|
public PDOMCStructure(PDOM pdom, int record) {
|
||||||
super(pdom, record);
|
super(pdom, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||||
|
if (newBinding instanceof ICompositeType) {
|
||||||
|
ICompositeType ct= (ICompositeType) newBinding;
|
||||||
|
setKind(ct);
|
||||||
|
super.update(linkage, newBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setKind(ICompositeType ct) throws CoreException {
|
||||||
|
try {
|
||||||
|
pdom.getDB().putByte(record + KEY, (byte) ct.getKey());
|
||||||
|
} catch (DOMException e) {
|
||||||
|
throw new CoreException(Util.createStatus(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||||
super.accept(visitor);
|
super.accept(visitor);
|
||||||
new PDOMNodeLinkedList(pdom, record+MEMBERLIST, getLinkageImpl()).accept(visitor);
|
new PDOMNodeLinkedList(pdom, record+MEMBERLIST, getLinkageImpl()).accept(visitor);
|
||||||
|
|
|
@ -75,11 +75,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
super(pdom, parent, classType.getNameCharArray());
|
super(pdom, parent, classType.getNameCharArray());
|
||||||
|
|
||||||
try {
|
setKind(classType);
|
||||||
pdom.getDB().putByte(record + KEY, (byte) classType.getKey());
|
|
||||||
} catch (DOMException e) {
|
|
||||||
throw new CoreException(Util.createStatus(e));
|
|
||||||
}
|
|
||||||
// linked list is initialized by storage being zero'd by malloc
|
// linked list is initialized by storage being zero'd by malloc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +83,22 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
|
||||||
super(pdom, bindingRecord);
|
super(pdom, bindingRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||||
|
if (newBinding instanceof ICPPClassType) {
|
||||||
|
ICPPClassType ct= (ICPPClassType) newBinding;
|
||||||
|
setKind(ct);
|
||||||
|
super.update(linkage, newBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setKind(ICPPClassType ct) throws CoreException {
|
||||||
|
try {
|
||||||
|
pdom.getDB().putByte(record + KEY, (byte) ct.getKey());
|
||||||
|
} catch (DOMException e) {
|
||||||
|
throw new CoreException(Util.createStatus(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addMember(PDOMNode member) throws CoreException {
|
public void addMember(PDOMNode member) throws CoreException {
|
||||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
|
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
|
||||||
list.addMember(member);
|
list.addMember(member);
|
||||||
|
|
Loading…
Add table
Reference in a new issue