clang  14.0.0git
DependencyDirectivesSourceMinimizer.h
Go to the documentation of this file.
1 //===- clang/Lex/DependencyDirectivesSourceMinimizer.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 is the interface for minimizing header and source files to the
11 /// minimum necessary preprocessor directives for evaluating includes. It
12 /// reduces the source down to #define, #include, #import, @import, and any
13 /// conditional preprocessor logic that contains one of those.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_CLANG_LEX_DEPENDENCY_DIRECTIVES_SOURCE_MINIMIZER_H
18 #define LLVM_CLANG_LEX_DEPENDENCY_DIRECTIVES_SOURCE_MINIMIZER_H
19 
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 
25 namespace clang {
26 
27 class DiagnosticsEngine;
28 
29 namespace minimize_source_to_dependency_directives {
30 
31 /// Represents the kind of preprocessor directive or a module declaration that
32 /// is tracked by the source minimizer in its token output.
33 enum TokenKind {
59 };
60 
61 /// Represents a simplified token that's lexed as part of the source
62 /// minimization. It's used to track the location of various preprocessor
63 /// directives that could potentially have an effect on the depedencies.
64 struct Token {
65  /// The kind of token.
67 
68  /// Offset into the output byte stream of where the directive begins.
69  int Offset = -1;
70 
72 };
73 
74 /// Simplified token range to track the range of a potentially skippable PP
75 /// directive.
76 struct SkippedRange {
77  /// Offset into the output byte stream of where the skipped directive begins.
78  int Offset;
79 
80  /// The number of bytes that can be skipped before the preprocessing must
81  /// resume.
82  int Length;
83 };
84 
85 /// Computes the potential source ranges that can be skipped by the preprocessor
86 /// when skipping a directive like #if, #ifdef or #elsif.
87 ///
88 /// \returns false on success, true on error.
91 
92 } // end namespace minimize_source_to_dependency_directives
93 
94 /// Minimize the input down to the preprocessor directives that might have
95 /// an effect on the dependencies for a compilation unit.
96 ///
97 /// This function deletes all non-preprocessor code, and strips anything that
98 /// can't affect what gets included. It canonicalizes whitespace where
99 /// convenient to stabilize the output against formatting changes in the input.
100 ///
101 /// Clears the output vectors at the beginning of the call.
102 ///
103 /// \returns false on success, true on error. If the diagnostic engine is not
104 /// null, an appropriate error is reported using the given input location
105 /// with the offset that corresponds to the minimizer's current buffer offset.
107  llvm::StringRef Input, llvm::SmallVectorImpl<char> &Output,
109  &Tokens,
110  DiagnosticsEngine *Diags = nullptr,
111  SourceLocation InputSourceLoc = SourceLocation());
112 
113 } // end namespace clang
114 
115 #endif // LLVM_CLANG_LEX_DEPENDENCY_DIRECTIVES_SOURCE_MINIMIZER_H
clang::minimize_source_to_dependency_directives::pp_pragma_push_macro
@ pp_pragma_push_macro
Definition: DependencyDirectivesSourceMinimizer.h:42
clang::minimize_source_to_dependency_directives::pp_ifdef
@ pp_ifdef
Definition: DependencyDirectivesSourceMinimizer.h:47
clang::minimize_source_to_dependency_directives::decl_at_import
@ decl_at_import
Definition: DependencyDirectivesSourceMinimizer.h:54
clang::minimize_source_to_dependency_directives::pp_elifdef
@ pp_elifdef
Definition: DependencyDirectivesSourceMinimizer.h:50
clang::minimize_source_to_dependency_directives::pp_pragma_include_alias
@ pp_pragma_include_alias
Definition: DependencyDirectivesSourceMinimizer.h:44
clang::minimize_source_to_dependency_directives::SkippedRange::Length
int Length
The number of bytes that can be skipped before the preprocessing must resume.
Definition: DependencyDirectivesSourceMinimizer.h:82
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::minimizeSourceToDependencyDirectives
bool minimizeSourceToDependencyDirectives(llvm::StringRef Input, llvm::SmallVectorImpl< char > &Output, llvm::SmallVectorImpl< minimize_source_to_dependency_directives::Token > &Tokens, DiagnosticsEngine *Diags=nullptr, SourceLocation InputSourceLoc=SourceLocation())
Minimize the input down to the preprocessor directives that might have an effect on the dependencies ...
clang::minimize_source_to_dependency_directives::pp_eof
@ pp_eof
Definition: DependencyDirectivesSourceMinimizer.h:58
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::minimize_source_to_dependency_directives::cxx_module_decl
@ cxx_module_decl
Definition: DependencyDirectivesSourceMinimizer.h:56
clang::minimize_source_to_dependency_directives::pp_ifndef
@ pp_ifndef
Definition: DependencyDirectivesSourceMinimizer.h:48
clang::minimize_source_to_dependency_directives::pp_import
@ pp_import
Definition: DependencyDirectivesSourceMinimizer.h:39
clang::minimize_source_to_dependency_directives::pp_define
@ pp_define
Definition: DependencyDirectivesSourceMinimizer.h:37
clang::minimize_source_to_dependency_directives::cxx_export_decl
@ cxx_export_decl
Definition: DependencyDirectivesSourceMinimizer.h:55
clang::minimize_source_to_dependency_directives::pp_pragma_import
@ pp_pragma_import
Definition: DependencyDirectivesSourceMinimizer.h:40
clang::minimize_source_to_dependency_directives::Token::Offset
int Offset
Offset into the output byte stream of where the directive begins.
Definition: DependencyDirectivesSourceMinimizer.h:69
clang::minimize_source_to_dependency_directives::pp_if
@ pp_if
Definition: DependencyDirectivesSourceMinimizer.h:46
clang::minimize_source_to_dependency_directives::cxx_import_decl
@ cxx_import_decl
Definition: DependencyDirectivesSourceMinimizer.h:57
clang::minimize_source_to_dependency_directives::pp_include_next
@ pp_include_next
Definition: DependencyDirectivesSourceMinimizer.h:45
clang::minimize_source_to_dependency_directives::SkippedRange::Offset
int Offset
Offset into the output byte stream of where the skipped directive begins.
Definition: DependencyDirectivesSourceMinimizer.h:78
clang::minimize_source_to_dependency_directives::SkippedRange
Simplified token range to track the range of a potentially skippable PP directive.
Definition: DependencyDirectivesSourceMinimizer.h:76
clang::minimize_source_to_dependency_directives::pp_include
@ pp_include
Definition: DependencyDirectivesSourceMinimizer.h:35
clang::minimize_source_to_dependency_directives::pp_elifndef
@ pp_elifndef
Definition: DependencyDirectivesSourceMinimizer.h:51
clang::minimize_source_to_dependency_directives::pp_else
@ pp_else
Definition: DependencyDirectivesSourceMinimizer.h:52
clang::minimize_source_to_dependency_directives::pp_none
@ pp_none
Definition: DependencyDirectivesSourceMinimizer.h:34
clang::minimize_source_to_dependency_directives::pp_pragma_pop_macro
@ pp_pragma_pop_macro
Definition: DependencyDirectivesSourceMinimizer.h:43
clang::minimize_source_to_dependency_directives::Token::Token
Token(TokenKind K, int Offset)
Definition: DependencyDirectivesSourceMinimizer.h:71
clang::minimize_source_to_dependency_directives::Token::K
TokenKind K
The kind of token.
Definition: DependencyDirectivesSourceMinimizer.h:66
SourceLocation.h
clang::minimize_source_to_dependency_directives::pp_undef
@ pp_undef
Definition: DependencyDirectivesSourceMinimizer.h:38
clang::minimize_source_to_dependency_directives::computeSkippedRanges
bool computeSkippedRanges(ArrayRef< Token > Input, llvm::SmallVectorImpl< SkippedRange > &Range)
Computes the potential source ranges that can be skipped by the preprocessor when skipping a directiv...
Definition: DependencyDirectivesSourceMinimizer.cpp:925
llvm::ArrayRef
Definition: LLVM.h:34
clang::minimize_source_to_dependency_directives::Token
Represents a simplified token that's lexed as part of the source minimization.
Definition: DependencyDirectivesSourceMinimizer.h:64
clang
Definition: CalledOnceCheck.h:17
clang::minimize_source_to_dependency_directives::pp___include_macros
@ pp___include_macros
Definition: DependencyDirectivesSourceMinimizer.h:36
clang::minimize_source_to_dependency_directives::pp_endif
@ pp_endif
Definition: DependencyDirectivesSourceMinimizer.h:53
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::minimize_source_to_dependency_directives::TokenKind
TokenKind
Represents the kind of preprocessor directive or a module declaration that is tracked by the source m...
Definition: DependencyDirectivesSourceMinimizer.h:33
clang::minimize_source_to_dependency_directives::pp_pragma_once
@ pp_pragma_once
Definition: DependencyDirectivesSourceMinimizer.h:41
clang::minimize_source_to_dependency_directives::pp_elif
@ pp_elif
Definition: DependencyDirectivesSourceMinimizer.h:49