]> granicus.if.org Git - clang/commitdiff
Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL
authorDaniel Dunbar <daniel@zuster.org>
Fri, 18 Mar 2011 21:23:38 +0000 (21:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 18 Mar 2011 21:23:38 +0000 (21:23 +0000)
comments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127910 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
lib/Frontend/CompilerInvocation.cpp
lib/Lex/Lexer.cpp
test/Preprocessor/traditional-cpp.c [new file with mode: 0644]

index 83a6746d9209147cdf9a5cae9199fe4506951d29..ebdcddeb353d84f8c6f1e2e92ad6df94ce905bc2 100644 (file)
@@ -56,6 +56,7 @@ public:
   unsigned ObjCExceptions    : 1;  // Support Objective-C exceptions.
   unsigned CXXExceptions     : 1;  // Support C++ exceptions.
   unsigned SjLjExceptions    : 1;  // Use setjmp-longjump exception handling.
+  unsigned TraditionalCPP    : 1; /// Enable some traditional CPP emulation.
   unsigned RTTI              : 1;  // Support RTTI information.
 
   unsigned MSBitfields       : 1; // MS-compatible structure layout
@@ -169,7 +170,7 @@ public:
     C99 = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0;
     CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
     Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0;
-    Freestanding = NoBuiltin = 0;
+    TraditionalCPP = Freestanding = NoBuiltin = 0;
     MSBitfields = 0;
     NeXTRuntime = 1;
     RTTI = 1;
index e103b5bb7d8287e87a0f94aa382cfdfd186521ce..bb8759e2702956b96f051a12d835e0e76224bcb4 100644 (file)
@@ -511,6 +511,8 @@ def fwritable_strings : Flag<"-fwritable-strings">,
   HelpText<"Store string literals as writable data">;
 def fno_bitfield_type_align : Flag<"-fno-bitfield-type-align">,
   HelpText<"Ignore bit-field types when aligning structures">;
+def traditional_cpp : Flag<"-traditional-cpp">,
+  HelpText<"Enable some traditional CPP emulation">;
 
 //===----------------------------------------------------------------------===//
 // Header Search Options
index 31fcee2de888a48990b661b7630518f26a918383..9d9c99611cf75e7d0557d3e55446980238b2d651 100644 (file)
@@ -574,6 +574,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
     Res.push_back("-fcxx-exceptions");
   if (Opts.SjLjExceptions)
     Res.push_back("-fsjlj-exceptions");
+  if (Opts.TraditionalCPP)
+    Res.push_back("-traditional-cpp");
   if (!Opts.RTTI)
     Res.push_back("-fno-rtti");
   if (Opts.MSBitfields)
@@ -1442,6 +1444,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
   Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
   Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
+  Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
 
   Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
   Opts.Blocks = Args.hasArg(OPT_fblocks);
index b511421ee777f1934b435ab533f5f91d09eb1b01..6f3d611fb075c13556e499efce6b1babbe639b82 100644 (file)
@@ -2091,7 +2091,7 @@ LexNextToken:
     // If the next token is obviously a // or /* */ comment, skip it efficiently
     // too (without going through the big switch stmt).
     if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() &&
-        Features.BCPLComment) {
+        Features.BCPLComment && !Features.TraditionalCPP) {
       if (SkipBCPLComment(Result, CurPtr+2))
         return; // There is a token to return.
       goto SkipIgnoredUnits;
@@ -2280,8 +2280,10 @@ LexNextToken:
       // this as "foo / bar" and langauges with BCPL comments would lex it as
       // "foo".  Check to see if the character after the second slash is a '*'.
       // If so, we will lex that as a "/" instead of the start of a comment.
-      if (Features.BCPLComment ||
-          getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') {
+      // However, we never do this in -traditional-cpp mode.
+      if ((Features.BCPLComment ||
+           getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*') &&
+          !Features.TraditionalCPP) {
         if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result)))
           return; // There is a token to return.
 
diff --git a/test/Preprocessor/traditional-cpp.c b/test/Preprocessor/traditional-cpp.c
new file mode 100644 (file)
index 0000000..5fc9ee3
--- /dev/null
@@ -0,0 +1,12 @@
+/* Clang supports a very limited subset of -traditional-cpp, basically we only
+ * intend to add support for things that people actually rely on when doing
+ * things like using /usr/bin/cpp to preprocess non-source files. */
+
+/*
+ RUN: %clang_cc1 -traditional-cpp %s -E -o %t
+ RUN: FileCheck < %t %s
+*/
+
+/* CHECK: foo // bar
+ */
+foo // bar