Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 1 | //===---------------- SemaCodeComplete.cpp - Code Completion ----*- 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 | // This file defines the code-completion semantic actions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "Sema.h" |
| 14 | #include "clang/Sema/CodeCompleteConsumer.h" |
| 15 | |
| 16 | using namespace clang; |
| 17 | |
| 18 | /// \brief Set the code-completion consumer for semantic analysis. |
| 19 | void Sema::setCodeCompleteConsumer(CodeCompleteConsumer *CCC) { |
| 20 | assert(((CodeCompleter != 0) != (CCC != 0)) && |
| 21 | "Already set or cleared a code-completion consumer?"); |
| 22 | CodeCompleter = CCC; |
| 23 | } |
| 24 | |
| 25 | void Sema::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE, |
| 26 | SourceLocation OpLoc, |
| 27 | bool IsArrow) { |
| 28 | if (!BaseE || !CodeCompleter) |
| 29 | return; |
| 30 | |
| 31 | Expr *Base = static_cast<Expr *>(BaseE); |
| 32 | QualType BaseType = Base->getType(); |
| 33 | |
| 34 | CodeCompleter->CodeCompleteMemberReferenceExpr(S, BaseType, IsArrow); |
| 35 | } |
| 36 | |
Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 37 | void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) { |
| 38 | if (!CodeCompleter) |
| 39 | return; |
| 40 | |
| 41 | TagDecl::TagKind TK; |
| 42 | switch ((DeclSpec::TST)TagSpec) { |
| 43 | case DeclSpec::TST_enum: |
| 44 | TK = TagDecl::TK_enum; |
| 45 | break; |
| 46 | |
| 47 | case DeclSpec::TST_union: |
| 48 | TK = TagDecl::TK_union; |
| 49 | break; |
| 50 | |
| 51 | case DeclSpec::TST_struct: |
| 52 | TK = TagDecl::TK_struct; |
| 53 | break; |
| 54 | |
| 55 | case DeclSpec::TST_class: |
| 56 | TK = TagDecl::TK_class; |
| 57 | break; |
| 58 | |
| 59 | default: |
| 60 | assert(false && "Unknown type specifier kind in CodeCompleteTag"); |
| 61 | return; |
| 62 | } |
| 63 | CodeCompleter->CodeCompleteTag(S, TK); |
| 64 | } |
| 65 | |
Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 66 | void Sema::CodeCompleteQualifiedId(Scope *S, const CXXScopeSpec &SS, |
| 67 | bool EnteringContext) { |
| 68 | if (!SS.getScopeRep() || !CodeCompleter) |
| 69 | return; |
| 70 | |
| 71 | CodeCompleter->CodeCompleteQualifiedId(S, |
| 72 | (NestedNameSpecifier *)SS.getScopeRep(), |
| 73 | EnteringContext); |
| 74 | } |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 75 | |
| 76 | void Sema::CodeCompleteUsing(Scope *S) { |
| 77 | if (!CodeCompleter) |
| 78 | return; |
| 79 | |
| 80 | CodeCompleter->CodeCompleteUsing(S); |
| 81 | } |
| 82 | |
| 83 | void Sema::CodeCompleteUsingDirective(Scope *S) { |
| 84 | if (!CodeCompleter) |
| 85 | return; |
| 86 | |
| 87 | CodeCompleter->CodeCompleteUsingDirective(S); |
| 88 | } |
| 89 | |
| 90 | void Sema::CodeCompleteNamespaceDecl(Scope *S) { |
| 91 | if (!CodeCompleter) |
| 92 | return; |
| 93 | |
| 94 | CodeCompleter->CodeCompleteNamespaceDecl(S); |
| 95 | } |
| 96 | |
| 97 | void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) { |
| 98 | if (!CodeCompleter) |
| 99 | return; |
| 100 | |
| 101 | CodeCompleter->CodeCompleteNamespaceAliasDecl(S); |
| 102 | } |
| 103 | |
| 104 | |