1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 305976: New character types.

This commit is contained in:
Markus Schorn 2010-04-07 10:00:51 +00:00
parent c9d58591b0
commit 855df3774a
19 changed files with 184 additions and 29 deletions

View file

@ -8526,4 +8526,24 @@ public class AST2CPPTests extends AST2BaseTest {
String code= getAboveComment();
parseAndCheckBindings(code);
}
// void f(int);
// void f(unsigned int);
// void test() {
// char16_t c16= '1';
// char32_t c32= '1';
// f(c16);
// f(c32);
// }
public void testNewCharacterTypes_305976() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
IFunction f1= bh.assertNonProblem("f(int)", 1);
IFunction f2= bh.assertNonProblem("f(unsigned int)", 1);
IBinding b= bh.assertNonProblem("f(c16)", 1);
assertSame(f1, b);
b= bh.assertNonProblem("f(c32)", 1);
assertSame(f2, b);
}
}

View file

@ -626,6 +626,12 @@ public class ASTStringUtil {
case IASTSimpleDeclSpecifier.t_wchar_t:
buffer.append(Keywords.WCHAR_T).append(' ');
break;
case IASTSimpleDeclSpecifier.t_char16_t:
buffer.append(Keywords.CHAR16_T).append(' ');
break;
case IASTSimpleDeclSpecifier.t_char32_t:
buffer.append(Keywords.CHAR32_T).append(' ');
break;
default:
}
} else if (declSpecifier instanceof IASTNamedTypeSpecifier) {

View file

@ -737,6 +737,22 @@ public class ASTSignatureUtil {
result.append(Keywords.WCHAR_T);
needSpace = true;
break;
case IASTSimpleDeclSpecifier.t_char16_t:
if (needSpace) {
result.append(SPACE);
needSpace = false;
}
result.append(Keywords.CHAR16_T);
needSpace = true;
break;
case IASTSimpleDeclSpecifier.t_char32_t:
if (needSpace) {
result.append(SPACE);
needSpace = false;
}
result.append(Keywords.CHAR32_T);
needSpace = true;
break;
case IASTSimpleDeclSpecifier.t_double:
if (needSpace) {
result.append(SPACE);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others.
* Copyright (c) 2005, 2010 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
@ -324,6 +324,14 @@ public class ASTTypeUtil {
if (needSpace) result.append(SPACE);
result.append(Keywords.WCHAR_T);
break;
case eChar16:
if (needSpace) result.append(SPACE);
result.append(Keywords.CHAR16_T);
break;
case eChar32:
if (needSpace) result.append(SPACE);
result.append(Keywords.CHAR32_T);
break;
case eUnspecified:
break;
}

View file

@ -66,7 +66,7 @@ public interface IASTSimpleDeclSpecifier extends IASTDeclSpecifier {
public static final int t_bool = 6;
/**
* <code>t_wchar_t c;</code>
* <code>wchar_t c;</code>
* @since 5.2
*/
public static final int t_wchar_t = 7;
@ -89,6 +89,19 @@ public interface IASTSimpleDeclSpecifier extends IASTDeclSpecifier {
*/
public static final int t_auto = 10;
/**
* <code>char16_t c;</code>
* @since 5.2
*/
public static final int t_char16_t = 11;
/**
* <code>char32_t c;</code>
* @since 5.2
*/
public static final int t_char32_t = 12;
/**
* @since 5.1
*/

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 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
@ -22,7 +22,7 @@ public interface IBasicType extends IType {
* @since 5.2
*/
enum Kind {
eUnspecified, eVoid, eChar, eWChar, eInt, eFloat, eDouble, eBoolean
eUnspecified, eVoid, eChar, eWChar, eInt, eFloat, eDouble, eBoolean, eChar16, eChar32
}
/**

View file

@ -109,6 +109,10 @@ public interface IToken {
int t_case = 62;
int t_catch = 63;
int t_char = 64;
/** @since 5.2 */
int t_char16_t= 5202;
/** @since 5.2 */
int t_char32_t= 5203;
int t_class = 65;
/** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int tCOMPL= tBITCOMPLEMENT;
/** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int t_compl = 66;
@ -117,7 +121,7 @@ public interface IToken {
int t_const_cast = 69;
int t_continue = 70;
/** @since 5.2 */
int t_decltype= 5202;
int t_decltype= 5204;
int t_default = 71;
int t_delete = 72;
int t_do = 73;
@ -155,7 +159,7 @@ public interface IToken {
int t_sizeof = 105;
int t_static = 106;
/** @since 5.2 */
int t_static_assert = 5203;
int t_static_assert = 5205;
int t_static_cast = 107;
int t_signed = 108;
int t_struct = 109;

View file

@ -39,6 +39,10 @@ public class Keywords {
public static final String CASE = "case";
public static final String CATCH = "catch";
public static final String CHAR = "char";
/** @since 5.2 */
public static final String CHAR16_T = "char16_t";
/** @since 5.2 */
public static final String CHAR32_T = "char32_t";
public static final String CLASS = "class";
public static final String COMPL = "compl";
public static final String CONST = "const";
@ -124,6 +128,10 @@ public class Keywords {
public static final char[] cCASE = "case".toCharArray();
public static final char[] cCATCH = "catch".toCharArray();
public static final char[] cCHAR = "char".toCharArray();
/** @since 5.2 */
public static final char[] cCHAR16_T = CHAR16_T.toCharArray();
/** @since 5.2 */
public static final char[] cCHAR32_T = CHAR32_T.toCharArray();
public static final char[] cCLASS = "class".toCharArray();
public static final char[] cCOMPL = "compl".toCharArray();
public static final char[] cCONST = "const".toCharArray();
@ -335,6 +343,8 @@ public class Keywords {
private static void addCpp(CharArrayIntMap cppkeywords) {
cppkeywords.put(Keywords.cBOOL, IToken.t_bool);
cppkeywords.put(Keywords.cCATCH, IToken.t_catch);
cppkeywords.put(Keywords.cCHAR16_T, IToken.t_char16_t);
cppkeywords.put(Keywords.cCHAR32_T, IToken.t_char32_t);
cppkeywords.put(Keywords.cCLASS, IToken.t_class);
cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast);
cppkeywords.put(Keywords.cDECLTYPE, IToken.t_decltype);

View file

@ -2414,6 +2414,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
case IToken.tCOLONCOLON:
case IToken.t_void:
case IToken.t_char:
case IToken.t_char16_t:
case IToken.t_char32_t:
case IToken.t_wchar_t:
case IToken.t_bool:
case IToken.t_short:

View file

@ -103,6 +103,8 @@ public abstract class ArithmeticConversion {
switch(kind) {
case eBoolean:
case eChar:
case eChar16:
case eChar32:
case eInt:
case eWChar:
return true;
@ -199,7 +201,11 @@ public abstract class ArithmeticConversion {
case eBoolean:
case eChar:
case eWChar:
case eChar16:
return createBasicType(Kind.eInt, domain.getModifier());
case eChar32:
// Assuming 32 bits
return createBasicType(Kind.eInt, domain.getModifier() | IBasicType.IS_UNSIGNED);
case eInt:
if (bt.isShort())

View file

@ -87,6 +87,8 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
return t_bool;
case eChar:
case eWChar:
case eChar16:
case eChar32:
return t_char;
case eDouble:
return t_double;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others.
* Copyright (c) 2005, 2010 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
@ -189,6 +189,8 @@ public class CBasicType implements ICBasicType, ISerializableType {
return t_Bool;
case eChar:
case eWChar:
case eChar16:
case eChar32:
return t_char;
case eDouble:
return t_double;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 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
@ -14,10 +14,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -128,7 +128,16 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
}
private Kind getCharType() {
return getValue()[0] == 'L' ? Kind.eWChar : Kind.eChar;
switch (getValue()[0]) {
case 'L':
return Kind.eWChar;
case 'u':
return Kind.eChar16;
case 'U':
return Kind.eChar32;
default:
return Kind.eChar;
}
}
private IType classifyTypeOfFloatLiteral() {

View file

@ -75,6 +75,10 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
return t_char;
case eWChar:
return t_wchar_t;
case eChar16:
return t_char16_t;
case eChar32:
return t_char32_t;
case eDouble:
return t_double;
case eFloat:

View file

@ -79,6 +79,10 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
return Kind.eChar;
case IASTSimpleDeclSpecifier.t_wchar_t:
return Kind.eWChar;
case IASTSimpleDeclSpecifier.t_char16_t:
return Kind.eChar16;
case IASTSimpleDeclSpecifier.t_char32_t:
return Kind.eChar32;
case IASTSimpleDeclSpecifier.t_double:
return Kind.eDouble;
case IASTSimpleDeclSpecifier.t_float:
@ -218,6 +222,8 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType {
case eBoolean:
return t_bool;
case eChar:
case eChar16:
case eChar32:
return t_char;
case eWChar:
return t_wchar_t;

View file

@ -417,6 +417,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// postfix expression
case IToken.t_typename:
case IToken.t_char:
case IToken.t_char16_t:
case IToken.t_char32_t:
case IToken.t_wchar_t:
case IToken.t_bool:
case IToken.t_short:
@ -1174,6 +1176,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// simple-type-specifier braced-init-list
case IToken.t_typename:
case IToken.t_char:
case IToken.t_char16_t:
case IToken.t_char32_t:
case IToken.t_wchar_t:
case IToken.t_bool:
case IToken.t_short:
@ -2148,7 +2152,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* "typedef" | "friend" |
* "const" | "volatile" |
* "short" | "long" | "signed" | "unsigned" | "int" |
* "char" | "wchar_t" | "bool" | "float" | "double" | "void" |
* "char" | "wchar_t" | "bool" | "float" | "double" | "void" |
* "auto" |
* ("typename")? name |
* { "class" | "struct" | "union" } classSpecifier |
@ -2313,6 +2317,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
encounteredRawType= true;
endOffset= consume().getEndOffset();
break;
case IToken.t_char16_t:
if (encounteredTypename)
break declSpecifiers;
simpleType = IASTSimpleDeclSpecifier.t_char16_t;
encounteredRawType= true;
endOffset= consume().getEndOffset();
break;
case IToken.t_char32_t:
if (encounteredTypename)
break declSpecifiers;
simpleType = IASTSimpleDeclSpecifier.t_char32_t;
encounteredRawType= true;
endOffset= consume().getEndOffset();
break;
case IToken.t_bool:
if (encounteredTypename)
break declSpecifiers;

View file

@ -934,20 +934,31 @@ public class Conversions {
final IBasicType basicSrc = (IBasicType) src;
Kind sKind = basicSrc.getKind();
if (tKind == Kind.eInt) {
switch (sKind) {
case eInt: // short, and unsigned short
if (basicSrc.isShort()) {
canPromote= true;
if (!basicTgt.isLong() && !basicTgt.isLongLong() && !basicTgt.isShort()) {
switch (sKind) {
case eInt: // short, and unsigned short
if (basicSrc.isShort() && !basicTgt.isUnsigned()) {
canPromote= true;
}
break;
case eChar:
case eBoolean:
case eWChar:
case eChar16:
case eUnspecified: // treat unspecified as int
if (!basicTgt.isUnsigned()) {
canPromote= true;
}
break;
case eChar32:
if (basicTgt.isUnsigned()) {
canPromote= true;
}
break;
default:
break;
}
break;
case eChar:
case eBoolean:
case eWChar:
case eUnspecified: // treat unspecified as int
canPromote= true;
break;
default:
break;
}
} else if (tKind == Kind.eDouble && sKind == Kind.eFloat) {
canPromote= true;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -16,10 +16,10 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
@ -28,11 +28,12 @@ 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.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -112,6 +113,14 @@ public class DeclSpecWriter extends NodeWriter {
if (isCpp)
return WCHAR_T;
break;
case IASTSimpleDeclSpecifier.t_char16_t:
if (isCpp)
return Keywords.CHAR16_T;
break;
case IASTSimpleDeclSpecifier.t_char32_t:
if (isCpp)
return Keywords.CHAR32_T;
break;
}
System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$

View file

@ -101,7 +101,6 @@ public class KeywordSets {
DECL_SPECIFIER_SEQUENCE_C.add( Keywords._COMPLEX);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords._IMAGINARY);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.CHAR);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.WCHAR_T);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords._BOOL);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.INT);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.FLOAT);
@ -122,6 +121,10 @@ public class KeywordSets {
DECL_SPECIFIER_SEQUENCE_CPP.remove( Keywords._IMAGINARY);
DECL_SPECIFIER_SEQUENCE_CPP.remove( Keywords._BOOL);
// CPP specific stuff
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.WCHAR_T);
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.CHAR16_T);
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.CHAR32_T);
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.VIRTUAL);
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.MUTABLE);
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.EXPLICIT);
@ -173,7 +176,6 @@ public class KeywordSets {
{
EXPRESSION_C = new TreeSet<String>();
EXPRESSION_C.add( Keywords.CHAR );
EXPRESSION_C.add( Keywords.WCHAR_T);
EXPRESSION_C.add( Keywords.SHORT);
EXPRESSION_C.add( Keywords.INT);
EXPRESSION_C.add( Keywords.LONG);
@ -190,6 +192,9 @@ public class KeywordSets {
{
EXPRESSION_CPP = new TreeSet<String>(EXPRESSION_C);
EXPRESSION_CPP.add( Keywords.BOOL );
EXPRESSION_CPP.add( Keywords.CHAR16_T );
EXPRESSION_CPP.add( Keywords.CHAR32_T );
EXPRESSION_CPP.add( Keywords.WCHAR_T );
EXPRESSION_CPP.add( Keywords.NEW );
EXPRESSION_CPP.add( Keywords.DELETE );
EXPRESSION_CPP.add( Keywords.TYPENAME );
@ -411,6 +416,8 @@ public class KeywordSets {
ALL_CPP.add( Keywords.CASE);
ALL_CPP.add( Keywords.CATCH);
ALL_CPP.add( Keywords.CHAR);
ALL_CPP.add( Keywords.CHAR16_T);
ALL_CPP.add( Keywords.CHAR32_T);
ALL_CPP.add( Keywords.CLASS);
ALL_CPP.add( Keywords.COMPL);
ALL_CPP.add( Keywords.CONST);
@ -624,6 +631,8 @@ public class KeywordSets {
TYPES_CPP = new TreeSet<String>();
TYPES_CPP.add( Keywords.BOOL );
TYPES_CPP.add( Keywords.CHAR );
TYPES_CPP.add( Keywords.CHAR16_T );
TYPES_CPP.add( Keywords.CHAR32_T );
TYPES_CPP.add( Keywords.DOUBLE );
TYPES_CPP.add( Keywords.FLOAT );
TYPES_CPP.add( Keywords.INT );