1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

More testcases and a fix for 186123, information stored with bindings not updated.

This commit is contained in:
Markus Schorn 2007-07-27 12:01:35 +00:00
parent 128f34e967
commit 8d8572bbcb
3 changed files with 158 additions and 11 deletions

View file

@ -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.DOMException;
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.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
@ -588,4 +590,124 @@ public class IndexUpdateTests extends IndexTestBase {
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();
}
}
}

View file

@ -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.PDOMASTAdapter;
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.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
@ -53,18 +54,30 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
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
try {
pdom.getDB().putByte(record + KEY, (byte) compType.getKey());
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
public PDOMCStructure(PDOM pdom, int 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 {
super.accept(visitor);

View file

@ -75,11 +75,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
throws CoreException {
super(pdom, parent, classType.getNameCharArray());
try {
pdom.getDB().putByte(record + KEY, (byte) classType.getKey());
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
setKind(classType);
// linked list is initialized by storage being zero'd by malloc
}
@ -87,6 +83,22 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
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 {
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
list.addMember(member);