r213349 - Add dump() for MacroDirective and MacroInfo.
Richard Smith
richard-llvm at metafoo.co.uk
Thu Jul 17 21:54:02 PDT 2014
Author: rsmith
Date: Thu Jul 17 23:54:02 2014
New Revision: 213349
URL: http://llvm.org/viewvc/llvm-project?rev=213349&view=rev
Log:
Add dump() for MacroDirective and MacroInfo.
Modified:
cfe/trunk/include/clang/Lex/MacroInfo.h
cfe/trunk/lib/Lex/MacroInfo.cpp
Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=213349&r1=213348&r2=213349&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Thu Jul 17 23:54:02 2014
@@ -299,6 +299,8 @@ public:
return 0;
}
+ void dump() const;
+
private:
unsigned getDefinitionLengthSlow(SourceManager &SM) const;
@@ -450,6 +452,8 @@ public:
/// this macro was not defined there, return NULL.
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const;
+ void dump() const;
+
static bool classof(const MacroDirective *) { return true; }
};
Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=213349&r1=213348&r2=213349&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Thu Jul 17 23:54:02 2014
@@ -126,6 +126,49 @@ bool MacroInfo::isIdenticalTo(const Macr
return true;
}
+void MacroInfo::dump() const {
+ llvm::raw_ostream &Out = llvm::errs();
+
+ // FIXME: Dump locations.
+ Out << "MacroInfo " << this;
+ if (IsBuiltinMacro) Out << " builtin";
+ if (IsDisabled) Out << " disabled";
+ if (IsUsed) Out << " used";
+ if (IsAllowRedefinitionsWithoutWarning)
+ Out << " allow_redefinitions_without_warning";
+ if (IsWarnIfUnused) Out << " warn_if_unused";
+ if (FromASTFile) Out << " imported";
+ if (UsedForHeaderGuard) Out << " header_guard";
+
+ Out << "\n #define <macro>";
+ if (IsFunctionLike) {
+ Out << "(";
+ for (unsigned I = 0; I != NumArguments; ++I) {
+ if (I) Out << ", ";
+ Out << ArgumentList[I]->getName();
+ }
+ if (IsC99Varargs || IsGNUVarargs) {
+ if (NumArguments && IsC99Varargs) Out << ", ";
+ Out << "...";
+ }
+ Out << ")";
+ }
+
+ for (const Token &Tok : ReplacementTokens) {
+ Out << " ";
+ if (const char *Punc = tok::getPunctuatorSpelling(Tok.getKind()))
+ Out << Punc;
+ else if (const char *Kwd = tok::getKeywordSpelling(Tok.getKind()))
+ Out << Kwd;
+ else if (Tok.is(tok::identifier))
+ Out << Tok.getIdentifierInfo()->getName();
+ else if (Tok.isLiteral() && Tok.getLiteralData())
+ Out << StringRef(Tok.getLiteralData(), Tok.getLength());
+ else
+ Out << Tok.getName();
+ }
+}
+
MacroDirective::DefInfo MacroDirective::getDefinition() {
MacroDirective *MD = this;
SourceLocation UndefLoc;
@@ -161,3 +204,32 @@ MacroDirective::findDirectiveAtLoc(Sourc
}
return DefInfo();
}
+
+void MacroDirective::dump() const {
+ llvm::raw_ostream &Out = llvm::errs();
+
+ switch (getKind()) {
+ case MD_Define: Out << "DefMacroDirective"; break;
+ case MD_Undefine: Out << "UndefMacroDirective"; break;
+ case MD_Visibility: Out << "VisibilityMacroDirective"; break;
+ }
+ Out << " " << this;
+ // FIXME: Dump SourceLocation.
+ if (auto *Prev = getPrevious())
+ Out << " prev " << Prev;
+ if (IsFromPCH) Out << " from_pch";
+ if (IsImported) Out << " imported";
+ if (IsAmbiguous) Out << " ambiguous";
+
+ if (IsPublic)
+ Out << " public";
+ else if (isa<VisibilityMacroDirective>(this))
+ Out << " private";
+
+ if (auto *DMD = dyn_cast<DefMacroDirective>(this)) {
+ if (auto *Info = DMD->getInfo()) {
+ Out << "\n ";
+ Info->dump();
+ }
+ }
+}
More information about the cfe-commits
mailing list