From adef5a84f74d4ae137c9c607f329664e83dca979 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 19 Jul 2010 12:59:11 +0000 Subject: [PATCH] Bug 319186: Marshalling char16_t and char32_t. --- .../tests/IndexCPPBindingResolutionBugs.java | 18 +++++++++++ .../core/dom/parser/c/CBasicType.java | 31 ++++++++++--------- .../core/dom/parser/cpp/CPPBasicType.java | 31 ++++++++++--------- .../eclipse/cdt/internal/core/pdom/PDOM.java | 8 +++-- 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index b19a8fbae1f..d628b64b5a5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -16,6 +16,7 @@ import java.util.regex.Pattern; import junit.framework.TestSuite; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -1269,4 +1270,21 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas getBindingFromASTName("f255", 0); getBindingFromASTName("f256", 0); } + + // void f(char16_t x); + // void f(char32_t x); + + // void test() { + // char16_t c16; + // char32_t c32; + // f(c16); f(c32); + // } + + public void testChar16_Bug319186() throws Exception { + IFunction f= getBindingFromASTName("f(c16)", 1); + assertEquals("char16_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0])); + + f= getBindingFromASTName("f(c32)", 1); + assertEquals("char32_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0])); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java index 321c81ee4cb..d559b71bba2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBasicType.java @@ -159,27 +159,28 @@ public class CBasicType implements ICBasicType, ISerializableType { } 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); + final int kind= getKind().ordinal(); + final int shiftedKind= kind * ITypeMarshalBuffer.FLAG1; + final int modifiers= getModifiers(); + if (shiftedKind < ITypeMarshalBuffer.FLAG4 && modifiers == 0) { + buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); } else { - buffer.putByte((byte) firstByte); - } + buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | ITypeMarshalBuffer.FLAG4)); + buffer.putByte((byte) kind); + buffer.putByte((byte) modifiers); + } } public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - int kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + final boolean dense= (firstByte & ITypeMarshalBuffer.FLAG4) == 0; int modifiers= 0; - if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + int kind; + if (dense) { + kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + } else { + kind= buffer.getByte(); modifiers= buffer.getByte(); - } + } return new CBasicType(Kind.values()[kind], modifiers); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index ace0a75aea8..47e6dc79889 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -185,27 +185,28 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } 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); + final int kind= getKind().ordinal(); + final int shiftedKind= kind * ITypeMarshalBuffer.FLAG1; + final int modifiers= getModifiers(); + if (shiftedKind < ITypeMarshalBuffer.FLAG4 && modifiers == 0) { + buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | shiftedKind)); } else { - buffer.putByte((byte) firstByte); - } + buffer.putByte((byte) (ITypeMarshalBuffer.BASIC_TYPE | ITypeMarshalBuffer.FLAG4)); + buffer.putByte((byte) kind); + buffer.putByte((byte) modifiers); + } } public static IType unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { - int kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + final boolean dense= (firstByte & ITypeMarshalBuffer.FLAG4) == 0; int modifiers= 0; - if (((firstByte & ITypeMarshalBuffer.FLAG4) != 0)) { + int kind; + if (dense) { + kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + } else { + kind= buffer.getByte(); modifiers= buffer.getByte(); - } + } return new CPPBasicType(Kind.values()[kind], modifiers); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 59c3bd1c169..fefa3ceff09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -194,13 +194,15 @@ public class PDOM extends PlatformObject implements IPDOM { * 96.0 - storing pack expansions in the template parameter map, bug 294730. * 97.0 - storing file contents hash in PDOMFile, bug 302083. * #98.0# - strongly typed enums, bug 305975. <> + * 99.0 - correct marshalling of basic types, bug 319186. * * CDT 8.0 development (versions not supported on the 7.0.x branch) * 110.0 - update index on encoding change, bug 317435. + * 111.0 - correct marshalling of basic types, bug 319186. */ - private static final int MIN_SUPPORTED_VERSION= version(110, 0); - private static final int MAX_SUPPORTED_VERSION= version(110, Short.MAX_VALUE); - private static final int DEFAULT_VERSION = version(110, 0); + private static final int MIN_SUPPORTED_VERSION= version(111, 0); + private static final int MAX_SUPPORTED_VERSION= version(111, Short.MAX_VALUE); + private static final int DEFAULT_VERSION = version(111, 0); private static int version(int major, int minor) { return (major << 16) + minor;