clang  9.0.0
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 {
50 };
51 
52 /// Represents a simplified token that's lexed as part of the source
53 /// minimization. It's used to track the location of various preprocessor
54 /// directives that could potentially have an effect on the depedencies.
55 struct Token {
56  /// The kind of token.
58 
59  /// Offset into the output byte stream of where the directive begins.
60  int Offset = -1;
61 
62  Token(TokenKind K, int Offset) : K(K), Offset(Offset) {}
63 };
64 
65 } // end namespace minimize_source_to_dependency_directives
66 
67 /// Minimize the input down to the preprocessor directives that might have
68 /// an effect on the dependencies for a compilation unit.
69 ///
70 /// This function deletes all non-preprocessor code, and strips anything that
71 /// can't affect what gets included. It canonicalizes whitespace where
72 /// convenient to stabilize the output against formatting changes in the input.
73 ///
74 /// Clears the output vectors at the beginning of the call.
75 ///
76 /// \returns false on success, true on error. If the diagnostic engine is not
77 /// null, an appropriate error is reported using the given input location
78 /// with the offset that corresponds to the minimizer's current buffer offset.
80  llvm::StringRef Input, llvm::SmallVectorImpl<char> &Output,
82  &Tokens,
83  DiagnosticsEngine *Diags = nullptr,
84  SourceLocation InputSourceLoc = SourceLocation());
85 
86 } // end namespace clang
87 
88 #endif // LLVM_CLANG_LEX_DEPENDENCY_DIRECTIVES_SOURCE_MINIMIZER_H
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 ...
int Offset
Offset into the output byte stream of where the directive begins.
Represents a simplified token that&#39;s lexed as part of the source minimization.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
TokenKind
Represents the kind of preprocessor directive or a module declaration that is tracked by the source m...
Encodes a location in the source.
Dataflow Directional Tag Classes.
Defines the clang::SourceLocation class and associated facilities.