[PATCH] Lex and ignore Microsoft's #pragma warning(...)
Richard Smith
richard at metafoo.co.uk
Wed Sep 11 16:06:42 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>;
----------------
Typo 'supress'... I hope?
================
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);
----------------
Does MSVC support octal/hex/binary literals?
I think you should also check for !Literal.hasUDSuffix() and Literal.isIntegerLiteral() here.
================
Comment at: lib/Lex/Pragma.cpp:1045
@@ +1044,3 @@
+ }
+ PPCallbacks *Callbacks = PP.getPPCallbacks();
+
----------------
Move this earlier or later? It's a bit strange for this to be between lexing the '(' and the next token.
================
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()) {
----------------
Maybe use a StringSwitch for this?
================
Comment at: lib/Lex/Pragma.cpp:1106
@@ +1105,3 @@
+ // Collect the warning ids.
+ SmallVector<int, 1> Ids;
+ PP.Lex(Tok);
----------------
Only 1 inline ID? Cheapskate! =) Maybe 10? 16?
================
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;
+ }
+ }
----------------
Do you need to also check for extra junk after the ')' here?
http://llvm-reviews.chandlerc.com/D1652
More information about the cfe-commits
mailing list