Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/AST/DataCollection.cpp
Line
Count
Source
1
//===-- DataCollection.cpp --------------------------------------*- 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
#include "clang/AST/DataCollection.h"
10
11
#include "clang/Lex/Lexer.h"
12
13
namespace clang {
14
namespace data_collection {
15
16
/// Prints the macro name that contains the given SourceLocation into the given
17
/// raw_string_ostream.
18
static void printMacroName(llvm::raw_string_ostream &MacroStack,
19
6.07k
                           ASTContext &Context, SourceLocation Loc) {
20
6.07k
  MacroStack << Lexer::getImmediateMacroName(Loc, Context.getSourceManager(),
21
6.07k
                                             Context.getLangOpts());
22
6.07k
23
6.07k
  // Add an empty space at the end as a padding to prevent
24
6.07k
  // that macro names concatenate to the names of other macros.
25
6.07k
  MacroStack << " ";
26
6.07k
}
27
28
/// Returns a string that represents all macro expansions that expanded into the
29
/// given SourceLocation.
30
///
31
/// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
32
/// A and B are expanded from the same macros in the same order.
33
20.2k
std::string getMacroStack(SourceLocation Loc, ASTContext &Context) {
34
20.2k
  std::string MacroStack;
35
20.2k
  llvm::raw_string_ostream MacroStackStream(MacroStack);
36
20.2k
  SourceManager &SM = Context.getSourceManager();
37
20.2k
38
20.2k
  // Iterate over all macros that expanded into the given SourceLocation.
39
26.2k
  while (Loc.isMacroID()) {
40
6.07k
    // Add the macro name to the stream.
41
6.07k
    printMacroName(MacroStackStream, Context, Loc);
42
6.07k
    Loc = SM.getImmediateMacroCallerLoc(Loc);
43
6.07k
  }
44
20.2k
  MacroStackStream.flush();
45
20.2k
  return MacroStack;
46
20.2k
}
47
48
} // end namespace data_collection
49
} // end namespace clang