зеркало из https://github.com/microsoft/clang.git
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
This commit is contained in:
Родитель
5ce872fdcd
Коммит
2ed42287b9
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче