blob: e53c0c66f1797ea96b09a1463cb144a75adf945e [file] [log] [blame]
Ted Kremenek1b6869a2010-01-05 22:06:45 +00001//===- CIndexUSR.cpp - Clang-C Source Indexing Library --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the generation and use of USRs from CXEntities.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CIndexer.h"
15
16extern "C" {
17
18// Some notes on CXEntity:
19//
20// - Since the 'ordinary' namespace includes functions, data, typedefs,
21// ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one
22// entity for 2 different types). For example:
23//
24// module1.m: @interface Foo @end Foo *x;
25// module2.m: void Foo(int);
26//
27// - Since the unique name spans translation units, static data/functions
28// within a CXTranslationUnit are *not* currently represented by entities.
29// As a result, there will be no entity for the following:
30//
31// module.m: static void Foo() { }
32//
Ted Kremenek31723832010-01-11 23:56:39 +000033
34static inline Entity GetEntity(const CXEntity &E) {
35 return Entity::getFromOpaquePtr(E.data);
36}
37
38static inline ASTUnit *GetTranslationUnit(CXTranslationUnit TU) {
39 return (ASTUnit*) TU;
Ted Kremenek1b6869a2010-01-05 22:06:45 +000040}
41
Ted Kremenek31723832010-01-11 23:56:39 +000042static inline ASTContext &GetASTContext(CXTranslationUnit TU) {
43 return GetTranslationUnit(TU)->getASTContext();
44}
45
46static inline CXEntity NullCXEntity() {
47 CXEntity CE;
48 CE.index = NULL;
49 CE.data = NULL;
50 return CE;
51}
52
53static inline CXEntity MakeEntity(CXIndex CIdx, const Entity &E) {
54 CXEntity CE;
55 CE.index = CIdx;
56 CE.data = E.getAsOpaquePtr();
57 return CE;
58}
59
60static inline Program &GetProgram(CXIndex CIdx) {
61 return ((CIndexer*) CIdx)->getProgram();
62}
63
64/// clang_getDeclaration() maps from a CXEntity to the matching CXDecl (if any)
65/// in a specified translation unit.
66CXDecl clang_getDeclaration(CXEntity CE, CXTranslationUnit TU) {
67 return (CXDecl) GetEntity(CE).getDecl(GetASTContext(TU));
68}
69
70
71CXEntity clang_getEntityFromDecl(CXIndex CIdx, CXDecl CE) {
72 if (Decl *D = (Decl *) CE)
73 return MakeEntity(CIdx, Entity::get(D, GetProgram(CIdx)));
74 return NullCXEntity();
75}
76
Ted Kremenek1b6869a2010-01-05 22:06:45 +000077const char *clang_getUSR(CXEntity) {
78 return "";
79}
80
Ted Kremenek1b6869a2010-01-05 22:06:45 +000081} // end extern "C"