blob: 996c20529ac98f87e01cb880b7f2118aaeb5be18 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001/*
2 * ClangASTSource.cpp
3 * lldb
4 *
5 * Created by John McCall on 6/1/10.
6 * Copyright 2010 Apple. All rights reserved.
7 *
8 */
9
10#define NO_RTTI
11
12#include "clang/AST/ASTContext.h"
13#include "lldb/Expression/ClangASTSource.h"
14#include "lldb/Expression/ClangExpression.h"
15#include "lldb/Expression/ClangExpressionDeclMap.h"
16
17using namespace clang;
18using namespace lldb_private;
19
20ClangASTSource::~ClangASTSource() {}
21
22void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
23 // Tell Sema to ask us when looking into the translation unit's decl.
24 Context.getTranslationUnitDecl()->setHasExternalVisibleStorage();
25 Context.getTranslationUnitDecl()->setHasExternalLexicalStorage();
26}
27
28// These are only required for AST source that want to lazily load
29// the declarations (or parts thereof) that they return.
30Decl *ClangASTSource::GetExternalDecl(uint32_t) { return 0; }
31Stmt *ClangASTSource::GetExternalDeclStmt(uint64_t) { return 0; }
32
33// These are also optional, although it might help with ObjC
34// debugging if we have respectable signatures. But a more
35// efficient interface (that didn't require scanning all files
36// for method signatures!) might help.
37Selector ClangASTSource::GetExternalSelector(uint32_t) { return Selector(); }
38uint32_t ClangASTSource::GetNumExternalSelectors() { return 0; }
39
40// The core lookup interface.
41DeclContext::lookup_result ClangASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
42 switch (Name.getNameKind()) {
43 // Normal identifiers.
44 case DeclarationName::Identifier:
45 break;
46
47 // Operator names. Not important for now.
48 case DeclarationName::CXXOperatorName:
49 case DeclarationName::CXXLiteralOperatorName:
50 return DeclContext::lookup_result();
51
52 // Using directives found in this context.
53 // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
54 case DeclarationName::CXXUsingDirective:
55 return SetNoExternalVisibleDeclsForName(DC, Name);
56
57 // These aren't looked up like this.
58 case DeclarationName::ObjCZeroArgSelector:
59 case DeclarationName::ObjCOneArgSelector:
60 case DeclarationName::ObjCMultiArgSelector:
61 return DeclContext::lookup_result();
62
63 // These aren't possible in the global context.
64 case DeclarationName::CXXConstructorName:
65 case DeclarationName::CXXDestructorName:
66 case DeclarationName::CXXConversionFunctionName:
67 return DeclContext::lookup_result();
68 }
69
70 llvm::SmallVector<NamedDecl*, 4> Decls;
71
72 NameSearchContext NSC(*this, Decls, Name, DC);
73
74 DeclMap.GetDecls(NSC, Name.getAsString().c_str());
75 return SetExternalVisibleDeclsForName(DC, Name, Decls);
76}
77
78// This is used to support iterating through an entire lexical context,
79// which isn't something the debugger should ever need to do.
80bool ClangASTSource::FindExternalLexicalDecls(const DeclContext *DC, llvm::SmallVectorImpl<Decl*> &Decls) {
81 // true is for error, that's good enough for me
82 return true;
83}
84
85clang::ASTContext *NameSearchContext::GetASTContext() {
86 return &ASTSource.Context;
87}
88
89clang::NamedDecl *NameSearchContext::AddVarDecl(void *type) {
90 clang::NamedDecl *Decl = VarDecl::Create(ASTSource.Context,
91 const_cast<DeclContext*>(DC),
92 SourceLocation(),
93 Name.getAsIdentifierInfo(),
94 QualType::getFromOpaquePtr(type),
95 0,
96 VarDecl::Static,
97 VarDecl::Static);
98 Decls.push_back(Decl);
99
100 return Decl;
101}