clang
20.0.0git
include
clang
AST
DataCollection.h
Go to the documentation of this file.
1
//===--- DatatCollection.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
/// \file
9
/// This file declares helper methods for collecting data from AST nodes.
10
///
11
/// To collect data from Stmt nodes, subclass ConstStmtVisitor and include
12
/// StmtDataCollectors.inc after defining the macros that you need. This
13
/// provides data collection implementations for most Stmt kinds. Note
14
/// that the code requires some conditions to be met:
15
///
16
/// - There must be a method addData(const T &Data) that accepts strings,
17
/// integral types as well as QualType. All data is forwarded using
18
/// to this method.
19
/// - The ASTContext of the Stmt must be accessible by the name Context.
20
///
21
/// It is also possible to override individual visit methods. Have a look at
22
/// the DataCollector in lib/Analysis/CloneDetection.cpp for a usage example.
23
///
24
//===----------------------------------------------------------------------===//
25
26
#ifndef LLVM_CLANG_AST_DATACOLLECTION_H
27
#define LLVM_CLANG_AST_DATACOLLECTION_H
28
29
#include "
clang/AST/ASTContext.h
"
30
31
namespace
clang
{
32
namespace
data_collection {
33
34
/// Returns a string that represents all macro expansions that expanded into the
35
/// given SourceLocation.
36
///
37
/// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
38
/// A and B are expanded from the same macros in the same order.
39
std::string
getMacroStack
(
SourceLocation
Loc
,
ASTContext
&Context);
40
41
/// Utility functions for implementing addData() for a consumer that has a
42
/// method update(StringRef)
43
template
<
class
T>
44
void
addDataToConsumer
(
T
&DataConsumer, llvm::StringRef Str) {
45
DataConsumer.update(Str);
46
}
47
48
template
<
class
T>
void
addDataToConsumer
(
T
&DataConsumer,
const
QualType
&QT) {
49
addDataToConsumer
(DataConsumer, QT.
getAsString
());
50
}
51
52
template
<
class
T,
class
Type>
53
std::enable_if_t<std::is_integral<Type>::value || std::is_enum<Type>::value ||
54
std::is_convertible<Type, size_t>::value
// for llvm::hash_code
55
>
56
addDataToConsumer
(
T
&DataConsumer,
Type
Data
) {
57
DataConsumer.update(StringRef(
reinterpret_cast<
char
*
>
(&
Data
),
sizeof
(
Data
)));
58
}
59
60
}
// end namespace data_collection
61
}
// end namespace clang
62
63
#endif
// LLVM_CLANG_AST_DATACOLLECTION_H
ASTContext.h
Defines the clang::ASTContext interface.
Loc
SourceLocation Loc
Definition:
SemaObjC.cpp:759
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:187
clang::QualType
A (possibly-)qualified type.
Definition:
Type.h:941
clang::QualType::getAsString
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition:
Type.h:1339
clang::SourceLocation
Encodes a location in the source.
Definition:
SourceLocation.h:88
clang::Type
The base class of the type hierarchy.
Definition:
Type.h:1829
clang::data_collection::addDataToConsumer
void addDataToConsumer(T &DataConsumer, llvm::StringRef Str)
Utility functions for implementing addData() for a consumer that has a method update(StringRef)
Definition:
DataCollection.h:44
clang::data_collection::getMacroStack
std::string getMacroStack(SourceLocation Loc, ASTContext &Context)
Returns a string that represents all macro expansions that expanded into the given SourceLocation.
Definition:
DataCollection.cpp:33
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
clang::OpenACCDirectiveKind::Data
@ Data
clang::T
const FunctionProtoType * T
Definition:
RecursiveASTVisitor.h:1359
Generated on Fri Nov 22 2024 09:47:01 for clang by
1.9.6