clang 19.0.0git
ASTOps.h
Go to the documentation of this file.
1//===-- ASTOps.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//
9// Operations on AST nodes that are used in flow-sensitive analysis.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_ASTOPS_H
14#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_ASTOPS_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/Expr.h"
18#include "clang/AST/Type.h"
20#include "llvm/ADT/DenseSet.h"
21#include "llvm/ADT/SetVector.h"
22
23namespace clang {
24namespace dataflow {
25
26/// Skip past nodes that the CFG does not emit. These nodes are invisible to
27/// flow-sensitive analysis, and should be ignored as they will effectively not
28/// exist.
29///
30/// * `ParenExpr` - The CFG takes the operator precedence into account, but
31/// otherwise omits the node afterwards.
32///
33/// * `ExprWithCleanups` - The CFG will generate the appropriate calls to
34/// destructors and then omit the node.
35///
36const Expr &ignoreCFGOmittedNodes(const Expr &E);
37const Stmt &ignoreCFGOmittedNodes(const Stmt &S);
38
39/// A set of `FieldDecl *`. Use `SmallSetVector` to guarantee deterministic
40/// iteration order.
42
43/// Returns the set of all fields in the type.
45
46/// Returns whether `Fields` and `FieldLocs` contain the same fields.
47bool containsSameFields(const FieldSet &Fields,
48 const RecordStorageLocation::FieldToLoc &FieldLocs);
49
50/// Helper class for initialization of a record with an `InitListExpr`.
51/// `InitListExpr::inits()` contains the initializers for both the base classes
52/// and the fields of the record; this helper class separates these out into two
53/// different lists. In addition, it deals with special cases associated with
54/// unions.
56public:
57 // `InitList` must have record type.
58 RecordInitListHelper(const InitListExpr *InitList);
59 RecordInitListHelper(const CXXParenListInitExpr *ParenInitList);
60
61 // Base classes with their associated initializer expressions.
63 return BaseInits;
64 }
65
66 // Fields with their associated initializer expressions.
68 return FieldInits;
69 }
70
71private:
72 RecordInitListHelper(QualType Ty, std::vector<const FieldDecl *> Fields,
73 ArrayRef<Expr *> Inits);
74
77
78 // We potentially synthesize an `ImplicitValueInitExpr` for unions. It's a
79 // member variable because we store a pointer to it in `FieldInits`.
80 std::optional<ImplicitValueInitExpr> ImplicitValueInitForUnion;
81};
82
83/// A collection of several types of declarations, all referenced from the same
84/// function.
86 /// Non-static member variables.
88 /// All variables with static storage duration, notably including static
89 /// member variables and static variables declared within a function.
91 /// Free functions and member functions which are referenced (but not
92 /// necessarily called).
94};
95
96/// Returns declarations that are declared in or referenced from `FD`.
98
99/// Returns declarations that are declared in or referenced from `S`.
101
102} // namespace dataflow
103} // namespace clang
104
105#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_ASTOPS_H
C Language Family Type Representation.
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4920
Represents a function declaration or definition.
Definition: Decl.h:1971
Describes an C or C++ initializer list.
Definition: Expr.h:4847
A (possibly-)qualified type.
Definition: Type.h:940
Stmt - This represents one statement.
Definition: Stmt.h:84
The base class of the type hierarchy.
Definition: Type.h:1813
Helper class for initialization of a record with an InitListExpr.
Definition: ASTOps.h:55
ArrayRef< std::pair< const FieldDecl *, Expr * > > field_inits() const
Definition: ASTOps.h:67
ArrayRef< std::pair< const CXXBaseSpecifier *, Expr * > > base_inits() const
Definition: ASTOps.h:62
llvm::DenseMap< const ValueDecl *, StorageLocation * > FieldToLoc
ReferencedDecls getReferencedDecls(const FunctionDecl &FD)
Returns declarations that are declared in or referenced from FD.
Definition: ASTOps.cpp:246
const Expr & ignoreCFGOmittedNodes(const Expr &E)
Skip past nodes that the CFG does not emit.
Definition: ASTOps.cpp:34
FieldSet getObjectFields(QualType Type)
Returns the set of all fields in the type.
Definition: ASTOps.cpp:74
bool containsSameFields(const FieldSet &Fields, const RecordStorageLocation::FieldToLoc &FieldLocs)
Returns whether Fields and FieldLocs contain the same fields.
Definition: ASTOps.cpp:80
The JSON file list parser is used to communicate input to InstallAPI.
A collection of several types of declarations, all referenced from the same function.
Definition: ASTOps.h:85
llvm::DenseSet< const VarDecl * > Globals
All variables with static storage duration, notably including static member variables and static vari...
Definition: ASTOps.h:90
llvm::DenseSet< const FunctionDecl * > Functions
Free functions and member functions which are referenced (but not necessarily called).
Definition: ASTOps.h:93
FieldSet Fields
Non-static member variables.
Definition: ASTOps.h:87