Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 16 | extern "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 Kremenek | 3172383 | 2010-01-11 23:56:39 +0000 | [diff] [blame^] | 33 | |
| 34 | static inline Entity GetEntity(const CXEntity &E) { |
| 35 | return Entity::getFromOpaquePtr(E.data); |
| 36 | } |
| 37 | |
| 38 | static inline ASTUnit *GetTranslationUnit(CXTranslationUnit TU) { |
| 39 | return (ASTUnit*) TU; |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Ted Kremenek | 3172383 | 2010-01-11 23:56:39 +0000 | [diff] [blame^] | 42 | static inline ASTContext &GetASTContext(CXTranslationUnit TU) { |
| 43 | return GetTranslationUnit(TU)->getASTContext(); |
| 44 | } |
| 45 | |
| 46 | static inline CXEntity NullCXEntity() { |
| 47 | CXEntity CE; |
| 48 | CE.index = NULL; |
| 49 | CE.data = NULL; |
| 50 | return CE; |
| 51 | } |
| 52 | |
| 53 | static 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 | |
| 60 | static 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. |
| 66 | CXDecl clang_getDeclaration(CXEntity CE, CXTranslationUnit TU) { |
| 67 | return (CXDecl) GetEntity(CE).getDecl(GetASTContext(TU)); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | CXEntity 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 Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 77 | const char *clang_getUSR(CXEntity) { |
| 78 | return ""; |
| 79 | } |
| 80 | |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 81 | } // end extern "C" |