[cfe-commits] r94462 - in /cfe/trunk/tools/CIndex: CIndex.cpp CXSourceLocation.h
Ted Kremenek
kremenek at apple.com
Mon Jan 25 14:34:44 PST 2010
Author: kremenek
Date: Mon Jan 25 16:34:44 2010
New Revision: 94462
URL: http://llvm.org/viewvc/llvm-project?rev=94462&view=rev
Log:
Pull functions that translate from CXSourceLocation to SourceLocation (and back) to a separate header file.
Added:
cfe/trunk/tools/CIndex/CXSourceLocation.h
Modified:
cfe/trunk/tools/CIndex/CIndex.cpp
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=94462&r1=94461&r2=94462&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Jan 25 16:34:44 2010
@@ -14,6 +14,7 @@
#include "CIndexer.h"
#include "CXCursor.h"
+#include "CXSourceLocation.h"
#include "clang/Basic/Version.h"
#include "clang/AST/DeclVisitor.h"
@@ -116,34 +117,6 @@
#endif
#endif
-typedef llvm::PointerIntPair<ASTContext *, 1, bool> CXSourceLocationPtr;
-
-/// \brief Translate a Clang source location into a CIndex source location.
-static CXSourceLocation translateSourceLocation(ASTContext &Context,
- SourceLocation Loc,
- bool AtEnd = false) {
- CXSourceLocationPtr Ptr(&Context, AtEnd);
- CXSourceLocation Result = { Ptr.getOpaqueValue(), Loc.getRawEncoding() };
- return Result;
-}
-
-/// \brief Translate a Clang source range into a CIndex source range.
-static CXSourceRange translateSourceRange(ASTContext &Context, SourceRange R) {
- CXSourceRange Result = { &Context,
- R.getBegin().getRawEncoding(),
- R.getEnd().getRawEncoding() };
- return Result;
-}
-
-static SourceLocation translateSourceLocation(CXSourceLocation L) {
- return SourceLocation::getFromRawEncoding(L.int_data);
-}
-
-static SourceRange translateSourceRange(CXSourceRange R) {
- return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data),
- SourceLocation::getFromRawEncoding(R.end_int_data));
-}
-
/// \brief The result of comparing two source ranges.
enum RangeComparisonResult {
/// \brief Either the ranges overlap or one of the ranges is invalid.
@@ -315,7 +288,7 @@
}
RangeComparisonResult CursorVisitor::CompareRegionOfInterest(CXSourceRange CXR) {
- return CompareRegionOfInterest(translateSourceRange(CXR));
+ return CompareRegionOfInterest(cxloc::translateSourceRange(CXR));
}
/// \brief Visit the given cursor and, if requested by the visitor,
@@ -346,7 +319,7 @@
// we're done.
if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) {
CXSourceRange Range = clang_getCursorExtent(Cursor);
- if (translateSourceRange(Range).isInvalid() ||
+ if (cxloc::translateSourceRange(Range).isInvalid() ||
CompareRegionOfInterest(Range))
return false;
}
@@ -1122,7 +1095,7 @@
static_cast<const FileEntry *>(file),
line, column);
- return translateSourceLocation(CXXUnit->getASTContext(), SLoc, false);
+ return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc, false);
}
CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) {
@@ -1139,8 +1112,8 @@
CXFile *file,
unsigned *line,
unsigned *column) {
- CXSourceLocationPtr Ptr
- = CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
+ cxloc::CXSourceLocationPtr Ptr
+ = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
if (!Ptr.getPointer() || Loc.isInvalid()) {
@@ -1411,7 +1384,7 @@
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
- SourceLocation SLoc = translateSourceLocation(Loc);
+ SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
if (SLoc.isValid()) {
SourceRange RegionOfInterest(SLoc,
@@ -1482,24 +1455,24 @@
case CXCursor_ObjCSuperClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCSuperClassRef(C);
- return translateSourceLocation(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCProtocolRef: {
std::pair<ObjCProtocolDecl *, SourceLocation> P
= getCursorObjCProtocolRef(C);
- return translateSourceLocation(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCClassRef(C);
- return translateSourceLocation(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_TypeRef: {
std::pair<TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
- return translateSourceLocation(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
default:
@@ -1509,7 +1482,7 @@
}
if (clang_isExpression(C.kind))
- return translateSourceLocation(getCursorContext(C),
+ return cxloc::translateSourceLocation(getCursorContext(C),
getLocationFromExpr(getCursorExpr(C)));
if (!getCursorDecl(C)) {
@@ -1521,7 +1494,7 @@
SourceLocation Loc = D->getLocation();
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D))
Loc = Class->getClassLoc();
- return translateSourceLocation(D->getASTContext(), Loc);
+ return cxloc::translateSourceLocation(D->getASTContext(), Loc);
}
CXSourceRange clang_getCursorExtent(CXCursor C) {
@@ -1530,25 +1503,25 @@
case CXCursor_ObjCSuperClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCSuperClassRef(C);
- return translateSourceRange(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceRange(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCProtocolRef: {
std::pair<ObjCProtocolDecl *, SourceLocation> P
= getCursorObjCProtocolRef(C);
- return translateSourceRange(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceRange(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCClassRef(C);
- return translateSourceRange(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceRange(P.first->getASTContext(), P.second);
}
case CXCursor_TypeRef: {
std::pair<TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
- return translateSourceRange(P.first->getASTContext(), P.second);
+ return cxloc::translateSourceRange(P.first->getASTContext(), P.second);
}
default:
@@ -1558,11 +1531,11 @@
}
if (clang_isExpression(C.kind))
- return translateSourceRange(getCursorContext(C),
+ return cxloc::translateSourceRange(getCursorContext(C),
getCursorExpr(C)->getSourceRange());
if (clang_isStatement(C.kind))
- return translateSourceRange(getCursorContext(C),
+ return cxloc::translateSourceRange(getCursorContext(C),
getCursorStmt(C)->getSourceRange());
if (!getCursorDecl(C)) {
@@ -1571,7 +1544,7 @@
}
Decl *D = getCursorDecl(C);
- return translateSourceRange(D->getASTContext(), D->getSourceRange());
+ return cxloc::translateSourceRange(D->getASTContext(), D->getSourceRange());
}
CXCursor clang_getCursorReferenced(CXCursor C) {
Added: cfe/trunk/tools/CIndex/CXSourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXSourceLocation.h?rev=94462&view=auto
==============================================================================
--- cfe/trunk/tools/CIndex/CXSourceLocation.h (added)
+++ cfe/trunk/tools/CIndex/CXSourceLocation.h Mon Jan 25 16:34:44 2010
@@ -0,0 +1,58 @@
+//===- CXSourceLocation.h - Routines for manipulating CXSourceLocations ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines routines for manipulating CXSourceLocations.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CXSOURCELOCATION_H
+#define LLVM_CLANG_CXSOURCELOCATION_H
+
+#include "clang-c/Index.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+
+class ASTContext;
+
+namespace cxloc {
+
+typedef llvm::PointerIntPair<ASTContext *, 1, bool> CXSourceLocationPtr;
+
+/// \brief Translate a Clang source location into a CIndex source location.
+static inline CXSourceLocation translateSourceLocation(ASTContext &Context,
+ SourceLocation Loc,
+ bool AtEnd = false) {
+ CXSourceLocationPtr Ptr(&Context, AtEnd);
+ CXSourceLocation Result = { Ptr.getOpaqueValue(), Loc.getRawEncoding() };
+ return Result;
+}
+
+/// \brief Translate a Clang source range into a CIndex source range.
+static inline CXSourceRange translateSourceRange(ASTContext &Context,
+ SourceRange R) {
+ CXSourceRange Result = { &Context,
+ R.getBegin().getRawEncoding(),
+ R.getEnd().getRawEncoding() };
+ return Result;
+}
+
+static inline SourceLocation translateSourceLocation(CXSourceLocation L) {
+ return SourceLocation::getFromRawEncoding(L.int_data);
+}
+
+static inline SourceRange translateSourceRange(CXSourceRange R) {
+ return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data),
+ SourceLocation::getFromRawEncoding(R.end_int_data));
+}
+
+
+}} // end namespace: clang::cxloc
+
+#endif
More information about the cfe-commits
mailing list