]> granicus.if.org Git - clang/commitdiff
Make LexOnOffSwitch a Preprocessor member function
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 14 Feb 2011 01:42:24 +0000 (01:42 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 14 Feb 2011 01:42:24 +0000 (01:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125473 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
include/clang/Basic/TokenKinds.h
include/clang/Lex/Preprocessor.h
lib/Lex/Pragma.cpp
test/Preprocessor/pragma_unknown.c

index 8f61c69f9ea282aed5fc382c723aaa29d6c61c3d..85573de02cfb5f778cf225ba1fed78bad398ff2b 100644 (file)
@@ -244,11 +244,11 @@ def warn_pragma_ignored : Warning<"unknown pragma ignored">,
    InGroup<UnknownPragmas>, DefaultIgnore;
 def ext_stdc_pragma_ignored : ExtWarn<"unknown pragma in STDC namespace">,
    InGroup<UnknownPragmas>;
-def ext_stdc_pragma_syntax :
+def ext_on_off_switch_syntax :
    ExtWarn<"expected 'ON' or 'OFF' or 'DEFAULT' in pragma">,
    InGroup<UnknownPragmas>;
-def ext_stdc_pragma_syntax_eom :
-   ExtWarn<"expected end of macro in STDC pragma">,
+def ext_pragma_syntax_eom :
+   ExtWarn<"expected end of macro in pragma">,
    InGroup<UnknownPragmas>;
 def warn_stdc_fenv_access_not_supported :
    Warning<"pragma STDC FENV_ACCESS ON is not supported, ignoring pragma">,
index 85dc0671de62974b0fbf2155eb831d69f16d8042..515390a8ce93de771ca2feb219800be51d98e75a 100644 (file)
@@ -43,6 +43,12 @@ enum ObjCKeywordKind {
   NUM_OBJC_KEYWORDS
 };
 
+/// OnOffSwitch - This defines the possible values of an on-off-switch
+/// (C99 6.10.6p2).
+enum OnOffSwitch {
+  OOS_ON, OOS_OFF, OOS_DEFAULT
+};
+
 /// \brief Determines the name of a token as used within the front end.
 ///
 /// The name of a token will be an internal name (such as "l_square")
index df3a5b234bc9a94d79ddf19718d522eacb0c7a79..018f7e9c8c0205a138dbfa91e0602133764332d9 100644 (file)
@@ -843,6 +843,10 @@ public:
   bool ConcatenateIncludeName(llvm::SmallString<128> &FilenameBuffer,
                               SourceLocation &End);
 
+  /// LexOnOffSwitch - Lex an on-off-switch (C99 6.10.6p2) and verify that it is
+  /// followed by EOM.  Return true if the token is not a valid on-off-switch.
+  bool LexOnOffSwitch(tok::OnOffSwitch &OOS);
+
 private:
 
   void PushIncludeMacroStack() {
index da66b502b2619b50d132787f3ed798bbb541d00a..acea2cc886ce2f98f6cfd7e0f895f45acbaf8a5f 100644 (file)
@@ -723,6 +723,33 @@ void Preprocessor::RemovePragmaHandler(llvm::StringRef Namespace,
     PragmaHandlers->RemovePragmaHandler(NS);
 }
 
+bool Preprocessor::LexOnOffSwitch(tok::OnOffSwitch &Result) {
+  Token Tok;
+  LexUnexpandedToken(Tok);
+
+  if (Tok.isNot(tok::identifier)) {
+    Diag(Tok, diag::ext_on_off_switch_syntax);
+    return true;
+  }
+  IdentifierInfo *II = Tok.getIdentifierInfo();
+  if (II->isStr("ON"))
+    Result = tok::OOS_ON;
+  else if (II->isStr("OFF"))
+    Result = tok::OOS_OFF;
+  else if (II->isStr("DEFAULT"))
+    Result = tok::OOS_DEFAULT;
+  else {
+    Diag(Tok, diag::ext_on_off_switch_syntax);
+    return true;
+  }
+
+  // Verify that this is followed by EOM.
+  LexUnexpandedToken(Tok);
+  if (Tok.isNot(tok::eom))
+    Diag(Tok, diag::ext_pragma_syntax_eom);
+  return false;
+}
+
 namespace {
 /// PragmaOnceHandler - "#pragma once" marks the file as atomically included.
 struct PragmaOnceHandler : public PragmaHandler {
@@ -935,38 +962,6 @@ struct PragmaPopMacroHandler : public PragmaHandler {
 
 // Pragma STDC implementations.
 
-enum STDCSetting {
-  STDC_ON, STDC_OFF, STDC_DEFAULT, STDC_INVALID
-};
-
-static STDCSetting LexOnOffSwitch(Preprocessor &PP) {
-  Token Tok;
-  PP.LexUnexpandedToken(Tok);
-
-  if (Tok.isNot(tok::identifier)) {
-    PP.Diag(Tok, diag::ext_stdc_pragma_syntax);
-    return STDC_INVALID;
-  }
-  IdentifierInfo *II = Tok.getIdentifierInfo();
-  STDCSetting Result;
-  if (II->isStr("ON"))
-    Result = STDC_ON;
-  else if (II->isStr("OFF"))
-    Result = STDC_OFF;
-  else if (II->isStr("DEFAULT"))
-    Result = STDC_DEFAULT;
-  else {
-    PP.Diag(Tok, diag::ext_stdc_pragma_syntax);
-    return STDC_INVALID;
-  }
-
-  // Verify that this is followed by EOM.
-  PP.LexUnexpandedToken(Tok);
-  if (Tok.isNot(tok::eom))
-    PP.Diag(Tok, diag::ext_stdc_pragma_syntax_eom);
-  return Result;
-}
-
 /// PragmaSTDC_FP_CONTRACTHandler - "#pragma STDC FP_CONTRACT ...".
 struct PragmaSTDC_FP_CONTRACTHandler : public PragmaHandler {
   PragmaSTDC_FP_CONTRACTHandler() : PragmaHandler("FP_CONTRACT") {}
@@ -976,7 +971,8 @@ struct PragmaSTDC_FP_CONTRACTHandler : public PragmaHandler {
     // at all, our default is OFF and setting it to ON is an optimization hint
     // we can safely ignore.  When we support -ffma or something, we would need
     // to diagnose that we are ignoring FMA.
-    LexOnOffSwitch(PP);
+    tok::OnOffSwitch OOS;
+    PP.LexOnOffSwitch(OOS);
   }
 };
 
@@ -985,7 +981,10 @@ struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
   PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
   virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                             Token &Tok) {
-    if (LexOnOffSwitch(PP) == STDC_ON)
+    tok::OnOffSwitch OOS;
+    if (PP.LexOnOffSwitch(OOS))
+     return;
+    if (OOS == tok::OOS_ON)
       PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
   }
 };
@@ -996,7 +995,8 @@ struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
     : PragmaHandler("CX_LIMITED_RANGE") {}
   virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                             Token &Tok) {
-    LexOnOffSwitch(PP);
+    tok::OnOffSwitch OOS;
+    PP.LexOnOffSwitch(OOS);
   }
 };
 
index c1851534cc3342676f8d3ccaefcb241e8584ab92..0672ade660594088be57cdee88963513a853092c 100644 (file)
@@ -21,7 +21,7 @@
 #pragma STDC CX_LIMITED_RANGE IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
 
 #pragma STDC CX_LIMITED_RANGE    // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
-#pragma STDC CX_LIMITED_RANGE ON FULL POWER  // expected-warning {{expected end of macro in STDC pragma}}
+#pragma STDC CX_LIMITED_RANGE ON FULL POWER  // expected-warning {{expected end of macro in pragma}}
 
 #pragma STDC SO_GREAT  // expected-warning {{unknown pragma in STDC namespace}}
 #pragma STDC   // expected-warning {{unknown pragma in STDC namespace}}