[cfe-commits] r109952 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/Parser.h lib/Parse/ParsePragma.cpp lib/Parse/ParsePragma.h lib/Parse/Parser.cpp test/Parser/pragma-options.c

Daniel Dunbar daniel at zuster.org
Sat Jul 31 12:17:07 PDT 2010


Author: ddunbar
Date: Sat Jul 31 14:17:07 2010
New Revision: 109952

URL: http://llvm.org/viewvc/llvm-project?rev=109952&view=rev
Log:
Parser: Add support for #pragma align, which is just another spelling of #pragma
options align.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParsePragma.cpp
    cfe/trunk/lib/Parse/ParsePragma.h
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/test/Parser/pragma-options.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Jul 31 14:17:07 2010
@@ -374,10 +374,10 @@
 // - #pragma options
 def warn_pragma_options_expected_align : Warning<
   "expected 'align' following '#pragma options' - ignored">;
-def warn_pragma_options_expected_equal : Warning<
-  "expected '=' following '#pragma options align' - ignored">;
-def warn_pragma_options_invalid_option : Warning<
-  "invalid alignment option in '#pragma options align' - ignored">;
+def warn_pragma_align_expected_equal : Warning<
+  "expected '=' following '#pragma %select{align|options align}0' - ignored">;
+def warn_pragma_align_invalid_option : Warning<
+  "invalid alignment option in '#pragma %select{align|options align}0' - ignored">;
 // - #pragma pack
 def warn_pragma_pack_invalid_action : Warning<
   "unknown action for '#pragma pack' - ignored">;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Jul 31 14:17:07 2010
@@ -109,6 +109,7 @@
   IdentifierInfo *Ident_vector;
   IdentifierInfo *Ident_pixel;
 
+  llvm::OwningPtr<PragmaHandler> AlignHandler;
   llvm::OwningPtr<PragmaHandler> OptionsHandler;
   llvm::OwningPtr<PragmaHandler> PackHandler;
   llvm::OwningPtr<PragmaHandler> UnusedHandler;

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Sat Jul 31 14:17:07 2010
@@ -110,27 +110,32 @@
                           LParenLoc, RParenLoc);
 }
 
-// #pragma 'options' 'align' '=' {'native','natural','mac68k','power','reset'}
-void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
-  SourceLocation OptionsLoc = OptionsTok.getLocation();
-
+// #pragma 'align' '=' {'native','natural','mac68k','power','reset'}
+// #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'}
+static void ParseAlignPragma(Action &Actions, Preprocessor &PP, Token &FirstTok,
+                             bool IsOptions) {
   Token Tok;
-  PP.Lex(Tok);
-  if (Tok.isNot(tok::identifier) || !Tok.getIdentifierInfo()->isStr("align")) {
-    PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align);
-    return;
+
+  if (IsOptions) {
+    PP.Lex(Tok);
+    if (Tok.isNot(tok::identifier) ||
+        !Tok.getIdentifierInfo()->isStr("align")) {
+      PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align);
+      return;
+    }
   }
 
   PP.Lex(Tok);
   if (Tok.isNot(tok::equal)) {
-    PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_equal);
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal)
+      << IsOptions;
     return;
   }
 
   PP.Lex(Tok);
   if (Tok.isNot(tok::identifier)) {
     PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
-      << "options";
+      << (IsOptions ? "options" : "align");
     return;
   }
 
@@ -149,7 +154,8 @@
   else if (II->isStr("reset"))
     Kind = Action::POAK_Reset;
   else {
-    PP.Diag(Tok.getLocation(), diag::warn_pragma_options_invalid_option);
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option)
+      << IsOptions;
     return;
   }
 
@@ -157,11 +163,19 @@
   PP.Lex(Tok);
   if (Tok.isNot(tok::eom)) {
     PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
-      << "options";
+      << (IsOptions ? "options" : "align");
     return;
   }
 
-  Actions.ActOnPragmaOptionsAlign(Kind, OptionsLoc, KindLoc);
+  Actions.ActOnPragmaOptionsAlign(Kind, FirstTok.getLocation(), KindLoc);
+}
+
+void PragmaAlignHandler::HandlePragma(Preprocessor &PP, Token &AlignTok) {
+  ParseAlignPragma(Actions, PP, AlignTok, /*IsOptions=*/false);
+}
+
+void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
+  ParseAlignPragma(Actions, PP, OptionsTok, /*IsOptions=*/true);
 }
 
 // #pragma unused(identifier)

Modified: cfe/trunk/lib/Parse/ParsePragma.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.h?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.h (original)
+++ cfe/trunk/lib/Parse/ParsePragma.h Sat Jul 31 14:17:07 2010
@@ -20,6 +20,14 @@
   class Action;
   class Parser;
 
+class PragmaAlignHandler : public PragmaHandler {
+  Action &Actions;
+public:
+  explicit PragmaAlignHandler(Action &A) : PragmaHandler("align"), Actions(A) {}
+
+  virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
+};
+
 class PragmaOptionsHandler : public PragmaHandler {
   Action &Actions;
 public:

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sat Jul 31 14:17:07 2010
@@ -33,6 +33,9 @@
 
   // Add #pragma handlers. These are removed and destroyed in the
   // destructor.
+  AlignHandler.reset(new PragmaAlignHandler(actions));
+  PP.AddPragmaHandler(AlignHandler.get());
+
   OptionsHandler.reset(new PragmaOptionsHandler(actions));
   PP.AddPragmaHandler(OptionsHandler.get());
 
@@ -298,6 +301,8 @@
     delete ScopeCache[i];
 
   // Remove the pragma handlers we installed.
+  PP.RemovePragmaHandler(AlignHandler.get());
+  AlignHandler.reset();
   PP.RemovePragmaHandler(OptionsHandler.get());
   OptionsHandler.reset();
   PP.RemovePragmaHandler(PackHandler.get());

Modified: cfe/trunk/test/Parser/pragma-options.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/pragma-options.c?rev=109952&r1=109951&r2=109952&view=diff
==============================================================================
--- cfe/trunk/test/Parser/pragma-options.c (original)
+++ cfe/trunk/test/Parser/pragma-options.c Sat Jul 31 14:17:07 2010
@@ -10,3 +10,13 @@
 #pragma options align=reset
 #pragma options align=mac68k
 #pragma options align=power
+
+/* expected-warning {{expected '=' following '#pragma align'}} */ #pragma align
+/* expected-warning {{expected identifier in '#pragma align'}} */ #pragma align =
+/* expected-warning {{invalid alignment option in '#pragma align'}} */ #pragma align = foo
+/* expected-warning {{extra tokens at end of '#pragma align'}} */ #pragma align = reset foo
+
+#pragma align=natural
+#pragma align=reset
+#pragma align=mac68k
+#pragma align=power





More information about the cfe-commits mailing list