1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Safe type representation for index, bug 294306

This commit is contained in:
Markus Schorn 2009-11-09 15:42:58 +00:00
parent fd76393f9e
commit dfc2e4f842
103 changed files with 1707 additions and 3179 deletions

View file

@ -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[]{});
}
}

View file

@ -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();

View file

@ -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();
}

View file

@ -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");
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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() {

View file

@ -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);

View file

@ -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) {

View file

@ -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;
}

View file

@ -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) {

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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<IIndexFragmentBinding> ts = new TreeSet<IIndexFragmentBinding>(fragmentComparator);
for(int i=0; i<fragmentBindings.length; i++)
for(int j=0; j<fragmentBindings[i].length; j++)
ts.add(fragmentBindings[i][j]);
for (IIndexFragmentBinding[] fragmentBinding : fragmentBindings)
for (IIndexFragmentBinding element : fragmentBinding)
ts.add(element);
return ts.toArray(new IIndexFragmentBinding[ts.size()]);
}
@ -98,11 +117,11 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
IIndexFragmentBinding[] ibs= findEquivalentBindings(binding);
IBinding def= null;
IBinding dec= ibs.length>0 ? ibs[0] : null;
for(int i=0; i<ibs.length; i++) {
if(ibs[i].hasDefinition()) {
def= ibs[i];
} else if(allowDeclaration && ibs[i].hasDeclaration()) {
dec= ibs[i];
for (IIndexFragmentBinding ib : ibs) {
if(ib.hasDefinition()) {
def= ib;
} else if(allowDeclaration && ib.hasDeclaration()) {
dec= ib;
}
}
return (IIndexFragmentBinding) (def == null ? dec : def);
@ -120,8 +139,8 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
}
public int compare(IIndexFragmentBinding f1, IIndexFragmentBinding f2) {
for(int i=0; i<comparators.length; i++) {
int cmp= comparators[i].compare(f1, f2);
for (IIndexFragmentBindingComparator comparator : comparators) {
int cmp= comparator.compare(f1, f2);
if(cmp!=Integer.MIN_VALUE) {
return cmp;
}

View file

@ -1,37 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.ArrayTypeClone;
public class CompositeArrayType extends CompositeTypeContainer implements IArrayType {
public CompositeArrayType(IArrayType arrayType, ICompositesFactory cf) {
super((ITypeContainer) arrayType, cf);
}
@Override
public Object clone() {
return new ArrayTypeClone(this);
}
public IValue getSize() {
return ((IArrayType) type).getSize();
}
@Deprecated
public IASTExpression getArraySizeExpression() {
return null;
}
}

View file

@ -1,39 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.index.IIndexType;
public class CompositeFunctionType extends CompositeType implements IFunctionType {
public CompositeFunctionType(IFunctionType rtype, ICompositesFactory cf) {
super(rtype, cf);
}
public IType[] getParameterTypes() {
IType[] result = ((IFunctionType) type).getParameterTypes();
for (int i = 0; i < result.length; i++) {
result[i] = cf.getCompositeType((IIndexType)result[i]);
}
return result;
}
public IType getReturnType() {
return cf.getCompositeType((IIndexType) ((IFunctionType) type).getReturnType());
}
@Override
public boolean isSameType(IType other) {
return type.isSameType(other);
}
}

View file

@ -1,40 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.PointerTypeClone;
public class CompositePointerType extends CompositeTypeContainer implements IPointerType {
public CompositePointerType(IPointerType pointerType, ICompositesFactory cf) {
super((ITypeContainer) pointerType, cf);
}
public boolean isConst() {
return ((IPointerType) type).isConst();
}
public boolean isVolatile() {
return ((IPointerType) type).isVolatile();
}
@Override
public boolean isSameType(IType other) {
return ((IPointerType) type).isSameType(other);
}
@Override
public Object clone() {
return new PointerTypeClone(this);
}
}

View file

@ -1,40 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.QualifierTypeClone;
public class CompositeQualifierType extends CompositeTypeContainer implements IQualifierType {
public CompositeQualifierType(IQualifierType qualifierType, ICompositesFactory cf) {
super((ITypeContainer) qualifierType, cf);
}
public boolean isConst() {
return ((IQualifierType)type).isConst();
}
public boolean isVolatile() {
return ((IQualifierType)type).isVolatile();
}
@Override
public boolean isSameType(IType other) {
return ((IQualifierType)type).isSameType(other);
}
@Override
public Object clone() {
return new QualifierTypeClone(this);
}
}

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
public class CompositeTypeContainer extends CompositeType implements ITypeContainer {
@ -22,7 +21,7 @@ public class CompositeTypeContainer extends CompositeType implements ITypeContai
}
public final IType getType() {
return cf.getCompositeType((IIndexType) ((ITypeContainer) type).getType());
return cf.getCompositeType(((ITypeContainer) type).getType());
}
@Override

View file

@ -12,10 +12,10 @@ package org.eclipse.cdt.internal.core.index.composite;
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.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
public interface ICompositesFactory {
@ -25,7 +25,7 @@ public interface ICompositesFactory {
* Returns a composite (in the sense of potentially spanning multiple index fragments - i.e. not to be confused
* with ICompositeType) type for the specified type.
*/
public IType getCompositeType(IIndexType rtype);
public IType getCompositeType(IType rtype);
/**
* Returns a composite (index context carrying) binding for the specified binding. It does not
@ -45,4 +45,9 @@ public interface ICompositesFactory {
* Selects all equivalent bindings from the available fragments
*/
public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding);
/**
* Converts values.
*/
public IValue getCompositeValue(IValue v);
}

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.index.composite.c;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -21,24 +20,25 @@ 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.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
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.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexMacroContainer;
import org.eclipse.cdt.internal.core.dom.parser.c.CArrayType;
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.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
import org.eclipse.cdt.internal.core.index.composite.CompositeFunctionType;
import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer;
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
public class CCompositesFactory extends AbstractCompositeFactory {
@ -68,34 +68,70 @@ public class CCompositesFactory extends AbstractCompositeFactory {
/*
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeType(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IType)
*/
public IType getCompositeType(IIndexType rtype) {
IType result;
if(rtype==null) {
result = null;
} else if(rtype instanceof IFunctionType) {
result = new CompositeFunctionType((IFunctionType)rtype, this);
} else if(rtype instanceof ICompositeType) {
result = (ICompositeType) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if (rtype instanceof IEnumeration) {
result = (IEnumeration) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if(rtype instanceof IPointerType) {
result = new CompositePointerType((IPointerType)rtype, this);
} else if(rtype instanceof IQualifierType) {
result = new CompositeQualifierType((IQualifierType) rtype, this);
} else if(rtype instanceof IArrayType) {
result = new CompositeArrayType((IArrayType) rtype, this);
} else if(rtype instanceof ITypedef) {
result = new CompositeCTypedef(this, (IIndexFragmentBinding) rtype);
} else if(rtype instanceof IBasicType) {
result = rtype; // no context required its a leaf with no way to traverse upward
} else {
throw new CompositingNotImplementedError();
}
public IType getCompositeType(IType rtype) {
return result;
if (rtype instanceof IIndexFragmentBinding) {
return (IType) getCompositeBinding((IIndexFragmentBinding) rtype);
}
if (rtype instanceof IFunctionType) {
IFunctionType ft= (IFunctionType) rtype;
IType r= ft.getReturnType();
IType r2= getCompositeType(r);
IType[] p= ft.getParameterTypes();
IType[] p2= getCompositeTypes(p);
if (r != r2 || p != p2) {
return new CFunctionType(r2, p2);
}
return ft;
}
if (rtype instanceof ICPointerType) {
ICPointerType pt= (ICPointerType) rtype;
IType r= pt.getType();
IType r2= getCompositeType(r);
if (r != r2) {
int q= 0;
if (pt.isConst())
q |= CPointerType.IS_CONST;
if (pt.isVolatile())
q |= CPointerType.IS_VOLATILE;
if (pt.isRestrict())
q |= CPointerType.IS_RESTRICT;
return new CPointerType(r2, q);
}
return pt;
}
if (rtype instanceof ICQualifierType) {
ICQualifierType qt= (ICQualifierType) rtype;
IType r= qt.getType();
IType r2= getCompositeType(r);
if (r != r2) {
return new CQualifierType(r2, qt.isConst(), qt.isVolatile(), qt.isRestrict());
}
return qt;
}
if (rtype instanceof ICArrayType) {
ICArrayType at= (ICArrayType) rtype;
IType r= at.getType();
IType r2= getCompositeType(r);
IValue v= at.getSize();
IValue v2= getCompositeValue(v);
if (r != r2 || v != v2) {
CArrayType at2 = new CArrayType(r2, at.isConst(), at.isVolatile(), at.isRestrict(), v2);
at2.setIsStatic(at.isStatic());
at2.setIsVariableLength(at.isVariableLength());
}
return at;
}
if (rtype instanceof IBasicType || rtype == null) {
return rtype;
}
throw new CompositingNotImplementedError();
}
public IValue getCompositeValue(IValue v) {
return v;
}
/*
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeBinding(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IBinding)

View file

@ -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
@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCEnumerator extends CompositeCBinding implements IEnumerator {
@ -24,7 +23,7 @@ class CompositeCEnumerator extends CompositeCBinding implements IEnumerator {
}
public IType getType() throws DOMException {
return cf.getCompositeType((IIndexType) ((IEnumerator) rbinding).getType());
return cf.getCompositeType(((IEnumerator) rbinding).getType());
}
public IValue getValue() {

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c;
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCFunction extends CompositeCBinding implements IFunction {
@ -43,7 +42,7 @@ class CompositeCFunction extends CompositeCBinding implements IFunction {
public IFunctionType getType() throws DOMException {
IType rtype = ((IFunction)rbinding).getType();
return (IFunctionType) cf.getCompositeType((IIndexType)rtype);
return (IFunctionType) cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {

View file

@ -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
@ -15,7 +15,6 @@ 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.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCParameter extends CompositeCBinding implements IParameter {
@ -26,7 +25,7 @@ class CompositeCParameter extends CompositeCBinding implements IParameter {
public IType getType() throws DOMException {
IType rtype = ((IParameter)rbinding).getType();
return cf.getCompositeType((IIndexType)rtype);
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {

View file

@ -24,7 +24,7 @@ class CompositeCTypedef extends CompositeCBinding implements ITypedef, IIndexTyp
public IType getType() {
IType type = ((ITypedef)rbinding).getType();
return cf.getCompositeType((IIndexType)type);
return cf.getCompositeType(type);
}
public boolean isSameType(IType type) {

View file

@ -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
@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCVariable extends CompositeCBinding implements IVariable {
@ -26,7 +25,7 @@ class CompositeCVariable extends CompositeCBinding implements IVariable {
public IType getType() throws DOMException {
IType rtype = ((IVariable)rbinding).getType();
return cf.getCompositeType((IIndexType)rtype);
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
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.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
@ -52,20 +53,24 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexMacroContainer;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
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.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
import org.eclipse.cdt.internal.core.index.CIndex;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer;
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
import org.eclipse.core.runtime.CoreException;
@ -116,40 +121,87 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeType(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IType)
*/
public IType getCompositeType(IIndexType rtype) {
IType result;
if (rtype instanceof ICPPSpecialization) {
result = (IIndexType) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if (rtype instanceof ICPPClassType) {
result = (ICPPClassType) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if (rtype instanceof ITypedef) {
result = new CompositeCPPTypedef(this, (ICPPBinding) rtype);
} else if (rtype instanceof IEnumeration) {
result = (IEnumeration) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if (rtype instanceof ICPPFunctionType) {
result = new CompositeCPPFunctionType((ICPPFunctionType) rtype, this);
} else if (rtype instanceof ICPPPointerToMemberType) {
result = new CompositeCPPPointerToMemberType(this, (ICPPPointerToMemberType) rtype);
} else if (rtype instanceof IPointerType) {
result = new CompositePointerType((IPointerType) rtype, this);
} else if (rtype instanceof ICPPReferenceType) {
result = new CompositeCPPReferenceType((ICPPReferenceType)rtype, this);
} else if (rtype instanceof IQualifierType) {
result = new CompositeQualifierType((IQualifierType) rtype, this);
} else if (rtype instanceof IArrayType) {
result = new CompositeArrayType((IArrayType) rtype, this);
} else if (rtype == null) {
result = null;
} else if (rtype instanceof ICPPTemplateTypeParameter) {
result = (IIndexType) getCompositeBinding((IIndexFragmentBinding) rtype);
} else if (rtype instanceof IBasicType) {
result = rtype; // no context required its a leaf with no way to traverse upward
} else {
throw new CompositingNotImplementedError();
public IType getCompositeType(IType rtype) {
if (rtype instanceof IIndexFragmentBinding) {
return (IType) getCompositeBinding((IIndexFragmentBinding) rtype);
}
if (rtype instanceof ICPPFunctionType) {
ICPPFunctionType ft= (ICPPFunctionType) rtype;
IType r= ft.getReturnType();
IType r2= getCompositeType(r);
IType[] p= ft.getParameterTypes();
IType[] p2= getCompositeTypes(p);
if (r != r2 || p != p2) {
return new CPPFunctionType(r2, p2, ft.isConst(), ft.isVolatile());
}
return ft;
}
if (rtype instanceof ICPPPointerToMemberType) {
ICPPPointerToMemberType pmt= (ICPPPointerToMemberType) rtype;
IType ct= pmt.getMemberOfClass();
IType ct2= getCompositeType(ct);
IType t= pmt.getType();
IType t2= getCompositeType(t);
if (ct != ct2 || t != t2) {
return new CPPPointerToMemberType(t2, ct2, pmt.isConst(), pmt.isVolatile());
}
return pmt;
}
if (rtype instanceof IPointerType) {
IPointerType pt= (IPointerType) rtype;
IType r= pt.getType();
IType r2= getCompositeType(r);
if (r != r2) {
return new CPPPointerType(r2, pt.isConst(), pt.isVolatile());
}
return pt;
}
return result;
if (rtype instanceof ICPPReferenceType) {
ICPPReferenceType rt= (ICPPReferenceType) rtype;
IType r= rt.getType();
IType r2= getCompositeType(r);
if (r != r2) {
return new CPPReferenceType(r2);
}
return rt;
}
if (rtype instanceof IQualifierType) {
IQualifierType qt= (IQualifierType) rtype;
IType r= qt.getType();
IType r2= getCompositeType(r);
if (r != r2) {
return new CPPQualifierType(r2, qt.isConst(), qt.isVolatile());
}
return qt;
}
if (rtype instanceof IArrayType) {
IArrayType at= (IArrayType) rtype;
IType r= at.getType();
IType r2= getCompositeType(r);
IValue v= at.getSize();
IValue v2= getCompositeValue(v);
if (r != r2 || v != v2) {
return new CPPArrayType(r2, v2);
}
return at;
}
if (rtype instanceof IBasicType || rtype == null) {
return rtype;
}
throw new CompositingNotImplementedError();
}
public IValue getCompositeValue(IValue v) {
IBinding[] b= v.getUnknownBindings();
if (b.length == 0)
return v;
ICPPUnknownBinding[] b2= new ICPPUnknownBinding[b.length];
for (int i = 0; i < b2.length; i++) {
b2[i]= (ICPPUnknownBinding) getCompositeBinding((IIndexFragmentBinding) b[i]);
}
return Value.fromInternalRepresentation(v.getInternalExpression(), b2);
}
private ICPPNamespace[] getNamespaces(IBinding rbinding) throws CoreException {
@ -259,10 +311,14 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
result = new CompositeCPPField(this, (ICPPField) binding);
} else if (binding instanceof ICPPVariable) {
result = new CompositeCPPVariable(this, (ICPPVariable) binding);
} else if (binding instanceof ICPPUnknownClassInstance) {
result = new CompositeCPPUnknownClassInstance(this, (ICPPUnknownClassInstance) binding);
} else if (binding instanceof ICPPUnknownClassType) {
result = new CompositeCPPUnknownClassType(this, (ICPPUnknownClassType) binding);
} else if (binding instanceof ICPPUnknownBinding) {
if (binding instanceof ICPPUnknownClassInstance) {
result = new CompositeCPPUnknownClassInstance(this, (ICPPUnknownClassInstance) binding);
} else if (binding instanceof ICPPUnknownClassType) {
result = new CompositeCPPUnknownClassType(this, (ICPPUnknownClassType) binding);
} else {
result= new CompositeCPPUnknownBinding(this, (ICPPUnknownBinding) binding);
}
} else if (binding instanceof ICPPClassType) {
ICPPClassType def = (ICPPClassType) findOneBinding(binding);
result = def == null ? null : new CompositeCPPClassType(this, def);

View file

@ -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,7 +14,6 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPEnumerator extends CompositeCPPBinding implements IEnumerator {
@ -24,7 +23,7 @@ class CompositeCPPEnumerator extends CompositeCPPBinding implements IEnumerator
public IType getType() throws DOMException {
IType type = ((IEnumerator) rbinding).getType();
return cf.getCompositeType((IIndexType) type);
return cf.getCompositeType(type);
}
public IValue getValue() {

View file

@ -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
@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
@ -54,7 +53,7 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
public ICPPFunctionType getType() throws DOMException {
IType rtype = ((ICPPFunction)rbinding).getType();
return (ICPPFunctionType) cf.getCompositeType((IIndexType)rtype);
return (ICPPFunctionType) cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {
@ -100,7 +99,7 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
IType[] result= new IType[es.length];
for (int i = 0; i < result.length; i++) {
result[i]= cf.getCompositeType((IIndexType) es[i]);
result[i]= cf.getCompositeType(es[i]);
}
return result;
}

View file

@ -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
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPFunctionSpecialization extends CompositeCPPFunction implements ICPPSpecialization {
@ -63,7 +62,7 @@ public class CompositeCPPFunctionSpecialization extends CompositeCPPFunction imp
IType[] result= new IType[es.length];
for (int i = 0; i < result.length; i++) {
result[i]= cf.getCompositeType((IIndexType) result[i]);
result[i]= cf.getCompositeType(result[i]);
}
return result;
}

View file

@ -1,42 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.index.composite.CompositeFunctionType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPFunctionType extends CompositeFunctionType implements ICPPFunctionType {
public CompositeCPPFunctionType(ICPPFunctionType rtype, ICompositesFactory cf) {
super(rtype, cf);
}
@Deprecated
public IPointerType getThisType() {
return null;
}
public boolean isConst() {
return ((ICPPFunctionType) type).isConst();
}
public boolean isVolatile() {
return ((ICPPFunctionType) type).isVolatile();
}
@Override
public Object clone() {
fail(); return null;
}
}

View file

@ -1,36 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.internal.core.index.CPPPointerToMemberTypeClone;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPPointerToMemberType extends CompositePointerType implements ICPPPointerToMemberType {
CompositeCPPPointerToMemberType(ICompositesFactory cf, ICPPPointerToMemberType pointerToMemberType) {
super(pointerToMemberType, cf);
}
public IType getMemberOfClass() {
IIndexFragmentBinding rbinding = (IIndexFragmentBinding) ((ICPPPointerToMemberType) type).getMemberOfClass();
return (IType) cf.getCompositeBinding(rbinding);
}
@Override
public Object clone() {
return new CPPPointerToMemberTypeClone(this);
}
}

View file

@ -1,28 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.CPPReferenceTypeClone;
import org.eclipse.cdt.internal.core.index.composite.CompositeTypeContainer;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPReferenceType extends CompositeTypeContainer implements ICPPReferenceType {
public CompositeCPPReferenceType(ICPPReferenceType referenceType, ICompositesFactory cf) {
super((ITypeContainer) referenceType, cf);
}
@Override
public Object clone() {
return new CPPReferenceTypeClone(this);
}
}

View file

@ -44,7 +44,7 @@ public class CompositeCPPTemplateTemplateParameter extends CompositeCPPBinding
}
public IType getDefault() throws DOMException {
IIndexType preresult= (IIndexType) ((ICPPTemplateTemplateParameter)rbinding).getDefault();
IType preresult= ((ICPPTemplateTemplateParameter)rbinding).getDefault();
return cf.getCompositeType(preresult);
}

View file

@ -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
@ -34,7 +34,7 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
}
public IType getDefault() throws DOMException {
IIndexType preresult= (IIndexType) ((ICPPTemplateTypeParameter)rbinding).getDefault();
IType preresult= ((ICPPTemplateTypeParameter)rbinding).getDefault();
return cf.getCompositeType(preresult);
}

View file

@ -25,7 +25,7 @@ class CompositeCPPTypedef extends CompositeCPPBinding implements ITypedef, IInde
public IType getType() {
IType type = ((ITypedef)rbinding).getType();
return cf.getCompositeType((IIndexType)type);
return cf.getCompositeType(type);
}
public boolean isSameType(IType type) {

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* 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 (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPUnknownBinding extends CompositeCPPBinding implements ICPPUnknownBinding {
public CompositeCPPUnknownBinding(ICompositesFactory cf, ICPPUnknownBinding rbinding) {
super(cf, rbinding);
}
@Override
public Object clone() {
fail(); return null;
}
public ICPPScope asScope() {
return null;
}
public IASTName getUnknownName() {
return ((ICPPUnknownBinding) rbinding).getUnknownName();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Google, Inc and others.
* Copyright (c) 2008, 2009 Google, 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
@ -12,7 +12,6 @@
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -28,22 +27,14 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
/**
* @author Sergey Prigogin
*/
class CompositeCPPUnknownClassType extends CompositeCPPBinding implements ICPPUnknownClassType, IIndexType {
class CompositeCPPUnknownClassType extends CompositeCPPUnknownBinding implements ICPPUnknownClassType, IIndexType {
private ICPPScope unknownScope;
public CompositeCPPUnknownClassType(ICompositesFactory cf, ICPPUnknownClassType rbinding) {
super(cf, rbinding);
}
@Override
public Object clone() {
fail(); return null;
}
public IField findField(String name) throws DOMException {
IField preResult = ((ICPPClassType) rbinding).findField(name);
return (IField) cf.getCompositeBinding((IIndexFragmentBinding)preResult);
@ -125,6 +116,7 @@ class CompositeCPPUnknownClassType extends CompositeCPPBinding implements ICPPUn
return ((ICPPClassType) rbinding).isSameType(type);
}
@Override
public ICPPScope asScope() {
if (unknownScope == null) {
unknownScope= new CompositeCPPUnknownScope(this, getUnknownName());
@ -132,10 +124,6 @@ class CompositeCPPUnknownClassType extends CompositeCPPBinding implements ICPPUn
return unknownScope;
}
public IASTName getUnknownName() {
return ((ICPPUnknownClassType) rbinding).getUnknownName();
}
public boolean isAnonymous() {
return false;
}

View file

@ -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,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable {
@ -35,7 +34,7 @@ class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable {
public IType getType() throws DOMException {
IType rtype = ((ICPPVariable)rbinding).getType();
return cf.getCompositeType((IIndexType)rtype);
return cf.getCompositeType(rtype);
}
public boolean isAuto() throws DOMException {

View file

@ -16,6 +16,7 @@ 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.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
@ -28,7 +29,6 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
/**
@ -92,11 +92,18 @@ public class TemplateInstanceUtil {
if (arg == null)
return null;
if (arg.isNonTypeValue()) {
final IType t= arg.getTypeOfNonTypeValue();
final IType t2= cf.getCompositeType(t);
final IValue v= arg.getNonTypeValue();
final IValue v2= cf.getCompositeValue(v);
if (t != t2 || v != v2) {
return new CPPTemplateArgument(v2, t2);
}
return arg;
}
final IType typeValue = arg.getTypeValue();
if (typeValue instanceof IIndexType) {
IType t= cf.getCompositeType((IIndexType) typeValue);
IType t= cf.getCompositeType(typeValue);
if (t != typeValue) {
return new CPPTemplateArgument(t);
}
return arg;
@ -122,7 +129,7 @@ public class TemplateInstanceUtil {
IType type= (IType) preresult.get(keys[i]);
result.put(
cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]),
cf.getCompositeType((IIndexType)type));
cf.getCompositeType(type));
}
} catch(DOMException de) {
CCorePlugin.log(de);
@ -149,7 +156,7 @@ public class TemplateInstanceUtil {
@Deprecated
private static IType[] getArguments(ICompositesFactory cf, IType[] result) {
for(int i=0; i<result.length; i++) {
result[i] = cf.getCompositeType((IIndexType)result[i]);
result[i] = cf.getCompositeType(result[i]);
}
return result;
}

View file

@ -186,10 +186,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* 91.0 - storing unknown bindings other than unknown class types, bug 284686.
* 92.0 - simplification of basic types, bug 231859.
* 93.0 - further simplification of basic types, bug 231859.
* 94.0 - new model for storing types, bug 294306.
*/
private static final int MIN_SUPPORTED_VERSION= version(93, 0);
private static final int MAX_SUPPORTED_VERSION= version(93, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(93, 0);
private static final int MIN_SUPPORTED_VERSION= version(94, 0);
private static final int MAX_SUPPORTED_VERSION= version(94, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(94, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

@ -84,47 +84,45 @@ final class Chunk {
assert fLocked;
fDirty= true;
int idx= recPtrToIndex( offset );
fBuffer[idx]= (byte)(value >> 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<len) {
fBuffer[idx++]= data[i++];
}
}
public void get(final long offset, byte[] data) {
int idx = recPtrToIndex(offset);
final int end= idx + data.length;
int i= 0;
while (idx < end) {
data[i++]= fBuffer[idx++];
}
}
}

View file

@ -74,6 +74,7 @@ public class Database {
public static final int MAX_BLOCK_DELTAS = CHUNK_SIZE/BLOCK_SIZE_DELTA;
public static final int MAX_MALLOC_SIZE = MAX_BLOCK_DELTAS*BLOCK_SIZE_DELTA - BLOCK_HEADER_SIZE;
public static final int PTR_SIZE = 4; // size of a pointer in the database in bytes
public static final int TYPE_SIZE = 2+PTR_SIZE; // size of a type in the database in bytes
public static final long MAX_DB_SIZE= ((long) 1 << (Integer.SIZE + BLOCK_SIZE_DELTA_BITS));
@ -514,6 +515,18 @@ public class Database {
return getChunk(offset).getChar(offset);
}
public void clearBytes(long offset, int byteCount) throws CoreException {
getChunk(offset).clear(offset, byteCount);
}
public void putBytes(long offset, byte[] data, int len) throws CoreException {
getChunk(offset).put(offset, data, len);
}
public void getBytes(long offset, byte[] data) throws CoreException {
getChunk(offset).get(offset, data);
}
public IString newString(String string) throws CoreException {
if (string.length() > ShortString.MAX_LENGTH)
return new LongString(this, string);
@ -754,5 +767,4 @@ public class Database {
}
return 0;
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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<ptypes.length ? ptypes[i] : null;
final PDOMCParameter par = new PDOMCParameter(linkage, next, type);
next= par.getNextPtr();
result[i]= par;
}
return params;
return result;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IParameter[0];
return IParameter.EMPTY_PARAMETER_ARRAY;
}
}

View file

@ -1,194 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IBasicType;
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.IBasicType.Kind;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunctionType {
/**
* Offset for linked list of types of parameters of this function (relative to
* the beginning of the record).
*/
private static final int TYPELIST = PDOMNode.RECORD_SIZE + 0;
/**
* Offset for return type of this function (relative to
* the beginning of the record).
*/
private static final int RETURN_TYPE= PDOMNode.RECORD_SIZE + 4;
/**
* The size in bytes of a PDOMCFunctionType record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE= PDOMNode.RECORD_SIZE + 8;
private IType[] parameterTypes;
public PDOMCFunctionType(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public PDOMCFunctionType(PDOMLinkage linkage, PDOMNode parent, IFunctionType type) throws CoreException {
super(linkage, parent);
PDOMNodeLinkedList list= new PDOMNodeLinkedList(parent.getLinkage(), record + TYPELIST, true);
setReturnType(type.getReturnType());
IType[] pt= type.getParameterTypes();
for (IType element : pt) {
PDOMNode typeNode;
if (element == null || element instanceof IProblemBinding) {
typeNode= null;
} else {
typeNode= linkage.addType(this, element);
}
list.addMember(typeNode);
}
}
@Override
public void delete(final PDOMLinkage linkage) throws CoreException {
linkage.deleteType(getReturnType(), record);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + TYPELIST, true);
list.accept(new IPDOMVisitor() {
public void leave(IPDOMNode node) throws CoreException {
}
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof IType) {
linkage.deleteType((IType) node, record);
}
return false;
}
});
list.deleteListItems();
super.delete(linkage);
}
@Override
public int getNodeType() {
return IIndexCBindingConstants.CFUNCTIONTYPE;
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
public boolean isSameType(IType type) {
if (type instanceof ITypedef) {
return type.isSameType(this);
}
if (type instanceof IFunctionType) {
IFunctionType ft = (IFunctionType) type;
IType rt1= getReturnType();
IType rt2= ft.getReturnType();
if (rt1 != rt2) {
if (rt1 == null || !rt1.isSameType(rt2)) {
return false;
}
}
IType[] params1= getParameterTypes();
IType[] params2= ft.getParameterTypes();
if (params1.length == 1 && params2.length == 0) {
IType p0= SemanticUtil.getNestedType(params1[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (params2.length == 1 && params1.length == 0) {
IType p0= SemanticUtil.getNestedType(params2[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (params1.length != params2.length) {
return false;
} else {
for (int i = 0; i < params1.length; i++) {
if (params1[i] == null || !params1[i].isSameType(params2[i]))
return false;
}
}
return true;
}
return false;
}
public final IType[] getParameterTypes() {
if (parameterTypes == null)
parameterTypes= readParameterTypes();
// public method, it is safer to clone.
return parameterTypes.clone();
}
private final IType[] readParameterTypes() {
final List<IType> result= new ArrayList<IType>();
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();
}
}

View file

@ -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$
}
}

View file

@ -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<<PDOMCAnnotation.REGISTER_OFFSET;
return hasFlag(flag, false);
}
public boolean isStatic() throws DOMException {
throw new PDOMNotImplementedError();
}
public String getName() {
return new String(getNameCharArray());
}
@ -187,14 +143,18 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
@Override
public void delete(PDOMLinkage linkage) throws CoreException {
linkage.deleteType(getType(), record);
PDOMCParameter next= getNextParameter();
if (next != null) {
next.delete(linkage);
long rec = getNextPtr();
if (rec != 0) {
new PDOMCParameter(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;
}
@ -221,7 +181,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
protected boolean hasFlag(byte flag, boolean defValue) {
try {
byte myflags= getDB().getByte(record + FLAGS);
byte myflags= getDB().getByte(record + FLAG_OFFSET);
return (myflags & flag) == flag;
} catch (CoreException e) {
CCorePlugin.log(e);
@ -229,4 +189,12 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
return defValue;
}
public boolean isExtern() throws DOMException {
return false;
}
public boolean isStatic() throws DOMException {
return false;
}
}

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
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.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -33,10 +34,10 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer, IIndexType {
private static final int TYPE = PDOMBinding.RECORD_SIZE + 0;
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE + 0;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
protected static final int RECORD_SIZE = TYPE_OFFSET + Database.TYPE_SIZE;
public PDOMCTypedef(PDOMLinkage linkage, PDOMNode parent, ITypedef typedef)
throws CoreException {
@ -58,13 +59,8 @@ class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer, IInd
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof ITypedef) {
ITypedef td= (ITypedef) newBinding;
IType mytype= getType();
try {
IType newType= td.getType();
setType(linkage, newType);
if (mytype != null) {
linkage.deleteType(mytype, record);
}
setType(linkage, td.getType());
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
@ -72,12 +68,10 @@ class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer, IInd
}
private void setType(final PDOMLinkage linkage, IType newType) throws CoreException, DOMException {
PDOMNode typeNode = linkage.addType(this, newType);
if (introducesRecursion((IType) typeNode, getNameCharArray())) {
linkage.deleteType((IType) typeNode, record);
typeNode= null;
linkage.storeType(record+TYPE_OFFSET, newType);
if (introducesRecursion(getType(), getNameCharArray())) {
linkage.storeType(record+TYPE_OFFSET, null);
}
getDB().putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
}
private boolean introducesRecursion(IType type, char[] tdname) throws DOMException {
@ -121,8 +115,7 @@ class PDOMCTypedef extends PDOMBinding implements ITypedef, ITypeContainer, IInd
public IType getType() {
try {
long typeRec = getDB().getRecPtr(record + TYPE);
return (IType)getLinkage().getNode(typeRec);
return getLinkage().loadType(record + TYPE_OFFSET);
} catch (CoreException e) {
CCorePlugin.log(e);
return null;

View file

@ -39,25 +39,25 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
* 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;
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE;
/**
* 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;
private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE;
/**
* Offset of annotation information (relative to the beginning of the
* record).
*/
private static final int ANNOTATIONS = PDOMBinding.RECORD_SIZE + 8;
private static final int ANNOTATIONS = VALUE_OFFSET + Database.PTR_SIZE;
/**
* The size in bytes of a PDOMCVariable record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 9;
protected static final int RECORD_SIZE = ANNOTATIONS + 1;
public PDOMCVariable(PDOMLinkage linkage, PDOMNode parent, IVariable variable) throws CoreException {
super(linkage, parent, variable.getNameCharArray());
@ -84,7 +84,6 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
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();
@ -92,8 +91,6 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
db.putByte(record + ANNOTATIONS, PDOMCAnnotation.encodeAnnotation(var));
setValue(db, var);
if (mytype != null)
linkage.deleteType(mytype, record);
PDOMValue.delete(db, valueRec);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
@ -102,8 +99,7 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
}
private void setType(final PDOMLinkage linkage, final IType type) throws CoreException {
final PDOMNode typeNode = linkage.addType(this, type);
getDB().putRecPtr(record + TYPE_OFFSET, typeNode != null ? typeNode.getRecord() : 0);
linkage.storeType(record + TYPE_OFFSET, type);
}
public PDOMCVariable(PDOMLinkage linkage, long record) {
@ -122,8 +118,7 @@ class PDOMCVariable extends PDOMBinding implements IVariable {
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;

View file

@ -27,6 +27,9 @@ import org.eclipse.core.runtime.CoreException;
* Collects methods to store an argument list in the database
*/
public class PDOMCPPArgumentList {
private static final int VALUE_OFFSET= Database.TYPE_SIZE;
private static final int NODE_SIZE = VALUE_OFFSET + Database.PTR_SIZE;
/**
* Stores the given template arguments in the database.
* @return the record by which the arguments can be referenced.
@ -34,24 +37,20 @@ public class PDOMCPPArgumentList {
public static long putArguments(PDOMNode parent, ICPPTemplateArgument[] templateArguments) throws CoreException {
final PDOMLinkage linkage= parent.getLinkage();
final Database db= linkage.getDB();
final short len= (short) Math.min(templateArguments.length, (Database.MAX_MALLOC_SIZE-2)/8);
final long block= db.malloc(2+8*len);
final short len= (short) Math.min(templateArguments.length, (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE);
final long block= db.malloc(2+NODE_SIZE*len);
long p= block;
db.putShort(p, len); p+=2;
for (int i=0; i<len; i++, p+=8) {
for (int i=0; i<len; i++, p+=NODE_SIZE) {
final ICPPTemplateArgument arg = templateArguments[i];
final boolean isNonType= arg.isNonTypeValue();
if (isNonType) {
final PDOMNode type= linkage.addType(parent, arg.getTypeOfNonTypeValue());
// type can be null, if it is a local type
db.putRecPtr(p, type == null ? 0 : type.getRecord());
linkage.storeType(p, arg.getTypeOfNonTypeValue());
long valueRec= PDOMValue.store(db, linkage, arg.getNonTypeValue());
db.putRecPtr(p+4, valueRec);
db.putRecPtr(p+VALUE_OFFSET, valueRec);
} else {
final PDOMNode type= linkage.addType(parent, arg.getTypeValue());
// type can be null, if it is a local type.
db.putRecPtr(p, type == null ? 0 : type.getRecord());
linkage.storeType(p, arg.getTypeValue());
}
}
return block;
@ -66,17 +65,13 @@ public class PDOMCPPArgumentList {
final Database db= linkage.getDB();
final short len= db.getShort(record);
Assert.isTrue(len >= 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<len; i++) {
final long typeRec= db.getRecPtr(p);
if (typeRec != 0) {
final IType t= (IType) linkage.getNode(typeRec);
linkage.deleteType(t, parent.getRecord());
}
final long nonTypeValueRec= db.getRecPtr(p+4);
linkage.storeType(p, null);
final long nonTypeValueRec= db.getRecPtr(p+VALUE_OFFSET);
PDOMValue.delete(db, nonTypeValueRec);
p+= 8;
p+= NODE_SIZE;
}
db.free(record);
}
@ -89,7 +84,7 @@ public class PDOMCPPArgumentList {
final Database db= linkage.getDB();
final short len= db.getShort(rec);
Assert.isTrue(len >= 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<len; i++) {
final long typeRec= db.getRecPtr(rec);
final IType type= typeRec == 0 ? new CPPBasicType(Kind.eUnspecified,CPPBasicType.UNIQUE_TYPE_QUALIFIER) : (IType) linkage.getNode(typeRec);
final long nonTypeValRec= db.getRecPtr(rec+4);
IType type= linkage.loadType(rec);
if (type == null) {
type= new CPPBasicType(Kind.eUnspecified,CPPBasicType.UNIQUE_TYPE_QUALIFIER);
}
final long nonTypeValRec= db.getRecPtr(rec+VALUE_OFFSET);
if (nonTypeValRec != 0) {
final IValue val= PDOMValue.restore(db, linkage, nonTypeValRec);
result[i]= new CPPTemplateArgument(val, type);
} else {
result[i]= new CPPTemplateArgument(type);
}
rec+= 8;
rec+= NODE_SIZE;
}
return result;
}

View file

@ -1,214 +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)
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
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.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
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 built-in c++ types.
*/
final class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
private static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
private static final int QUALIFIER_FLAGS = PDOMNode.RECORD_SIZE + 2; // short
@SuppressWarnings("hiding")
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
protected short fFlags= -1;
private Kind fKind;
public PDOMCPPBasicType(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public PDOMCPPBasicType(PDOMLinkage linkage, PDOMNode parent, ICPPBasicType type) throws CoreException {
this(linkage, parent, type, encodeFlags(type));
}
protected PDOMCPPBasicType(PDOMLinkage linkage, PDOMNode parent, ICPPBasicType type, final short flags) throws CoreException {
super(linkage, parent);
fFlags= flags;
Database db = getDB();
db.putShort(record + TYPE_ID, (short) type.getKind().ordinal());
db.putShort(record + QUALIFIER_FLAGS, flags);
}
protected static short encodeFlags(ICPPBasicType type) {
short flags = 0;
if (type.isLong())
flags |= IS_LONG;
if (type.isShort())
flags |= IS_SHORT;
if (type.isSigned())
flags |= IS_SIGNED;
if (type.isUnsigned())
flags |= IS_UNSIGNED;
if (type.isComplex())
flags |= IS_COMPLEX;
if (type.isImaginary())
flags |= IS_IMAGINARY;
if (type.isLongLong())
flags |= IS_LONG_LONG;
return flags;
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPPBASICTYPE;
}
public Kind getKind() {
if (fKind == null) {
fKind= readKind();
}
return fKind;
}
private Kind readKind() {
try {
int idx= getDB().getChar(record + TYPE_ID);
return Kind.values()[idx];
} catch (CoreException e) {
CCorePlugin.log(e);
return Kind.eInt;
}
}
public final int getModifiers() {
if (fFlags == -1) {
try {
fFlags= getDB().getShort(record + QUALIFIER_FLAGS);
}
catch (CoreException e) {
CCorePlugin.log(e);
fFlags= 0;
}
}
return fFlags;
}
@Deprecated
public final int getQualifierBits() {
return getModifiers();
}
public boolean isLong() {
return (getModifiers() & IS_LONG) != 0;
}
public boolean isShort() {
return (getModifiers() & IS_SHORT) != 0;
}
public boolean isSigned() {
return (getModifiers() & IS_SIGNED) != 0;
}
public boolean isUnsigned() {
return (getModifiers() & IS_UNSIGNED) != 0;
}
public boolean isComplex() {
return (getModifiers() & IS_COMPLEX) != 0;
}
public boolean isImaginary() {
return (getModifiers() & IS_IMAGINARY) != 0;
}
public boolean isLongLong() {
return (getModifiers() & IS_LONG_LONG) != 0;
}
public boolean isSameType(IType rhs) {
if (rhs instanceof ITypedef)
return rhs.isSameType(this);
if (!(rhs instanceof ICPPBasicType))
return false;
ICPPBasicType rhs1 = (ICPPBasicType) rhs;
Kind kind = getKind();
if (kind != rhs1.getKind())
return false;
if (kind == Kind.eInt) {
// signed int and int are equivalent
return (getModifiers() & ~IBasicType.IS_SIGNED) == (rhs1.getModifiers() & ~IBasicType.IS_SIGNED);
}
return getModifiers() == rhs1.getModifiers();
}
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
@Deprecated
public int getType() {
Kind kind= getKind();
switch (kind) {
case eBoolean:
return t_bool;
case eChar:
return t_char;
case eWChar:
return t_wchar_t;
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;
}
}

View file

@ -31,22 +31,12 @@ import org.eclipse.core.runtime.CoreException;
/**
* Binding for a specialization of a field, used in the index.
*/
class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
ICPPField {
class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements ICPPField {
private static final int TYPE = PDOMCPPSpecialization.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;
/**
* The size in bytes of a PDOMCPPFieldSpecialization record in the database.
*/
private static final int TYPE_OFFSET = PDOMCPPSpecialization.RECORD_SIZE + 0;
private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8;
protected static final int RECORD_SIZE = VALUE_OFFSET + Database.PTR_SIZE;
public PDOMCPPFieldSpecialization(PDOMLinkage linkage, PDOMNode parent,
ICPPField field, PDOMBinding specialized)
@ -55,13 +45,8 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
try {
final Database db = getDB();
IType type = field.getType();
PDOMNode typeNode = linkage.addType(this, type);
if (typeNode != null) {
db.putRecPtr(record + TYPE, typeNode.getRecord());
}
IValue val= field.getInitialValue();
long rec= PDOMValue.store(db, linkage, val);
linkage.storeType(record + TYPE_OFFSET, field.getType());
long rec= PDOMValue.store(db, linkage, field.getInitialValue());
db.putRecPtr(record + VALUE_OFFSET, rec);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
@ -92,10 +77,7 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
public IType getType() throws DOMException {
try {
PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + TYPE));
if (node instanceof IType) {
return (IType) node;
}
return getLinkage().loadType(record + TYPE_OFFSET);
} catch (CoreException e) {
CCorePlugin.log(e);
}

View file

@ -15,7 +15,6 @@ 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.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;
@ -25,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
@ -44,43 +42,44 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
* Offset of total number of function parameters (relative to the
* beginning of the record).
*/
private static final int NUM_PARAMS = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int NUM_PARAMS = PDOMCPPBinding.RECORD_SIZE;
/**
* Offset of pointer to the first parameter of this function (relative to
* the beginning of the record).
*/
private static final int FIRST_PARAM = PDOMCPPBinding.RECORD_SIZE + 4;
private static final int FIRST_PARAM = NUM_PARAMS + 4;
/**
* Offset of pointer to the function type record of this function (relative to
* the beginning of the record).
*/
protected static final int FUNCTION_TYPE= PDOMCPPBinding.RECORD_SIZE + 8;
protected static final int FUNCTION_TYPE= FIRST_PARAM + Database.PTR_SIZE;
/**
* Offset of hash of parameter information to allow fast comparison
*/
private static final int SIGNATURE_HASH = PDOMCPPBinding.RECORD_SIZE + 12;
private static final int SIGNATURE_HASH = FUNCTION_TYPE + Database.TYPE_SIZE;
/**
* Offset of start of exception specifications
*/
protected static final int EXCEPTION_SPEC = PDOMCPPBinding.RECORD_SIZE + 16; // int
protected static final int EXCEPTION_SPEC = SIGNATURE_HASH + 4; // int
/**
* Offset of annotation information (relative to the beginning of the
* record).
*/
private static final int ANNOTATION = PDOMCPPBinding.RECORD_SIZE + 20; // byte
private static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // byte
/**
* The size in bytes of a PDOMCPPFunction record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 21;
protected static final int RECORD_SIZE = ANNOTATION + 1;
private byte annotation= -1;
private ICPPFunctionType fType;
public PDOMCPPFunction(PDOMLinkage linkage, PDOMNode parent, ICPPFunction function, boolean setTypes) throws CoreException, DOMException {
super(linkage, parent, function.getNameCharArray());
@ -95,10 +94,9 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
}
public void initData(ICPPFunctionType ftype, IParameter[] params, IType[] exceptionSpec) {
PDOMCPPFunctionType pft;
try {
pft = setType(ftype);
setParameters(pft, params);
setType(ftype);
setParameters(params);
storeExceptionSpec(exceptionSpec);
} catch (CoreException e) {
CCorePlugin.log(e);
@ -120,17 +118,11 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
throw new CoreException(Util.createStatus(e));
}
IFunctionType oldType= getType();
PDOMCPPParameter oldParams= getFirstParameter();
if (oldType instanceof PDOMCPPFunctionType && oldType.isSameType(newType)) {
setParameters((PDOMCPPFunctionType) oldType, newParams);
} else {
PDOMCPPFunctionType pft= setType(newType);
setParameters(pft, newParams);
if (oldType != null) {
linkage.deleteType(oldType, record);
}
}
fType= null;
getLinkage().storeType(record+FUNCTION_TYPE, newType);
PDOMCPPParameter oldParams= getFirstParameter(null);
setParameters(newParams);
if (oldParams != null) {
oldParams.delete(linkage);
}
@ -167,22 +159,21 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
return exceptionSpec;
}
private void setParameters(PDOMCPPFunctionType pft, IParameter[] params) throws CoreException {
private void setParameters(IParameter[] params) throws CoreException {
final PDOMLinkage linkage = getLinkage();
final Database db= getDB();
db.putInt(record + NUM_PARAMS, params.length);
db.putRecPtr(record + FIRST_PARAM, 0);
IType[] paramTypes= pft.getParameterTypes();
for (int i= 0; i < params.length; ++i) {
long ptRecord= i < paramTypes.length && paramTypes[i] != null ? ((PDOMNode) paramTypes[i]).getRecord() : 0;
setFirstParameter(new PDOMCPPParameter(getLinkage(), this, params[i], ptRecord));
PDOMCPPParameter next= null;
for (int i= params.length-1; 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<ptypes.length ? ptypes[i] : null;
final PDOMCPPParameter par = new PDOMCPPParameter(linkage, next, type);
next= par.getNextPtr();
result[i]= par;
}
return params;
return result;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IParameter[0];
return IParameter.EMPTY_PARAMETER_ARRAY;
}
}
public final ICPPFunctionType getType() {
final PDOM pdom= getPDOM();
ICPPFunctionType ftype= (ICPPFunctionType) pdom.getCachedResult(record);
if (ftype == null) {
ftype= readFunctionType();
pdom.putCachedResult(record, ftype, false);
if (fType == null) {
try {
fType= (ICPPFunctionType) getLinkage().loadType(record+FUNCTION_TYPE);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return ftype;
return fType;
}
private final ICPPFunctionType readFunctionType() {
try {
long offset= getDB().getRecPtr(record + FUNCTION_TYPE);
return offset==0 ? null : new PDOMCPPFunctionType(getLinkage(), offset);
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
}
}
public boolean isAuto() throws DOMException {
// ISO/IEC 14882:2003 7.1.1.2
return false;

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
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.ICPPMethod;
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;
@ -40,78 +39,73 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
* Offset of total number of function parameters (relative to the
* beginning of the record).
*/
private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE + 0;
private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE;
/**
* Offset of pointer to the first parameter of this function (relative to
* the beginning of the record).
*/
private static final int FIRST_PARAM = PDOMCPPSpecialization.RECORD_SIZE + 4;
private static final int FIRST_PARAM = NUM_PARAMS + 4;
/**
* Offset for type of this function (relative to
* the beginning of the record).
*/
private static final int FUNCTION_TYPE = PDOMCPPSpecialization.RECORD_SIZE + 8;
private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE;
/**
* Offset of start of exception specification
*/
protected static final int EXCEPTION_SPEC = PDOMCPPSpecialization.RECORD_SIZE + 12; // int
protected static final int EXCEPTION_SPEC = FUNCTION_TYPE + Database.TYPE_SIZE; // int
/**
* Offset of annotation information (relative to the beginning of the
* record).
*/
protected static final int ANNOTATION = PDOMCPPSpecialization.RECORD_SIZE + 16; // byte
protected static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // byte
/**
* The size in bytes of a PDOMCPPFunction record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 17;
protected static final int RECORD_SIZE = ANNOTATION + 1;
private ICPPFunctionType fType;
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction function, PDOMBinding specialized) throws CoreException {
super(linkage, parent, (ICPPSpecialization) function, specialized);
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction astFunction, PDOMBinding specialized) throws CoreException {
super(linkage, parent, (ICPPSpecialization) astFunction, specialized);
Database db = getDB();
try {
IParameter[] params= function.getParameters();
IType[] paramTypes= IType.EMPTY_TYPE_ARRAY;
IFunctionType ft= function.getType();
if (ft != null) {
PDOMNode typeNode = getLinkage().addType(this, ft);
if (typeNode != null) {
db.putRecPtr(record + FUNCTION_TYPE, typeNode.getRecord());
paramTypes= ((IFunctionType) typeNode).getParameterTypes();
}
IParameter[] astParams= astFunction.getParameters();
IFunctionType astFt= astFunction.getType();
if (astFt != null) {
getLinkage().storeType(record + FUNCTION_TYPE, astFt);
}
ICPPFunction sFunc= (ICPPFunction) ((ICPPSpecialization)function).getSpecializedBinding();
IParameter[] sParams= sFunc.getParameters();
IType[] sParamTypes= sFunc.getType().getParameterTypes();
ICPPFunction spAstFunc= (ICPPFunction) ((ICPPSpecialization)astFunction).getSpecializedBinding();
IParameter[] spAstParams= spAstFunc.getParameters();
final int length= Math.min(sParams.length, params.length);
final int length= Math.min(spAstParams.length, astParams.length);
db.putInt(record + NUM_PARAMS, length);
for (int i=0; i<length; ++i) {
final PDOMNode stype= linkage.addType(this, i<sParamTypes.length ? sParamTypes[i] : null);
final long stypeRec= stype == null ? 0 : stype.getRecord();
PDOMCPPParameter sParam = new PDOMCPPParameter(getLinkage(), this, sParams[i], stypeRec);
long typeRecord= i<paramTypes.length && paramTypes[i]!=null ? ((PDOMNode)paramTypes[i]).getRecord() : 0;
final ICPPParameter param = (ICPPParameter) params[i];
setFirstParameter(new PDOMCPPParameterSpecialization(getLinkage(), this, param, sParam, typeRecord));
db.putRecPtr(record + FIRST_PARAM, 0);
PDOMCPPParameterSpecialization next= null;
for (int i= length-1; 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= i<ptypes.length ? ptypes[i] : null;
final PDOMCPPParameterSpecialization par = new PDOMCPPParameterSpecialization(linkage, next, type);
next= par.getNextPtr();
result[i]= par;
}
return params;
return result;
} catch (CoreException e) {
CCorePlugin.log(e);
return new IParameter[0];
@ -175,13 +165,14 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
}
public ICPPFunctionType getType() throws DOMException {
try {
long offset= getDB().getRecPtr(record + FUNCTION_TYPE);
return offset==0 ? null : new PDOMCPPFunctionType(getLinkage(), offset);
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
if (fType == null) {
try {
fType= (ICPPFunctionType) getLinkage().loadType(record + FUNCTION_TYPE);
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
}
return fType;
}
public boolean isAuto() throws DOMException {

View file

@ -36,13 +36,10 @@ import org.eclipse.core.runtime.CoreException;
class PDOMCPPFunctionTemplate extends PDOMCPPFunction
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, IPDOMCPPTemplateParameterOwner {
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE + 0;
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE;
/**
* The size in bytes of a PDOMCPPFunctionTemplate record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 4;
protected static final int RECORD_SIZE = TEMPLATE_PARAMS + Database.PTR_SIZE;
private IPDOMCPPTemplateParameter[] params; // Cached template parameters.

View file

@ -1,137 +0,0 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial Implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
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.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCFunctionType;
import org.eclipse.core.runtime.CoreException;
public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFunctionType {
private static IType FALLBACK_RETURN_TYPE= new CPPBasicType(Kind.eVoid, 0);
static ICPPFunctionType FALLBACK= new ICPPFunctionType() {
@Deprecated
public IPointerType getThisType() {
return null;
}
public boolean isConst() {
return false;
}
public boolean isVolatile() {
return false;
}
public IType[] getParameterTypes() {
return IType.EMPTY_TYPE_ARRAY;
}
public IType getReturnType() {
return FALLBACK_RETURN_TYPE;
}
public boolean isSameType(IType type) {
return this == type || type.isSameType(this);
}
@Override
public Object clone() {
return this;
}
};
/**
* Offset for <code>this</code> 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);
}
}

View file

@ -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$
}
}

View file

@ -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);
}
}
}

View file

@ -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;
}

View file

@ -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<pars.length; parPos++) {
IParameter par= pars[parPos];
if (equals(par)) {
break;
}
}
if (parPos < pars.length) {
parent= ((ICPPSpecialization) parent).getSpecializedBinding();
if (parent instanceof ICPPFunction) {
ICPPFunctionType ftype = ((ICPPFunction) parent).getType();
if (ftype != null) {
IType[] ptypes= ftype.getParameterTypes();
if (parPos < ptypes.length) {
type= ptypes[parPos];
}
}
}
}
} catch (DOMException e) {
}
}
return new PDOMCPPParameter(getLinkage(), record, type);
}
private ICPPParameter getParameter(){
return (ICPPParameter) getSpecializedBinding();
}

View file

@ -1,103 +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
* Bryan Wilkinson (QNX)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
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.index.CPPPointerToMemberTypeClone;
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.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMPointerType;
import org.eclipse.core.runtime.CoreException;
/**
* Pointer to member type
*/
class PDOMCPPPointerToMemberType extends PDOMPointerType implements ICPPPointerToMemberType {
private static final int TYPE = PDOMPointerType.RECORD_SIZE;
@SuppressWarnings("hiding")
private static final int RECORD_SIZE= TYPE + 4;
public PDOMCPPPointerToMemberType(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public PDOMCPPPointerToMemberType(PDOMLinkage linkage, PDOMNode parent, ICPPPointerToMemberType type) throws CoreException {
super(linkage, parent, type);
Database db = getDB();
// type
IType ct = type.getMemberOfClass();
long typeRec = 0;
if (ct != null) {
PDOMNode targetTypeNode = getLinkage().addType(this, ct);
if (targetTypeNode != null)
typeRec = targetTypeNode.getRecord();
}
db.putRecPtr(record + TYPE, typeRec);
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_POINTER_TO_MEMBER_TYPE;
}
public IType getMemberOfClass() {
try {
long rec = getDB().getRecPtr(record + TYPE);
return (IType) getLinkage().getNode(rec);
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
@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;
}
@Override
public Object clone() {
return new CPPPointerToMemberTypeClone(this);
}
@Override
public void delete(PDOMLinkage linkage) throws CoreException {
linkage.deleteType(getMemberOfClass(), record);
super.delete(linkage);
}
}

View file

@ -1,119 +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
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
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.ITypeContainer;
import org.eclipse.cdt.internal.core.index.CPPReferenceTypeClone;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
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.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
class PDOMCPPReferenceType extends PDOMNode implements ICPPReferenceType, ITypeContainer, IIndexType {
private static final int TYPE = PDOMNode.RECORD_SIZE + 0;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
private IType targetType;
public PDOMCPPReferenceType(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public PDOMCPPReferenceType(PDOMLinkage linkage, PDOMNode parent, ICPPReferenceType type) throws CoreException {
super(linkage, parent);
Database db = getDB();
// type
long typeRec = 0;
if (type != null) {
IType targetType = type.getType();
PDOMNode targetTypeNode = getLinkage().addType(this, targetType);
if (targetTypeNode != null)
typeRec = targetTypeNode.getRecord();
}
db.putRecPtr(record + TYPE, typeRec);
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_REFERENCE_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;
}
}
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) {
throw new PDOMNotImplementedError();
}
@Override
public Object clone() {
return new CPPReferenceTypeClone(this);
}
@Override
public void delete(PDOMLinkage linkage) throws CoreException {
linkage.deleteType(getType(), record);
super.delete(linkage);
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
}

View file

@ -69,13 +69,17 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements ICPPSpeci
if (fSpecializedCache == null) {
try {
long specializedRec = getDB().getRecPtr(record + SPECIALIZED);
fSpecializedCache= (IPDOMBinding) getLinkage().getNode(specializedRec);
fSpecializedCache= loadSpecializedBinding(specializedRec);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return fSpecializedCache;
}
protected IPDOMBinding loadSpecializedBinding(long specializedRec) throws CoreException {
return (IPDOMBinding) getLinkage().getNode(specializedRec);
}
@Deprecated
public ObjectMap getArgumentMap() {

View file

@ -39,16 +39,13 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem
ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter {
private static final int TYPE_OFFSET= PDOMCPPBinding.RECORD_SIZE;
private static final int PARAMETERID= PDOMCPPBinding.RECORD_SIZE + 4;
private static final int DEFAULTVAL= PDOMCPPBinding.RECORD_SIZE + 8;
private static final int PARAMETERID= TYPE_OFFSET + Database.TYPE_SIZE;
private static final int DEFAULTVAL= PARAMETERID + 4;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = DEFAULTVAL + Database.PTR_SIZE;
private int fCachedParamID= -1;
/**
* The size in bytes of a PDOMCPPTemplateTypeParameter record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPVariable.RECORD_SIZE + 12;
public PDOMCPPTemplateNonTypeParameter(PDOMLinkage linkage, PDOMNode parent,
ICPPTemplateNonTypeParameter param) throws CoreException {
@ -91,13 +88,10 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem
ICPPTemplateNonTypeParameter ntp= (ICPPTemplateNonTypeParameter) newBinding;
updateName(newBinding.getNameCharArray());
final Database db = getDB();
IType mytype= getType();
long valueRec= db.getRecPtr(record + DEFAULTVAL);
try {
IType newType= ntp.getType();
setType(linkage, newType);
if (mytype != null)
linkage.deleteType(mytype, record);
if (setDefaultValue(db, ntp)) {
PDOMValue.delete(db, valueRec);
}
@ -109,12 +103,9 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem
public void forceDelete(PDOMLinkage linkage) throws CoreException {
getDBName().delete();
IType type= getType();
if (type instanceof PDOMNode) {
((PDOMNode) type).delete(linkage);
}
Database db= getDB();
long valueRec= db.getRecPtr(record + DEFAULTVAL);
linkage.storeType(record+TYPE_OFFSET, null);
final Database db= getDB();
final long valueRec= db.getRecPtr(record + DEFAULTVAL);
PDOMValue.delete(db, valueRec);
}
@ -146,8 +137,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem
}
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);
linkage.storeType(record + TYPE_OFFSET, newType);
}
public void configure(ICPPTemplateParameter param) {
@ -180,8 +170,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem
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;

View file

@ -29,6 +29,11 @@ import org.eclipse.core.runtime.CoreException;
* Collects methods to store an argument list in the database
*/
public class PDOMCPPTemplateParameterMap {
private static final int PARAMPOS_OFFSET= 0;
private static final int TYPE_OFFSET= PARAMPOS_OFFSET + 4;
private static final int VALUE_OFFSET= TYPE_OFFSET + Database.TYPE_SIZE;
private static final int NODE_SIZE = VALUE_OFFSET + Database.PTR_SIZE;
/**
* Stores the given template parameter map in the database.
* @return the record by which the arguments can be referenced.
@ -37,28 +42,22 @@ public class PDOMCPPTemplateParameterMap {
final PDOMLinkage linkage= parent.getLinkage();
final Database db= linkage.getDB();
Integer[] keys= map.getAllParameterPositions();
final short len= (short) Math.min(keys.length, (Database.MAX_MALLOC_SIZE-2)/12);
final long block= db.malloc(2+12*len);
final short len= (short) Math.min(keys.length, (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE);
final long block= db.malloc(2+NODE_SIZE*len);
long p= block;
db.putShort(p, len); p+=2;
for (int i=0; i<len; i++) {
final Integer paramPos = keys[i];
db.putInt(p, paramPos);
p+=4; //TODO? assumes stored pointer size is 4?
db.putInt(p + PARAMPOS_OFFSET, paramPos);
final ICPPTemplateArgument arg = map.getArgument(paramPos);
if (arg.isNonTypeValue()) {
final PDOMNode type= linkage.addType(parent, arg.getTypeOfNonTypeValue());
// type can be null, if it is local
db.putRecPtr(p, type == null ? 0 : type.getRecord());
long valueRec= PDOMValue.store(db, linkage, arg.getNonTypeValue());
db.putRecPtr(p+4, valueRec); //TODO: assumes that stored pointer size is 4.
linkage.storeType(p + TYPE_OFFSET, arg.getTypeOfNonTypeValue());
db.putRecPtr(p+VALUE_OFFSET, PDOMValue.store(db, linkage, arg.getNonTypeValue()));
} else {
final PDOMNode type= linkage.addType(parent, arg.getTypeValue());
// type can be null, if it is local
db.putRecPtr(p, type == null ? 0 : type.getRecord());
linkage.storeType(p + TYPE_OFFSET, arg.getTypeValue());
}
p+=8; //TODO; assumes stored pointer size
p+=NODE_SIZE;
}
return block;
}
@ -72,18 +71,12 @@ public class PDOMCPPTemplateParameterMap {
final Database db= linkage.getDB();
final short len= db.getShort(rec);
Assert.isTrue(len >= 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<len; i++) {
rec+=4;
final long typeRec= db.getRecPtr(rec);
if (typeRec != 0) {
final IType t= (IType) linkage.getNode(typeRec);
linkage.deleteType(t, parent.getRecord());
}
final long nonTypeValueRec= db.getRecPtr(rec+4);
PDOMValue.delete(db, nonTypeValueRec);
rec+= 8;
linkage.storeType(rec+TYPE_OFFSET, null);
PDOMValue.delete(db, db.getRecPtr(rec+VALUE_OFFSET));
rec+= NODE_SIZE;
}
db.free(rec);
}
@ -96,7 +89,7 @@ public class PDOMCPPTemplateParameterMap {
final Database db= linkage.getDB();
final short len= db.getShort(rec);
Assert.isTrue(len >= 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<len; i++) {
final int parPos= db.getInt(rec);
final long typeRec= db.getRecPtr(rec+4);
final IType type= typeRec == 0 ? new CPPBasicType(Kind.eUnspecified, CPPBasicType.UNIQUE_TYPE_QUALIFIER) : (IType) linkage.getNode(typeRec);
final long nonTypeValRec= db.getRecPtr(rec+8);
final int parPos= db.getInt(rec + PARAMPOS_OFFSET);
IType type= linkage.loadType(rec + TYPE_OFFSET);
if (type == null) {
type= new CPPBasicType(Kind.eUnspecified, CPPBasicType.UNIQUE_TYPE_QUALIFIER);
}
final long nonTypeValRec= db.getRecPtr(rec+VALUE_OFFSET);
ICPPTemplateArgument arg;
if (nonTypeValRec != 0) {
IValue val= PDOMValue.restore(db, linkage, nonTypeValRec);
@ -116,7 +111,7 @@ public class PDOMCPPTemplateParameterMap {
arg= new CPPTemplateArgument(type);
}
result.put(parPos, arg);
rec+= 12;
rec+= NODE_SIZE;
}
return result;
}

View file

@ -51,16 +51,12 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding
implements ICPPTemplateTemplateParameter, ICPPUnknownBinding, ICPPUnknownType, IIndexType,
IPDOMCPPTemplateParameter, IPDOMCPPTemplateParameterOwner {
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
private static final int PARAMETERID= PDOMCPPBinding.RECORD_SIZE + 8;
private static final int PARAMETERS= PDOMCPPBinding.RECORD_SIZE + 12;
/**
* The size in bytes of a PDOMCPPTemplateTypeParameter record in the database.
*/
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE;
private static final int MEMBERLIST = DEFAULT_TYPE + Database.TYPE_SIZE;
private static final int PARAMETERID= MEMBERLIST + Database.PTR_SIZE;
private static final int PARAMETERS= PARAMETERID + 4;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 14;
protected static final int RECORD_SIZE = PARAMETERS + Database.PTR_SIZE;
private ICPPScope fUnknownScope;
private int fCachedParamID= -1;
@ -144,10 +140,7 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding
public IType getDefault() {
try {
PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + DEFAULT_TYPE));
if (node instanceof IType) {
return (IType) node;
}
return getLinkage().loadType(record + DEFAULT_TYPE);
} catch (CoreException e) {
CCorePlugin.log(e);
}
@ -183,11 +176,7 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding
if (val != null) {
IType dflt= val.getTypeValue();
if (dflt != null) {
final Database db= getPDOM().getDB();
PDOMNode typeNode = getLinkage().addType(this, dflt);
if (typeNode != null) {
db.putRecPtr(record + DEFAULT_TYPE, typeNode.getRecord());
}
getLinkage().storeType(record + DEFAULT_TYPE, dflt);
}
}
} catch (CoreException e) {
@ -208,13 +197,7 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding
// ignore
}
if (newDefault != null) {
IType mytype= getDefault();
PDOMNode typeNode = getLinkage().addType(this, newDefault);
if (typeNode != null) {
db.putRecPtr(record + DEFAULT_TYPE, typeNode.getRecord());
if (mytype != null)
linkage.deleteType(mytype, record);
}
linkage.storeType(record + DEFAULT_TYPE, newDefault);
}
long oldRec= db.getRecPtr(record + PARAMETERS);
IPDOMCPPTemplateParameter[] oldParams= getTemplateParameters();
@ -234,15 +217,9 @@ public class PDOMCPPTemplateTemplateParameter extends PDOMCPPBinding
public void forceDelete(PDOMLinkage linkage) throws CoreException {
getDBName().delete();
IType type= getDefault();
if (type instanceof PDOMNode) {
((PDOMNode) type).delete(linkage);
}
Database db= getDB();
long valueRec= db.getRecPtr(record + DEFAULT_TYPE);
if (valueRec != 0)
db.getString(valueRec).delete();
linkage.storeType(record + DEFAULT_TYPE, null);
final Database db= getDB();
long oldRec= db.getRecPtr(record + PARAMETERS);
IPDOMCPPTemplateParameter[] oldParams= getTemplateParameters();
if (oldRec != 0)

View file

@ -43,15 +43,11 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
ICPPTemplateTypeParameter, ICPPUnknownBinding, ICPPUnknownType, IIndexType,
IPDOMCPPTemplateParameter {
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
private static final int PARAMETERID= PDOMCPPBinding.RECORD_SIZE + 8;
/**
* The size in bytes of a PDOMCPPTemplateTypeParameter record in the database.
*/
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE;
private static final int MEMBERLIST = DEFAULT_TYPE + Database.TYPE_SIZE;
private static final int PARAMETERID= MEMBERLIST + Database.PTR_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 12;
protected static final int RECORD_SIZE = PARAMETERID + 4;
private ICPPScope fUnknownScope;
private int fCachedParamID= -1;
@ -130,10 +126,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
public IType getDefault() {
try {
PDOMNode node = getLinkage().getNode(getDB().getRecPtr(record + DEFAULT_TYPE));
if (node instanceof IType) {
return (IType) node;
}
return getLinkage().loadType(record + DEFAULT_TYPE);
} catch (CoreException e) {
CCorePlugin.log(e);
}
@ -169,11 +162,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
if (val != null) {
IType dflt= val.getTypeValue();
if (dflt != null) {
final Database db= getPDOM().getDB();
PDOMNode typeNode = getLinkage().addType(this, dflt);
if (typeNode != null) {
db.putRecPtr(record + DEFAULT_TYPE, typeNode.getRecord());
}
getLinkage().storeType(record + DEFAULT_TYPE, dflt);
}
}
} catch (CoreException e) {
@ -193,23 +182,13 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
// ignore
}
if (newDefault != null) {
final Database db = getDB();
IType mytype= getDefault();
PDOMNode typeNode = getLinkage().addType(this, newDefault);
if (typeNode != null) {
db.putRecPtr(record + DEFAULT_TYPE, typeNode.getRecord());
if (mytype != null)
linkage.deleteType(mytype, record);
}
getLinkage().storeType(record + DEFAULT_TYPE, newDefault);
}
}
}
public void forceDelete(PDOMLinkage linkage) throws CoreException {
getDBName().delete();
IType type= getDefault();
if (type instanceof PDOMNode) {
((PDOMNode) type).delete(linkage);
}
getLinkage().storeType(record + DEFAULT_TYPE, null);
}
}

View file

@ -21,7 +21,7 @@ import org.eclipse.core.runtime.CoreException;
* Stores a list of types
*/
class PDOMCPPTypeList {
protected static final int NODE_SIZE = 4;
private static final int NODE_SIZE = Database.TYPE_SIZE;
/**
* Stores the given types in the database.
@ -40,14 +40,7 @@ class PDOMCPPTypeList {
db.putShort(p, len); p+=2;
for (int i=0; i<len; i++, p+=NODE_SIZE) {
final IType type = types[i];
long rec= 0;
if (type != null) {
final PDOMNode pdomType = linkage.addType(parent, type);
if (pdomType != null) {
rec= pdomType.getRecord();
}
}
db.putRecPtr(p, rec);
linkage.storeType(p, type);
}
return block;
}
@ -67,9 +60,7 @@ class PDOMCPPTypeList {
rec+=2;
IType[] result= new IType[len];
for (int i=0; i<len; i++, rec+=NODE_SIZE) {
final long typeRec= db.getRecPtr(rec);
if (typeRec != 0)
result[i]= (IType)linkage.getNode(typeRec);
result[i]= linkage.loadType(rec);
}
return result;
}
@ -88,9 +79,7 @@ class PDOMCPPTypeList {
Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE);
long p= record+2;
for (int i=0; i<len; i++, p+=NODE_SIZE) {
final long typeRec= db.getRecPtr(p);
final IType t= (IType) linkage.getNode(typeRec);
linkage.deleteType(t, parent.getRecord());
linkage.storeType(p, null);
}
db.free(record);
}

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.CPPTypedefClone;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
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.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -33,10 +34,10 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer, IIndexType {
private static final int TYPE = PDOMBinding.RECORD_SIZE + 0;
private static final int TYPE_OFFSET = PDOMBinding.RECORD_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
protected static final int RECORD_SIZE = TYPE_OFFSET + Database.TYPE_SIZE;
public PDOMCPPTypedef(PDOMLinkage linkage, PDOMNode parent, ITypedef typedef) throws CoreException {
super(linkage, parent, typedef.getNameCharArray());
@ -55,13 +56,8 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer,
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof ITypedef) {
ITypedef td= (ITypedef) newBinding;
IType mytype= getType();
try {
IType newType= td.getType();
setType(linkage, newType);
if (mytype != null) {
linkage.deleteType(mytype, record);
}
setType(linkage, td.getType());
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
@ -69,12 +65,10 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer,
}
private void setType(final PDOMLinkage linkage, IType newType) throws CoreException, DOMException {
PDOMNode typeNode = linkage.addType(this, newType);
if (introducesRecursion((IType) typeNode, getParentNodeRec(), getNameCharArray())) {
linkage.deleteType((IType) typeNode, record);
typeNode= null;
linkage.storeType(record + TYPE_OFFSET, newType);
if (introducesRecursion(getType(), getParentNodeRec(), getNameCharArray())) {
linkage.storeType(record + TYPE_OFFSET, null);
}
getDB().putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
}
private boolean introducesRecursion(IType type, long parentRec, char[] tdname) throws DOMException {
@ -126,8 +120,7 @@ class PDOMCPPTypedef extends PDOMCPPBinding implements ITypedef, ITypeContainer,
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;

Some files were not shown because too many files have changed in this diff Show more