[cfe-commits] r39170 - in /cfe/cfe/trunk: AST/SemaDecl.cpp AST/SemaType.cpp AST/Type.cpp Sema/SemaDecl.cpp Sema/SemaType.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:40:28 PDT 2007


Author: sabre
Date: Wed Jul 11 11:40:27 2007
New Revision: 39170

URL: http://llvm.org/viewvc/llvm-project?rev=39170&view=rev
Log:
implement conversion of simple declspec base types, and implement TypeRef::dump

Modified:
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/AST/SemaType.cpp
    cfe/cfe/trunk/AST/Type.cpp
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/Sema/SemaType.cpp

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39170&r1=39169&r2=39170&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:40:27 2007
@@ -32,7 +32,7 @@
   
   // FIXME: Temporary.
   if (!DeclaratorType.isNull())
-    DeclaratorType->dump();
+    DeclaratorType.dump();
     
   
   IdentifierInfo *II = D.getIdentifier();

Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39170&r1=39169&r2=39170&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:40:27 2007
@@ -72,7 +72,76 @@
   Context.LongDoubleComplexTy = new BuiltinType("long double _Complex");
 }
 
+/// ConvertDeclSpecToType - Convert the specified declspec to the appropriate
+/// type object.  This returns null on error.
+static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
+  // FIXME: Should move the logic from DeclSpec::Finish to here for validity
+  // checking.
+  
+  switch (DS.TypeSpecType) {
+  default: return TypeRef(); // FIXME: Handle unimp cases!
+  case DeclSpec::TST_void: return Ctx.VoidTy;
+  case DeclSpec::TST_char:
+    if (DS.TypeSpecSign == DeclSpec::TSS_unspecified)
+      return Ctx.CharTy;
+    else if (DS.TypeSpecSign == DeclSpec::TSS_signed)
+      return Ctx.SignedCharTy;
+    else {
+      assert(DS.TypeSpecSign == DeclSpec::TSS_unsigned && "Unknown TSS value");
+      return Ctx.UnsignedCharTy;
+    }
+  case DeclSpec::TST_int:
+    if (DS.TypeSpecSign != DeclSpec::TSS_unsigned) {
+      switch (DS.TypeSpecWidth) {
+      case DeclSpec::TSW_unspecified: return Ctx.IntTy;
+      case DeclSpec::TSW_short:       return Ctx.ShortTy;
+      case DeclSpec::TSW_long:        return Ctx.LongTy;
+      case DeclSpec::TSW_longlong:    return Ctx.LongLongTy;
+      }
+    } else {
+      switch (DS.TypeSpecWidth) {
+      case DeclSpec::TSW_unspecified: return Ctx.UnsignedIntTy;
+      case DeclSpec::TSW_short:       return Ctx.UnsignedShortTy;
+      case DeclSpec::TSW_long:        return Ctx.UnsignedLongTy;
+      case DeclSpec::TSW_longlong:    return Ctx.UnsignedLongLongTy;
+      }
+    }
+  case DeclSpec::TST_float:
+    if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+      return Ctx.FloatTy;
+    assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+           "FIXME: imaginary types not supported yet!");
+    return Ctx.FloatComplexTy;
+    
+  case DeclSpec::TST_double: {
+    bool isLong = DS.TypeSpecWidth == DeclSpec::TSW_long;
+    if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+      return isLong ? Ctx.LongDoubleTy : Ctx.DoubleTy;
+    assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+           "FIXME: imaginary types not supported yet!");
+    return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
+  }
+  case DeclSpec::TST_bool:         // _Bool
+    return Ctx.BoolTy;
+  case DeclSpec::TST_decimal32:    // _Decimal32
+  case DeclSpec::TST_decimal64:    // _Decimal64
+  case DeclSpec::TST_decimal128:   // _Decimal128
+    assert(0 && "FIXME: GNU decimal extensions not supported yet!"); 
+    //DeclSpec::TST_enum:
+    //DeclSpec::TST_union:
+    //DeclSpec::TST_struct:
+    //DeclSpec::TST_typedef:
+      
+  }
+}
 
+/// GetTypeForDeclarator - Convert the type for the specified declarator to Type
+/// instances.
 TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
+  TypeRef T = ConvertDeclSpecToType(D.getDeclSpec(), Context);
+  
+  // FIXME: Apply const/volatile/restrict qualifiers to T.
+  
+  return T;
   return TypeRef();
 }

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

==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:40:27 2007
@@ -18,3 +18,22 @@
 Type::~Type() {}
 
 
+#include <iostream>  // FIXME: REMOVE
+void TypeRef::dump() const {
+  if (isNull()) {
+    std::cerr << "NULL TYPE\n";
+    return;
+  }
+  
+  (*this)->dump();
+  
+  // Print qualifiers as appropriate.
+  if (isConstQualified())
+    std::cerr << " const";
+  if (isVolatileQualified())
+    std::cerr << " volatile";
+  if (isRestrictQualified())
+    std::cerr << " restrict";
+  
+  std::cerr << "\n";
+}

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:40:27 2007
@@ -32,7 +32,7 @@
   
   // FIXME: Temporary.
   if (!DeclaratorType.isNull())
-    DeclaratorType->dump();
+    DeclaratorType.dump();
     
   
   IdentifierInfo *II = D.getIdentifier();

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:40:27 2007
@@ -72,7 +72,76 @@
   Context.LongDoubleComplexTy = new BuiltinType("long double _Complex");
 }
 
+/// ConvertDeclSpecToType - Convert the specified declspec to the appropriate
+/// type object.  This returns null on error.
+static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
+  // FIXME: Should move the logic from DeclSpec::Finish to here for validity
+  // checking.
+  
+  switch (DS.TypeSpecType) {
+  default: return TypeRef(); // FIXME: Handle unimp cases!
+  case DeclSpec::TST_void: return Ctx.VoidTy;
+  case DeclSpec::TST_char:
+    if (DS.TypeSpecSign == DeclSpec::TSS_unspecified)
+      return Ctx.CharTy;
+    else if (DS.TypeSpecSign == DeclSpec::TSS_signed)
+      return Ctx.SignedCharTy;
+    else {
+      assert(DS.TypeSpecSign == DeclSpec::TSS_unsigned && "Unknown TSS value");
+      return Ctx.UnsignedCharTy;
+    }
+  case DeclSpec::TST_int:
+    if (DS.TypeSpecSign != DeclSpec::TSS_unsigned) {
+      switch (DS.TypeSpecWidth) {
+      case DeclSpec::TSW_unspecified: return Ctx.IntTy;
+      case DeclSpec::TSW_short:       return Ctx.ShortTy;
+      case DeclSpec::TSW_long:        return Ctx.LongTy;
+      case DeclSpec::TSW_longlong:    return Ctx.LongLongTy;
+      }
+    } else {
+      switch (DS.TypeSpecWidth) {
+      case DeclSpec::TSW_unspecified: return Ctx.UnsignedIntTy;
+      case DeclSpec::TSW_short:       return Ctx.UnsignedShortTy;
+      case DeclSpec::TSW_long:        return Ctx.UnsignedLongTy;
+      case DeclSpec::TSW_longlong:    return Ctx.UnsignedLongLongTy;
+      }
+    }
+  case DeclSpec::TST_float:
+    if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+      return Ctx.FloatTy;
+    assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+           "FIXME: imaginary types not supported yet!");
+    return Ctx.FloatComplexTy;
+    
+  case DeclSpec::TST_double: {
+    bool isLong = DS.TypeSpecWidth == DeclSpec::TSW_long;
+    if (DS.TypeSpecComplex == DeclSpec::TSC_unspecified)
+      return isLong ? Ctx.LongDoubleTy : Ctx.DoubleTy;
+    assert(DS.TypeSpecComplex == DeclSpec::TSC_complex &&
+           "FIXME: imaginary types not supported yet!");
+    return isLong ? Ctx.LongDoubleComplexTy : Ctx.DoubleComplexTy;
+  }
+  case DeclSpec::TST_bool:         // _Bool
+    return Ctx.BoolTy;
+  case DeclSpec::TST_decimal32:    // _Decimal32
+  case DeclSpec::TST_decimal64:    // _Decimal64
+  case DeclSpec::TST_decimal128:   // _Decimal128
+    assert(0 && "FIXME: GNU decimal extensions not supported yet!"); 
+    //DeclSpec::TST_enum:
+    //DeclSpec::TST_union:
+    //DeclSpec::TST_struct:
+    //DeclSpec::TST_typedef:
+      
+  }
+}
 
+/// GetTypeForDeclarator - Convert the type for the specified declarator to Type
+/// instances.
 TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
+  TypeRef T = ConvertDeclSpecToType(D.getDeclSpec(), Context);
+  
+  // FIXME: Apply const/volatile/restrict qualifiers to T.
+  
+  return T;
   return TypeRef();
 }





More information about the cfe-commits mailing list