[cfe-commits] r54585 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Type.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/DeclSpec.h lib/AST/ASTContext.cpp lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaType.cpp test/Sema/cxx-wchar_t.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Aug 9 09:51:54 PDT 2008
Author: akirtzidis
Date: Sat Aug 9 11:51:54 2008
New Revision: 54585
URL: http://llvm.org/viewvc/llvm-project?rev=54585&view=rev
Log:
Implement support for the 'wchar_t' C++ type.
Added:
cfe/trunk/test/Sema/cxx-wchar_t.cpp
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/DeclSpec.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Parse/DeclSpec.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Aug 9 11:51:54 2008
@@ -118,6 +118,7 @@
QualType VoidTy;
QualType BoolTy;
QualType CharTy;
+ QualType WCharTy; // [C++ 3.9.1p5]
QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy;
QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
QualType UnsignedLongLongTy;
@@ -236,6 +237,14 @@
/// getWcharType - Return the unique type for "wchar_t" (C99 7.17), defined
/// in <stddef.h>. Wide strings require this (C99 6.4.5p5).
QualType getWcharType() const;
+
+ /// getSignedWCharType - Return the type of "signed wchar_t".
+ /// Used when in C++, as a GCC extension.
+ QualType getSignedWCharType() const;
+
+ /// getUnsignedWCharType - Return the type of "unsigned wchar_t".
+ /// Used when in C++, as a GCC extension.
+ QualType getUnsignedWCharType() const;
/// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sat Aug 9 11:51:54 2008
@@ -476,7 +476,9 @@
Long,
LongLong,
- Float, Double, LongDouble
+ Float, Double, LongDouble,
+
+ WChar // This is 'wchar_t' for C++.
};
private:
Kind TypeKind;
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sat Aug 9 11:51:54 2008
@@ -571,6 +571,8 @@
"cannot combine with previous '%0' declaration specifier")
DIAG(err_invalid_sign_spec, ERROR,
"'%0' cannot be signed or unsigned")
+DIAG(ext_invalid_sign_spec, EXTENSION,
+ "'%0' cannot be signed or unsigned")
DIAG(err_invalid_short_spec, ERROR,
"'short %0' is invalid")
DIAG(err_invalid_long_spec, ERROR,
Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Sat Aug 9 11:51:54 2008
@@ -63,6 +63,7 @@
TST_unspecified,
TST_void,
TST_char,
+ TST_wchar, // C++ wchar_t
TST_int,
TST_float,
TST_double,
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Aug 9 11:51:54 2008
@@ -161,7 +161,10 @@
InitBuiltinType(FloatTy, BuiltinType::Float);
InitBuiltinType(DoubleTy, BuiltinType::Double);
InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble);
-
+
+ // C++ 3.9.1p5
+ InitBuiltinType(WCharTy, BuiltinType::WChar);
+
// C99 6.2.5p11.
FloatComplexTy = getComplexType(FloatTy);
DoubleComplexTy = getComplexType(DoubleTy);
@@ -246,6 +249,10 @@
Width = Target.getCharWidth();
Align = Target.getCharAlign();
break;
+ case BuiltinType::WChar:
+ Width = Target.getWCharWidth();
+ Align = Target.getWCharAlign();
+ break;
case BuiltinType::UShort:
case BuiltinType::Short:
Width = Target.getShortWidth();
@@ -996,11 +1003,28 @@
/// width of characters in wide strings, The value is target dependent and
/// needs to agree with the definition in <stddef.h>.
QualType ASTContext::getWcharType() const {
+ if (LangOpts.CPlusPlus)
+ return WCharTy;
+
// On Darwin, wchar_t is defined as a "int".
// FIXME: should derive from "Target".
return IntTy;
}
+/// getSignedWCharType - Return the type of "signed wchar_t".
+/// Used when in C++, as a GCC extension.
+QualType ASTContext::getSignedWCharType() const {
+ // FIXME: derive from "Target" ?
+ return WCharTy;
+}
+
+/// getUnsignedWCharType - Return the type of "unsigned wchar_t".
+/// Used when in C++, as a GCC extension.
+QualType ASTContext::getUnsignedWCharType() const {
+ // FIXME: derive from "Target" ?
+ return UnsignedIntTy;
+}
+
/// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
QualType ASTContext::getPointerDiffType() const {
Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Sat Aug 9 11:51:54 2008
@@ -87,6 +87,7 @@
case DeclSpec::TST_unspecified: return "unspecified";
case DeclSpec::TST_void: return "void";
case DeclSpec::TST_char: return "char";
+ case DeclSpec::TST_wchar: return "wchar_t";
case DeclSpec::TST_int: return "int";
case DeclSpec::TST_float: return "float";
case DeclSpec::TST_double: return "double";
@@ -214,11 +215,12 @@
const LangOptions &Lang) {
// Check the type specifier components first.
- // signed/unsigned are only valid with int/char.
+ // signed/unsigned are only valid with int/char/wchar_t.
if (TypeSpecSign != TSS_unspecified) {
if (TypeSpecType == TST_unspecified)
TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
- else if (TypeSpecType != TST_int && TypeSpecType != TST_char) {
+ else if (TypeSpecType != TST_int &&
+ TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec,
getSpecifierName( (TST)TypeSpecType));
// signed double -> double.
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Aug 9 11:51:54 2008
@@ -376,6 +376,7 @@
/// struct-or-union-specifier
/// enum-specifier
/// typedef-name
+/// [C++] 'wchar_t'
/// [C++] 'bool'
/// [C99] '_Bool'
/// [C99] '_Complex'
@@ -517,6 +518,9 @@
case tok::kw_double:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
break;
+ case tok::kw_wchar_t: // [C++ 2.11p1]
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec);
+ break;
case tok::kw_bool: // [C++ 2.11p1]
case tok::kw__Bool:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
@@ -941,6 +945,7 @@
case tok::kw__Imaginary:
case tok::kw_void:
case tok::kw_char:
+ case tok::kw_wchar_t:
case tok::kw_int:
case tok::kw_float:
case tok::kw_double:
@@ -992,6 +997,7 @@
case tok::kw__Imaginary:
case tok::kw_void:
case tok::kw_char:
+ case tok::kw_wchar_t:
case tok::kw_int:
case tok::kw_float:
case tok::kw_double:
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=54585&r1=54584&r2=54585&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Aug 9 11:51:54 2008
@@ -42,6 +42,21 @@
Result = Context.UnsignedCharTy;
}
break;
+ case DeclSpec::TST_wchar:
+ if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
+ Result = Context.WCharTy;
+ else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) {
+ Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec,
+ DS.getSpecifierName(DS.getTypeSpecType()));
+ Result = Context.getSignedWCharType();
+ } else {
+ assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
+ "Unknown TSS value");
+ Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec,
+ DS.getSpecifierName(DS.getTypeSpecType()));
+ Result = Context.getUnsignedWCharType();
+ }
+ break;
case DeclSpec::TST_unspecified:
// "<proto1,proto2>" is an objc qualified ID with a missing id.
if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
Added: cfe/trunk/test/Sema/cxx-wchar_t.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cxx-wchar_t.cpp?rev=54585&view=auto
==============================================================================
--- cfe/trunk/test/Sema/cxx-wchar_t.cpp (added)
+++ cfe/trunk/test/Sema/cxx-wchar_t.cpp Sat Aug 9 11:51:54 2008
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -pedantic -verify %s
+wchar_t x;
+
+void f(wchar_t p) {
+ wchar_t x;
+ unsigned wchar_t y; // expected-warning {{'wchar_t' cannot be signed or unsigned}}
+ signed wchar_t z; // expected-warning {{'wchar_t' cannot be signed or unsigned}}
+}
More information about the cfe-commits
mailing list