annotate clang/lib/AST/DataCollection.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- DataCollection.cpp --------------------------------------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include "clang/AST/DataCollection.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
10 #include "clang/Basic/SourceManager.h"
150
anatofuz
parents:
diff changeset
11 #include "clang/Lex/Lexer.h"
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 namespace clang {
anatofuz
parents:
diff changeset
14 namespace data_collection {
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 /// Prints the macro name that contains the given SourceLocation into the given
anatofuz
parents:
diff changeset
17 /// raw_string_ostream.
anatofuz
parents:
diff changeset
18 static void printMacroName(llvm::raw_string_ostream &MacroStack,
anatofuz
parents:
diff changeset
19 ASTContext &Context, SourceLocation Loc) {
anatofuz
parents:
diff changeset
20 MacroStack << Lexer::getImmediateMacroName(Loc, Context.getSourceManager(),
anatofuz
parents:
diff changeset
21 Context.getLangOpts());
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // Add an empty space at the end as a padding to prevent
anatofuz
parents:
diff changeset
24 // that macro names concatenate to the names of other macros.
anatofuz
parents:
diff changeset
25 MacroStack << " ";
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 /// Returns a string that represents all macro expansions that expanded into the
anatofuz
parents:
diff changeset
29 /// given SourceLocation.
anatofuz
parents:
diff changeset
30 ///
anatofuz
parents:
diff changeset
31 /// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
anatofuz
parents:
diff changeset
32 /// A and B are expanded from the same macros in the same order.
anatofuz
parents:
diff changeset
33 std::string getMacroStack(SourceLocation Loc, ASTContext &Context) {
anatofuz
parents:
diff changeset
34 std::string MacroStack;
anatofuz
parents:
diff changeset
35 llvm::raw_string_ostream MacroStackStream(MacroStack);
anatofuz
parents:
diff changeset
36 SourceManager &SM = Context.getSourceManager();
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 // Iterate over all macros that expanded into the given SourceLocation.
anatofuz
parents:
diff changeset
39 while (Loc.isMacroID()) {
anatofuz
parents:
diff changeset
40 // Add the macro name to the stream.
anatofuz
parents:
diff changeset
41 printMacroName(MacroStackStream, Context, Loc);
anatofuz
parents:
diff changeset
42 Loc = SM.getImmediateMacroCallerLoc(Loc);
anatofuz
parents:
diff changeset
43 }
anatofuz
parents:
diff changeset
44 MacroStackStream.flush();
anatofuz
parents:
diff changeset
45 return MacroStack;
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 } // end namespace data_collection
anatofuz
parents:
diff changeset
49 } // end namespace clang