[cfe-commits] r39237 - in /cfe/cfe/trunk: AST/ASTContext.cpp AST/Type.cpp include/clang/AST/ASTContext.h include/clang/AST/Type.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:41:43 PDT 2007


Author: sabre
Date: Wed Jul 11 11:41:43 2007
New Revision: 39237

URL: http://llvm.org/viewvc/llvm-project?rev=39237&view=rev
Log:
implement a fixme: make BuiltinType have an enum, specifying which type it is,
instead of having a string.

Modified:
    cfe/cfe/trunk/AST/ASTContext.cpp
    cfe/cfe/trunk/AST/Type.cpp
    cfe/cfe/trunk/include/clang/AST/ASTContext.h
    cfe/cfe/trunk/include/clang/AST/Type.h

Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39237&r1=39236&r2=39237&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:41:43 2007
@@ -37,8 +37,8 @@
   }
 }
 
-void ASTContext::InitBuiltinType(TypeRef &R, const char *Name) {
-  Types.push_back((R = new BuiltinType(Name)).getTypePtr());
+void ASTContext::InitBuiltinType(TypeRef &R, BuiltinType::Kind K) {
+  Types.push_back((R = new BuiltinType(K)).getTypePtr());
 }
 
 
@@ -46,35 +46,35 @@
   assert(VoidTy.isNull() && "Context reinitialized?");
   
   // C99 6.2.5p19.
-  InitBuiltinType(VoidTy, "void");
+  InitBuiltinType(VoidTy,              BuiltinType::Void);
   
   // C99 6.2.5p2.
-  InitBuiltinType(BoolTy, "_Bool");
+  InitBuiltinType(BoolTy,              BuiltinType::Bool);
   // C99 6.2.5p3.
-  InitBuiltinType(CharTy, "char");
+  InitBuiltinType(CharTy,              BuiltinType::Char);
   // C99 6.2.5p4.
-  InitBuiltinType(SignedCharTy, "signed char");
-  InitBuiltinType(ShortTy, "short");
-  InitBuiltinType(IntTy, "int");
-  InitBuiltinType(LongTy, "long");
-  InitBuiltinType(LongLongTy, "long long");
+  InitBuiltinType(SignedCharTy,        BuiltinType::SChar);
+  InitBuiltinType(ShortTy,             BuiltinType::Short);
+  InitBuiltinType(IntTy,               BuiltinType::Int);
+  InitBuiltinType(LongTy,              BuiltinType::Long);
+  InitBuiltinType(LongLongTy,          BuiltinType::LongLong);
   
   // C99 6.2.5p6.
-  InitBuiltinType(UnsignedCharTy, "unsigned char");
-  InitBuiltinType(UnsignedShortTy, "unsigned short");
-  InitBuiltinType(UnsignedIntTy, "unsigned int");
-  InitBuiltinType(UnsignedLongTy, "unsigned long");
-  InitBuiltinType(UnsignedLongLongTy, "unsigned long long");
+  InitBuiltinType(UnsignedCharTy,      BuiltinType::UChar);
+  InitBuiltinType(UnsignedShortTy,     BuiltinType::UShort);
+  InitBuiltinType(UnsignedIntTy,       BuiltinType::UInt);
+  InitBuiltinType(UnsignedLongTy,      BuiltinType::ULong);
+  InitBuiltinType(UnsignedLongLongTy,  BuiltinType::ULongLong);
   
   // C99 6.2.5p10.
-  InitBuiltinType(FloatTy, "float");
-  InitBuiltinType(DoubleTy, "double");
-  InitBuiltinType(LongDoubleTy, "long double");
+  InitBuiltinType(FloatTy,             BuiltinType::Float);
+  InitBuiltinType(DoubleTy,            BuiltinType::Double);
+  InitBuiltinType(LongDoubleTy,        BuiltinType::LongDouble);
   
   // C99 6.2.5p11.
-  InitBuiltinType(FloatComplexTy, "float _Complex");
-  InitBuiltinType(DoubleComplexTy, "double _Complex");
-  InitBuiltinType(LongDoubleComplexTy, "long double _Complex");
+  InitBuiltinType(FloatComplexTy,      BuiltinType::FloatComplex);
+  InitBuiltinType(DoubleComplexTy,     BuiltinType::DoubleComplex);
+  InitBuiltinType(LongDoubleComplexTy, BuiltinType::LongDoubleComplex);
 }
 
 /// getPointerType - Return the uniqued reference to the type for a pointer to

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

==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:41:43 2007
@@ -22,13 +22,36 @@
 
 /// isVoidType - Helper method to determine if this is the 'void' type.
 bool Type::isVoidType() const {
-  if (const BuiltinType *BT = dyn_cast<BuiltinType>(getCanonicalType())) {
-    // FIXME: USE ENUMS!
-    return !strcmp(BT->getName(), "void");
-  }
+  if (const BuiltinType *BT = dyn_cast<BuiltinType>(getCanonicalType()))
+    return BT->getKind() == BuiltinType::Void;
   return false;
 }
 
+const char *BuiltinType::getName() const {
+  switch (getKind()) {
+  default: assert(0 && "Unknown builtin type!");
+  case Void:              return "void";
+  case Bool:              return "_Bool";
+  case Char:              return "char";
+  case SChar:             return "signed char";
+  case Short:             return "short";
+  case Int:               return "int";
+  case Long:              return "long";
+  case LongLong:          return "long long";
+  case UChar:             return "unsigned char";
+  case UShort:            return "unsigned short";
+  case UInt:              return "unsigned int";
+  case ULong:             return "unsigned long";
+  case ULongLong:         return "unsigned long long";
+  case Float:             return "float";
+  case Double:            return "double";
+  case LongDouble:        return "long double";
+  case FloatComplex:      return "float _Complex";
+  case DoubleComplex:     return "double _Complex";
+  case LongDoubleComplex: return "long double _Complex";
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Type Printing
 //===----------------------------------------------------------------------===//
@@ -68,11 +91,11 @@
 
 void BuiltinType::getAsString(std::string &S) const {
   if (S.empty()) {
-    S = Name;
+    S = getName();
   } else {
     // Prefix the basic type, e.g. 'int X'.
     S = ' ' + S;
-    S = Name + S;
+    S = getName() + S;
   }
 }
 

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:41:43 2007
@@ -69,7 +69,7 @@
   
 private:
   void InitBuiltinTypes();
-  void InitBuiltinType(TypeRef &R, const char *Name);
+  void InitBuiltinType(TypeRef &R, BuiltinType::Kind K);
 };
   
 }  // end namespace clang

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:41:43 2007
@@ -179,11 +179,21 @@
 /// BuiltinType - This class is used for builtin types like 'int'.  Builtin
 /// types are always canonical and have a literal name field.
 class BuiltinType : public Type {
-  const char *Name;
 public:
-  BuiltinType(const char *name) : Type(Builtin, 0), Name(name) {}
+  enum Kind {
+    Void, Bool, Char,
+    SChar,  Short,  Int,  Long,  LongLong,
+    UChar, UShort, UInt, ULong, ULongLong,
+    Float, Double, LongDouble,
+    FloatComplex, DoubleComplex, LongDoubleComplex
+  };
+private:
+  Kind TypeKind;
+public:
+  BuiltinType(Kind K) : Type(Builtin, 0), TypeKind(K) {}
   
-  const char *getName() const { return Name; }
+  Kind getKind() const { return TypeKind; }
+  const char *getName() const;
   
   virtual void getAsString(std::string &InnerString) const;
   





More information about the cfe-commits mailing list