From dfc2e4f842c8bf00fcbfb273353401f98157596a Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 9 Nov 2009 15:42:58 +0000 Subject: [PATCH] Safe type representation for index, bug 294306 --- .../index/tests/IndexUpdateTests.java | 7 +- .../eclipse/cdt/core/dom/ast/ASTTypeUtil.java | 39 ++-- .../cdt/core/dom/ast/c/ICArrayType.java | 11 +- .../cdt/core/parser/util/ASTPrinter.java | 8 +- .../core/dom/parser/ISerializableType.java | 21 ++ .../core/dom/parser/ITypeMarshalBuffer.java | 46 ++++ .../core/dom/parser/c/CArrayType.java | 174 +++++++++----- .../core/dom/parser/c/CBasicType.java | 39 +++- .../core/dom/parser/c/CEnumeration.java | 8 +- .../core/dom/parser/c/CFunctionType.java | 44 +++- .../core/dom/parser/c/CPointerType.java | 19 +- .../core/dom/parser/c/CQualifierType.java | 20 +- .../core/dom/parser/c/CStructure.java | 16 +- .../internal/core/dom/parser/c/CVisitor.java | 10 +- .../core/dom/parser/cpp/CPPArrayType.java | 41 +++- .../core/dom/parser/cpp/CPPBasicType.java | 34 ++- .../core/dom/parser/cpp/CPPClassInstance.java | 3 +- .../parser/cpp/CPPClassSpecialization.java | 3 +- .../core/dom/parser/cpp/CPPClassTemplate.java | 4 +- ...CPPClassTemplatePartialSpecialization.java | 4 +- .../core/dom/parser/cpp/CPPClassType.java | 3 +- .../core/dom/parser/cpp/CPPEnumeration.java | 8 +- .../core/dom/parser/cpp/CPPFunctionType.java | 42 +++- .../parser/cpp/CPPPointerToMemberType.java | 19 ++ .../core/dom/parser/cpp/CPPPointerType.java | 20 +- .../core/dom/parser/cpp/CPPQualifierType.java | 24 +- .../core/dom/parser/cpp/CPPReferenceType.java | 19 +- .../parser/cpp/GPPPointerToMemberType.java | 43 ++-- .../core/dom/parser/cpp/GPPPointerType.java | 49 ++-- .../parser/cpp/semantics/SemanticUtil.java | 7 +- .../internal/core/index/ArrayTypeClone.java | 83 ------- .../index/CPPPointerToMemberTypeClone.java | 49 ---- .../core/index/CPPReferenceTypeClone.java | 61 ----- .../core/index/IIndexBindingConstants.java | 5 +- .../core/index/IIndexCBindingConstants.java | 4 +- .../core/index/IIndexCPPBindingConstants.java | 7 +- .../internal/core/index/PointerTypeClone.java | 76 ------- .../core/index/QualifierTypeClone.java | 70 ------ .../composite/AbstractCompositeFactory.java | 41 +++- .../index/composite/CompositeArrayType.java | 37 --- .../composite/CompositeFunctionType.java | 39 ---- .../index/composite/CompositePointerType.java | 40 ---- .../composite/CompositeQualifierType.java | 40 ---- .../composite/CompositeTypeContainer.java | 3 +- .../index/composite/ICompositesFactory.java | 9 +- .../index/composite/c/CCompositesFactory.java | 102 ++++++--- .../composite/c/CompositeCEnumerator.java | 5 +- .../index/composite/c/CompositeCFunction.java | 7 +- .../composite/c/CompositeCParameter.java | 5 +- .../index/composite/c/CompositeCTypedef.java | 2 +- .../index/composite/c/CompositeCVariable.java | 5 +- .../composite/cpp/CPPCompositesFactory.java | 138 +++++++---- .../composite/cpp/CompositeCPPEnumerator.java | 5 +- .../composite/cpp/CompositeCPPFunction.java | 7 +- .../CompositeCPPFunctionSpecialization.java | 5 +- .../cpp/CompositeCPPFunctionType.java | 42 ---- .../cpp/CompositeCPPPointerToMemberType.java | 36 --- .../cpp/CompositeCPPReferenceType.java | 28 --- ...CompositeCPPTemplateTemplateParameter.java | 2 +- .../CompositeCPPTemplateTypeParameter.java | 4 +- .../composite/cpp/CompositeCPPTypedef.java | 2 +- .../cpp/CompositeCPPUnknownBinding.java | 35 +++ .../cpp/CompositeCPPUnknownClassType.java | 20 +- .../composite/cpp/CompositeCPPVariable.java | 5 +- .../composite/cpp/TemplateInstanceUtil.java | 17 +- .../eclipse/cdt/internal/core/pdom/PDOM.java | 7 +- .../cdt/internal/core/pdom/db/Chunk.java | 138 ++++++++--- .../cdt/internal/core/pdom/db/Database.java | 14 +- .../core/pdom/db/TypeMarshalBuffer.java | 201 ++++++++++++++++ .../internal/core/pdom/dom/PDOMArrayType.java | 141 ------------ .../internal/core/pdom/dom/PDOMLinkage.java | 112 +++++---- .../core/pdom/dom/PDOMPointerType.java | 166 -------------- .../core/pdom/dom/PDOMQualifierType.java | 172 -------------- .../core/pdom/dom/c/PDOMCBasicType.java | 156 ------------- .../core/pdom/dom/c/PDOMCFunction.java | 91 +++----- .../core/pdom/dom/c/PDOMCFunctionType.java | 194 ---------------- .../core/pdom/dom/c/PDOMCLinkage.java | 56 +++-- .../core/pdom/dom/c/PDOMCParameter.java | 92 +++----- .../core/pdom/dom/c/PDOMCTypedef.java | 23 +- .../core/pdom/dom/c/PDOMCVariable.java | 17 +- .../pdom/dom/cpp/PDOMCPPArgumentList.java | 43 ++-- .../core/pdom/dom/cpp/PDOMCPPBasicType.java | 214 ------------------ .../dom/cpp/PDOMCPPFieldSpecialization.java | 32 +-- .../core/pdom/dom/cpp/PDOMCPPFunction.java | 115 ++++------ .../cpp/PDOMCPPFunctionSpecialization.java | 107 ++++----- .../pdom/dom/cpp/PDOMCPPFunctionTemplate.java | 7 +- .../pdom/dom/cpp/PDOMCPPFunctionType.java | 137 ----------- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 101 ++++----- .../pdom/dom/cpp/PDOMCPPNamespaceAlias.java | 14 +- .../core/pdom/dom/cpp/PDOMCPPParameter.java | 77 ++----- .../cpp/PDOMCPPParameterSpecialization.java | 122 +++++----- .../dom/cpp/PDOMCPPPointerToMemberType.java | 103 --------- .../pdom/dom/cpp/PDOMCPPReferenceType.java | 119 ---------- .../pdom/dom/cpp/PDOMCPPSpecialization.java | 6 +- .../cpp/PDOMCPPTemplateNonTypeParameter.java | 29 +-- .../dom/cpp/PDOMCPPTemplateParameterMap.java | 53 ++--- .../cpp/PDOMCPPTemplateTemplateParameter.java | 43 +--- .../dom/cpp/PDOMCPPTemplateTypeParameter.java | 37 +-- .../core/pdom/dom/cpp/PDOMCPPTypeList.java | 19 +- .../core/pdom/dom/cpp/PDOMCPPTypedef.java | 23 +- .../dom/cpp/PDOMCPPTypedefSpecialization.java | 28 +-- .../core/pdom/dom/cpp/PDOMCPPVariable.java | 38 +--- .../lrparser/c99/bindings/C99ArrayType.java | 18 +- 103 files changed, 1707 insertions(+), 3179 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISerializableType.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPPointerToMemberTypeClone.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeArrayType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeFunctionType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositePointerType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeQualifierType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPPointerToMemberType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPReferenceType.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPUnknownBinding.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunctionType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBasicType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPPointerToMemberType.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPReferenceType.java 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 60e20d6b402..33a1c4d91e3 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 @@ -1177,9 +1177,12 @@ public class IndexUpdateTests extends IndexTestBase { // typeof(funcTypeDeletion) storeRef; // char funcTypeDeletion(int); // delete type // typeof(storeRef) useRef; // use reference - public void _testTypedeletion_Bug294306() throws Exception { + public void testTypedeletion_Bug294306() throws Exception { setupHeader(2, true); setupFile(2, true); - checkFunction("useRef", new String[]{"char", "void"}, new String[]{}); + checkFunction("useRef", new String[]{"void", "int"}, new String[]{}); + fContentUsed--; + updateFile(); + checkFunction("useRef", new String[]{"char", "int"}, new String[]{}); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 31ac87a1ee4..8083c669eb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -201,30 +201,27 @@ public class ASTTypeUtil { if (type instanceof IArrayType) { result.append(Keywords.cpLBRACKET); if (type instanceof ICArrayType) { - try { - final ICArrayType catype = (ICArrayType) type; - if (catype.isConst()) { - result.append(Keywords.CONST); needSpace = true; + final ICArrayType catype = (ICArrayType) type; + if (catype.isConst()) { + result.append(Keywords.CONST); needSpace = true; + } + if (catype.isRestrict()) { + if (needSpace) { + result.append(SPACE); needSpace = false; } - if (catype.isRestrict()) { - if (needSpace) { - result.append(SPACE); needSpace = false; - } - result.append(Keywords.RESTRICT); needSpace = true; + result.append(Keywords.RESTRICT); needSpace = true; + } + if (catype.isStatic()) { + if (needSpace) { + result.append(SPACE); needSpace = false; } - if (catype.isStatic()) { - if (needSpace) { - result.append(SPACE); needSpace = false; - } - result.append(Keywords.STATIC); needSpace = true; + result.append(Keywords.STATIC); needSpace = true; + } + if (catype.isVolatile()) { + if (needSpace) { + result.append(SPACE); needSpace = false; } - if (catype.isVolatile()) { - if (needSpace) { - result.append(SPACE); needSpace = false; - } - result.append(Keywords.VOLATILE); - } - } catch (DOMException e) { + result.append(Keywords.VOLATILE); } } IValue val= ((IArrayType) type).getSize(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java index 0316f6dbbce..a70dcd9e8c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICArrayType.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.c; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IArrayType; /** @@ -18,13 +17,13 @@ import org.eclipse.cdt.core.dom.ast.IArrayType; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICArrayType extends IArrayType { - public boolean isConst() throws DOMException; + public boolean isConst(); - public boolean isRestrict() throws DOMException; + public boolean isRestrict(); - public boolean isVolatile() throws DOMException; + public boolean isVolatile(); - public boolean isStatic() throws DOMException; + public boolean isStatic(); - public boolean isVariableLength() throws DOMException; + public boolean isVariableLength(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ASTPrinter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ASTPrinter.java index 6e184d03b85..51ea600e6d1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ASTPrinter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ASTPrinter.java @@ -199,12 +199,8 @@ public class ASTPrinter { if (n instanceof ICArrayType) { ICArrayType at = (ICArrayType)n; - try { - if (at.isRestrict()) { - out.print(" restrict"); - } - } catch (DOMException e) { - e.printStackTrace(); + if (at.isRestrict()) { + out.print(" restrict"); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISerializableType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISerializableType.java new file mode 100644 index 00000000000..017bbb5ac85 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISerializableType.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser; + +import org.eclipse.core.runtime.CoreException; + + +/** + * Interface for marshalling types for storage in the index. + */ +public interface ISerializableType { + void marshal(ITypeMarshalBuffer buffer) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java new file mode 100644 index 00000000000..a7d8d0e62ee --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser; + +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.core.runtime.CoreException; + +/** + * Buffer for marshalling and unmarshalling types. + */ +public interface ITypeMarshalBuffer { + final static byte BASIC_TYPE= 1; + final static byte POINTER= 2; + final static byte ARRAY= 3; + final static byte CVQUALIFIER= 4; + final static byte FUNCTION_TYPE= 5; + final static byte REFERENCE= 6; + final static byte POINTER_TO_MEMBER= 7; + static final byte KIND_MASK = 0xf; + + final static int FLAG1 = 0x10; + final static int FLAG2 = 0x20; + final static int FLAG3 = 0x40; + final static int FLAG4 = 0x80; + + CoreException unmarshallingError(); + + IType unmarshalType() throws CoreException; + byte getByte() throws CoreException; + short getShort() throws CoreException; + IValue getValue() throws CoreException; + + void marshalType(IType type) throws CoreException; + void putByte(byte data); + void putShort(short data); + void putValue(IValue val) throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index daca3228d46..844e5a5dac7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IType; @@ -20,36 +19,55 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICArrayType; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; -import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.core.runtime.CoreException; -public class CArrayType implements ICArrayType, ITypeContainer { +public class CArrayType implements ICArrayType, ITypeContainer, ISerializableType { IType type; - ICASTArrayModifier mod; + private IASTExpression sizeExpression; + private IValue value= Value.NOT_INITIALIZED; + private boolean isConst; + private boolean isVolatile; + private boolean isRestrict; + private boolean isStatic; + private boolean isVariableSized; public CArrayType(IType type) { this.type = type; } + + public CArrayType(IType type, boolean isConst, boolean isVolatile, boolean isRestrict, IValue size) { + this.type= type; + this.isConst= isConst; + this.isVolatile= isVolatile; + this.isRestrict= isRestrict; + this.value= size; + } + public void setIsStatic(boolean val) { + isStatic= val; + } + public void setIsVariableLength(boolean val) { + isVariableSized= val; + } + public boolean isSameType(IType obj) { if (obj == this) return true; - if (obj instanceof ITypedef || obj instanceof IIndexType) + if (obj instanceof ITypedef) return obj.isSameType(this); if (obj instanceof ICArrayType) { ICArrayType at = (ICArrayType) obj; - try { - if (isConst() != at.isConst()) return false; - if (isRestrict() != at.isRestrict()) return false; - if (isStatic() != at.isStatic()) return false; - if (isVolatile() != at.isVolatile()) return false; - if (isVariableLength() != at.isVariableLength()) return false; + if (isConst() != at.isConst()) return false; + if (isRestrict() != at.isRestrict()) return false; + if (isStatic() != at.isStatic()) return false; + if (isVolatile() != at.isVolatile()) return false; + if (isVariableLength() != at.isVariableLength()) return false; - return at.getType().isSameType(type) && hasSameSize(at); - } catch (DOMException e) { - return false; - } + return at.getType().isSameType(type) && hasSameSize(at); } return false; } @@ -76,68 +94,42 @@ public class CArrayType implements ICArrayType, ITypeContainer { } public void setModifier(ICASTArrayModifier mod) { - this.mod = mod; + isConst= mod.isConst(); + isVolatile= mod.isVolatile(); + isRestrict= mod.isRestrict(); + isStatic= mod.isStatic(); + isVariableSized= mod.isVariableSized(); + sizeExpression= mod.getConstantExpression(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isConst() - */ public boolean isConst() { - if (mod == null) return false; - return mod.isConst(); + return isConst; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isRestrict() - */ public boolean isRestrict() { - if (mod == null) return false; - return mod.isRestrict(); + return isRestrict; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isVolatile() - */ public boolean isVolatile() { - if (mod == null) return false; - return mod.isVolatile(); + return isVolatile; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isStatic() - */ public boolean isStatic() { - if (mod == null) return false; - return mod.isStatic(); + return isStatic; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isVariableLength() - */ public boolean isVariableLength() { - if (mod == null) return false; - return mod.isVariableSized(); + return isVariableSized; } - public ICASTArrayModifier getModifier() { - return mod; - } - public IValue getSize() { - if (mod != null) { - IASTExpression sizeExpression = mod.getConstantExpression(); - if (sizeExpression != null) { - return Value.create(sizeExpression, Value.MAX_RECURSION_DEPTH); - } - } - return null; - } + if (value != Value.NOT_INITIALIZED) + return value; + + if (sizeExpression == null) + return value= null; - @Deprecated - public IASTExpression getArraySizeExpression() { - if (mod != null) - return mod.getConstantExpression(); - return null; + return value= Value.create(sizeExpression, Value.MAX_RECURSION_DEPTH); } @Override @@ -155,4 +147,70 @@ public class CArrayType implements ICArrayType, ITypeContainer { public String toString() { return ASTTypeUtil.getType(this); } + + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.ARRAY; + int flags= 0; + short nval= -1; + IValue val= null; + + if (isConst()) flags |= 0x01; + if (isVolatile()) flags |= 0x02; + if (isRestrict()) flags |= 0x04; + if (isStatic()) flags |= 0x08; + if (isVariableLength()) flags |= 0x10; + if (flags != 0) { + firstByte |= ITypeMarshalBuffer.FLAG1; + } + + + val= getSize(); + if (val != null) { + firstByte |= ITypeMarshalBuffer.FLAG2; + Long num= val.numericalValue(); + if (num != null) { + long l= num; + if (l>=0 && l <= Short.MAX_VALUE) { + nval= (short) l; + firstByte |= ITypeMarshalBuffer.FLAG3; + } + } + } + buffer.putByte((byte) firstByte); + if (flags != 0) { + buffer.putByte((byte) flags); + } + if (nval >= 0) { + buffer.putShort(nval); + } else if (val != null) { + buffer.putValue(val); + } + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + int flags= 0; + IValue value= null; + if ( (firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + flags= buffer.getByte(); + } + if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) { + value = Value.create(buffer.getShort()); + } else if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + value = buffer.getValue(); + } + IType nested= buffer.unmarshalType(); + CArrayType result= new CArrayType(nested, (flags & 0x01) != 0, (flags & 0x02) != 0, (flags & 0x04) != 0, value); + result.setIsStatic((flags & 0x08) != 0); + result.setIsVariableLength((flags & 0x10) != 0); + return result; + } + + @Deprecated + public IASTExpression getArraySizeExpression() { + if (sizeExpression != null) + return sizeExpression; + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index 3c8e2b99588..0e33b92c033 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -17,9 +17,11 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICBasicType; -import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CBasicType implements ICBasicType { +public class CBasicType implements ICBasicType, ISerializableType { private final Kind fKind; private int fModifiers = 0; private IASTExpression value = null; @@ -104,10 +106,10 @@ public class CBasicType implements ICBasicType { } public boolean isSameType(IType obj) { - if( obj == this ) - return true; - if( obj instanceof ITypedef || obj instanceof IIndexType) - return obj.isSameType( this ); + if (obj == this) + return true; + if (obj instanceof ITypedef) + return obj.isSameType(this); if (!(obj instanceof ICBasicType)) return false; @@ -155,6 +157,31 @@ public class CBasicType implements ICBasicType { return ( fModifiers & IS_IMAGINARY) != 0; } + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.BASIC_TYPE; + + int kind= getKind().ordinal() * ITypeMarshalBuffer.FLAG1; + assert kind < ITypeMarshalBuffer.FLAG4; + firstByte |= kind; + + int modifiers= getModifiers(); + if (modifiers != 0) { + buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG4)); + buffer.putByte((byte) modifiers); + } else { + buffer.putByte((byte) firstByte); + } + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + int kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + int modifiers= 0; + if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + modifiers= buffer.getByte(); + } + return new CBasicType(Kind.values()[kind], modifiers); + } + @Deprecated public int getType() { switch (fKind) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java index 074e379606f..a36fb36e334 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -28,12 +28,12 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.dom.Linkage; -import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** - * @author aniefer + * Binding for enumerations in C. */ public class CEnumeration extends PlatformObject implements IEnumeration, ICInternalBinding { @@ -155,7 +155,7 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef || type instanceof IIndexBinding) return type.isSameType(this); return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java index 508d03cb4d4..0a7a7d21e58 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java @@ -13,15 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CFunctionType implements IFunctionType { +public class CFunctionType implements IFunctionType, ISerializableType { IType[] parameters = null; IType returnType = null; - /** - * @param returnType - * @param types - */ public CFunctionType( IType returnType, IType [] types ) { this.returnType = returnType; this.parameters = types; @@ -71,4 +70,39 @@ public class CFunctionType implements IFunctionType { } return t; } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.FUNCTION_TYPE; + + int len= parameters.length & 0xffff; + int codedLen= len * ITypeMarshalBuffer.FLAG1; + if (codedLen < ITypeMarshalBuffer.FLAG4) { + firstByte |= codedLen; + buffer.putByte((byte) firstByte); + } else { + firstByte |= ITypeMarshalBuffer.FLAG4; + buffer.putByte((byte) firstByte); + buffer.putShort((short) len); + } + + buffer.marshalType(returnType); + for (int i = 0; i < len; i++) { + buffer.marshalType(parameters[i]); + } + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + int len; + if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + len= buffer.getShort() & 0xffff; + } else { + len= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + } + IType rt= buffer.unmarshalType(); + IType[] pars= new IType[len]; + for (int i = 0; i < pars.length; i++) { + pars[i]= buffer.unmarshalType(); + } + return new CFunctionType(rt, pars); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java index a502d793b93..fa8247e0ca0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CPointerType.java @@ -13,9 +13,12 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.c.ICPointerType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CPointerType implements ICPointerType, ITypeContainer { +public class CPointerType implements ICPointerType, ITypeContainer, ISerializableType { static public final int IS_CONST = 1; static public final int IS_RESTRICT = 1 << 1; static public final int IS_VOLATILE = 1 << 2; @@ -93,4 +96,18 @@ public class CPointerType implements ICPointerType, ITypeContainer { public void setQualifiers(int qualifiers) { this.qualifiers = qualifiers; } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.POINTER; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; + buffer.putByte((byte) firstByte); + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + return new CPointerType(nested, firstByte/ITypeMarshalBuffer.FLAG1); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java index f3cc13db0e0..26ef8f901ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CQualifierType.java @@ -19,9 +19,12 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICQualifierType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CQualifierType implements ICQualifierType, ITypeContainer { +public class CQualifierType implements ICQualifierType, ITypeContainer, ISerializableType { private boolean isConst; private boolean isVolatile; @@ -125,4 +128,19 @@ public class CQualifierType implements ICQualifierType, ITypeContainer { } return t; } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.CVQUALIFIER; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + if (isRestrict()) firstByte |= ITypeMarshalBuffer.FLAG3; + buffer.putByte((byte) firstByte); + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + return new CQualifierType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, + (firstByte & ITypeMarshalBuffer.FLAG2) != 0, (firstByte & ITypeMarshalBuffer.FLAG3) != 0); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index ee0d75ec5ba..09e549c5bc9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -33,11 +33,11 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -260,13 +260,13 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ - public boolean isSameType( IType type ) { - if( type == this ) - return true; - if( type instanceof ITypedef || type instanceof IIndexType) - return type.isSameType( this ); - return false; - } + public boolean isSameType(IType type) { + if (type == this) + return true; + if (type instanceof ITypedef || type instanceof IIndexBinding) + return type.isSameType(this); + return false; + } public ILinkage getLinkage() { return Linkage.C_LINKAGE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index c89d88c2067..bbbeaef1486 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -1280,13 +1280,9 @@ public class CVisitor extends ASTQueries { int q= 0; if (at instanceof ICArrayType) { ICArrayType cat= (ICArrayType) at; - try { - if (cat.isConst()) q |= CPointerType.IS_CONST; - if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE; - if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT; - } catch (DOMException e) { - // ignore the qualifiers - } + if (cat.isConst()) q |= CPointerType.IS_CONST; + if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE; + if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT; } type = new CPointerType(at.getType(), q); } else if (paramType instanceof IFunctionType) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index bc83450f549..93f978414f2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -18,10 +18,13 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.core.runtime.CoreException; -public class CPPArrayType implements IArrayType, ITypeContainer { +public class CPPArrayType implements IArrayType, ITypeContainer, ISerializableType { private IType type; private IASTExpression sizeExpression; private IValue value= Value.NOT_INITIALIZED; @@ -102,4 +105,40 @@ public class CPPArrayType implements IArrayType, ITypeContainer { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + final byte firstByte = ITypeMarshalBuffer.ARRAY; + + IValue val= getSize(); + if (val == null) { + buffer.putByte(firstByte); + buffer.marshalType(getType()); + return; + } + + Long num= val.numericalValue(); + if (num != null) { + long lnum= num; + if (lnum >= 0 && lnum <= Short.MAX_VALUE) { + buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG1)); + buffer.putShort((short) lnum); + buffer.marshalType(getType()); + return; + } + } + buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG2)); + buffer.putValue(val); + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IValue value= null; + if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) { + value = Value.create(buffer.getShort()); + } else if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { + value = buffer.getValue(); + } + IType nested= buffer.unmarshalType(); + return new CPPArrayType(nested, value); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index 7910901632f..040c3450fb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -20,12 +20,14 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; -import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; /** * Integral c++ type. */ -public class CPPBasicType implements ICPPBasicType { +public class CPPBasicType implements ICPPBasicType, ISerializableType { public static int UNIQUE_TYPE_QUALIFIER= -1; private final Kind fKind; private final int fModifiers; @@ -104,7 +106,7 @@ public class CPPBasicType implements ICPPBasicType { if (fModifiers == UNIQUE_TYPE_QUALIFIER) return false; - if (object instanceof ITypedef || object instanceof IIndexType) + if (object instanceof ITypedef) return object.isSameType(this); if (!(object instanceof ICPPBasicType)) @@ -183,6 +185,32 @@ public class CPPBasicType implements ICPPBasicType { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.BASIC_TYPE; + + int kind= getKind().ordinal() * ITypeMarshalBuffer.FLAG1; + assert kind < ITypeMarshalBuffer.FLAG4; + firstByte |= kind; + + int modifiers= getModifiers(); + if (modifiers != 0) { + buffer.putByte((byte) (firstByte | ITypeMarshalBuffer.FLAG4)); + buffer.putByte((byte) modifiers); + } else { + buffer.putByte((byte) firstByte); + } + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + int kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + int modifiers= 0; + if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + modifiers= buffer.getByte(); + } + return new CPPBasicType(Kind.values()[kind], modifiers); + } + @Deprecated public int getQualifierBits() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java index eef7eab9818..6f486d8ac40 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java @@ -25,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.index.IIndexType; /** * The result of instantiating a class template. @@ -68,7 +67,7 @@ public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemp public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef) return type.isSameType(this); return isSameClassInstance(this, type); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index 4bb256b3e4d..1b59e3ffe86 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -44,7 +44,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.index.IIndexType; /** * Specialization of a class. @@ -283,7 +282,7 @@ public class CPPClassSpecialization extends CPPSpecialization public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef) return type.isSameType(this); if (type instanceof ICPPClassSpecialization) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index 16cd40ad9dc..4207da3c12c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -44,11 +44,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.core.index.IIndexType; /** * Represents a class template. @@ -212,7 +212,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef || type instanceof IIndexBinding) return type.isSameType(this); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java index af7ab84839f..c7f1ef4b349 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java @@ -23,9 +23,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.index.IIndexType; /** * A partial class template specialization. @@ -97,7 +97,7 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef || type instanceof IIndexBinding) return type.isSameType(this); if (type instanceof ICPPClassTemplatePartialSpecialization) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 0d88669c0e3..82fd727fb79 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -51,7 +51,6 @@ import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** @@ -359,7 +358,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef || type instanceof IIndexBinding) return type.isSameType(this); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index 3a0dfe22361..22ecbe413be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) *******************************************************************************/ @@ -24,13 +24,13 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** - * @author aniefer + * Enumerations in C++ */ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPPInternalBinding { private IASTName enumName; @@ -113,7 +113,7 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP public boolean isSameType(IType type) { if (type == this) return true; - if (type instanceof ITypedef || type instanceof IIndexType) + if (type instanceof ITypedef || type instanceof IIndexBinding) return type.isSameType(this); return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java index 35f30c7de09..48c66820f66 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionType.java @@ -18,12 +18,15 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; +import org.eclipse.core.runtime.CoreException; /** * Represents c++ function types. Note that we keep typedefs as part of the function type. */ -public class CPPFunctionType implements ICPPFunctionType { +public class CPPFunctionType implements ICPPFunctionType, ISerializableType { private IType[] parameters; private IType returnType; private boolean isConst; @@ -126,4 +129,41 @@ public class CPPFunctionType implements ICPPFunctionType { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.FUNCTION_TYPE; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + + int len= (parameters.length & 0xffff); + if (len > 0xff) { + firstByte |= ITypeMarshalBuffer.FLAG3; + buffer.putByte((byte) firstByte); + buffer.putShort((short) len); + } else { + buffer.putByte((byte) firstByte); + buffer.putByte((byte) len); + } + + buffer.marshalType(returnType); + for (int i = 0; i < len; i++) { + buffer.marshalType(parameters[i]); + } + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + int len; + if (((firstByte & ITypeMarshalBuffer.FLAG3) != 0)) { + len= buffer.getShort(); + } else { + len= buffer.getByte(); + } + IType rt= buffer.unmarshalType(); + IType[] pars= new IType[len]; + for (int i = 0; i < pars.length; i++) { + pars[i]= buffer.unmarshalType(); + } + return new CPPFunctionType(rt, pars, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, + (firstByte & ITypeMarshalBuffer.FLAG2) != 0); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java index 6ef4f9e2493..77177053414 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java @@ -20,6 +20,8 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; /** * Models pointer to members. @@ -86,4 +88,21 @@ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointe } return classType; } + + @Override + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.POINTER_TO_MEMBER; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + buffer.putByte((byte) firstByte); + buffer.marshalType(getType()); + buffer.marshalType(getMemberOfClass()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + IType memberOf= buffer.unmarshalType(); + return new CPPPointerToMemberType(nested, memberOf, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, + (firstByte & ITypeMarshalBuffer.FLAG2) != 0); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java index 769634f3799..2a7e716b85e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java @@ -17,12 +17,15 @@ import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; /** * Pointers in c++ */ -public class CPPPointerType implements IPointerType, ITypeContainer { +public class CPPPointerType implements IPointerType, ITypeContainer, ISerializableType { protected IType type = null; private boolean isConst = false; private boolean isVolatile = false; @@ -106,4 +109,19 @@ public class CPPPointerType implements IPointerType, ITypeContainer { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.POINTER; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + buffer.putByte((byte) firstByte); + final IType nestedType = getType(); + buffer.marshalType(nestedType); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + return new CPPPointerType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, + (firstByte & ITypeMarshalBuffer.FLAG2) != 0); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java index 498f2d0593c..e292d63f10e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPQualifierType.java @@ -15,10 +15,12 @@ import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; -import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CPPQualifierType implements IQualifierType, ITypeContainer { +public class CPPQualifierType implements IQualifierType, ITypeContainer, ISerializableType { private final boolean isConst; private final boolean isVolatile; private IType type; @@ -30,13 +32,13 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer { } public boolean isSameType(IType o) { - if (o instanceof ITypedef || o instanceof IIndexType) + if (o instanceof ITypedef) return o.isSameType(this); if (!(o instanceof IQualifierType)) return false; IQualifierType pt = (IQualifierType) o; - if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile()) + if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile() && type != null) return type.isSameType(pt.getType()); return false; } @@ -81,4 +83,18 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.CVQUALIFIER; + if (isConst()) firstByte |= ITypeMarshalBuffer.FLAG1; + if (isVolatile()) firstByte |= ITypeMarshalBuffer.FLAG2; + buffer.putByte((byte) firstByte); + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + return new CPPQualifierType(nested, (firstByte & ITypeMarshalBuffer.FLAG1) != 0, + (firstByte & ITypeMarshalBuffer.FLAG2) != 0); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java index 3d3fa3cbacf..783327f5787 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java @@ -14,12 +14,14 @@ import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.core.runtime.CoreException; -public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { +public class CPPReferenceType implements ICPPReferenceType, ITypeContainer, ISerializableType { IType type = null; - public CPPReferenceType(IType type) { this.type = type; } @@ -39,7 +41,7 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { return ((ITypedef)obj).isSameType(this); if (type == null) - return (obj == null); + return false; if (obj instanceof ICPPReferenceType) { return type.isSameType(((ICPPReferenceType) obj).getType()); @@ -62,4 +64,15 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { public String toString() { return ASTTypeUtil.getType(this); } + + public void marshal(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= ITypeMarshalBuffer.REFERENCE; + buffer.putByte((byte) firstByte); + buffer.marshalType(getType()); + } + + public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { + IType nested= buffer.unmarshalType(); + return new CPPReferenceType(nested); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java index 7e9d98f71a3..f8a45daf94f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java @@ -1,36 +1,24 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Mar 11, 2005 - */ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType; -import org.eclipse.cdt.internal.core.index.IIndexType; -/** - * @author aniefer - */ public class GPPPointerToMemberType extends CPPPointerToMemberType implements IGPPPointerToMemberType { private boolean isRestrict; - /** - * @param type - * @param operator - */ public GPPPointerToMemberType(IType type, IGPPASTPointerToMember operator) { super(type, operator); this.isRestrict = operator.isRestrict(); @@ -60,17 +48,18 @@ public class GPPPointerToMemberType extends CPPPointerToMemberType implements IG @Override public boolean isSameType(IType o) { - if (o == this) { - return true; - } - if (o instanceof ITypedef || o instanceof IIndexType) { - return o.isSameType(this); - } - - if (!super.isSameType(o)) return false; - if (o instanceof IGPPPointerToMemberType) { - return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict()); - } - return (isRestrict == false); - } + if (o == this) { + return true; + } + if (o instanceof ITypedef) { + return o.isSameType(this); + } + + if (!super.isSameType(o)) + return false; + if (o instanceof IGPPPointerToMemberType) { + return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict()); + } + return (isRestrict == false); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java index 442f4931bdd..e1f17743707 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java @@ -1,35 +1,24 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Mar 11, 2005 - */ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType; -import org.eclipse.cdt.internal.core.index.IIndexType; -/** - * @author aniefer - */ public class GPPPointerType extends CPPPointerType implements IGPPPointerType { private boolean isRestrict = false; - /** - * @param type - * @param operator - */ + public GPPPointerType( IType type, IGPPASTPointer operator ) { super( type, operator ); isRestrict = operator.isRestrict(); @@ -39,9 +28,6 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType { super( type ); } - /** - * @param type - */ public GPPPointerType( IType type, boolean isConst, boolean isVolatile, boolean isRestrict ) { super( type, isConst, isVolatile ); this.isRestrict = isRestrict; @@ -71,19 +57,20 @@ public class GPPPointerType extends CPPPointerType implements IGPPPointerType { } @Override - public boolean isSameType( IType o ){ - if (o==this) { - return true; - } - if (o instanceof ITypedef || o instanceof IIndexType) { - return o.isSameType(this); - } + public boolean isSameType(IType o) { + if (o == this) { + return true; + } + if (o instanceof ITypedef) { + return o.isSameType(this); + } - if( !super.isSameType( o ) ) return false; - - if( o instanceof IGPPPointerType ){ - return (isRestrict == ((IGPPPointerType) o).isRestrict()); - } - return (isRestrict == false); - } + if (!super.isSameType(o)) + return false; + + if (o instanceof IGPPPointerType) { + return (isRestrict == ((IGPPPointerType) o).isRestrict()); + } + return (isRestrict == false); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 814a708bbfa..4bd639901f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArraySet; @@ -49,7 +50,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; -import org.eclipse.cdt.internal.core.index.IIndexType; /** * @@ -340,9 +340,6 @@ public class SemanticUtil { } public static IType mapToAST(IType type, IASTNode node) { - if (!(type instanceof IIndexType)) - return type; - if (type instanceof IFunctionType) { final ICPPFunctionType ft = (ICPPFunctionType) type; final IType r = ft.getReturnType(); @@ -363,7 +360,7 @@ public class SemanticUtil { return replaceNestedType(tc, newType); } return type; - } else if (type instanceof ICPPClassType && type instanceof IIndexType) { + } else if (type instanceof ICPPClassType && type instanceof IIndexBinding) { IASTTranslationUnit tu = node.getTranslationUnit(); if (tu instanceof CPPASTTranslationUnit) { return ((CPPASTTranslationUnit) tu).mapToAST((ICPPClassType) type); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java deleted file mode 100644 index e727bcea22f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index; - -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IArrayType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; - -public class ArrayTypeClone implements IIndexType, IArrayType, ITypeContainer { - private final IArrayType delegate; - private IType type; - - public ArrayTypeClone(IArrayType array) { - this.delegate = array; - } - - public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return ((ITypedef) type).isSameType(this); - - if (!(type instanceof IArrayType)) - return false; - - IType type1= this.getType(); - if (type1 == null) - return false; - - IArrayType rhs = (IArrayType) type; - if (type1.isSameType(rhs.getType())) { - IValue s1= getSize(); - IValue s2= rhs.getSize(); - if (s1 == s2) - return true; - if (s1 == null || s2 == null) - return false; - return CharArrayUtils.equals(s1.getSignature(), s2.getSignature()); - } - return false; - } - - public IValue getSize() { - return delegate.getSize(); - } - - @Deprecated - public IASTExpression getArraySizeExpression() throws DOMException { - return delegate.getArraySizeExpression(); - } - - public IType getType() { - if (type == null) { - return delegate.getType(); - } - return type; - } - - public void setType(IType type) { - this.type = type; - } - - @Override - public Object clone() { - return new ArrayTypeClone(this); - } - - @Override - public String toString() { - return delegate.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPPointerToMemberTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPPointerToMemberTypeClone.java deleted file mode 100644 index ac3df8a3974..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPPointerToMemberTypeClone.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index; - -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; - -public class CPPPointerToMemberTypeClone extends PointerTypeClone implements ICPPPointerToMemberType { - public CPPPointerToMemberTypeClone(ICPPPointerToMemberType pointer) { - super(pointer); - } - - public IType getMemberOfClass() { - return ((ICPPPointerToMemberType) delegate).getMemberOfClass(); - } - - @Override - public Object clone() { - return new CPPPointerToMemberTypeClone((ICPPPointerToMemberType) delegate); - } - - @Override - public boolean isSameType(IType o) { - if (o instanceof ITypedef) - return o.isSameType(this); - - if (!(o instanceof ICPPPointerToMemberType)) - return false; - - if (!super.isSameType(o)) - return false; - - ICPPPointerToMemberType pt = (ICPPPointerToMemberType) o; - IType cls = pt.getMemberOfClass(); - if (cls != null) - return cls.isSameType(getMemberOfClass()); - - return false; - } -} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java deleted file mode 100644 index cd92e1cfb5f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index; - -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; - -public class CPPReferenceTypeClone implements ICPPReferenceType, ITypeContainer, IIndexType { - private final ICPPReferenceType delegate; - private IType type; - - public CPPReferenceTypeClone(ICPPReferenceType reference) { - this.delegate = reference; - } - - public IType getType() { - if (type == null) { - return delegate.getType(); - } - return type; - } - - public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return type.isSameType(this); - - if (!(type instanceof ICPPReferenceType)) - return false; - - ICPPReferenceType rhs = (ICPPReferenceType) type; - IType type1= getType(); - if (type1 != null) { - return type1.isSameType(rhs.getType()); - } - return false; - } - - public void setType(IType type) { - this.type = type; - } - - @Override - public Object clone() { - return new CPPReferenceTypeClone(this); - } - - @Override - public String toString() { - return delegate.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java index 1ea24109f87..e52028562b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Symbian Software Systems and others. + * Copyright (c) 2007, 2009 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,9 +14,6 @@ package org.eclipse.cdt.internal.core.index; * Constants used by IIndexFragment implementations for identifying persisted binding types */ public interface IIndexBindingConstants { - int POINTER_TYPE= 1; - int ARRAY_TYPE= 2; - int QUALIFIER_TYPE= 3; int MACRO_DEFINITION = 4; int MACRO_CONTAINER = 5; int LAST_CONSTANT= MACRO_CONTAINER; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCBindingConstants.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCBindingConstants.java index 05d7056f71f..e5046545405 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCBindingConstants.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCBindingConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Symbian Software Systems and others. + * Copyright (c) 2007, 2009 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,6 +22,4 @@ public interface IIndexCBindingConstants { int CENUMERATOR = IIndexBindingConstants.LAST_CONSTANT + 6; int CTYPEDEF = IIndexBindingConstants.LAST_CONSTANT + 7; int CPARAMETER = IIndexBindingConstants.LAST_CONSTANT + 8; - int CBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 9; - int CFUNCTIONTYPE = IIndexBindingConstants.LAST_CONSTANT + 10; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCPPBindingConstants.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCPPBindingConstants.java index 16292213811..d1bcbbf76de 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCPPBindingConstants.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexCPPBindingConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Symbian Software Systems and others. + * Copyright (c) 2007, 2009 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,14 +22,11 @@ public interface IIndexCPPBindingConstants { int CPPMETHOD = IIndexBindingConstants.LAST_CONSTANT + 5; int CPPNAMESPACE = IIndexBindingConstants.LAST_CONSTANT + 6; int CPPNAMESPACEALIAS = IIndexBindingConstants.LAST_CONSTANT + 7; - int CPPBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 8; int CPPPARAMETER = IIndexBindingConstants.LAST_CONSTANT + 9; int CPPENUMERATION = IIndexBindingConstants.LAST_CONSTANT + 10; int CPPENUMERATOR = IIndexBindingConstants.LAST_CONSTANT + 11; int CPPTYPEDEF = IIndexBindingConstants.LAST_CONSTANT + 12; - int CPP_POINTER_TO_MEMBER_TYPE= IIndexBindingConstants.LAST_CONSTANT + 13; int CPP_CONSTRUCTOR= IIndexBindingConstants.LAST_CONSTANT + 14; - int CPP_REFERENCE_TYPE= IIndexBindingConstants.LAST_CONSTANT + 15; int CPP_FUNCTION_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 16; int CPP_METHOD_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 17; int CPP_CONSTRUCTOR_TEMPLATE= IIndexBindingConstants.LAST_CONSTANT + 18; @@ -52,8 +49,6 @@ public interface IIndexCPPBindingConstants { int CPP_CLASS_TEMPLATE_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 36; int CPP_TYPEDEF_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 37; int CPP_TEMPLATE_TYPE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 38; - int CPP_FUNCTION_TYPE= IIndexBindingConstants.LAST_CONSTANT + 39; - int GPPBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 40; int CPP_USING_DECLARATION= IIndexBindingConstants.LAST_CONSTANT + 41; int CPP_UNKNOWN_CLASS_TYPE= IIndexBindingConstants.LAST_CONSTANT + 42; int CPP_UNKNOWN_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 43; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java deleted file mode 100644 index cc7b4b2eff6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index; - -import org.eclipse.cdt.core.dom.ast.IPointerType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; - -public class PointerTypeClone implements IPointerType, ITypeContainer, IIndexType { - protected final IPointerType delegate; - private IType type; - - public PointerTypeClone(IPointerType pointer) { - this.delegate = pointer; - } - - public IType getType() { - if (type == null) { - return delegate.getType(); - } - return type; - } - - public boolean isConst() { - return delegate.isConst(); - } - - public boolean isVolatile() { - return delegate.isVolatile(); - } - - public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return ((ITypedef)type).isSameType(this); - - if (!(type instanceof IPointerType)) - return false; - - if (this instanceof ICPPPointerToMemberType != type instanceof ICPPPointerToMemberType) - return false; - - IPointerType rhs = (IPointerType) type; - if (isConst() == rhs.isConst() && isVolatile() == rhs.isVolatile()) { - IType type1= getType(); - if (type1 != null) { - return type1.isSameType(rhs.getType()); - } - } - return false; - } - - public void setType(IType type) { - this.type = type; - } - - @Override - public Object clone() { - return new PointerTypeClone(this); - } - - @Override - public String toString() { - return delegate.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java deleted file mode 100644 index fca6794c3d9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index; - -import org.eclipse.cdt.core.dom.ast.IQualifierType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; - -public class QualifierTypeClone implements IQualifierType, ITypeContainer, IIndexType { - private final IQualifierType delegate; - private IType type; - - public QualifierTypeClone(IQualifierType qualifier) { - this.delegate = qualifier; - } - - public IType getType() { - if (type == null) { - return delegate.getType(); - } - return type; - } - - public boolean isConst() { - return delegate.isConst(); - } - - public boolean isVolatile() { - return delegate.isVolatile(); - } - - public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return type.isSameType(this); - if (!(type instanceof IQualifierType)) - return false; - - IQualifierType pt = (IQualifierType) type; - if (isConst() == pt.isConst() && isVolatile() == pt.isVolatile()) { - IType myType= getType(); - return myType != null && myType.isSameType(pt.getType()); - } - return false; - } - - public void setType(IType type) { - this.type = type; - } - - @Override - public Object clone() { - return new QualifierTypeClone(this); - } - - @Override - public String toString() { - return delegate.toString(); - } -} - diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java index 47f210fd271..374e27ac38e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Symbian Software Systems and others. + * Copyright (c) 2007, 2009 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ import java.util.TreeSet; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.index.CIndex; @@ -52,6 +53,24 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory { return result; } + protected final IType[] getCompositeTypes(IType[] types) { + // Don't create a new array until it's really needed. + IType[] result = types; + for (int i = 0; i < types.length; i++) { + IType type = getCompositeType(types[i]); + if (result != types) { + result[i]= type; + } else if (type != types[i]) { + result = new IType[types.length]; + if (i > 0) { + System.arraycopy(types, 0, result, 0, i); + } + result[i]= type; + } + } + return result; + } + /* * @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getComposites(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.internal.core.index.IIndexFragmentBinding[][]) */ @@ -77,9 +96,9 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory { */ protected IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) { TreeSet ts = new TreeSet(fragmentComparator); - for(int i=0; i0 ? ibs[0] : null; - for(int i=0; i> 24); - fBuffer[++idx]= (byte)(value >> 16); - fBuffer[++idx]= (byte)(value >> 8); - fBuffer[++idx]= (byte)(value); + putInt(value, fBuffer, idx); } + + static final void putInt(final int value, final byte[] buffer, int idx) { + buffer[idx]= (byte)(value >> 24); + buffer[++idx]= (byte)(value >> 16); + buffer[++idx]= (byte)(value >> 8); + buffer[++idx]= (byte)(value); + } + public int getInt(final long offset) { - int idx= recPtrToIndex( offset ); - return ((fBuffer[idx] & 0xff) << 24) | - ((fBuffer[++idx] & 0xff) << 16) | - ((fBuffer[++idx] & 0xff) << 8) | - ((fBuffer[++idx] & 0xff) << 0); + return getInt(fBuffer, recPtrToIndex(offset)); } - - /* - * A Record Pointer is a pointer as returned by Database.malloc(). - * This is a pointer to a block + BLOCK_HEADER_SIZE. - * + + static final int getInt(final byte[] buffer, int idx) { + return ((buffer[idx] & 0xff) << 24) | + ((buffer[++idx] & 0xff) << 16) | + ((buffer[++idx] & 0xff) << 8) | + ((buffer[++idx] & 0xff) << 0); + } + + + /** * A free Record Pointer is a pointer to a raw block, i.e. the * pointer is not moved past the BLOCK_HEADER_SIZE. */ - public void putRecPtr(final long offset, final long value) { - putFreeRecPtr(offset, value == 0 ? value : value - Database.BLOCK_HEADER_SIZE); - } - - public void putFreeRecPtr(final long offset, final long value) { - /* - * This assert verifies the alignment. We expect the low bits to be clear. - */ + private static int compressFreeRecPtr(final long value) { + // This assert verifies the alignment. We expect the low bits to be clear. assert (value & (Database.BLOCK_SIZE_DELTA - 1)) == 0; - putInt(offset, (int) (value >> Database.BLOCK_SIZE_DELTA_BITS)); + final int dense = (int) (value >> Database.BLOCK_SIZE_DELTA_BITS); + return dense; } - public long getRecPtr(final long offset) { - long address = getFreeRecPtr(offset); - return address != 0 ? (address + Database.BLOCK_HEADER_SIZE) : address; - } - - - public long getFreeRecPtr(final long offset) { - int value = getInt(offset); + /** + * A free Record Pointer is a pointer to a raw block, i.e. the + * pointer is not moved past the BLOCK_HEADER_SIZE. + */ + private static long expandToFreeRecPtr(int value) { /* * We need to properly manage the integer that was read. The value will be sign-extended * so if the most significant bit is set, the resulting long will look negative. By @@ -136,6 +134,59 @@ final class Chunk { return address << Database.BLOCK_SIZE_DELTA_BITS; } + + /** + * A Record Pointer is a pointer as returned by Database.malloc(). + * This is a pointer to a block + BLOCK_HEADER_SIZE. + */ + static void putRecPtr(final long value, byte[] buffer, int idx) { + final int denseValue = value == 0 ? 0 : compressFreeRecPtr(value - Database.BLOCK_HEADER_SIZE); + putInt(denseValue, buffer, idx); + } + + /** + * A Record Pointer is a pointer as returned by Database.malloc(). + * This is a pointer to a block + BLOCK_HEADER_SIZE. + */ + static long getRecPtr(byte[] buffer, final int idx) { + int value = getInt(buffer, idx); + long address = expandToFreeRecPtr(value); + return address != 0 ? (address + Database.BLOCK_HEADER_SIZE) : address; + } + + /** + * A Record Pointer is a pointer as returned by Database.malloc(). + * This is a pointer to a block + BLOCK_HEADER_SIZE. + */ + public void putRecPtr(final long offset, final long value) { + assert fLocked; + fDirty = true; + int idx = recPtrToIndex(offset); + putRecPtr(value, fBuffer, idx); + } + + + /** + * A free Record Pointer is a pointer to a raw block, i.e. the + * pointer is not moved past the BLOCK_HEADER_SIZE. + */ + public void putFreeRecPtr(final long offset, final long value) { + assert fLocked; + fDirty = true; + int idx = recPtrToIndex(offset); + putInt(compressFreeRecPtr(value), fBuffer, idx); + } + + public long getRecPtr(final long offset) { + final int idx = recPtrToIndex(offset); + return getRecPtr(fBuffer, idx); + } + + public long getFreeRecPtr(final long offset) { + final int idx = recPtrToIndex(offset); + int value = getInt(fBuffer, idx); + return expandToFreeRecPtr(value); + } public void put3ByteUnsignedInt(final long offset, final int value) { assert fLocked; @@ -215,10 +266,29 @@ final class Chunk { void clear(final long offset, final int length) { assert fLocked; fDirty= true; - int idx= recPtrToIndex( offset ); - final int end= idx + length; + int idx = recPtrToIndex(offset); + final int end = idx + length; for (; idx < end; idx++) { - fBuffer[idx]= 0; + fBuffer[idx] = 0; + } + } + + void put(final long offset, final byte[] data, final int len) { + assert fLocked; + fDirty= true; + int idx = recPtrToIndex(offset); + int i=0; + while (i ShortString.MAX_LENGTH) return new LongString(this, string); @@ -754,5 +767,4 @@ public class Database { } return 0; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java new file mode 100644 index 00000000000..4e3bcceb10f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.db; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; +import org.eclipse.core.runtime.CoreException; + +/** + * For marshalling types to byte arrays. + */ +public class TypeMarshalBuffer implements ITypeMarshalBuffer { + public final static byte [] EMPTY= {0,0,0,0,0,0}; + public final static byte NULL_TYPE= 0; + public final static byte INDIRECT_TYPE= (byte) -1; + public final static byte BINDING_TYPE= (byte) -2; + + static { + assert EMPTY.length == Database.TYPE_SIZE; + } + + private final PDOMLinkage fLinkage; + private int fPos; + private byte[] fBuffer; + + /** + * Constructor for output buffer. + */ + public TypeMarshalBuffer(PDOMLinkage linkage) { + fLinkage= linkage; + } + + /** + * Constructor for input buffer. + */ + public TypeMarshalBuffer(PDOMLinkage linkage, byte[] data) { + fLinkage= linkage; + fBuffer= data; + } + + public int getPosition() { + return fPos; + } + + public byte[] getBuffer() { + return fBuffer; + } + + public void marshalType(IType type) throws CoreException { + if (type instanceof IBinding) { + PDOMBinding pb= fLinkage.addTypeBinding((IBinding) type); + if (pb == null) { + putByte(NULL_TYPE); + } else { + putByte(BINDING_TYPE); + putByte((byte) 0); + putRecordPointer(pb.getRecord()); + } + } else if (type instanceof ISerializableType) { + ((ISerializableType) type).marshal(this); + } else { + assert type == null : "Cannot serialize " + ASTTypeUtil.getType(type) + "(" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + putByte(NULL_TYPE); + } + } + + private void request(int i) { + if (fBuffer == null) { + if (i <= Database.TYPE_SIZE) { + fBuffer= new byte[Database.TYPE_SIZE]; + } else { + fBuffer= new byte[i]; + } + } else { + final int bufLen = fBuffer.length; + int needLen = fPos + i; + if (needLen > bufLen) { + needLen= Math.max(needLen, 2 * bufLen); + byte[] newBuffer= new byte[needLen]; + System.arraycopy(fBuffer, 0, newBuffer, 0, fPos); + fBuffer= newBuffer; + } + } + } + + public void putByte(byte b) { + request(1); + fBuffer[fPos++]= b; + } + + public byte getByte() throws CoreException { + if (fPos+1 > fBuffer.length) + throw unmarshallingError(); + return fBuffer[fPos++]; + } + + public CoreException unmarshallingError() { + return new CoreException(CCorePlugin.createStatus("Unmarshalling error")); //$NON-NLS-1$ + } + public CoreException marshallingError() { + return new CoreException(CCorePlugin.createStatus("Marshalling error")); //$NON-NLS-1$ + } + + public void putShort(short value) { + request(2); + fBuffer[fPos++]= (byte)(value >> 8); + fBuffer[fPos++]= (byte)(value); + } + + public short getShort() throws CoreException { + if (fPos+2 > fBuffer.length) + throw unmarshallingError(); + return (short) (((fBuffer[fPos++] << 8) | (fBuffer[fPos++] & 0xff))); + } + + private void putRecordPointer(long record) { + request(Database.PTR_SIZE); + Chunk.putRecPtr(record, fBuffer, fPos); + fPos+= Database.PTR_SIZE; + } + + private long getRecordPointer() throws CoreException { + final int pos= fPos; + fPos += Database.PTR_SIZE; + if (fPos > fBuffer.length) { + fPos= fBuffer.length; + throw unmarshallingError(); + } + return Chunk.getRecPtr(fBuffer, pos); + } + + public IValue getValue() throws CoreException { + short replen= getShort(); + short unknwonLen= getShort(); + + char[] rep= new char[replen]; + for (int i = 0; i < replen; i++) { + rep[i]= (char) getShort(); + } + ICPPUnknownBinding[] unknown= new ICPPUnknownBinding[unknwonLen]; + for (int i = 0; i < unknwonLen; i++) { + long ptr= getRecordPointer(); + IBinding b= fLinkage.getBinding(ptr); + if (b instanceof ICPPUnknownBinding) { + unknown[i]= (ICPPUnknownBinding) b; + } + } + return Value.fromInternalRepresentation(rep, unknown); + } + + public void putValue(IValue value) throws CoreException { + char[] rep= value.getInternalExpression(); + IBinding[] unknown= value.getUnknownBindings(); + putShort((short) rep.length); + putShort((short) unknown.length); + + int len= rep.length & 0xffff; + for (int i = 0; i < len; i++) { + putShort((short) rep[i]); + } + len= unknown.length & 0xffff; + for (int i = 0; i < len; i++) { + PDOMBinding uv = fLinkage.addUnknownValue(unknown[i]); + putRecordPointer(uv != null ? uv.getRecord() : 0); + } + } + + public IType unmarshalType() throws CoreException { + if (fPos >= fBuffer.length) + throw unmarshallingError(); + + byte firstByte= fBuffer[fPos]; + if (firstByte == BINDING_TYPE) { + fPos+= 2; + long rec= getRecordPointer(); + return (IType) fLinkage.getNode(rec); + } else if (firstByte == 0) { + fPos++; + return null; + } + + return fLinkage.unmarshalType(this); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java deleted file mode 100644 index d8121bebd61..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Markus Schorn - initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.pdom.dom; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IArrayType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; -import org.eclipse.cdt.internal.core.dom.parser.Value; -import org.eclipse.cdt.internal.core.index.ArrayTypeClone; -import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexType; -import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.core.runtime.CoreException; - -public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, ITypeContainer { - - private static final int TYPE = PDOMNode.RECORD_SIZE; - private static final int ARRAYSIZE= TYPE + Database.PTR_SIZE; - @SuppressWarnings("hiding") - private static final int RECORD_SIZE= ARRAYSIZE + Database.PTR_SIZE; - - private IType fCachedType= null; - private IValue fCachedValue= Value.NOT_INITIALIZED; - - public PDOMArrayType(PDOMLinkage linkage, long record) { - super(linkage, record); - } - - public PDOMArrayType(PDOMLinkage linkage, PDOMNode parent, IArrayType type) throws CoreException { - super(linkage, parent); - PDOMNode targetTypeNode = getLinkage().addType(this, type.getType()); - if (targetTypeNode != null) { - long typeRec = targetTypeNode.getRecord(); - final Database db = getDB(); - db.putRecPtr(record + TYPE, typeRec); - IValue val= type.getSize(); - if (val != null) { - long ptr= PDOMValue.store(db, linkage, val); - db.putRecPtr(record + ARRAYSIZE, ptr); - } - } - } - - @Override - protected int getRecordSize() { - return RECORD_SIZE; - } - - @Override - public int getNodeType() { - return IIndexBindingConstants.ARRAY_TYPE; - } - - public IType getType() { - if (fCachedType == null) { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - if (node instanceof IType) { - return fCachedType= (IType) node; - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - return fCachedType; - } - - - public IValue getSize() { - if (fCachedValue == Value.NOT_INITIALIZED) { - try { - final Database db = getDB(); - long ptr= db.getRecPtr(record + ARRAYSIZE); - return fCachedValue= PDOMValue.restore(db, getLinkage(), ptr); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return fCachedValue= null; - } - return fCachedValue; - } - - public boolean isSameType(IType type) { - if( type instanceof ITypedef ) - return ((ITypedef)type).isSameType( this ); - - if( !( type instanceof IArrayType )) - return false; - - IType type1= this.getType(); - if( type1 == null ) - return false; - - IArrayType rhs = (IArrayType) type; - if (type1.isSameType(rhs.getType())) { - IValue s1 = getSize(); - IValue s2 = rhs.getSize(); - if (s1 == s2) - return true; - if (s1 == null || s2 == null) - return false; - return CharArrayUtils.equals(s1.getSignature(), s2.getSignature()); - } - return false; - } - - public void setType(IType type) { - throw new PDOMNotImplementedError(); - } - - @Override - public Object clone() { - return new ArrayTypeClone(this); - } - - @Override - public void delete(PDOMLinkage linkage) throws CoreException { - linkage.deleteType(getType(), record); - super.delete(linkage); - } - - @Deprecated - public IASTExpression getArraySizeExpression() throws DOMException { - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index 8f8245f72a1..e4881124af9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -21,16 +21,13 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IArrayType; 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.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IParameter; -import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; @@ -38,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.core.parser.util.CharArrayMap; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM; @@ -46,6 +44,7 @@ import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.db.IString; +import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -183,29 +182,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage switch (nodeType) { case LINKAGE: return null; - case POINTER_TYPE: - return new PDOMPointerType(this, record); - case ARRAY_TYPE: - return new PDOMArrayType(this, record); - case QUALIFIER_TYPE: - return new PDOMQualifierType(this, record); } return getNode(record, nodeType); } abstract public PDOMNode getNode(long record, int nodeType) throws CoreException; - public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { - if (type instanceof IPointerType) - return new PDOMPointerType(this, parent, (IPointerType)type); - else if (type instanceof IArrayType) - return new PDOMArrayType(this, parent, (IArrayType) type); - else if (type instanceof IQualifierType) - return new PDOMQualifierType(this, parent, (IQualifierType)type); - else - return null; - } - public abstract IBTreeComparator getIndexComparator(); public IBTreeComparator getNestedBindingsComparator() { @@ -331,7 +313,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } /** - * Callback informing the linkage that a binding is about to be removed. Used to index nested bindings. + * Call-back informing the linkage that a binding is about to be removed. Used to index nested bindings. * @param pdomBinding * @throws CoreException * @since 4.0.1 @@ -342,26 +324,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } } - public void deleteType(IType type, long ownerRec) throws CoreException { - if (type instanceof PDOMNode) { - PDOMNode node= (PDOMNode) type; - // at this point only delete types that are actually owned by the requesting party. - if (node.getParentNodeRec() == ownerRec) { - assert ! (node instanceof IBinding); - node.delete(this); - } - } - } - - public void deleteBinding(IBinding binding) throws CoreException { - // no implementation, yet. - } - - @Override - public void delete(PDOMLinkage linkage) throws CoreException { - assert false; // no need to delete linkages. - } - public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException { return ICPPUsingDirective.EMPTY_ARRAY; } @@ -461,4 +423,72 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } return map; } + + public abstract PDOMBinding addTypeBinding(IBinding type) throws CoreException; + public abstract IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException; + + public void storeType(long offset, IType type) throws CoreException { + final Database db= getDB(); + deleteType(db, offset); + storeType(db, offset, type); + } + + private void storeType(Database db, long offset, IType type) throws CoreException { + if (type != null) { + TypeMarshalBuffer bc= new TypeMarshalBuffer(this); + bc.marshalType(type); + int len= bc.getPosition(); + if (len > 0) { + if (len <= Database.TYPE_SIZE) { + db.putBytes(offset, bc.getBuffer(), len); + } else if (len <= Database.MAX_MALLOC_SIZE-2){ + long ptr= db.malloc(len+2); + db.putShort(ptr, (short) len); + db.putBytes(ptr+2, bc.getBuffer(), len); + db.putByte(offset, TypeMarshalBuffer.INDIRECT_TYPE); + db.putRecPtr(offset+2, ptr); + } + } + } + } + + private void deleteType(Database db, long offset) throws CoreException { + byte firstByte= db.getByte(offset); + if (firstByte == TypeMarshalBuffer.INDIRECT_TYPE) { + long ptr= db.getRecPtr(offset+2); + clearType(db, offset); + db.free(ptr); + } else { + clearType(db, offset); + } + } + + private void clearType(Database db, long offset) throws CoreException { + db.clearBytes(offset, Database.TYPE_SIZE); + } + + public IType loadType(long offset) throws CoreException { + final Database db= getDB(); + final byte firstByte= db.getByte(offset); + byte[] data= null; + switch(firstByte) { + case TypeMarshalBuffer.INDIRECT_TYPE: + long ptr= db.getRecPtr(offset+2); + int len= db.getShort(ptr) & 0xffff; + data= new byte[len]; + db.getBytes(ptr+2, data); + break; + case TypeMarshalBuffer.NULL_TYPE: + break; + default: + data= new byte[Database.TYPE_SIZE]; + db.getBytes(offset, data); + break; + } + + if (data != null) { + return new TypeMarshalBuffer(this, data).unmarshalType(); + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java deleted file mode 100644 index 44b26a37da7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMPointerType.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.pdom.dom; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.IPointerType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; -import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexType; -import org.eclipse.cdt.internal.core.index.PointerTypeClone; -import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.core.runtime.CoreException; - -/** - * Pointer types for c and c++. - */ -public class PDOMPointerType extends PDOMNode implements IPointerType, - ITypeContainer, IIndexType { - - private static final int FLAGS = PDOMNode.RECORD_SIZE + 0; // byte - private static final int TYPE = PDOMNode.RECORD_SIZE + 1; - - @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5; - - private static final int CONST = 0x1; - private static final int VOLATILE = 0x2; - - - // cached values - private byte flags= -1; - private IType targetType; - - public PDOMPointerType(PDOMLinkage linkage, long record) { - super(linkage, record); - } - - public PDOMPointerType(PDOMLinkage linkage, PDOMNode parent, IPointerType type) throws CoreException { - super(linkage, parent); - - Database db = getDB(); - - // type - long typeRec = 0; - byte flags = 0; - if (type != null) { - IType targetType= type.getType(); - PDOMNode targetTypeNode = getLinkage().addType(this, targetType); - if (targetTypeNode != null) - typeRec = targetTypeNode.getRecord(); - if (type.isConst()) - flags |= CONST; - if (type.isVolatile()) - flags |= VOLATILE; - } - db.putRecPtr(record + TYPE, typeRec); - db.putByte(record + FLAGS, flags); - } - - @Override - protected int getRecordSize() { - return RECORD_SIZE; - } - - @Override - public int getNodeType() { - return IIndexBindingConstants.POINTER_TYPE; - } - - private byte getFlags() throws CoreException { - if (flags == -1) { - flags= getDB().getByte(record + FLAGS); - } - return flags; - } - - public IType getType() { - if (targetType == null) - targetType= readType(); - - return targetType; - } - - private IType readType() { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; - } catch (CoreException e) { - CCorePlugin.log(e); - return null; - } - } - - public boolean isConst() { - try { - return (getFlags() & CONST) != 0; - } catch (CoreException e) { - CCorePlugin.log(e); - return false; - } - } - - public boolean isVolatile() { - try { - return (getFlags() & VOLATILE) != 0; - } catch (CoreException e) { - CCorePlugin.log(e); - return false; - } - } - - public boolean isSameType(IType type) { - if( type instanceof ITypedef ) - return ((ITypedef)type).isSameType( this ); - - if (!(type instanceof IPointerType)) - return false; - - if (this instanceof ICPPPointerToMemberType != type instanceof ICPPPointerToMemberType) - return false; - - IPointerType rhs = (IPointerType) type; - if (isConst() == rhs.isConst() && isVolatile() == rhs.isVolatile()) { - IType type1= getType(); - if (type1 != null) { - return type1.isSameType(rhs.getType()); - } - } - return false; - } - - public void setType(IType type) { - throw new PDOMNotImplementedError(); - } - - @Override - public Object clone() { - return new PointerTypeClone(this); - } - - @Override - public void delete(PDOMLinkage linkage) throws CoreException { - linkage.deleteType(getType(), record); - super.delete(linkage); - } - - @Override - public String toString() { - return ASTTypeUtil.getType(this); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java deleted file mode 100644 index 3d331f4594a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMQualifierType.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.pdom.dom; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.IQualifierType; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.c.ICQualifierType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; -import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexType; -import org.eclipse.cdt.internal.core.index.QualifierTypeClone; -import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.core.runtime.CoreException; - -/** - * Type qualifier for the index. - */ -public class PDOMQualifierType extends PDOMNode implements IQualifierType, ICQualifierType, - ITypeContainer, IIndexType { - - private static final int FLAGS = PDOMNode.RECORD_SIZE; - private static final int TYPE = PDOMNode.RECORD_SIZE + 1; - - @SuppressWarnings("hiding") - private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5; - - private static final int CONST = 0x1; - private static final int VOLATILE = 0x2; - private static final int RESTRICT = 0x4; - - // cached values - private byte flags= -1; - private IType targetType; - - public PDOMQualifierType(PDOMLinkage linkage, long record) { - super(linkage, record); - } - - public PDOMQualifierType(PDOMLinkage linkage, PDOMNode parent, IQualifierType type) throws CoreException { - super(linkage, parent); - - Database db = getDB(); - - if (type != null) { - IType targetType = type.getType(); - PDOMNode targetTypeNode = getLinkage().addType(this, targetType); - if (targetTypeNode != null) { - db.putRecPtr(record + TYPE, targetTypeNode.getRecord()); - } - // flags - byte flags = 0; - if (type.isConst()) - flags |= CONST; - if (type.isVolatile()) - flags |= VOLATILE; - if (type instanceof ICQualifierType && ((ICQualifierType)type).isRestrict()) - flags |= RESTRICT; - db.putByte(record + FLAGS, flags); - } - } - - @Override - protected int getRecordSize() { - return RECORD_SIZE; - } - - @Override - public int getNodeType() { - return IIndexBindingConstants.QUALIFIER_TYPE; - } - - public IType getType() { - if (targetType == null) - targetType= readType(); - - return targetType; - } - - private IType readType() { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; - } catch (CoreException e) { - CCorePlugin.log(e); - return null; - } - } - - private byte getFlags() throws CoreException { - if (flags == -1) { - flags= getDB().getByte(record + FLAGS); - } - return flags; - } - - public boolean isConst() { - try { - return (getFlags() & CONST) != 0; - } catch (CoreException e) { - CCorePlugin.log(e); - return false; - } - } - - public boolean isVolatile() { - try { - return (getFlags() & VOLATILE) != 0; - } catch (CoreException e) { - CCorePlugin.log(e); - return false; - } - } - - public boolean isRestrict() { - try { - return (getFlags() & RESTRICT) != 0; - } catch (CoreException e) { - CCorePlugin.log(e); - return false; - } - } - - public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return type.isSameType(this); - if (!(type instanceof IQualifierType)) - return false; - - IQualifierType pt = (IQualifierType) type; - boolean flagsMatch= isConst() == pt.isConst() && isVolatile() == pt.isVolatile(); - if (flagsMatch && type instanceof ICQualifierType) - flagsMatch &= isRestrict() == ((ICQualifierType) type).isRestrict(); - if (flagsMatch) { - IType myType= getType(); - return myType != null && myType.isSameType(pt.getType()); - } - return false; - } - - public void setType(IType type) { - throw new PDOMNotImplementedError(); - } - - @Override - public Object clone() { - return new QualifierTypeClone(this); - } - - @Override - public void delete(PDOMLinkage linkage) throws CoreException { - linkage.deleteType(getType(), record); - super.delete(linkage); - } - - @Override - public String toString() { - return ASTTypeUtil.getType(this); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java deleted file mode 100644 index eb0003f1799..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCBasicType.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer (QNX) - Initial API and implementation - * Andrew Ferguson (Symbian) - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.pdom.dom.c; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.c.ICBasicType; -import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexType; -import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.core.runtime.CoreException; - -/** - * Models integral c-types. - */ -class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType { - - public static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short - public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short - - @SuppressWarnings("hiding") - public static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4; - - private int fModifiers= -1; - - public PDOMCBasicType(PDOMLinkage linkage, long record) { - super(linkage, record); - } - - public PDOMCBasicType(PDOMLinkage linkage, PDOMNode parent, ICBasicType type) throws CoreException { - super(linkage, parent); - - Database db = getDB(); - db.putChar(record + TYPE_ID, (char)type.getKind().ordinal()); - - char flags = (char) type.getModifiers(); - db.putChar(record + FLAGS, flags); - } - - @Override - protected int getRecordSize() { - return RECORD_SIZE; - } - - @Override - public int getNodeType() { - return IIndexCBindingConstants.CBASICTYPE; - } - - public Kind getKind() { - try { - int idx= getDB().getChar(record + TYPE_ID); - return Kind.values()[idx]; - } catch (CoreException e) { - CCorePlugin.log(e); - return Kind.eInt; - } - } - - public boolean isLong() { return flagSet(IS_LONG); } - public boolean isShort() { return flagSet(IS_SHORT); } - public boolean isSigned() { return flagSet(IS_SIGNED); } - public boolean isUnsigned() { return flagSet(IS_UNSIGNED); } - public boolean isLongLong() { return flagSet(IS_LONG_LONG); } - public boolean isImaginary() { return flagSet(IS_IMAGINARY); } - public boolean isComplex() { return flagSet(IS_COMPLEX); } - - - public boolean isSameType(IType rhs) { - if( rhs instanceof ITypedef ) - return rhs.isSameType( this ); - - if( !(rhs instanceof ICBasicType)) - return false; - - ICBasicType rhs1= (ICBasicType) rhs; - Kind kind = getKind(); - if (kind != rhs1.getKind()) - return false; - - if (kind == Kind.eInt) { - //signed int and int are equivalent - return (getModifiers() & ~IS_SIGNED) == (rhs1.getModifiers() & ~IS_SIGNED); - } else { - return (getModifiers() == rhs1.getModifiers()); - } - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } - - public int getModifiers() { - if (fModifiers == -1) { - try { - fModifiers= getDB().getChar(record + FLAGS); - } catch (CoreException e) { - CCorePlugin.log(e); - fModifiers= 0; - } - } - return fModifiers; - } - - private boolean flagSet(int flag) { - return (getModifiers() & flag) != 0; - } - - @Deprecated - public int getType() { - final Kind kind = getKind(); - switch (kind) { - case eBoolean: - return t_Bool; - case eChar: - case eWChar: - return t_char; - case eDouble: - return t_double; - case eFloat: - return t_float; - case eInt: - return t_int; - case eVoid: - return t_void; - case eUnspecified: - return t_unspecified; - } - return t_unspecified; - } - - @Deprecated - public IASTExpression getValue() throws DOMException { - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java index d3441878c8d..1d68bb7953d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java @@ -21,8 +21,10 @@ import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; +import org.eclipse.cdt.internal.core.pdom.db.Database; 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; @@ -37,31 +39,31 @@ class PDOMCFunction extends PDOMBinding implements IFunction { * Offset of total number of function parameters (relative to the * beginning of the record). */ - public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE + 0; + public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE; /** * Offset of total number of function parameters (relative to the * beginning of the record). */ - public static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4; + public static final int FIRST_PARAM = NUM_PARAMS + 4; /** * Offset for the type of this function (relative to * the beginning of the record). */ - private static final int FUNCTION_TYPE = PDOMBinding.RECORD_SIZE + 8; + private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE; /** * Offset of annotation information (relative to the beginning of the * record). */ - private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 12; // byte + private static final int ANNOTATIONS = FUNCTION_TYPE + Database.TYPE_SIZE; // byte /** * The size in bytes of a PDOMCPPFunction record in the database. */ @SuppressWarnings("hiding") - public static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 13; + public static final int RECORD_SIZE = ANNOTATIONS + 1; public PDOMCFunction(PDOMLinkage linkage, long record) { super(linkage, record); @@ -100,17 +102,9 @@ class PDOMCFunction extends PDOMBinding implements IFunction { throw new CoreException(Util.createStatus(e)); } - IFunctionType oldType= getType(); - if (oldType != null && oldType.isSameType(newType)) { - oldType= null; - } else { - setType(linkage, newType); - } - PDOMCParameter oldParams= getFirstParameter(); + setType(linkage, newType); + PDOMCParameter oldParams= getFirstParameter(null); setParameters(newParams); - if (oldType != null) { - linkage.deleteType(oldType, record); - } if (oldParams != null) { oldParams.delete(linkage); } @@ -119,37 +113,26 @@ class PDOMCFunction extends PDOMBinding implements IFunction { } private void setType(PDOMLinkage linkage, IFunctionType ft) throws CoreException { - long rec= 0; - if (ft != null) { - PDOMNode typeNode = linkage.addType(this, ft); - if (typeNode != null) { - rec= typeNode.getRecord(); - } - } - getDB().putRecPtr(record + FUNCTION_TYPE, rec); + linkage.storeType(record+FUNCTION_TYPE, ft); } private void setParameters(IParameter[] params) throws CoreException { - getDB().putInt(record + NUM_PARAMS, params.length); - getDB().putRecPtr(record + FIRST_PARAM, 0); - for (int i = 0; i < params.length; ++i) { - setFirstParameter(new PDOMCParameter(getLinkage(), this, params[i])); + final PDOMLinkage linkage = getLinkage(); + final Database db= getDB(); + db.putInt(record + NUM_PARAMS, params.length); + db.putRecPtr(record + FIRST_PARAM, 0); + PDOMCParameter next= null; + for (int i= params.length-1; i >= 0; --i) { + next= new PDOMCParameter(linkage, this, params[i], next); } + db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord()); } - public PDOMCParameter getFirstParameter() throws CoreException { + public PDOMCParameter getFirstParameter(IType t) throws CoreException { long rec = getDB().getRecPtr(record + FIRST_PARAM); - return rec != 0 ? new PDOMCParameter(getLinkage(), rec) : null; + return rec != 0 ? new PDOMCParameter(getLinkage(), rec, t) : null; } - public void setFirstParameter(PDOMCParameter param) throws CoreException { - if (param != null) - param.setNextParameter(getFirstParameter()); - long rec = param != null ? param.getRecord() : 0; - getDB().putRecPtr(record + FIRST_PARAM, rec); - } - - @Override protected int getRecordSize() { return RECORD_SIZE; @@ -161,16 +144,8 @@ class PDOMCFunction extends PDOMBinding implements IFunction { } public IFunctionType getType() { - /* - * CVisitor binding resolution assumes any IBinding which is - * also an IType should be converted to a IProblemBinding in a - * route through the code that triggers errors here. This means - * we can't use the convenient idea of having PDOMCFunction implement - * both the IType and IBinding interfaces. - */ try { - long offset= getDB().getRecPtr(record + FUNCTION_TYPE); - return offset==0 ? null : new PDOMCFunctionType(getLinkage(), offset); + return (IFunctionType) getLinkage().loadType(record + FUNCTION_TYPE); } catch(CoreException ce) { CCorePlugin.log(ce); return null; @@ -187,17 +162,25 @@ class PDOMCFunction extends PDOMBinding implements IFunction { public IParameter[] getParameters() throws DOMException { try { - int n = getDB().getInt(record + NUM_PARAMS); - IParameter[] params = new IParameter[n]; - PDOMCParameter param = getFirstParameter(); - while (param != null) { - params[--n] = param; - param = param.getNextParameter(); + PDOMLinkage linkage= getLinkage(); + Database db= getDB(); + IFunctionType ft = getType(); + IType[] ptypes= ft == null ? IType.EMPTY_TYPE_ARRAY : ft.getParameterTypes(); + + int n = db.getInt(record + NUM_PARAMS); + IParameter[] result = new IParameter[n]; + + long next = db.getRecPtr(record + FIRST_PARAM); + for (int i = 0; i < n && next != 0; i++) { + IType type= i result= new ArrayList(); - try { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + TYPELIST, true); - list.accept(new IPDOMVisitor() { - public void leave(IPDOMNode node) throws CoreException { - result.add((IType)node); - } - public boolean visit(IPDOMNode node) throws CoreException { - return false; - } - }); - } catch (CoreException ce) { - CCorePlugin.log(ce); - } - return result.toArray(new IType[result.size()]); - } - - public IType getReturnType() { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + RETURN_TYPE)); - if (node instanceof IType) { - return (IType) node; - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - public void setReturnType(IType type) throws CoreException { - PDOMNode typeNode = getLinkage().addType(this, type); - if (typeNode != null) { - getDB().putRecPtr(record + RETURN_TYPE, typeNode.getRecord()); - } - } - - @Override - public Object clone() { - throw new PDOMNotImplementedError(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index c19acd503c6..0a8904445c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -22,14 +22,17 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; -import org.eclipse.cdt.core.dom.ast.IFunctionType; -import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.c.CArrayType; +import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType; +import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType; +import org.eclipse.cdt.internal.core.dom.parser.c.CPointerType; +import org.eclipse.cdt.internal.core.dom.parser.c.CQualifierType; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -312,36 +315,39 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { return new PDOMCEnumerator(this, record); case CTYPEDEF: return new PDOMCTypedef(this, record); - case CPARAMETER: - return new PDOMCParameter(this, record); - case CBASICTYPE: - return new PDOMCBasicType(this, record); - case CFUNCTIONTYPE: - return new PDOMCFunctionType(this, record); } assert false; return null; } - - @Override - public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { - if(type instanceof IProblemBinding) - return null; - - if (type instanceof ICBasicType) { - return new PDOMCBasicType(this, parent, (ICBasicType)type); - } else if(type instanceof IFunctionType) { - return new PDOMCFunctionType(this, parent, (IFunctionType)type); - } else if (type instanceof IBinding) { - return addBinding((IBinding)type, null); - } - - return super.addType(parent, type); - } @Override public IBTreeComparator getIndexComparator() { return new FindBinding.DefaultBindingBTreeComparator(this); } + + @Override + public PDOMBinding addTypeBinding(IBinding type) throws CoreException { + return addBinding(type, null); + } + + + @Override + public IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= buffer.getByte() & 0xff; + switch((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + case ITypeMarshalBuffer.ARRAY: + return CArrayType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.BASIC_TYPE: + return CBasicType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.CVQUALIFIER: + return CQualifierType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.FUNCTION_TYPE: + return CFunctionType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.POINTER: + return CPointerType.unmarshal(firstByte, buffer); + } + + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java index fe9c074efbe..2d1b6322dc7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -14,13 +14,10 @@ package org.eclipse.cdt.internal.core.pdom.dom.c; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IParameter; -import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.index.IIndexFile; -import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexScope; @@ -35,43 +32,32 @@ import org.eclipse.core.runtime.CoreException; /** * Binding for a function parameter in the index. */ -class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { +final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { - private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0; - private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; - - protected static final int FLAGS = PDOMNamedNode.RECORD_SIZE + 8; - + private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE; + private static final int FLAG_OFFSET = NEXT_PARAM + Database.PTR_SIZE; @SuppressWarnings("hiding") - public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 9; + public static final int RECORD_SIZE = FLAG_OFFSET + 1; static { assert RECORD_SIZE <= 22; // 23 would yield a 32-byte block } - public PDOMCParameter(PDOMLinkage linkage, long record) { + private final IType fType; + public PDOMCParameter(PDOMLinkage linkage, long record, IType type) { super(linkage, record); + fType= type; } - public PDOMCParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param) + public PDOMCParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, PDOMCParameter next) throws CoreException { super(linkage, parent, param.getNameCharArray()); + fType= null; // this constructor is used for adding parameters to the database, only. Database db = getDB(); db.putRecPtr(record + NEXT_PARAM, 0); - try { - if(!(param instanceof IProblemBinding)) { - IType type = param.getType(); - if (type != null) { - PDOMNode typeNode = getLinkage().addType(this, type); - db.putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0); - } - byte flags = encodeFlags(param); - db.putByte(record + FLAGS, flags); - } - } catch(DOMException e) { - throw new CoreException(Util.createStatus(e)); - } + db.putRecPtr(record + NEXT_PARAM, next == null ? 0 : next.getRecord()); + db.putByte(record + FLAG_OFFSET, encodeFlags(param)); } @Override @@ -83,31 +69,9 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { public int getNodeType() { return IIndexCBindingConstants.CPARAMETER; } - - public void setNextParameter(PDOMCParameter nextParam) throws CoreException { - long rec = nextParam != null ? nextParam.getRecord() : 0; - getDB().putRecPtr(record + NEXT_PARAM, rec); - } - - public PDOMCParameter getNextParameter() throws CoreException { - long rec = getDB().getRecPtr(record + NEXT_PARAM); - return rec != 0 ? new PDOMCParameter(getLinkage(), rec) : null; - } - - public IASTInitializer getDefaultValue() { - return null; -// TODO throw new PDOMNotImplementedError(); - } - + public IType getType() { - try { - PDOMLinkage linkage = getLinkage(); - PDOMNode node = linkage.getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; - } catch (CoreException e) { - CCorePlugin.log(e); - return null; - } + return fType; } public boolean isAuto() throws DOMException { @@ -115,19 +79,11 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { return hasFlag(flag, true); } - public boolean isExtern() throws DOMException { - throw new PDOMNotImplementedError(); - } - public boolean isRegister() throws DOMException { byte flag = 1<= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/8); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); long p= record+2; for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/8); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); if (len == 0) { return ICPPTemplateArgument.EMPTY_ARGUMENTS; } @@ -97,16 +92,18 @@ public class PDOMCPPArgumentList { rec+=2; ICPPTemplateArgument[] result= new ICPPTemplateArgument[len]; for (int i=0; i= 0; --i) { + next= new PDOMCPPParameter(linkage, this, params[i], next); } + db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord()); } - private PDOMCPPFunctionType setType(ICPPFunctionType ft) throws CoreException { - PDOMCPPFunctionType pft = (PDOMCPPFunctionType) getLinkage().addType(this, ft); - getDB().putRecPtr(record + FUNCTION_TYPE, pft.getRecord()); - getPDOM().putCachedResult(record, pft, true); - return pft; + private void setType(ICPPFunctionType ft) throws CoreException { + fType= null; + getLinkage().storeType(record+FUNCTION_TYPE, ft); } public int getSignatureHash() throws CoreException { @@ -207,16 +198,9 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl return IIndexCPPBindingConstants.CPPFUNCTION; } - private PDOMCPPParameter getFirstParameter() throws CoreException { + private PDOMCPPParameter getFirstParameter(IType type) throws CoreException { long rec = getDB().getRecPtr(record + FIRST_PARAM); - return rec != 0 ? new PDOMCPPParameter(getLinkage(), rec) : null; - } - - private void setFirstParameter(PDOMCPPParameter param) throws CoreException { - if (param != null) - param.setNextParameter(getFirstParameter()); - long rec = param != null ? param.getRecord() : 0; - getDB().putRecPtr(record + FIRST_PARAM, rec); + return rec != 0 ? new PDOMCPPParameter(getLinkage(), rec, type) : null; } public boolean isInline() throws DOMException { @@ -243,40 +227,39 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl public IParameter[] getParameters() throws DOMException { try { - int n = getDB().getInt(record + NUM_PARAMS); - IParameter[] params = new IParameter[n]; - PDOMCPPParameter param = getFirstParameter(); - while (param != null) { - params[--n] = param; - param = param.getNextParameter(); + PDOMLinkage linkage= getLinkage(); + Database db= getDB(); + ICPPFunctionType ft = getType(); + IType[] ptypes= ft == null ? IType.EMPTY_TYPE_ARRAY : ft.getParameterTypes(); + + int n = db.getInt(record + NUM_PARAMS); + IParameter[] result = new IParameter[n]; + + long next = db.getRecPtr(record + FIRST_PARAM); + for (int i = 0; i < n && next != 0; i++) { + IType type= i= 0; --i) { + PDOMCPPParameter par= new PDOMCPPParameter(linkage, specialized, spAstParams[i], null); + next= new PDOMCPPParameterSpecialization(linkage, this, astParams[i], par, next); } - db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function)); + db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord()); + db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(astFunction)); } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } try { long typelist= 0; - if (function instanceof ICPPMethod && ((ICPPMethod) function).isImplicit()) { + if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) { // don't store the exception specification, computed it on demand. } else { - typelist = PDOMCPPTypeList.putTypes(this, function.getExceptionSpecification()); + typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification()); } db.putRecPtr(record + EXCEPTION_SPEC, typelist); } catch (DOMException e) { @@ -134,18 +128,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP return IIndexCPPBindingConstants.CPP_FUNCTION_SPECIALIZATION; } - public PDOMCPPParameterSpecialization getFirstParameter() throws CoreException { - long rec = getDB().getRecPtr(record + FIRST_PARAM); - return rec != 0 ? new PDOMCPPParameterSpecialization(getLinkage(), rec) : null; - } - - public void setFirstParameter(PDOMCPPParameterSpecialization param) throws CoreException { - if (param != null) - param.setNextParameter(getFirstParameter()); - long rec = param != null ? param.getRecord() : 0; - getDB().putRecPtr(record + FIRST_PARAM, rec); - } - public boolean isInline() throws DOMException { return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.INLINE_OFFSET); } @@ -160,14 +142,22 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP public IParameter[] getParameters() throws DOMException { try { - int n = getDB().getInt(record + NUM_PARAMS); - IParameter[] params = new IParameter[n]; - PDOMCPPParameterSpecialization param = getFirstParameter(); - while (param != null) { - params[--n] = param; - param = param.getNextParameter(); + PDOMLinkage linkage= getLinkage(); + Database db= getDB(); + ICPPFunctionType ft = getType(); + IType[] ptypes= ft == null ? IType.EMPTY_TYPE_ARRAY : ft.getParameterTypes(); + + int n = db.getInt(record + NUM_PARAMS); + IParameter[] result = new IParameter[n]; + + long next = db.getRecPtr(record + FIRST_PARAM); + for (int i = 0; i < n && next != 0; i++) { + IType type= ithis type of this function (relative to - * the beginning of the record). - */ - private static final int CV= PDOMCFunctionType.RECORD_SIZE; - - /** - * The size in bytes of a PDOMCFunctionType record in the database. - */ - @SuppressWarnings("hiding") - private static final int RECORD_SIZE= PDOMCFunctionType.RECORD_SIZE + 1; - - IPointerType thisType; // Cached value - int cvq= -1; // Cached value - - protected PDOMCPPFunctionType(PDOMLinkage linkage, long offset) { - super(linkage, offset); - } - - protected PDOMCPPFunctionType(PDOMLinkage linkage, PDOMNode parent, ICPPFunctionType type) - throws CoreException { - super(linkage, parent, type); - setcvq(type.isConst(), type.isVolatile()); - } - - private void setcvq(boolean isConst, boolean isVolatile) throws CoreException { - int v= (isConst ? 1 : 0) + (isVolatile ? 2 : 0); - getDB().putByte(record + CV, (byte) v); - } - - @Deprecated - public IPointerType getThisType() { - return null; - } - - public final boolean isConst() { - readcvq(); - return (cvq & 1) != 0; - } - - private void readcvq() { - if (cvq == -1) { - try { - cvq= getDB().getByte(record + CV); - } catch (CoreException e) { - cvq= 0; - } - } - } - - public final boolean isVolatile() { - readcvq(); - return (cvq & 2) != 0; - } - - @Override - protected int getRecordSize() { - return RECORD_SIZE; - } - - @Override - public boolean isSameType(IType type) { - if (type instanceof ICPPFunctionType) { - if (super.isSameType(type)) { - ICPPFunctionType ft= (ICPPFunctionType) type; - if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile()) { - return false; - } - return true; - } - } - return false; - } - - @Override - public int getNodeType() { - return IIndexCPPBindingConstants.CPP_FUNCTION_TYPE; - } - - @Override - public String toString() { - return ASTTypeUtil.getType(this); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index ebfb52c4d42..51565424c50 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; @@ -52,12 +51,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; @@ -66,6 +65,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; @@ -492,12 +499,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (binding instanceof ICPPTemplateParameter) { if (binding instanceof ICPPTemplateTypeParameter) { return CPP_TEMPLATE_TYPE_PARAMETER; - } -// TODO other template parameter types -// else if (binding instanceof ICPPTemplateTemplateParameter) -// return CPP_TEMPLATE_TEMPLATE_PARAMETER; -// else if (binding instanceof ICPPTemplateNonTypeParameter) -// return CPP_TEMPLATE_NON_TYPE_PARAMETER; + } else if (binding instanceof ICPPTemplateTemplateParameter) + return CPP_TEMPLATE_TEMPLATE_PARAMETER; + else if (binding instanceof ICPPTemplateNonTypeParameter) + return CPP_TEMPLATE_NON_TYPE_PARAMETER; } else if (binding instanceof ICPPField) { // this must be before variables return CPPFIELD; @@ -518,8 +523,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (binding instanceof ICPPMethod) { // this must be before functions return CPPMETHOD; - } else if (binding instanceof ICPPFunctionType) { - return CPP_FUNCTION_TYPE; } else if (binding instanceof ICPPFunction) { return CPPFUNCTION; } else if (binding instanceof ICPPUnknownBinding) { @@ -681,39 +684,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return adaptBinding(binding); } - @Override - public PDOMNode addType(PDOMNode parent, IType type) throws CoreException { - if (type instanceof IProblemBinding) { - return null; - } - if (type instanceof ICPPBasicType) { - return new PDOMCPPBasicType(this, parent, (ICPPBasicType) type); - } - if (type instanceof ICPPFunctionType) { - return new PDOMCPPFunctionType(this, parent, (ICPPFunctionType) type); - } - if (type instanceof ICPPClassType) { - return addBinding((ICPPClassType) type, null); - } - if (type instanceof IEnumeration) { - return addBinding((IEnumeration) type, null); - } - if (type instanceof ITypedef) { - return addBinding((ITypedef) type, null); - } - if (type instanceof ICPPReferenceType) { - return new PDOMCPPReferenceType(this, parent, (ICPPReferenceType) type); - } - if (type instanceof ICPPPointerToMemberType) { - return new PDOMCPPPointerToMemberType(this, parent, (ICPPPointerToMemberType) type); - } - if (type instanceof ICPPTemplateTypeParameter) { - return addBinding((ICPPTemplateTypeParameter) type, null); - } - - return super.addType(parent, type); - } - private void handlePostProcesses() { while (!postProcesses.isEmpty()) { postProcesses.removeFirst().run(); @@ -741,22 +711,12 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return new PDOMCPPNamespaceAlias(this, record); case CPP_USING_DECLARATION: return new PDOMCPPUsingDeclaration(this, record); - case GPPBASICTYPE: - return new PDOMCPPBasicType(this, record); - case CPPBASICTYPE: - return new PDOMCPPBasicType(this, record); - case CPPPARAMETER: - return new PDOMCPPParameter(this, record); case CPPENUMERATION: return new PDOMCPPEnumeration(this, record); case CPPENUMERATOR: return new PDOMCPPEnumerator(this, record); case CPPTYPEDEF: return new PDOMCPPTypedef(this, record); - case CPP_POINTER_TO_MEMBER_TYPE: - return new PDOMCPPPointerToMemberType(this, record); - case CPP_REFERENCE_TYPE: - return new PDOMCPPReferenceType(this, record); case CPP_FUNCTION_TEMPLATE: return new PDOMCPPFunctionTemplate(this, record); case CPP_METHOD_TEMPLATE: @@ -811,10 +771,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return new PDOMCPPClassTemplateSpecialization(this, record); case CPP_TYPEDEF_SPECIALIZATION: return new PDOMCPPTypedefSpecialization(this, record); - case CPP_FUNCTION_TYPE: - return new PDOMCPPFunctionType(this, record); - case CPP_PARAMETER_SPECIALIZATION: - return new PDOMCPPParameterSpecialization(this, record); } assert false : "nodeid= " + nodeType; //$NON-NLS-1$ return null; @@ -1007,4 +963,33 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } return super.getLocalToFile(binding, glob); } + + @Override + public PDOMBinding addTypeBinding(IBinding type) throws CoreException { + return addBinding(type, null); + } + + + @Override + public IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException { + int firstByte= buffer.getByte() & 0xff; + switch((firstByte & ITypeMarshalBuffer.KIND_MASK)) { + case ITypeMarshalBuffer.ARRAY: + return CPPArrayType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.BASIC_TYPE: + return CPPBasicType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.CVQUALIFIER: + return CPPQualifierType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.FUNCTION_TYPE: + return CPPFunctionType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.POINTER: + return CPPPointerType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.REFERENCE: + return CPPReferenceType.unmarshal(firstByte, buffer); + case ITypeMarshalBuffer.POINTER_TO_MEMBER: + return CPPPointerToMemberType.unmarshal(firstByte, buffer); + } + + throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal a type, first byte=" + firstByte)); //$NON-NLS-1$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespaceAlias.java index 579165f8370..23865cbda75 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespaceAlias.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * Doug Schaefer (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; +import org.eclipse.cdt.internal.core.pdom.db.Database; 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; @@ -25,14 +26,13 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.core.runtime.CoreException; /** - * @author Doug Schaefer - * + * Binding for namespace alias */ class PDOMCPPNamespaceAlias extends PDOMCPPBinding implements ICPPNamespaceAlias { - private static final int NAMESPACE_BINDING = PDOMCPPBinding.RECORD_SIZE + 0; + private static final int NAMESPACE_BINDING = PDOMCPPBinding.RECORD_SIZE; @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 4; + protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + Database.PTR_SIZE; public PDOMCPPNamespaceAlias(PDOMLinkage linkage, PDOMNode parent, ICPPNamespaceAlias alias) throws CoreException { @@ -48,12 +48,8 @@ class PDOMCPPNamespaceAlias extends PDOMCPPBinding implements ICPPNamespaceAlias public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException { if (newBinding instanceof ICPPNamespaceAlias) { ICPPNamespaceAlias alias= (ICPPNamespaceAlias) newBinding; - IBinding oldTarget= getBinding(); IBinding newTarget= alias.getBinding(); setTargetBinding(linkage, newTarget); - if (oldTarget != null) { - linkage.deleteBinding(oldTarget); - } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index bfb84c392a4..a0dfa88f63d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -36,58 +36,35 @@ import org.eclipse.core.runtime.CoreException; */ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBinding { - /** - * Offset of pointer to the next parameter (relative to the - * beginning of the record). - */ - private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0; - - /** - * Offset of pointer to type information for this parameter - * (relative to the beginning of the record). - */ - private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; - - /** - * Offset of annotation information (relative to the beginning of the - * record). - */ - private static final int ANNOTATIONS = PDOMNamedNode.RECORD_SIZE + 8; - - /** - * Offset of flags - * (relative to the beginning of the record). - */ - private static final int FLAGS = PDOMNamedNode.RECORD_SIZE + 9; - - - /** - * The size in bytes of a PDOMCPPParameter record in the database. - */ + private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE; + private static final int ANNOTATIONS = NEXT_PARAM + Database.PTR_SIZE; + private static final int FLAGS = ANNOTATIONS + 1; @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 10; + protected static final int RECORD_SIZE = FLAGS + 1; static { assert RECORD_SIZE <= 22; // 23 would yield a 32-byte block } - + private static final byte FLAG_DEFAULT_VALUE = 0x1; - public PDOMCPPParameter(PDOMLinkage linkage, long record) { + private final IType fType; + public PDOMCPPParameter(PDOMLinkage linkage, long record, IType type) { super(linkage, record); + fType= type; } - public PDOMCPPParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, long typeRecord) + public PDOMCPPParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, PDOMCPPParameter next) throws CoreException { super(linkage, parent, param.getNameCharArray()); + fType= null; // this constructor is used for adding parameters to the database, only. Database db = getDB(); db.putRecPtr(record + NEXT_PARAM, 0); byte flags= encodeFlags(param); db.putByte(record + FLAGS, flags); - - db.putRecPtr(record + TYPE, typeRecord); - + db.putRecPtr(record + NEXT_PARAM, next == null ? 0 : next.getRecord()); + try { byte annotations = PDOMCPPAnnotation.encodeAnnotation(param); db.putByte(record + ANNOTATIONS, annotations); @@ -116,16 +93,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind return IIndexCPPBindingConstants.CPPPARAMETER; } - public void setNextParameter(PDOMCPPParameter nextParam) throws CoreException { - long rec = nextParam != null ? nextParam.getRecord() : 0; - getDB().putRecPtr(record + NEXT_PARAM, rec); - } - - public PDOMCPPParameter getNextParameter() throws CoreException { - long rec = getDB().getRecPtr(record + NEXT_PARAM); - return rec != 0 ? new PDOMCPPParameter(getLinkage(), rec) : null; - } - public String[] getQualifiedName() { throw new PDOMNotImplementedError(); } @@ -144,13 +111,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind } public IType getType() { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; - } catch (CoreException e) { - CCorePlugin.log(e); - return null; - } + return fType; } public boolean isAuto() throws DOMException { @@ -240,14 +201,18 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind @Override public void delete(PDOMLinkage linkage) throws CoreException { - // the parameter reuses the type from the function type, so do not delete it. - PDOMCPPParameter next= getNextParameter(); - if (next != null) { - next.delete(linkage); + long rec = getNextPtr(); + if (rec != 0) { + new PDOMCPPParameter(linkage, rec, null).delete(linkage); } super.delete(linkage); } + public long getNextPtr() throws CoreException { + long rec = getDB().getRecPtr(record + NEXT_PARAM); + return rec; + } + public boolean isFileLocal() throws CoreException { return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java index b166462e572..022c54f6bbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java @@ -11,73 +11,45 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; -import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; /** * Binding for a specialization of a parameter in the index. */ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements ICPPParameter { - /** - * Offset of pointer to the next parameter (relative to the - * beginning of the record). - */ - private static final int NEXT_PARAM = PDOMCPPSpecialization.RECORD_SIZE + 0; - - /** - * Offset of pointer to type information for this parameter - * (relative to the beginning of the record). - */ - private static final int TYPE = PDOMCPPSpecialization.RECORD_SIZE + 4; - - /** - * The size in bytes of a PDOMCPPParameterSpecialization record in the database. - */ + private static final int NEXT_PARAM = PDOMCPPSpecialization.RECORD_SIZE; @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8; + private static final int RECORD_SIZE = NEXT_PARAM + Database.PTR_SIZE; - public PDOMCPPParameterSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPParameter param, PDOMCPPParameter specialized, long typeRecord) - throws CoreException { - super(linkage, parent, (ICPPSpecialization) param, specialized); - Database db = getDB(); - db.putRecPtr(record + NEXT_PARAM, 0); - db.putRecPtr(record + TYPE, typeRecord); - } - - public PDOMCPPParameterSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPParameter param, PDOMCPPParameter specialized, IType type) - throws CoreException { - super(linkage, parent, (ICPPSpecialization) param, specialized); - - Database db = getDB(); - - db.putRecPtr(record + NEXT_PARAM, 0); - - try { - if (type == null) - type= param.getType(); - if (type != null) { - PDOMNode typeNode = getLinkage().addType(this, type); - db.putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0); - } - } catch (DOMException e) { - throw new CoreException(Util.createStatus(e)); - } - } + private final IType fType; - public PDOMCPPParameterSpecialization(PDOMLinkage linkage, long record) { + public PDOMCPPParameterSpecialization(PDOMLinkage linkage, long record, IType t) { super(linkage, record); + fType= t; } - + + public PDOMCPPParameterSpecialization(PDOMLinkage linkage, PDOMCPPFunctionSpecialization parent, IParameter param, + PDOMCPPParameter specialized, PDOMCPPParameterSpecialization next) throws CoreException { + super(linkage, parent, (ICPPSpecialization) param, specialized); + fType= null; // this constructor is used for adding parameters to the database, only. + + Database db = getDB(); + db.putRecPtr(record + NEXT_PARAM, next == null ? 0 : next.getRecord()); + } + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -88,26 +60,54 @@ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements IC return IIndexCPPBindingConstants.CPP_PARAMETER_SPECIALIZATION; } - public void setNextParameter(PDOMCPPParameterSpecialization nextParam) throws CoreException { - long rec = nextParam != null ? nextParam.getRecord() : 0; - getDB().putRecPtr(record + NEXT_PARAM, rec); + public PDOMCPPParameterSpecialization getNextParameter(IType t) throws CoreException { + long rec = getNextPtr(); + return rec != 0 ? new PDOMCPPParameterSpecialization(getLinkage(), rec, t) : null; } - public PDOMCPPParameterSpecialization getNextParameter() throws CoreException { + long getNextPtr() throws CoreException { long rec = getDB().getRecPtr(record + NEXT_PARAM); - return rec != 0 ? new PDOMCPPParameterSpecialization(getLinkage(), rec) : null; + return rec; } - public IType getType() throws DOMException { - try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; - } catch (CoreException e) { - CCorePlugin.log(e); + public IType getType() { + return fType; + } + + @Override + protected IPDOMBinding loadSpecializedBinding(long record) throws CoreException { + if (record == 0) return null; - } + IType type= null; + IBinding parent = getParentBinding(); + if (parent instanceof ICPPSpecialization && parent instanceof ICPPFunction) { + try { + IParameter[] pars= ((ICPPFunction) parent).getParameters(); + int parPos= -1; + for (parPos= 0; parPos= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/12); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); rec+=2; for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/12); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); if (len == 0) { return CPPTemplateParameterMap.EMPTY; } @@ -104,10 +97,12 @@ public class PDOMCPPTemplateParameterMap { rec+=2; CPPTemplateParameterMap result= new CPPTemplateParameterMap(len); for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); long p= record+2; for (int i=0; i @@ -47,12 +47,7 @@ class PDOMCPPTypedefSpecialization extends PDOMCPPSpecialization return; } } - IType type = typedef.getType(); - // The following may try to add the same typedef specialization to the index again. - // We protect against infinite recursion using a counter inside typedef. - PDOMNode typeNode = parent.getLinkage().addType(this, type); - if (typeNode != null) - getDB().putRecPtr(record + TYPE, typeNode.getRecord()); + parent.getLinkage().storeType(record + TYPE_OFFSET, typedef.getType()); } finally { if (typedef instanceof CPPTypedefSpecialization) { ((CPPTypedefSpecialization) typedef).incResolutionDepth(-1); @@ -76,8 +71,7 @@ class PDOMCPPTypedefSpecialization extends PDOMCPPSpecialization public IType getType() { try { - PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE)); - return node instanceof IType ? (IType)node : null; + return getLinkage().loadType(record + TYPE_OFFSET); } catch (CoreException e) { CCorePlugin.log(e); return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java index 35722029c3a..c1efb8f5457 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.pdom.db.Database; -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.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -37,29 +36,11 @@ import org.eclipse.core.runtime.CoreException; */ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { - /** - * Offset of pointer to type information for this variable - * (relative to the beginning of the record). - */ - private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE + 0; - - /** - * Offset of pointer to value information for this variable - * (relative to the beginning of the record). - */ - private static final int VALUE_OFFSET = PDOMBinding.RECORD_SIZE + 4; - - /** - * Offset of annotation information (relative to the beginning of the - * record). - */ - protected static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 8; // byte - - /** - * The size in bytes of a PDOMCPPVariable record in the database. - */ + private static final int TYPE_OFFSET = PDOMCPPBinding.RECORD_SIZE; + private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE; + protected static final int ANNOTATIONS = VALUE_OFFSET + Database.PTR_SIZE; // byte @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9; + protected static final int RECORD_SIZE = ANNOTATIONS + 1; public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, IVariable variable) throws CoreException { super(linkage, parent, variable.getNameCharArray()); @@ -86,15 +67,12 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { if (newBinding instanceof IVariable) { final Database db = getDB(); IVariable var= (IVariable) newBinding; - IType mytype= getType(); long valueRec= db.getRecPtr(record + VALUE_OFFSET); try { IType newType= var.getType(); setType(linkage, newType); db.putByte(record + ANNOTATIONS, encodeFlags(var)); setValue(db, var); - if (mytype != null) - linkage.deleteType(mytype, record); PDOMValue.delete(db, valueRec); } catch (DOMException e) { @@ -104,9 +82,8 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { } - private void setType(final PDOMLinkage linkage, IType newType) throws CoreException, DOMException { - PDOMNode typeNode = linkage.addType(this, newType); - getDB().putRecPtr(record + TYPE_OFFSET, typeNode != null ? typeNode.getRecord() : 0); + private void setType(final PDOMLinkage linkage, IType newType) throws CoreException { + linkage.storeType(record+TYPE_OFFSET, newType); } protected byte encodeFlags(IVariable variable) throws DOMException { @@ -134,8 +111,7 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable { public IType getType() { try { - long typeRec = getDB().getRecPtr(record + TYPE_OFFSET); - return (IType)getLinkage().getNode(typeRec); + return getLinkage().loadType(record + TYPE_OFFSET); } catch (CoreException e) { CCorePlugin.log(e); return null; diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java index f3acd7c208c..9f289d9bd99 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -96,15 +96,13 @@ public class C99ArrayType implements ICArrayType, ITypeContainer { return t.isSameType(this); if(t instanceof ICArrayType) { ICArrayType at = (ICArrayType)t; - try { - if(at.isConst() == isConst && - at.isRestrict() == isRestrict && - at.isStatic() == isStatic && - at.isVolatile() == isVolatile && - at.isVariableLength() == isVariableLength) { - return at.isSameType(type); - } - } catch(DOMException _) { } + if(at.isConst() == isConst && + at.isRestrict() == isRestrict && + at.isStatic() == isStatic && + at.isVolatile() == isVolatile && + at.isVariableLength() == isVariableLength) { + return at.isSameType(type); + } } return false; }