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