On Mar 18, 2011, at 2:23 PM, Daniel Dunbar wrote: > Author: ddunbar > Date: Fri Mar 18 16:23:38 2011 > New Revision: 127910 > > URL: http://llvm.org/viewvc/llvm-project?rev=127910&view=rev > Log: > Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL > comments.
Hi Daniel, Why not just have TraditionalCPP turn off LangOpts.BCPLComment? -Chris > > Added: > cfe/trunk/test/Preprocessor/traditional-cpp.c > Modified: > cfe/trunk/include/clang/Basic/LangOptions.h > cfe/trunk/include/clang/Driver/CC1Options.td > cfe/trunk/lib/Frontend/CompilerInvocation.cpp > cfe/trunk/lib/Lex/Lexer.cpp > > Modified: cfe/trunk/include/clang/Basic/LangOptions.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Basic/LangOptions.h (original) > +++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Mar 18 16:23:38 2011 > @@ -56,6 +56,7 @@ > 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 @@ > 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; > > Modified: cfe/trunk/include/clang/Driver/CC1Options.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Driver/CC1Options.td (original) > +++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Mar 18 16:23:38 2011 > @@ -511,6 +511,8 @@ > 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 > > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Mar 18 16:23:38 2011 > @@ -574,6 +574,8 @@ > 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 @@ > 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); > > Modified: cfe/trunk/lib/Lex/Lexer.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=127910&r1=127909&r2=127910&view=diff > ============================================================================== > --- cfe/trunk/lib/Lex/Lexer.cpp (original) > +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Mar 18 16:23:38 2011 > @@ -2091,7 +2091,7 @@ > // 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 @@ > // 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. > > > Added: cfe/trunk/test/Preprocessor/traditional-cpp.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/traditional-cpp.c?rev=127910&view=auto > ============================================================================== > --- cfe/trunk/test/Preprocessor/traditional-cpp.c (added) > +++ cfe/trunk/test/Preprocessor/traditional-cpp.c Fri Mar 18 16:23:38 2011 > @@ -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 > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
