summaryrefslogtreecommitdiff
path: root/tools/libclang/CXSourceLocation.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-10 18:54:52 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-10 18:54:52 +0000
commitc6f5c6a58d34833d1fe458a518d5f59462926c7b (patch)
tree4d0ff3cd0e3a1a64017e966b5e127548633bdc60 /tools/libclang/CXSourceLocation.cpp
parent30f3b450c63a99ff5eef24b45cd999f8c2cf9b91 (diff)
downloadclang-c6f5c6a58d34833d1fe458a518d5f59462926c7b.tar.gz
[libclang] Enhance logging capabilities of libclang.
-provide a "raw_ostream'ish" class to make it convenient to output logging info. -use macros to automate a bit the logging functionality inside libclang functions -when logging, print a stack trace if "LIBCLANG_LOGGING=2" environment is set. -add logging to more functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172089 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CXSourceLocation.cpp')
-rw-r--r--tools/libclang/CXSourceLocation.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/tools/libclang/CXSourceLocation.cpp b/tools/libclang/CXSourceLocation.cpp
index 8d88a116e0..cee93b1daa 100644
--- a/tools/libclang/CXSourceLocation.cpp
+++ b/tools/libclang/CXSourceLocation.cpp
@@ -17,9 +17,12 @@
#include "CXSourceLocation.h"
#include "CXString.h"
#include "CXTranslationUnit.h"
+#include "CLog.h"
+#include "llvm/Support/Format.h"
using namespace clang;
using namespace clang::cxstring;
+using namespace clang::cxindex;
//===----------------------------------------------------------------------===//
// Internal predicates on CXSourceLocations.
@@ -122,24 +125,25 @@ CXSourceLocation clang_getLocation(CXTranslationUnit tu,
if (!tu || !file)
return clang_getNullLocation();
- bool Logging = ::getenv("LIBCLANG_LOGGING");
+ LogRef Log = Logger::make(__func__);
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
const FileEntry *File = static_cast<const FileEntry *>(file);
SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
if (SLoc.isInvalid()) {
- if (Logging)
- llvm::errs() << "clang_getLocation(\"" << File->getName()
- << "\", " << line << ", " << column << ") = invalid\n";
+ if (Log)
+ *Log << llvm::format("(\"%s\", %d, %d) = invalid",
+ File->getName(), line, column);
return clang_getNullLocation();
}
- if (Logging)
- llvm::errs() << "clang_getLocation(\"" << File->getName()
- << "\", " << line << ", " << column << ") = "
- << SLoc.getRawEncoding() << "\n";
+ CXSourceLocation CXLoc =
+ cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
+ if (Log)
+ *Log << llvm::format("(\"%s\", %d, %d) = ", File->getName(), line, column)
+ << CXLoc;
- return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
+ return CXLoc;
}
CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,