[cfe-commits] r49613 - in /cfe/trunk: include/clang/AST/Type.h include/clang/Parse/DeclSpec.h lib/AST/Type.cpp lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp

Chris Lattner sabre at nondot.org
Sun Apr 13 11:59:08 PDT 2008


Author: lattner
Date: Sun Apr 13 13:59:07 2008
New Revision: 49613

URL: http://llvm.org/viewvc/llvm-project?rev=49613&view=rev
Log:
This patch is just the easy part of the class names patch, which
allows the parsing of "class" in addition to "struct" and "union" to
declare a record.  So this patch allows:

 class C { };
 class C c1;

But it does not contain the lookup bits, so this won't work yet:

 C c2;

Patch by Doug Gregor!


Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Parse/DeclSpec.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Parse/DeclSpec.cpp
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Apr 13 13:59:07 2008
@@ -315,6 +315,7 @@
   bool isFunctionPointerType() const;
   bool isArrayType() const;
   bool isRecordType() const;
+  bool isClassType() const;   
   bool isStructureType() const;   
   bool isUnionType() const;
   bool isComplexIntegerType() const;            // GCC _Complex integer type.

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Sun Apr 13 13:59:07 2008
@@ -73,6 +73,7 @@
     TST_enum,
     TST_union,
     TST_struct,
+    TST_class,        // C++ class type
     TST_typedef,
     TST_typeofType,
     TST_typeofExpr
@@ -106,7 +107,7 @@
   /*TSW*/unsigned TypeSpecWidth : 2;
   /*TSC*/unsigned TypeSpecComplex : 2;
   /*TSS*/unsigned TypeSpecSign : 2;
-  /*TST*/unsigned TypeSpecType : 4;
+  /*TST*/unsigned TypeSpecType : 5;
   
   // type-qualifiers
   unsigned TypeQualifiers : 3;  // Bitwise OR of TQ.

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Apr 13 13:59:07 2008
@@ -60,6 +60,12 @@
   }
 }
 
+bool Type::isClassType() const {
+  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType))
+    if (RT->getDecl()->getKind() == Decl::Class)
+      return true;
+  return false;
+}
 bool Type::isStructureType() const {
   if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType))
     if (RT->getDecl()->getKind() == Decl::Struct)

Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Sun Apr 13 13:59:07 2008
@@ -95,6 +95,7 @@
   case DeclSpec::TST_decimal64:   return "_Decimal64";
   case DeclSpec::TST_decimal128:  return "_Decimal128";
   case DeclSpec::TST_enum:        return "enum";
+  case DeclSpec::TST_class:       return "class";
   case DeclSpec::TST_union:       return "union";
   case DeclSpec::TST_struct:      return "struct";
   case DeclSpec::TST_typedef:     return "typedef";

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Apr 13 13:59:07 2008
@@ -515,7 +515,8 @@
     case tok::kw__Decimal128:
       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec);
       break;
-      
+
+    case tok::kw_class:
     case tok::kw_struct:
     case tok::kw_union:
       ParseStructUnionSpecifier(DS);
@@ -620,9 +621,12 @@
 ///         'union'
 ///
 void Parser::ParseStructUnionSpecifier(DeclSpec &DS) {
-  assert((Tok.is(tok::kw_struct) || Tok.is(tok::kw_union)) &&
-         "Not a struct/union specifier");
+  assert((Tok.is(tok::kw_class) || 
+          Tok.is(tok::kw_struct) || 
+          Tok.is(tok::kw_union)) &&
+         "Not a class/struct/union specifier");
   DeclSpec::TST TagType =
+    Tok.is(tok::kw_class) ? DeclSpec::TST_class :
     Tok.is(tok::kw_union) ? DeclSpec::TST_union : DeclSpec::TST_struct;
   SourceLocation StartLoc = ConsumeToken();
 
@@ -923,7 +927,8 @@
   case tok::kw__Decimal64:
   case tok::kw__Decimal128:
     
-    // struct-or-union-specifier
+    // struct-or-union-specifier (C99) or class-specifier (C++)
+  case tok::kw_class:
   case tok::kw_struct:
   case tok::kw_union:
     // enum-specifier
@@ -973,7 +978,8 @@
   case tok::kw__Decimal64:
   case tok::kw__Decimal128:
   
-    // struct-or-union-specifier
+    // struct-or-union-specifier (C99) or class-specifier (C++)
+  case tok::kw_class:
   case tok::kw_struct:
   case tok::kw_union:
     // enum-specifier

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 13 13:59:07 2008
@@ -1299,7 +1299,7 @@
   default: assert(0 && "Unknown tag type!");
   case DeclSpec::TST_struct: Kind = Decl::Struct; break;
   case DeclSpec::TST_union:  Kind = Decl::Union; break;
-//case DeclSpec::TST_class:  Kind = Decl::Class; break;
+  case DeclSpec::TST_class:  Kind = Decl::Class; break;
   case DeclSpec::TST_enum:   Kind = Decl::Enum; break;
   }
   

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=49613&r1=49612&r2=49613&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun Apr 13 13:59:07 2008
@@ -95,11 +95,12 @@
   case DeclSpec::TST_decimal64:    // _Decimal64
   case DeclSpec::TST_decimal128:   // _Decimal128
     assert(0 && "FIXME: GNU decimal extensions not supported yet!"); 
+  case DeclSpec::TST_class:
   case DeclSpec::TST_enum:
   case DeclSpec::TST_union:
   case DeclSpec::TST_struct: {
     Decl *D = static_cast<Decl *>(DS.getTypeRep());
-    assert(D && "Didn't get a decl for a enum/union/struct?");
+    assert(D && "Didn't get a decl for a class/enum/union/struct?");
     assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
            DS.getTypeSpecSign() == 0 &&
            "Can't handle qualifiers on typedef names yet!");





More information about the cfe-commits mailing list