[PATCH] Lex and ignore Microsoft's #pragma warning(...)
Reid Kleckner
rnk at google.com
Fri Sep 13 11:26:01 PDT 2013
================
Comment at: include/clang/Basic/DiagnosticLexKinds.td:417
@@ +416,3 @@
+ ExtWarn<"#pragma warning expected 'push', 'pop', 'default', 'disable',"
+ " 'error', 'once', 'supress', 1, 2, 3, or 4">,
+ InGroup<UnknownPragmas>;
----------------
Richard Smith wrote:
> Typo 'supress'... I hope?
Yup.
================
Comment at: lib/Lex/Pragma.cpp:1017-1019
@@ +1016,5 @@
+ return 0;
+ NumericLiteralParser Literal(Spelling, Tok.getLocation(), PP);
+ if (Literal.hadError)
+ return 0;
+ llvm::APInt APVal(32, 0);
----------------
Richard Smith wrote:
> Does MSVC support octal/hex/binary literals?
>
> I think you should also check for !Literal.hasUDSuffix() and Literal.isIntegerLiteral() here.
Yes, it supports all the builtin ways of writing integer literals. Floats are out, and user-defined literals are out.
================
Comment at: lib/Lex/Pragma.cpp:1045
@@ +1044,3 @@
+ }
+ PPCallbacks *Callbacks = PP.getPPCallbacks();
+
----------------
Richard Smith wrote:
> Move this earlier or later? It's a bit strange for this to be between lexing the '(' and the next token.
Done.
================
Comment at: lib/Lex/Pragma.cpp:1085-1094
@@ +1084,12 @@
+ // Figure out which warning specifier this is.
+ const char *Specifiers[] = { "1", "2", "3",
+ "4", "default", "disable",
+ "error", "once", "suppress" };
+ StringRef Specifier;
+ for (int I = 0, E = llvm::array_lengthof(Specifiers); I != E; ++I) {
+ if (II->getName().equals(Specifiers[I])) {
+ Specifier = Specifiers[I];
+ break;
+ }
+ }
+ if (Specifier.empty()) {
----------------
Richard Smith wrote:
> Maybe use a StringSwitch for this?
Sure, that's easier.
================
Comment at: lib/Lex/Pragma.cpp:1106
@@ +1105,3 @@
+ // Collect the warning ids.
+ SmallVector<int, 1> Ids;
+ PP.Lex(Tok);
----------------
Richard Smith wrote:
> Only 1 inline ID? Cheapskate! =) Maybe 10? 16?
These are usually issued one by one. :)
================
Comment at: lib/Lex/Pragma.cpp:1126-1129
@@ +1125,6 @@
+
+ if (Tok.isNot(tok::r_paren)) {
+ PP.Diag(Tok, diag::warn_pragma_warning_expected) << ")";
+ return;
+ }
+ }
----------------
Richard Smith wrote:
> Do you need to also check for extra junk after the ')' here?
Done.
http://llvm-reviews.chandlerc.com/D1652
More information about the cfe-commits
mailing list