[cfe-commits] r85461 - in /cfe/trunk/lib: Analysis/GRExprEngine.cpp Driver/Tools.cpp Driver/Types.cpp
Douglas Gregor
dgregor at apple.com
Wed Oct 28 17:41:01 PDT 2009
Author: dgregor
Date: Wed Oct 28 19:41:01 2009
New Revision: 85461
URL: http://llvm.org/viewvc/llvm-project?rev=85461&view=rev
Log:
[llvm up]
Switch a few ugly switch-on-string-literal constructs to use the new
llvm::StringSwitch.
Modified:
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Driver/Types.cpp
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=85461&r1=85460&r2=85461&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Oct 28 19:41:01 2009
@@ -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 @@
// 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;
}
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=85461&r1=85460&r2=85461&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Oct 28 19:41:01 2009
@@ -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 @@
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?
Modified: cfe/trunk/lib/Driver/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Types.cpp?rev=85461&r1=85460&r2=85461&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Types.cpp (original)
+++ cfe/trunk/lib/Driver/Types.cpp Wed Oct 28 19:41:01 2009
@@ -9,6 +9,7 @@
#include "clang/Driver/Types.h"
+#include "llvm/ADT/StringSwitch.h"
#include <string.h>
#include <cassert>
@@ -102,51 +103,42 @@
}
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) {
More information about the cfe-commits
mailing list