[llvm-commits] [llvm] r121250 - /llvm/trunk/utils/TableGen/TGLexer.cpp
Chris Lattner
clattner at apple.com
Wed Dec 8 10:36:04 PST 2010
On Dec 8, 2010, at 5:03 AM, Bill Wendling wrote:
> Author: void
> Date: Wed Dec 8 07:03:15 2010
> New Revision: 121250
>
> URL: http://llvm.org/viewvc/llvm-project?rev=121250&view=rev
> Log:
> Cleanup table a bit.
StringSwitch would make it even nicer :)
-Chris
>
> Modified:
> llvm/trunk/utils/TableGen/TGLexer.cpp
>
> Modified: llvm/trunk/utils/TableGen/TGLexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGLexer.cpp?rev=121250&r1=121249&r2=121250&view=diff
> ==============================================================================
> --- llvm/trunk/utils/TableGen/TGLexer.cpp (original)
> +++ llvm/trunk/utils/TableGen/TGLexer.cpp Wed Dec 8 07:03:15 2010
> @@ -412,29 +412,43 @@
> /// LexExclaim - Lex '!' and '![a-zA-Z]+'.
> tgtok::TokKind TGLexer::LexExclaim() {
> if (!isalpha(*CurPtr))
> - return ReturnError(CurPtr-1, "Invalid \"!operator\"");
> + return ReturnError(CurPtr - 1, "Invalid \"!operator\"");
>
> const char *Start = CurPtr++;
> while (isalpha(*CurPtr))
> ++CurPtr;
>
> // Check to see which operator this is.
> - unsigned Len = CurPtr-Start;
> -
> - if (Len == 3 && !memcmp(Start, "con", 3)) return tgtok::XConcat;
> - if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA;
> - if (Len == 3 && !memcmp(Start, "srl", 3)) return tgtok::XSRL;
> - if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL;
> - if (Len == 2 && !memcmp(Start, "eq", 2)) return tgtok::XEq;
> - if (Len == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
> - if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
> - if (Len == 7 && !memcmp(Start, "foreach", 7)) return tgtok::XForEach;
> - if (Len == 4 && !memcmp(Start, "cast", 4)) return tgtok::XCast;
> - if (Len == 3 && !memcmp(Start, "car", 3)) return tgtok::XCar;
> - if (Len == 3 && !memcmp(Start, "cdr", 3)) return tgtok::XCdr;
> - if (Len == 4 && !memcmp(Start, "null", 4)) return tgtok::XNull;
> - if (Len == 2 && !memcmp(Start, "if", 2)) return tgtok::XIf;
> + switch (CurPtr - Start) {
> + default:
> + break;
> + case 2:
> + if (!memcmp(Start, "eq", 2)) return tgtok::XEq;
> + if (!memcmp(Start, "if", 2)) return tgtok::XIf;
> + break;
> + case 3:
> + if (!memcmp(Start, "car", 3)) return tgtok::XCar;
> + if (!memcmp(Start, "cdr", 3)) return tgtok::XCdr;
> + if (!memcmp(Start, "con", 3)) return tgtok::XConcat;
> + if (!memcmp(Start, "shl", 3)) return tgtok::XSHL;
> + if (!memcmp(Start, "sra", 3)) return tgtok::XSRA;
> + if (!memcmp(Start, "srl", 3)) return tgtok::XSRL;
> + break;
> + case 4:
> + if (!memcmp(Start, "cast", 4)) return tgtok::XCast;
> + if (!memcmp(Start, "null", 4)) return tgtok::XNull;
> + break;
> + case 5:
> + if (!memcmp(Start, "subst", 5)) return tgtok::XSubst;
> + break;
> + case 7:
> + if (!memcmp(Start, "foreach", 7)) return tgtok::XForEach;
> + break;
> + case 9:
> + if (!memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
> + break;
> + }
>
> - return ReturnError(Start-1, "Unknown operator");
> + return ReturnError(Start - 1, "Unknown operator");
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list