|
|
|||
File indexing completed on 2026-05-10 08:36:30
0001 //===--- DatatCollection.h --------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// \file 0009 /// This file declares helper methods for collecting data from AST nodes. 0010 /// 0011 /// To collect data from Stmt nodes, subclass ConstStmtVisitor and include 0012 /// StmtDataCollectors.inc after defining the macros that you need. This 0013 /// provides data collection implementations for most Stmt kinds. Note 0014 /// that the code requires some conditions to be met: 0015 /// 0016 /// - There must be a method addData(const T &Data) that accepts strings, 0017 /// integral types as well as QualType. All data is forwarded using 0018 /// to this method. 0019 /// - The ASTContext of the Stmt must be accessible by the name Context. 0020 /// 0021 /// It is also possible to override individual visit methods. Have a look at 0022 /// the DataCollector in lib/Analysis/CloneDetection.cpp for a usage example. 0023 /// 0024 //===----------------------------------------------------------------------===// 0025 0026 #ifndef LLVM_CLANG_AST_DATACOLLECTION_H 0027 #define LLVM_CLANG_AST_DATACOLLECTION_H 0028 0029 #include "clang/AST/ASTContext.h" 0030 0031 namespace clang { 0032 namespace data_collection { 0033 0034 /// Returns a string that represents all macro expansions that expanded into the 0035 /// given SourceLocation. 0036 /// 0037 /// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations 0038 /// A and B are expanded from the same macros in the same order. 0039 std::string getMacroStack(SourceLocation Loc, ASTContext &Context); 0040 0041 /// Utility functions for implementing addData() for a consumer that has a 0042 /// method update(StringRef) 0043 template <class T> 0044 void addDataToConsumer(T &DataConsumer, llvm::StringRef Str) { 0045 DataConsumer.update(Str); 0046 } 0047 0048 template <class T> void addDataToConsumer(T &DataConsumer, const QualType &QT) { 0049 addDataToConsumer(DataConsumer, QT.getAsString()); 0050 } 0051 0052 template <class T, class Type> 0053 std::enable_if_t<std::is_integral<Type>::value || std::is_enum<Type>::value || 0054 std::is_convertible<Type, size_t>::value // for llvm::hash_code 0055 > 0056 addDataToConsumer(T &DataConsumer, Type Data) { 0057 DataConsumer.update(StringRef(reinterpret_cast<char *>(&Data), sizeof(Data))); 0058 } 0059 0060 } // end namespace data_collection 0061 } // end namespace clang 0062 0063 #endif // LLVM_CLANG_AST_DATACOLLECTION_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|