Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
INPUTS
bindings
cmake
docs
examples
include
lib
ARCMigrate
AST
APValue.cpp
ASTConsumer.cpp
ASTContext.cpp.REMOVED.git-id
ASTDiagnostic.cpp
ASTDumper.cpp
ASTImporter.cpp.REMOVED.git-id
ASTStructuralEquivalence.cpp
ASTTypeTraits.cpp
AttrImpl.cpp
CMakeLists.txt
CXXABI.h
CXXInheritance.cpp
Comment.cpp
CommentBriefParser.cpp
CommentCommandTraits.cpp
CommentLexer.cpp
CommentParser.cpp
CommentSema.cpp
DataCollection.cpp
Decl.cpp.REMOVED.git-id
DeclBase.cpp
DeclCXX.cpp.REMOVED.git-id
DeclFriend.cpp
DeclGroup.cpp
DeclObjC.cpp
DeclOpenMP.cpp
DeclPrinter.cpp
DeclTemplate.cpp
DeclarationName.cpp
Expr.cpp.REMOVED.git-id
ExprCXX.cpp
ExprClassification.cpp
ExprConstant.cpp.REMOVED.git-id
ExprObjC.cpp
ExternalASTMerger.cpp
ExternalASTSource.cpp
InheritViz.cpp
ItaniumCXXABI.cpp
ItaniumMangle.cpp.REMOVED.git-id
Linkage.h
Mangle.cpp
MicrosoftCXXABI.cpp
MicrosoftMangle.cpp.REMOVED.git-id
NSAPI.cpp
NestedNameSpecifier.cpp
ODRHash.cpp
OpenMPClause.cpp
ParentMap.cpp
QualTypeNames.cpp
RawCommentList.cpp
RecordLayout.cpp
RecordLayoutBuilder.cpp.REMOVED.git-id
SelectorLocationsKind.cpp
Stmt.cpp
StmtCXX.cpp
StmtIterator.cpp
StmtObjC.cpp
StmtOpenMP.cpp
StmtPrinter.cpp
StmtProfile.cpp
StmtViz.cpp
TemplateBase.cpp
TemplateName.cpp
Type.cpp.REMOVED.git-id
TypeLoc.cpp
TypePrinter.cpp
VTTBuilder.cpp
VTableBuilder.cpp.REMOVED.git-id
ASTMatchers
Analysis
Basic
CodeGen
CrossTU
Driver
Edit
Format
Frontend
FrontendTool
Headers
Index
Lex
Parse
Rewrite
Sema
Serialization
StaticAnalyzer
Tooling
CMakeLists.txt
runtime
tools
unittests
utils
www
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt
clang-tools-extra
compiler-rt
libcxx
libcxxabi
libunwind
lld
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/clang/lib/AST/DataCollection.cpp
Xamarin Public Jenkins (auto-signing) 468663ddbb Imported Upstream version 6.10.0.49
Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
2020-01-16 16:38:04 +00:00

51 lines
1.8 KiB
C++

//===-- DataCollection.cpp --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/DataCollection.h"
#include "clang/Lex/Lexer.h"
namespace clang {
namespace data_collection {
/// Prints the macro name that contains the given SourceLocation into the given
/// raw_string_ostream.
static void printMacroName(llvm::raw_string_ostream &MacroStack,
ASTContext &Context, SourceLocation Loc) {
MacroStack << Lexer::getImmediateMacroName(Loc, Context.getSourceManager(),
Context.getLangOpts());
// Add an empty space at the end as a padding to prevent
// that macro names concatenate to the names of other macros.
MacroStack << " ";
}
/// Returns a string that represents all macro expansions that expanded into the
/// given SourceLocation.
///
/// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
/// A and B are expanded from the same macros in the same order.
std::string getMacroStack(SourceLocation Loc, ASTContext &Context) {
std::string MacroStack;
llvm::raw_string_ostream MacroStackStream(MacroStack);
SourceManager &SM = Context.getSourceManager();
// Iterate over all macros that expanded into the given SourceLocation.
while (Loc.isMacroID()) {
// Add the macro name to the stream.
printMacroName(MacroStackStream, Context, Loc);
Loc = SM.getImmediateMacroCallerLoc(Loc);
}
MacroStackStream.flush();
return MacroStack;
}
} // end namespace data_collection
} // end namespace clang