clang 19.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 and WrappingExtractAPIAction frontend
11/// actions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
16#define LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
17
20
21namespace clang {
22
23/// ExtractAPIAction sets up the output file and creates the ExtractAPIVisitor.
25 private ExtractAPIActionBase {
26protected:
27 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
28 StringRef InFile) override;
29
30private:
31
32 /// The input file originally provided on the command line.
33 ///
34 /// This captures the spelling used to include the file and whether the
35 /// include is quoted or not.
36 SmallVector<std::pair<SmallString<32>, bool>> KnownInputFiles;
37
38 /// Prepare to execute the action on the given CompilerInstance.
39 ///
40 /// This is called before executing the action on any inputs. This generates a
41 /// single header that includes all of CI's inputs and replaces CI's input
42 /// list with it before actually executing the action.
43 bool PrepareToExecuteAction(CompilerInstance &CI) override;
44
45 /// Called after executing the action on the synthesized input buffer.
46 ///
47 /// Note: Now that we have gathered all the API definitions to surface we can
48 /// emit them in this callback.
49 void EndSourceFileAction() override;
50
51 static StringRef getInputBufferName() { return "<extract-api-includes>"; }
52};
53
54/// Wrap ExtractAPIAction on top of a pre-existing action
55///
56/// Used when the ExtractAPI action needs to be executed as a side effect of a
57/// regular compilation job. Unlike ExtarctAPIAction, this is meant to be used
58/// on regular source files ( .m , .c files) instead of header files
60 private ExtractAPIActionBase {
61public:
62 WrappingExtractAPIAction(std::unique_ptr<FrontendAction> WrappedAction)
64
65protected:
66 /// Create ExtractAPI consumer multiplexed on another consumer.
67 ///
68 /// This allows us to execute ExtractAPI action while on top of
69 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
70 StringRef InFile) override;
71
72private:
73 /// Flag to check if the wrapper front end action's consumer is
74 /// craeted or not
75 bool CreatedASTConsumer = false;
76
77 void EndSourceFile() override { FrontendAction::EndSourceFile(); }
78
79 /// Called after executing the action on the synthesized input buffer.
80 ///
81 /// Executes both Wrapper and ExtractAPIBase end source file
82 /// actions. This is the place where all the gathered symbol graph
83 /// information is emited.
84 void EndSourceFileAction() override;
85};
86
87} // namespace clang
88
89#endif // LLVM_CLANG_EXTRACTAPI_FRONTEND_ACTIONS_H
This file defines the ExtractAPIActionBase class.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
Abstract base class to use for AST consumer-based frontend actions.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Base class to be used by front end actions to generate ExtarctAPI info.
ExtractAPIAction sets up the output file and creates the ExtractAPIVisitor.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
virtual void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
A frontend action which simply wraps some other runtime-specified frontend action.
std::unique_ptr< FrontendAction > WrappedAction
Wrap ExtractAPIAction on top of a pre-existing action.
WrappingExtractAPIAction(std::unique_ptr< FrontendAction > WrappedAction)
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create ExtractAPI consumer multiplexed on another consumer.
The JSON file list parser is used to communicate input to InstallAPI.
Definition: Format.h:5394