Switch a few ugly switch-on-string-literal constructs to use the new
llvm::StringSwitch.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85461 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2009-10-29 00:41:01 +00:00
Родитель d8ee95fd4f
Коммит 55d3f7ae51
3 изменённых файлов: 75 добавлений и 124 удалений

Просмотреть файл

@ -25,6 +25,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/ImmutableList.h"
#include "llvm/ADT/StringSwitch.h"
#ifndef NDEBUG
#include "llvm/Support/GraphWriter.h"
@ -1443,68 +1444,30 @@ static void MarkNoReturnFunction(const FunctionDecl *FD, CallExpr *CE,
// HACK: Some functions are not marked noreturn, and don't return.
// Here are a few hardwired ones. If this takes too long, we can
// potentially cache these results.
const char* s = FD->getIdentifier()->getNameStart();
switch (FD->getIdentifier()->getLength()) {
default:
break;
case 4:
if (!memcmp(s, "exit", 4)) Builder->BuildSinks = true;
break;
case 5:
if (!memcmp(s, "panic", 5))
Builder->BuildSinks = true;
else if (!memcmp(s, "error", 5))
Builder->BuildSinks = true;
break;
case 6:
if (!memcmp(s, "Assert", 6)) {
Builder->BuildSinks = true;
break;
}
// FIXME: This is just a wrapper around throwing an exception.
// Eventually inter-procedural analysis should handle this easily.
if (!memcmp(s, "ziperr", 6)) Builder->BuildSinks = true;
break;
case 7:
if (!memcmp(s, "assfail", 7)) Builder->BuildSinks = true;
break;
case 8:
if (!memcmp(s ,"db_error", 8) ||
!memcmp(s, "__assert", 8))
Builder->BuildSinks = true;
break;
case 12:
if (!memcmp(s, "__assert_rtn", 12)) Builder->BuildSinks = true;
break;
case 13:
if (!memcmp(s, "__assert_fail", 13)) Builder->BuildSinks = true;
break;
case 14:
if (!memcmp(s, "dtrace_assfail", 14) ||
!memcmp(s, "yy_fatal_error", 14))
Builder->BuildSinks = true;
break;
case 26:
if (!memcmp(s, "_XCAssertionFailureHandler", 26) ||
!memcmp(s, "_DTAssertionFailureHandler", 26) ||
!memcmp(s, "_TSAssertionFailureHandler", 26))
Builder->BuildSinks = true;
break;
}
using llvm::StringRef;
bool BuildSinks
= llvm::StringSwitch<bool>(StringRef(FD->getIdentifier()->getName()))
.Case("exit", true)
.Case("panic", true)
.Case("error", true)
.Case("Assert", true)
// FIXME: This is just a wrapper around throwing an exception.
// Eventually inter-procedural analysis should handle this easily.
.Case("ziperr", true)
.Case("assfail", true)
.Case("db_error", true)
.Case("__assert", true)
.Case("__assert_rtn", true)
.Case("__assert_fail", true)
.Case("dtrace_assfail", true)
.Case("yy_fatal_error", true)
.Case("_XCAssertionFailureHandler", true)
.Case("_DTAssertionFailureHandler", true)
.Case("_TSAssertionFailureHandler", true)
.Default(false);
if (BuildSinks)
Builder->BuildSinks = true;
}
}

Просмотреть файл

@ -22,6 +22,7 @@
#include "clang/Driver/Util.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@ -1667,23 +1668,18 @@ void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
static bool isSourceSuffix(const char *Str) {
// match: 'C', 'CPP', 'c', 'cc', 'cp', 'c++', 'cpp', 'cxx', 'm',
// 'mm'.
switch (strlen(Str)) {
default:
return false;
case 1:
return (memcmp(Str, "C", 1) == 0 ||
memcmp(Str, "c", 1) == 0 ||
memcmp(Str, "m", 1) == 0);
case 2:
return (memcmp(Str, "cc", 2) == 0 ||
memcmp(Str, "cp", 2) == 0 ||
memcmp(Str, "mm", 2) == 0);
case 3:
return (memcmp(Str, "CPP", 3) == 0 ||
memcmp(Str, "c++", 3) == 0 ||
memcmp(Str, "cpp", 3) == 0 ||
memcmp(Str, "cxx", 3) == 0);
}
return llvm::StringSwitch<bool>(Str)
.Case("C", true)
.Case("c", true)
.Case("m", true)
.Case("cc", true)
.Case("cp", true)
.Case("mm", true)
.Case("CPP", true)
.Case("c++", true)
.Case("cpp", true)
.Case("cxx", true)
.Default(false);
}
// FIXME: Can we tablegen this?

Просмотреть файл

@ -9,6 +9,7 @@
#include "clang/Driver/Types.h"
#include "llvm/ADT/StringSwitch.h"
#include <string.h>
#include <cassert>
@ -102,51 +103,42 @@ bool types::isCXX(ID Id) {
}
types::ID types::lookupTypeForExtension(const char *Ext) {
unsigned N = strlen(Ext);
switch (N) {
case 1:
if (memcmp(Ext, "c", 1) == 0) return TY_C;
if (memcmp(Ext, "i", 1) == 0) return TY_PP_C;
if (memcmp(Ext, "m", 1) == 0) return TY_ObjC;
if (memcmp(Ext, "M", 1) == 0) return TY_ObjCXX;
if (memcmp(Ext, "h", 1) == 0) return TY_CHeader;
if (memcmp(Ext, "C", 1) == 0) return TY_CXX;
if (memcmp(Ext, "H", 1) == 0) return TY_CXXHeader;
if (memcmp(Ext, "f", 1) == 0) return TY_PP_Fortran;
if (memcmp(Ext, "F", 1) == 0) return TY_Fortran;
if (memcmp(Ext, "s", 1) == 0) return TY_PP_Asm;
if (memcmp(Ext, "S", 1) == 0) return TY_Asm;
case 2:
if (memcmp(Ext, "ii", 2) == 0) return TY_PP_CXX;
if (memcmp(Ext, "mi", 2) == 0) return TY_PP_ObjC;
if (memcmp(Ext, "mm", 2) == 0) return TY_ObjCXX;
if (memcmp(Ext, "cc", 2) == 0) return TY_CXX;
if (memcmp(Ext, "cc", 2) == 0) return TY_CXX;
if (memcmp(Ext, "cp", 2) == 0) return TY_CXX;
if (memcmp(Ext, "hh", 2) == 0) return TY_CXXHeader;
break;
case 3:
if (memcmp(Ext, "ads", 3) == 0) return TY_Ada;
if (memcmp(Ext, "adb", 3) == 0) return TY_Ada;
if (memcmp(Ext, "ast", 3) == 0) return TY_AST;
if (memcmp(Ext, "cxx", 3) == 0) return TY_CXX;
if (memcmp(Ext, "cpp", 3) == 0) return TY_CXX;
if (memcmp(Ext, "CPP", 3) == 0) return TY_CXX;
if (memcmp(Ext, "cXX", 3) == 0) return TY_CXX;
if (memcmp(Ext, "for", 3) == 0) return TY_PP_Fortran;
if (memcmp(Ext, "FOR", 3) == 0) return TY_PP_Fortran;
if (memcmp(Ext, "fpp", 3) == 0) return TY_Fortran;
if (memcmp(Ext, "FPP", 3) == 0) return TY_Fortran;
if (memcmp(Ext, "f90", 3) == 0) return TY_PP_Fortran;
if (memcmp(Ext, "f95", 3) == 0) return TY_PP_Fortran;
if (memcmp(Ext, "F90", 3) == 0) return TY_Fortran;
if (memcmp(Ext, "F95", 3) == 0) return TY_Fortran;
if (memcmp(Ext, "mii", 3) == 0) return TY_PP_ObjCXX;
break;
}
return TY_INVALID;
return llvm::StringSwitch<types::ID>(Ext)
.Case("c", TY_C)
.Case("i", TY_PP_C)
.Case("m", TY_ObjC)
.Case("M", TY_ObjCXX)
.Case("h", TY_CHeader)
.Case("C", TY_CXX)
.Case("H", TY_CXXHeader)
.Case("f", TY_PP_Fortran)
.Case("F", TY_Fortran)
.Case("s", TY_PP_Asm)
.Case("S", TY_Asm)
.Case("ii", TY_PP_CXX)
.Case("mi", TY_PP_ObjC)
.Case("mm", TY_ObjCXX)
.Case("cc", TY_CXX)
.Case("CC", TY_CXX)
.Case("cp", TY_CXX)
.Case("hh", TY_CXXHeader)
.Case("ads", TY_Ada)
.Case("adb", TY_Ada)
.Case("ast", TY_AST)
.Case("cxx", TY_CXX)
.Case("cpp", TY_CXX)
.Case("CPP", TY_CXX)
.Case("CXX", TY_CXX)
.Case("for", TY_PP_Fortran)
.Case("FOR", TY_PP_Fortran)
.Case("fpp", TY_Fortran)
.Case("FPP", TY_Fortran)
.Case("f90", TY_PP_Fortran)
.Case("f95", TY_PP_Fortran)
.Case("F90", TY_Fortran)
.Case("F95", TY_Fortran)
.Case("mii", TY_PP_ObjCXX)
.Default(TY_INVALID);
}
types::ID types::lookupTypeForTypeSpecifier(const char *Name) {