clang
8.0.0
include
clang
AST
DataCollection.h
Go to the documentation of this file.
1
//===--- DatatCollection.h --------------------------------------*- C++ -*-===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
/// \file
10
/// This file declares helper methods for collecting data from AST nodes.
11
///
12
/// To collect data from Stmt nodes, subclass ConstStmtVisitor and include
13
/// StmtDataCollectors.inc after defining the macros that you need. This
14
/// provides data collection implementations for most Stmt kinds. Note
15
/// that the code requires some conditions to be met:
16
///
17
/// - There must be a method addData(const T &Data) that accepts strings,
18
/// integral types as well as QualType. All data is forwarded using
19
/// to this method.
20
/// - The ASTContext of the Stmt must be accessible by the name Context.
21
///
22
/// It is also possible to override individual visit methods. Have a look at
23
/// the DataCollector in lib/Analysis/CloneDetection.cpp for a usage example.
24
///
25
//===----------------------------------------------------------------------===//
26
27
#ifndef LLVM_CLANG_AST_DATACOLLECTION_H
28
#define LLVM_CLANG_AST_DATACOLLECTION_H
29
30
#include "
clang/AST/ASTContext.h
"
31
32
namespace
clang
{
33
namespace
data_collection {
34
35
/// Returns a string that represents all macro expansions that expanded into the
36
/// given SourceLocation.
37
///
38
/// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
39
/// A and B are expanded from the same macros in the same order.
40
std::string
getMacroStack
(
SourceLocation
Loc,
ASTContext
&Context);
41
42
/// Utility functions for implementing addData() for a consumer that has a
43
/// method update(StringRef)
44
template
<
class
T>
45
void
addDataToConsumer
(T &DataConsumer, llvm::StringRef Str) {
46
DataConsumer.update(Str);
47
}
48
49
template
<
class
T>
void
addDataToConsumer
(T &DataConsumer,
const
QualType
&QT) {
50
addDataToConsumer
(DataConsumer, QT.
getAsString
());
51
}
52
53
template
<
class
T,
class
Type>
54
typename
std::enable_if<
55
std::is_integral<Type>::value || std::is_enum<Type>::value ||
56
std::is_convertible<Type, size_t>::value
// for llvm::hash_code
57
>
::type
58
addDataToConsumer
(T &DataConsumer,
Type
Data) {
59
DataConsumer.update(StringRef(reinterpret_cast<char *>(&Data),
sizeof
(Data)));
60
}
61
62
}
// end namespace data_collection
63
}
// end namespace clang
64
65
#endif // LLVM_CLANG_AST_DATACOLLECTION_H
ASTContext.h
Defines the clang::ASTContext interface.
clang::QualType
A (possibly-)qualified type.
Definition:
Type.h:638
clang::Type
The base class of the type hierarchy.
Definition:
Type.h:1407
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:155
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:34
clang::SourceLocation
Encodes a location in the source.
Definition:
SourceLocation.h:88
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:45
clang
Dataflow Directional Tag Classes.
Definition:
CFGReachabilityAnalysis.h:22
type
clang::QualType::getAsString
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition:
Type.h:971
Generated on Fri Mar 8 2019 13:35:37 for clang by
1.8.13