Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Lex/DependencyDirectivesSourceMinimizer.h
Line
Count
Source
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
20
#include "clang/Basic/SourceLocation.h"
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 {
34
  pp_none,
35
  pp_include,
36
  pp___include_macros,
37
  pp_define,
38
  pp_undef,
39
  pp_import,
40
  pp_pragma_import,
41
  pp_pragma_once,
42
  pp_include_next,
43
  pp_if,
44
  pp_ifdef,
45
  pp_ifndef,
46
  pp_elif,
47
  pp_else,
48
  pp_endif,
49
  decl_at_import,
50
  pp_eof,
51
};
52
53
/// Represents a simplified token that's lexed as part of the source
54
/// minimization. It's used to track the location of various preprocessor
55
/// directives that could potentially have an effect on the depedencies.
56
struct Token {
57
  /// The kind of token.
58
  TokenKind K = pp_none;
59
60
  /// Offset into the output byte stream of where the directive begins.
61
  int Offset = -1;
62
63
197
  Token(TokenKind K, int Offset) : K(K), Offset(Offset) {}
64
};
65
66
} // end namespace minimize_source_to_dependency_directives
67
68
/// Minimize the input down to the preprocessor directives that might have
69
/// an effect on the dependencies for a compilation unit.
70
///
71
/// This function deletes all non-preprocessor code, and strips anything that
72
/// can't affect what gets included. It canonicalizes whitespace where
73
/// convenient to stabilize the output against formatting changes in the input.
74
///
75
/// Clears the output vectors at the beginning of the call.
76
///
77
/// \returns false on success, true on error. If the diagnostic engine is not
78
/// null, an appropriate error is reported using the given input location
79
/// with the offset that corresponds to the minimizer's current buffer offset.
80
bool minimizeSourceToDependencyDirectives(
81
    llvm::StringRef Input, llvm::SmallVectorImpl<char> &Output,
82
    llvm::SmallVectorImpl<minimize_source_to_dependency_directives::Token>
83
        &Tokens,
84
    DiagnosticsEngine *Diags = nullptr,
85
    SourceLocation InputSourceLoc = SourceLocation());
86
87
} // end namespace clang
88
89
#endif // LLVM_CLANG_LEX_DEPENDENCY_DIRECTIVES_SOURCE_MINIMIZER_H