aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-03-18 21:23:38 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-03-18 21:23:38 +0000
commit2ed42287b9b88a0bb08ab10e95e306da3f294ba9 (patch)
tree968485c50d1ca933ba0e3518d514d43c06abecbd
parent5ce872fdcdf868c60e91f4669b2c2925c5c2e6cc (diff)
Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL
comments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127910 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/LangOptions.h3
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
-rw-r--r--lib/Lex/Lexer.cpp8
-rw-r--r--test/Preprocessor/traditional-cpp.c12
5 files changed, 24 insertions, 4 deletions
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 83a6746d92..ebdcddeb35 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -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;
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index e103b5bb7d..bb8759e270 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -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
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 31fcee2de8..9d9c99611c 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -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);
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index b511421ee7..6f3d611fb0 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -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
index 0000000000..5fc9ee398e
--- /dev/null
+++ b/test/Preprocessor/traditional-cpp.c
@@ -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