blob: 5b7b48fa9010b3987b2f52cb4494c3c8037dd8c4 [file] [log] [blame]
Greg Claytond8b65022011-01-17 04:19:51 +00001//===-- ClangExternalASTSourceCallbacks.cpp ---------------------*- C++ -*-===//
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#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15
16// Clang headers like to use NDEBUG inside of them to enable/disable debug
17// releated features using "#ifndef NDEBUG" preprocessor blocks to do one thing
18// or another. This is bad because it means that if clang was built in release
19// mode, it assumes that you are building in release mode which is not always
20// the case. You can end up with functions that are defined as empty in header
21// files when NDEBUG is not defined, and this can cause link errors with the
22// clang .a files that you have since you might be missing functions in the .a
23// file. So we have to define NDEBUG when including clang headers to avoid any
24// mismatches. This is covered by rdar://problem/8691220
25
26#ifndef NDEBUG
27#define LLDB_DEFINED_NDEBUG_FOR_CLANG
28#define NDEBUG
29// Need to include assert.h so it is as clang would expect it to be (disabled)
30#include <assert.h>
31#endif
32
33#include "clang/AST/DeclBase.h"
34#include "clang/AST/DeclarationName.h"
35
36#ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
37#undef NDEBUG
38#undef LLDB_DEFINED_NDEBUG_FOR_CLANG
39// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
40#include <assert.h>
41#endif
42
43#include "lldb/Core/Log.h"
44
45using namespace clang;
46using namespace lldb_private;
47
48clang::DeclContextLookupResult
49ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName
50(
51 const clang::DeclContext *decl_ctx,
52 clang::DeclarationName clang_decl_name
53)
54{
Greg Claytone6d72ca2011-06-25 00:44:06 +000055 if (m_callback_find_by_name)
56 {
57 llvm::SmallVector <clang::NamedDecl *, 3> results;
58
59 m_callback_find_by_name (m_callback_baton, decl_ctx, clang_decl_name, &results);
60
61 DeclContextLookupResult lookup_result (SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, results));
62
63 return lookup_result;
64 }
65
Greg Claytond8b65022011-01-17 04:19:51 +000066 std::string decl_name (clang_decl_name.getAsString());
67
68 switch (clang_decl_name.getNameKind()) {
69 // Normal identifiers.
70 case clang::DeclarationName::Identifier:
71 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"Identifier\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
72 if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0)
73 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
74 break;
75
76 case clang::DeclarationName::ObjCZeroArgSelector:
77 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"ObjCZeroArgSelector\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
78 return DeclContext::lookup_result();
79 break;
80
81 case clang::DeclarationName::ObjCOneArgSelector:
82 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"ObjCOneArgSelector\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
83 return DeclContext::lookup_result();
84 break;
85
86 case clang::DeclarationName::ObjCMultiArgSelector:
87 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"ObjCMultiArgSelector\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
88 return DeclContext::lookup_result();
89 break;
90
91 case clang::DeclarationName::CXXConstructorName:
92 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXConstructorName\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
93 return DeclContext::lookup_result();
94 break;
95
96 case clang::DeclarationName::CXXDestructorName:
97 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXDestructorName\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
98 return DeclContext::lookup_result();
99 break;
100
101 case clang::DeclarationName::CXXConversionFunctionName:
102 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXConversionFunctionName\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
103 return DeclContext::lookup_result();
104 break;
105
106 case clang::DeclarationName::CXXOperatorName:
107 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXOperatorName\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
108 return DeclContext::lookup_result();
109 break;
110
111 case clang::DeclarationName::CXXLiteralOperatorName:
112 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXLiteralOperatorName\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
113 return DeclContext::lookup_result();
114 break;
115
116 case clang::DeclarationName::CXXUsingDirective:
117 //printf ("ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(decl_ctx = %p, decl_name = { kind = \"CXXUsingDirective\", name = \"%s\")\n", decl_ctx, decl_name.c_str());
118 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
119 }
120
121 return DeclContext::lookup_result();
122}
123
124void
125ClangExternalASTSourceCallbacks::CompleteType (TagDecl *tag_decl)
126{
127 if (m_callback_tag_decl)
128 m_callback_tag_decl (m_callback_baton, tag_decl);
129}
130
131void
132ClangExternalASTSourceCallbacks::CompleteType (ObjCInterfaceDecl *objc_decl)
133{
134 if (m_callback_objc_decl)
135 m_callback_objc_decl (m_callback_baton, objc_decl);
136}