[cfe-commits] r84599 - /cfe/trunk/lib/Sema/Sema.cpp

Chris Lattner sabre at nondot.org
Mon Oct 19 22:12:36 PDT 2009


Author: lattner
Date: Tue Oct 20 00:12:36 2009
New Revision: 84599

URL: http://llvm.org/viewvc/llvm-project?rev=84599&view=rev
Log:
code cleanup, convert if tree to switch etc.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Oct 20 00:12:36 2009
@@ -154,15 +154,19 @@
 
   std::string S;
   bool NeedQuotes = true;
-  if (Kind == Diagnostic::ak_qualtype) {
+  
+  switch (Kind) {
+  default: assert(0 && "unknown ArgumentKind");
+  case Diagnostic::ak_qualtype: {
     assert(ModLen == 0 && ArgLen == 0 &&
            "Invalid modifier for QualType argument");
 
     QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val)));
     S = ConvertTypeToDiagnosticString(Context, Ty);
     NeedQuotes = false;
-  } else if (Kind == Diagnostic::ak_declarationname) {
-
+    break;
+  }
+  case Diagnostic::ak_declarationname: {
     DeclarationName N = DeclarationName::getFromOpaqueInteger(Val);
     S = N.getAsString();
 
@@ -173,7 +177,9 @@
     else
       assert(ModLen == 0 && ArgLen == 0 &&
              "Invalid modifier for DeclarationName argument");
-  } else if (Kind == Diagnostic::ak_nameddecl) {
+    break;
+  }
+  case Diagnostic::ak_nameddecl: {
     bool Qualified;
     if (ModLen == 1 && Modifier[0] == 'q' && ArgLen == 0)
       Qualified = true;
@@ -182,22 +188,22 @@
            "Invalid modifier for NamedDecl* argument");
       Qualified = false;
     }
-    reinterpret_cast<NamedDecl*>(Val)->getNameForDiagnostic(S,
-                                                         Context.PrintingPolicy,
-                                                            Qualified);
-  } else if (Kind == Diagnostic::ak_nestednamespec) {
+    reinterpret_cast<NamedDecl*>(Val)->
+      getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
+    break;
+  }
+  case Diagnostic::ak_nestednamespec: {
     llvm::raw_string_ostream OS(S);
-    reinterpret_cast<NestedNameSpecifier*> (Val)->print(OS,
-                                                        Context.PrintingPolicy);
+    reinterpret_cast<NestedNameSpecifier*>(Val)->print(OS,
+                                                       Context.PrintingPolicy);
     NeedQuotes = false;
-  } else {
-    assert(Kind == Diagnostic::ak_declcontext);
+    break;
+  }
+  case Diagnostic::ak_declcontext: {
     DeclContext *DC = reinterpret_cast<DeclContext *> (Val);
-    NeedQuotes = false;
-    if (!DC) {
-      assert(false && "Should never have a null declaration context");
-      S = "unknown context";
-    } else if (DC->isTranslationUnit()) {
+    assert(DC && "Should never have a null declaration context");
+    
+    if (DC->isTranslationUnit()) {
       // FIXME: Get these strings from some localized place
       if (Context.getLangOptions().CPlusPlus)
         S = "the global namespace";
@@ -205,7 +211,6 @@
         S = "the global scope";
     } else if (TypeDecl *Type = dyn_cast<TypeDecl>(DC)) {
       S = ConvertTypeToDiagnosticString(Context, Context.getTypeDeclType(Type));
-      NeedQuotes = false;
     } else {
       // FIXME: Get these strings from some localized place
       NamedDecl *ND = cast<NamedDecl>(DC);
@@ -219,8 +224,10 @@
       S += "'";
       ND->getNameForDiagnostic(S, Context.PrintingPolicy, true);
       S += "'";
-      NeedQuotes = false;
     }
+    NeedQuotes = false;
+    break;
+  }
   }
 
   if (NeedQuotes)





More information about the cfe-commits mailing list