[pp-trace] Delete redundant clang::

And clarify command line options

llvm-svn: 356851
This commit is contained in:
Fangrui Song 2019-03-24 07:31:21 +00:00
parent be860a04b6
commit 54ce1b18c5
3 changed files with 87 additions and 104 deletions

View File

@ -23,7 +23,7 @@ pp-trace Usage
Command Line Format
-------------------
``pp-trace [<pp-trace-options>] <source-file> [<front-end-options>]``
``pp-trace [<pp-trace-options>] <source-file> [-- <front-end-options>]``
``<pp-trace-options>`` is a place-holder for options
specific to pp-trace, which are described below in

View File

@ -21,13 +21,13 @@ namespace clang {
namespace pp_trace {
// Get a "file:line:column" source location string.
static std::string getSourceLocationString(clang::Preprocessor &PP,
clang::SourceLocation Loc) {
static std::string getSourceLocationString(Preprocessor &PP,
SourceLocation Loc) {
if (Loc.isInvalid())
return std::string("(none)");
if (Loc.isFileID()) {
clang::PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
if (PLoc.isInvalid()) {
return std::string("(invalid)");
@ -91,7 +91,7 @@ static const char *const MappingStrings[] = { "0", "MAP_IGNORE",
PPCallbacksTracker::PPCallbacksTracker(const FilterType &Filters,
std::vector<CallbackCall> &CallbackCalls,
clang::Preprocessor &PP)
Preprocessor &PP)
: CallbackCalls(CallbackCalls), Filters(Filters), PP(PP) {}
PPCallbacksTracker::~PPCallbacksTracker() {}
@ -99,9 +99,10 @@ PPCallbacksTracker::~PPCallbacksTracker() {}
// Callback functions.
// Callback invoked whenever a source file is entered or exited.
void PPCallbacksTracker::FileChanged(
clang::SourceLocation Loc, clang::PPCallbacks::FileChangeReason Reason,
clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID) {
void PPCallbacksTracker::FileChanged(SourceLocation Loc,
PPCallbacks::FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) {
beginCallback("FileChanged");
appendArgument("Loc", Loc);
appendArgument("Reason", Reason, FileChangeReasonStrings);
@ -111,10 +112,9 @@ void PPCallbacksTracker::FileChanged(
// Callback invoked whenever a source file is skipped as the result
// of header guard optimization.
void
PPCallbacksTracker::FileSkipped(const clang::FileEntry &SkippedFile,
const clang::Token &FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) {
void PPCallbacksTracker::FileSkipped(const FileEntry &SkippedFile,
const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) {
beginCallback("FileSkipped");
appendArgument("ParentFile", &SkippedFile);
appendArgument("FilenameTok", FilenameTok);
@ -135,11 +135,10 @@ PPCallbacksTracker::FileNotFound(llvm::StringRef FileName,
// any kind (#include, #import, etc.) has been processed, regardless
// of whether the inclusion will actually result in an inclusion.
void PPCallbacksTracker::InclusionDirective(
clang::SourceLocation HashLoc, const clang::Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
clang::CharSourceRange FilenameRange, const clang::FileEntry *File,
SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName,
bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
llvm::StringRef SearchPath, llvm::StringRef RelativePath,
const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) {
const Module *Imported, SrcMgr::CharacteristicKind FileType) {
beginCallback("InclusionDirective");
appendArgument("IncludeTok", IncludeTok);
appendFilePathArgument("FileName", FileName);
@ -153,9 +152,9 @@ void PPCallbacksTracker::InclusionDirective(
// Callback invoked whenever there was an explicit module-import
// syntax.
void PPCallbacksTracker::moduleImport(clang::SourceLocation ImportLoc,
clang::ModuleIdPath Path,
const clang::Module *Imported) {
void PPCallbacksTracker::moduleImport(SourceLocation ImportLoc,
ModuleIdPath Path,
const Module *Imported) {
beginCallback("moduleImport");
appendArgument("ImportLoc", ImportLoc);
appendArgument("Path", Path);
@ -167,24 +166,23 @@ void PPCallbacksTracker::moduleImport(clang::SourceLocation ImportLoc,
void PPCallbacksTracker::EndOfMainFile() { beginCallback("EndOfMainFile"); }
// Callback invoked when a #ident or #sccs directive is read.
void PPCallbacksTracker::Ident(clang::SourceLocation Loc, llvm::StringRef Str) {
void PPCallbacksTracker::Ident(SourceLocation Loc, llvm::StringRef Str) {
beginCallback("Ident");
appendArgument("Loc", Loc);
appendArgument("Str", Str);
}
// Callback invoked when start reading any pragma directive.
void
PPCallbacksTracker::PragmaDirective(clang::SourceLocation Loc,
clang::PragmaIntroducerKind Introducer) {
void PPCallbacksTracker::PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) {
beginCallback("PragmaDirective");
appendArgument("Loc", Loc);
appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
}
// Callback invoked when a #pragma comment directive is read.
void PPCallbacksTracker::PragmaComment(clang::SourceLocation Loc,
const clang::IdentifierInfo *Kind,
void PPCallbacksTracker::PragmaComment(SourceLocation Loc,
const IdentifierInfo *Kind,
llvm::StringRef Str) {
beginCallback("PragmaComment");
appendArgument("Loc", Loc);
@ -194,7 +192,7 @@ void PPCallbacksTracker::PragmaComment(clang::SourceLocation Loc,
// Callback invoked when a #pragma detect_mismatch directive is
// read.
void PPCallbacksTracker::PragmaDetectMismatch(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaDetectMismatch(SourceLocation Loc,
llvm::StringRef Name,
llvm::StringRef Value) {
beginCallback("PragmaDetectMismatch");
@ -204,7 +202,7 @@ void PPCallbacksTracker::PragmaDetectMismatch(clang::SourceLocation Loc,
}
// Callback invoked when a #pragma clang __debug directive is read.
void PPCallbacksTracker::PragmaDebug(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaDebug(SourceLocation Loc,
llvm::StringRef DebugType) {
beginCallback("PragmaDebug");
appendArgument("Loc", Loc);
@ -212,9 +210,10 @@ void PPCallbacksTracker::PragmaDebug(clang::SourceLocation Loc,
}
// Callback invoked when a #pragma message directive is read.
void PPCallbacksTracker::PragmaMessage(
clang::SourceLocation Loc, llvm::StringRef Namespace,
clang::PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) {
void PPCallbacksTracker::PragmaMessage(SourceLocation Loc,
llvm::StringRef Namespace,
PPCallbacks::PragmaMessageKind Kind,
llvm::StringRef Str) {
beginCallback("PragmaMessage");
appendArgument("Loc", Loc);
appendArgument("Namespace", Namespace);
@ -224,7 +223,7 @@ void PPCallbacksTracker::PragmaMessage(
// Callback invoked when a #pragma gcc dianostic push directive
// is read.
void PPCallbacksTracker::PragmaDiagnosticPush(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaDiagnosticPush(SourceLocation Loc,
llvm::StringRef Namespace) {
beginCallback("PragmaDiagnosticPush");
appendArgument("Loc", Loc);
@ -233,7 +232,7 @@ void PPCallbacksTracker::PragmaDiagnosticPush(clang::SourceLocation Loc,
// Callback invoked when a #pragma gcc dianostic pop directive
// is read.
void PPCallbacksTracker::PragmaDiagnosticPop(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaDiagnosticPop(SourceLocation Loc,
llvm::StringRef Namespace) {
beginCallback("PragmaDiagnosticPop");
appendArgument("Loc", Loc);
@ -241,9 +240,9 @@ void PPCallbacksTracker::PragmaDiagnosticPop(clang::SourceLocation Loc,
}
// Callback invoked when a #pragma gcc dianostic directive is read.
void PPCallbacksTracker::PragmaDiagnostic(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaDiagnostic(SourceLocation Loc,
llvm::StringRef Namespace,
clang::diag::Severity Mapping,
diag::Severity Mapping,
llvm::StringRef Str) {
beginCallback("PragmaDiagnostic");
appendArgument("Loc", Loc);
@ -254,9 +253,10 @@ void PPCallbacksTracker::PragmaDiagnostic(clang::SourceLocation Loc,
// Called when an OpenCL extension is either disabled or
// enabled with a pragma.
void PPCallbacksTracker::PragmaOpenCLExtension(
clang::SourceLocation NameLoc, const clang::IdentifierInfo *Name,
clang::SourceLocation StateLoc, unsigned State) {
void PPCallbacksTracker::PragmaOpenCLExtension(SourceLocation NameLoc,
const IdentifierInfo *Name,
SourceLocation StateLoc,
unsigned State) {
beginCallback("PragmaOpenCLExtension");
appendArgument("NameLoc", NameLoc);
appendArgument("Name", Name);
@ -265,7 +265,7 @@ void PPCallbacksTracker::PragmaOpenCLExtension(
}
// Callback invoked when a #pragma warning directive is read.
void PPCallbacksTracker::PragmaWarning(clang::SourceLocation Loc,
void PPCallbacksTracker::PragmaWarning(SourceLocation Loc,
llvm::StringRef WarningSpec,
llvm::ArrayRef<int> Ids) {
beginCallback("PragmaWarning");
@ -285,23 +285,22 @@ void PPCallbacksTracker::PragmaWarning(clang::SourceLocation Loc,
}
// Callback invoked when a #pragma warning(push) directive is read.
void PPCallbacksTracker::PragmaWarningPush(clang::SourceLocation Loc,
int Level) {
void PPCallbacksTracker::PragmaWarningPush(SourceLocation Loc, int Level) {
beginCallback("PragmaWarningPush");
appendArgument("Loc", Loc);
appendArgument("Level", Level);
}
// Callback invoked when a #pragma warning(pop) directive is read.
void PPCallbacksTracker::PragmaWarningPop(clang::SourceLocation Loc) {
void PPCallbacksTracker::PragmaWarningPop(SourceLocation Loc) {
beginCallback("PragmaWarningPop");
appendArgument("Loc", Loc);
}
// Callback invoked when a #pragma execution_character_set(push) directive
// is read.
void PPCallbacksTracker::PragmaExecCharsetPush(clang::SourceLocation Loc,
clang::StringRef Str) {
void PPCallbacksTracker::PragmaExecCharsetPush(SourceLocation Loc,
StringRef Str) {
beginCallback("PragmaExecCharsetPush");
appendArgument("Loc", Loc);
appendArgument("Charset", Str);
@ -309,18 +308,17 @@ void PPCallbacksTracker::PragmaExecCharsetPush(clang::SourceLocation Loc,
// Callback invoked when a #pragma execution_character_set(pop) directive
// is read.
void PPCallbacksTracker::PragmaExecCharsetPop(clang::SourceLocation Loc) {
void PPCallbacksTracker::PragmaExecCharsetPop(SourceLocation Loc) {
beginCallback("PragmaExecCharsetPop");
appendArgument("Loc", Loc);
}
// Called by Preprocessor::HandleMacroExpandedIdentifier when a
// macro invocation is found.
void
PPCallbacksTracker::MacroExpands(const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition,
clang::SourceRange Range,
const clang::MacroArgs *Args) {
void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok,
const MacroDefinition &MacroDefinition,
SourceRange Range,
const MacroArgs *Args) {
beginCallback("MacroExpands");
appendArgument("MacroNameTok", MacroNameTok);
appendArgument("MacroDefinition", MacroDefinition);
@ -329,28 +327,26 @@ PPCallbacksTracker::MacroExpands(const clang::Token &MacroNameTok,
}
// Hook called whenever a macro definition is seen.
void
PPCallbacksTracker::MacroDefined(const clang::Token &MacroNameTok,
const clang::MacroDirective *MacroDirective) {
void PPCallbacksTracker::MacroDefined(const Token &MacroNameTok,
const MacroDirective *MacroDirective) {
beginCallback("MacroDefined");
appendArgument("MacroNameTok", MacroNameTok);
appendArgument("MacroDirective", MacroDirective);
}
// Hook called whenever a macro #undef is seen.
void PPCallbacksTracker::MacroUndefined(
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition,
const clang::MacroDirective *Undef) {
void PPCallbacksTracker::MacroUndefined(const Token &MacroNameTok,
const MacroDefinition &MacroDefinition,
const MacroDirective *Undef) {
beginCallback("MacroUndefined");
appendArgument("MacroNameTok", MacroNameTok);
appendArgument("MacroDefinition", MacroDefinition);
}
// Hook called whenever the 'defined' operator is seen.
void PPCallbacksTracker::Defined(const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition,
clang::SourceRange Range) {
void PPCallbacksTracker::Defined(const Token &MacroNameTok,
const MacroDefinition &MacroDefinition,
SourceRange Range) {
beginCallback("Defined");
appendArgument("MacroNameTok", MacroNameTok);
appendArgument("MacroDefinition", MacroDefinition);
@ -358,15 +354,14 @@ void PPCallbacksTracker::Defined(const clang::Token &MacroNameTok,
}
// Hook called when a source range is skipped.
void PPCallbacksTracker::SourceRangeSkipped(clang::SourceRange Range,
clang::SourceLocation EndifLoc) {
void PPCallbacksTracker::SourceRangeSkipped(SourceRange Range,
SourceLocation EndifLoc) {
beginCallback("SourceRangeSkipped");
appendArgument("Range", clang::SourceRange(Range.getBegin(), EndifLoc));
appendArgument("Range", SourceRange(Range.getBegin(), EndifLoc));
}
// Hook called whenever an #if is seen.
void PPCallbacksTracker::If(clang::SourceLocation Loc,
clang::SourceRange ConditionRange,
void PPCallbacksTracker::If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) {
beginCallback("If");
appendArgument("Loc", Loc);
@ -375,10 +370,9 @@ void PPCallbacksTracker::If(clang::SourceLocation Loc,
}
// Hook called whenever an #elif is seen.
void PPCallbacksTracker::Elif(clang::SourceLocation Loc,
clang::SourceRange ConditionRange,
void PPCallbacksTracker::Elif(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue,
clang::SourceLocation IfLoc) {
SourceLocation IfLoc) {
beginCallback("Elif");
appendArgument("Loc", Loc);
appendArgument("ConditionRange", ConditionRange);
@ -387,9 +381,8 @@ void PPCallbacksTracker::Elif(clang::SourceLocation Loc,
}
// Hook called whenever an #ifdef is seen.
void PPCallbacksTracker::Ifdef(clang::SourceLocation Loc,
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition) {
void PPCallbacksTracker::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MacroDefinition) {
beginCallback("Ifdef");
appendArgument("Loc", Loc);
appendArgument("MacroNameTok", MacroNameTok);
@ -397,9 +390,8 @@ void PPCallbacksTracker::Ifdef(clang::SourceLocation Loc,
}
// Hook called whenever an #ifndef is seen.
void PPCallbacksTracker::Ifndef(clang::SourceLocation Loc,
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition) {
void PPCallbacksTracker::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MacroDefinition) {
beginCallback("Ifndef");
appendArgument("Loc", Loc);
appendArgument("MacroNameTok", MacroNameTok);
@ -407,16 +399,14 @@ void PPCallbacksTracker::Ifndef(clang::SourceLocation Loc,
}
// Hook called whenever an #else is seen.
void PPCallbacksTracker::Else(clang::SourceLocation Loc,
clang::SourceLocation IfLoc) {
void PPCallbacksTracker::Else(SourceLocation Loc, SourceLocation IfLoc) {
beginCallback("Else");
appendArgument("Loc", Loc);
appendArgument("IfLoc", IfLoc);
}
// Hook called whenever an #endif is seen.
void PPCallbacksTracker::Endif(clang::SourceLocation Loc,
clang::SourceLocation IfLoc) {
void PPCallbacksTracker::Endif(SourceLocation Loc, SourceLocation IfLoc) {
beginCallback("Endif");
appendArgument("Loc", Loc);
appendArgument("IfLoc", IfLoc);
@ -472,8 +462,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
}
// Append a token argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::Token &Value) {
void PPCallbacksTracker::appendArgument(const char *Name, const Token &Value) {
appendArgument(Name, PP.getSpelling(Value));
}
@ -484,13 +473,12 @@ void PPCallbacksTracker::appendArgument(const char *Name, int Value,
}
// Append a FileID argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name, clang::FileID Value) {
void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) {
if (Value.isInvalid()) {
appendArgument(Name, "(invalid)");
return;
}
const clang::FileEntry *FileEntry =
PP.getSourceManager().getFileEntryForID(Value);
const FileEntry *FileEntry = PP.getSourceManager().getFileEntryForID(Value);
if (!FileEntry) {
appendArgument(Name, "(getFileEntryForID failed)");
return;
@ -500,7 +488,7 @@ void PPCallbacksTracker::appendArgument(const char *Name, clang::FileID Value) {
// Append a FileEntry argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::FileEntry *Value) {
const FileEntry *Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
@ -510,7 +498,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append a SourceLocation argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::SourceLocation Value) {
SourceLocation Value) {
if (Value.isInvalid()) {
appendArgument(Name, "(invalid)");
return;
@ -519,8 +507,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
}
// Append a SourceRange argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::SourceRange Value) {
void PPCallbacksTracker::appendArgument(const char *Name, SourceRange Value) {
if (DisableTrace)
return;
if (Value.isInvalid()) {
@ -536,7 +523,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append a CharSourceRange argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::CharSourceRange Value) {
CharSourceRange Value) {
if (Value.isInvalid()) {
appendArgument(Name, "(invalid)");
return;
@ -545,8 +532,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
}
// Append a SourceLocation argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::ModuleIdPath Value) {
void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) {
if (DisableTrace)
return;
std::string Str;
@ -565,7 +551,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append an IdentifierInfo argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::IdentifierInfo *Value) {
const IdentifierInfo *Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
@ -575,7 +561,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append a MacroDirective argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::MacroDirective *Value) {
const MacroDirective *Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
@ -585,7 +571,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append a MacroDefinition argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::MacroDefinition &Value) {
const MacroDefinition &Value) {
std::string Str;
llvm::raw_string_ostream SS(Str);
SS << "[";
@ -604,7 +590,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Append a MacroArgs argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::MacroArgs *Value) {
const MacroArgs *Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
@ -616,18 +602,17 @@ void PPCallbacksTracker::appendArgument(const char *Name,
// Each argument is is a series of contiguous Tokens, terminated by a eof.
// Go through each argument printing tokens until we reach eof.
for (unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
const clang::Token *Current = Value->getUnexpArgument(I);
const Token *Current = Value->getUnexpArgument(I);
if (I)
SS << ", ";
bool First = true;
while (Current->isNot(clang::tok::eof)) {
while (Current->isNot(tok::eof)) {
if (!First)
SS << " ";
// We need to be careful here because the arguments might not be legal in
// YAML, so we use the token name for anything but identifiers and
// numeric literals.
if (Current->isAnyIdentifier() ||
Current->is(clang::tok::numeric_constant)) {
if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
SS << PP.getSpelling(*Current);
} else {
SS << "<" << Current->getName() << ">";
@ -641,8 +626,7 @@ void PPCallbacksTracker::appendArgument(const char *Name,
}
// Append a Module argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
const clang::Module *Value) {
void PPCallbacksTracker::appendArgument(const char *Name, const Module *Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
@ -669,8 +653,7 @@ void PPCallbacksTracker::appendFilePathArgument(const char *Name,
}
// Get the raw source string of the range.
llvm::StringRef
PPCallbacksTracker::getSourceString(clang::CharSourceRange Range) {
llvm::StringRef PPCallbacksTracker::getSourceString(CharSourceRange Range) {
const char *B = PP.getSourceManager().getCharacterData(Range.getBegin());
const char *E = PP.getSourceManager().getCharacterData(Range.getEnd());
return llvm::StringRef(B, E - B);

View File

@ -17,7 +17,7 @@
//
// The pp-trace tool supports the following general command line format:
//
// pp-trace [pp-trace options] file... [-- compiler options]
// pp-trace [options] file... [-- compiler options]
//
// Basically you put the pp-trace options first, then the source file or files,
// and then -- followed by any options you want to pass to the compiler.
@ -81,8 +81,8 @@ public:
: Filters(Filters), OS(OS) {}
protected:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
Preprocessor &PP = CI.getPreprocessor();
PP.addPPCallbacks(
make_unique<PPCallbacksTracker>(Filters, CallbackCalls, PP));