clang  15.0.0git
FrontendActions.h
Go to the documentation of this file.
1 //===- ExtractAPI/FrontendActions.h -----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the ExtractAPIAction frontend action.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
15 #define LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
16 
17 #include "clang/ExtractAPI/API.h"
19 
20 namespace clang {
21 
22 /// ExtractAPIAction sets up the output file and creates the ExtractAPIVisitor.
24 protected:
25  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
26  StringRef InFile) override;
27 
28 private:
29  /// A representation of the APIs this action extracts.
30  std::unique_ptr<extractapi::APISet> API;
31 
32  /// A stream to the output file of this action.
33  std::unique_ptr<raw_pwrite_stream> OS;
34 
35  /// The product this action is extracting API information for.
36  std::string ProductName;
37 
38  /// The synthesized input buffer that contains all the provided input header
39  /// files.
40  std::unique_ptr<llvm::MemoryBuffer> Buffer;
41 
42  /// The input file originally provided on the command line.
43  ///
44  /// This captures the spelling used to include the file and whether the
45  /// include is quoted or not.
46  SmallVector<std::pair<SmallString<32>, bool>> KnownInputFiles;
47 
48  /// Prepare to execute the action on the given CompilerInstance.
49  ///
50  /// This is called before executing the action on any inputs. This generates a
51  /// single header that includes all of CI's inputs and replaces CI's input
52  /// list with it before actually executing the action.
53  bool PrepareToExecuteAction(CompilerInstance &CI) override;
54 
55  /// Called after executing the action on the synthesized input buffer.
56  ///
57  /// Note: Now that we have gathered all the API definitions to surface we can
58  /// emit them in this callback.
59  void EndSourceFileAction() override;
60 
61  static std::unique_ptr<llvm::raw_pwrite_stream>
62  CreateOutputFile(CompilerInstance &CI, StringRef InFile);
63 
64  static StringRef getInputBufferName() { return "<extract-api-includes>"; }
65 };
66 
67 } // namespace clang
68 
69 #endif // LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
FrontendAction.h
clang::ExtractAPIAction::CreateASTConsumer
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: ExtractAPIConsumer.cpp:875
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
API.h
clang
Definition: CalledOnceCheck.h:17
clang::ASTFrontendAction
Abstract base class to use for AST consumer-based frontend actions.
Definition: FrontendAction.h:243
clang::ExtractAPIAction
ExtractAPIAction sets up the output file and creates the ExtractAPIVisitor.
Definition: FrontendActions.h:23