1 // Copyright (C) 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEADER_CHECKER_ABI_DUMPER_FAKE_DECL_SOURCE_H_
16 #define HEADER_CHECKER_ABI_DUMPER_FAKE_DECL_SOURCE_H_
17 
18 #include <clang/Frontend/CompilerInstance.h>
19 #include <clang/Sema/ExternalSemaSource.h>
20 #include <clang/Sema/Sema.h>
21 
22 
23 namespace header_checker {
24 namespace dumper {
25 
26 
27 // This class creates fake declarations when the compiler queries for unknown
28 // types.
29 class FakeDeclSource : public clang::ExternalSemaSource {
30  private:
31   const clang::CompilerInstance &ci_;
32 
33   clang::CXXRecordDecl *CreateCXXRecordDecl(const clang::DeclarationName &name,
34                                             clang::DeclContext *decl_context);
35 
36   clang::ClassTemplateDecl *
37   CreateClassTemplateDecl(clang::CXXRecordDecl *cxx_record_decl,
38                           clang::DeclContext *decl_context);
39 
40   clang::NamespaceDecl *CreateNamespaceDecl(const clang::DeclarationName &name,
41                                             clang::DeclContext *decl_context);
42 
43   // This method creates a declaration in decl_context according to the lookup
44   // name kind and the declaration name kind. If this method doesn't support the
45   // kinds, it returns nullptr.
46   clang::NamedDecl *CreateDecl(clang::Sema::LookupNameKind kind,
47                                const clang::DeclarationNameInfo &name,
48                                clang::DeclContext *decl_context);
49 
50   // Return the DeclContext for CorrectTypo to create a declaration in.
51   clang::DeclContext *ResolveDeclContext(clang::DeclContext *member_context,
52                                          clang::Scope *scope,
53                                          clang::NestedNameSpecifier *nns);
54 
55  public:
56   FakeDeclSource(const clang::CompilerInstance &ci);
57 
58   clang::TypoCorrection
59   CorrectTypo(const clang::DeclarationNameInfo &typo, int lookup_kind,
60               clang::Scope *scope, clang::CXXScopeSpec *scope_spec,
61               clang::CorrectionCandidateCallback &ccc,
62               clang::DeclContext *member_context, bool entering_context,
63               const clang::ObjCObjectPointerType *opt) override;
64 
65   bool LookupUnqualified(clang::LookupResult &result,
66                          clang::Scope *scope) override;
67 };
68 
69 
70 }  // namespace dumper
71 }  // namespace header_checker
72 
73 
74 #endif  // HEADER_CHECKER_ABI_DUMPER_FAKE_DECL_SOURCE_H_
75