summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp1
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp22
-rw-r--r--clang/lib/Frontend/Rewrite/InclusionRewriter.cpp20
3 files changed, 20 insertions, 23 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index ef76cbfebd9..2098dec1729 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1826,6 +1826,7 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
Opts.ShowMacroComments = Args.hasArg(OPT_CC);
Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
+ Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives);
}
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 7c1d9a56883..6507f8e4b66 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -94,14 +94,14 @@ private:
bool Initialized;
bool DisableLineMarkers;
bool DumpDefines;
- bool UseLineDirective;
+ bool UseLineDirectives;
bool IsFirstFileEntered;
public:
- PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os,
- bool lineMarkers, bool defines)
- : PP(pp), SM(PP.getSourceManager()),
- ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers),
- DumpDefines(defines) {
+ PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
+ bool defines, bool UseLineDirectives)
+ : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
+ DisableLineMarkers(lineMarkers), DumpDefines(defines),
+ UseLineDirectives(UseLineDirectives) {
CurLine = 0;
CurFilename += "<uninit>";
EmittedTokensOnThisLine = false;
@@ -109,9 +109,6 @@ public:
FileType = SrcMgr::C_User;
Initialized = false;
IsFirstFileEntered = false;
-
- // If we're in microsoft mode, use normal #line instead of line markers.
- UseLineDirective = PP.getLangOpts().MicrosoftExt;
}
void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
@@ -183,7 +180,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
// Emit #line directives or GNU line markers depending on what mode we're in.
- if (UseLineDirective) {
+ if (UseLineDirectives) {
OS << "#line" << ' ' << LineNo << ' ' << '"';
OS.write_escaped(CurFilename);
OS << '"';
@@ -719,9 +716,8 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
// to -C or -CC.
PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
- PrintPPOutputPPCallbacks *Callbacks =
- new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers,
- Opts.ShowMacros);
+ PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
+ PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros, Opts.UseLineDirectives);
PP.AddPragmaHandler(new UnknownPragmaHandler("#pragma", Callbacks));
PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",Callbacks));
PP.AddPragmaHandler("clang",
diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
index 140055735a9..5cc503ad354 100644
--- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -43,14 +43,15 @@ class InclusionRewriter : public PPCallbacks {
StringRef MainEOL; ///< The line ending marker to use.
const llvm::MemoryBuffer *PredefinesBuffer; ///< The preprocessor predefines.
bool ShowLineMarkers; ///< Show #line markers.
- bool UseLineDirective; ///< Use of line directives or line markers.
+ bool UseLineDirectives; ///< Use of line directives or line markers.
typedef std::map<unsigned, FileChange> FileChangeMap;
FileChangeMap FileChanges; ///< Tracks which files were included where.
/// Used transitively for building up the FileChanges mapping over the
/// various \c PPCallbacks callbacks.
FileChangeMap::iterator LastInsertedFileChange;
public:
- InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers);
+ InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers,
+ bool UseLineDirectives);
bool Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) {
PredefinesBuffer = Buf;
@@ -89,13 +90,12 @@ private:
/// Initializes an InclusionRewriter with a \p PP source and \p OS destination.
InclusionRewriter::InclusionRewriter(Preprocessor &PP, raw_ostream &OS,
- bool ShowLineMarkers)
+ bool ShowLineMarkers,
+ bool UseLineDirectives)
: PP(PP), SM(PP.getSourceManager()), OS(OS), MainEOL("\n"),
PredefinesBuffer(nullptr), ShowLineMarkers(ShowLineMarkers),
- LastInsertedFileChange(FileChanges.end()) {
- // If we're in microsoft mode, use normal #line instead of line markers.
- UseLineDirective = PP.getLangOpts().MicrosoftExt;
-}
+ LastInsertedFileChange(FileChanges.end()),
+ UseLineDirectives(UseLineDirectives) {}
/// Write appropriate line information as either #line directives or GNU line
/// markers depending on what mode we're in, including the \p Filename and
@@ -106,7 +106,7 @@ void InclusionRewriter::WriteLineInfo(const char *Filename, int Line,
StringRef Extra) {
if (!ShowLineMarkers)
return;
- if (UseLineDirective) {
+ if (UseLineDirectives) {
OS << "#line" << ' ' << Line << ' ' << '"';
OS.write_escaped(Filename);
OS << '"';
@@ -561,8 +561,8 @@ bool InclusionRewriter::Process(FileID FileId,
void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS,
const PreprocessorOutputOptions &Opts) {
SourceManager &SM = PP.getSourceManager();
- InclusionRewriter *Rewrite = new InclusionRewriter(PP, *OS,
- Opts.ShowLineMarkers);
+ InclusionRewriter *Rewrite = new InclusionRewriter(
+ PP, *OS, Opts.ShowLineMarkers, Opts.UseLineDirectives);
Rewrite->detectMainFileEOL();
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Rewrite));
OpenPOWER on IntegriCloud