• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2016 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 #include "dumper/frontend_action.h"
16 
17 #include "dumper/ast_processing.h"
18 #include "dumper/diagnostic_consumer.h"
19 #include "dumper/fake_decl_source.h"
20 #include "repr/ir_representation.h"
21 #include "utils/header_abi_util.h"
22 
23 #include <clang/AST/ASTConsumer.h>
24 #include <clang/Frontend/CompilerInstance.h>
25 #include <clang/Lex/Preprocessor.h>
26 
27 #include <llvm/ADT/STLExtras.h>
28 
29 
30 namespace header_checker {
31 namespace dumper {
32 
33 
HeaderCheckerFrontendAction(HeaderCheckerOptions & options)34 HeaderCheckerFrontendAction::HeaderCheckerFrontendAction(
35     HeaderCheckerOptions &options)
36     : options_(options) {}
37 
38 std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance & ci,llvm::StringRef header_file)39 HeaderCheckerFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci,
40                                                llvm::StringRef header_file) {
41   // Create AST consumers.
42   return llvm::make_unique<HeaderASTConsumer>(&ci, options_);
43 }
44 
BeginInvocation(clang::CompilerInstance & ci)45 bool HeaderCheckerFrontendAction::BeginInvocation(clang::CompilerInstance &ci) {
46   if (options_.suppress_errors_) {
47     ci.getFrontendOpts().SkipFunctionBodies = true;
48     clang::DiagnosticsEngine &diagnostics = ci.getDiagnostics();
49     diagnostics.setClient(
50         new HeaderCheckerDiagnosticConsumer(diagnostics.takeClient()),
51         /* ShouldOwnClient */ true);
52   }
53   return true;
54 }
55 
BeginSourceFileAction(clang::CompilerInstance & ci)56 bool HeaderCheckerFrontendAction::BeginSourceFileAction(
57     clang::CompilerInstance &ci) {
58   if (options_.suppress_errors_) {
59     ci.setExternalSemaSource(new FakeDeclSource(ci));
60     ci.getPreprocessor().SetSuppressIncludeNotFoundError(true);
61   }
62   return true;
63 }
64 
65 
66 }  // dumper
67 }  // header_checker
68