From: Chris Lattner Date: Tue, 20 Oct 2009 05:12:36 +0000 (+0000) Subject: code cleanup, convert if tree to switch etc. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9cf9f868a5a39099d6a9cf57d5d5693c30486d8d;p=clang code cleanup, convert if tree to switch etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84599 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 5d5a57632f..6e9362f28c 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -154,15 +154,19 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, 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(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 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, 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 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, "Invalid modifier for NamedDecl* argument"); Qualified = false; } - reinterpret_cast(Val)->getNameForDiagnostic(S, - Context.PrintingPolicy, - Qualified); - } else if (Kind == Diagnostic::ak_nestednamespec) { + reinterpret_cast(Val)-> + getNameForDiagnostic(S, Context.PrintingPolicy, Qualified); + break; + } + case Diagnostic::ak_nestednamespec: { llvm::raw_string_ostream OS(S); - reinterpret_cast (Val)->print(OS, - Context.PrintingPolicy); + reinterpret_cast(Val)->print(OS, + Context.PrintingPolicy); NeedQuotes = false; - } else { - assert(Kind == Diagnostic::ak_declcontext); + break; + } + case Diagnostic::ak_declcontext: { DeclContext *DC = reinterpret_cast (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 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, S = "the global scope"; } else if (TypeDecl *Type = dyn_cast(DC)) { S = ConvertTypeToDiagnosticString(Context, Context.getTypeDeclType(Type)); - NeedQuotes = false; } else { // FIXME: Get these strings from some localized place NamedDecl *ND = cast(DC); @@ -219,8 +224,10 @@ static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, S += "'"; ND->getNameForDiagnostic(S, Context.PrintingPolicy, true); S += "'"; - NeedQuotes = false; } + NeedQuotes = false; + break; + } } if (NeedQuotes)