diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java index 8d022449e05..e2a482c9941 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java @@ -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(); + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java index f85b1673d8a..a2a1dd9f255 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index 0e508f047af..d9fcf4a017c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -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);