Skip to content

Commit c7fa409

Browse files
committed
[CUDA][HIP][OpenMP] Add lib/Sema/UsedDeclVisitor.h after D70172
1 parent 464729c commit c7fa409

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

clang/lib/Sema/UsedDeclVisitor.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===- UsedDeclVisitor.h - ODR-used declarations visitor --------*- 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+
// This file defines UsedDeclVisitor, a CRTP class which visits all the
9+
// declarations that are ODR-used by an expression or statement.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
14+
#define LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H
15+
16+
#include "clang/AST/EvaluatedExprVisitor.h"
17+
#include "clang/Sema/SemaInternal.h"
18+
19+
namespace clang {
20+
template <class Derived>
21+
class UsedDeclVisitor : public EvaluatedExprVisitor<Derived> {
22+
protected:
23+
Sema &S;
24+
25+
public:
26+
typedef EvaluatedExprVisitor<Derived> Inherited;
27+
28+
UsedDeclVisitor(Sema &S) : Inherited(S.Context), S(S) {}
29+
30+
Derived &asImpl() { return *static_cast<Derived *>(this); }
31+
32+
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
33+
asImpl().visitUsedDecl(
34+
E->getBeginLoc(),
35+
const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
36+
asImpl().Visit(E->getSubExpr());
37+
}
38+
39+
void VisitCXXNewExpr(CXXNewExpr *E) {
40+
if (E->getOperatorNew())
41+
asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorNew());
42+
if (E->getOperatorDelete())
43+
asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
44+
Inherited::VisitCXXNewExpr(E);
45+
}
46+
47+
void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
48+
if (E->getOperatorDelete())
49+
asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
50+
QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
51+
if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
52+
CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
53+
asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
54+
}
55+
56+
Inherited::VisitCXXDeleteExpr(E);
57+
}
58+
59+
void VisitCXXConstructExpr(CXXConstructExpr *E) {
60+
asImpl().visitUsedDecl(E->getBeginLoc(), E->getConstructor());
61+
Inherited::VisitCXXConstructExpr(E);
62+
}
63+
64+
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
65+
asImpl().Visit(E->getExpr());
66+
}
67+
};
68+
} // end namespace clang
69+
70+
#endif // LLVM_CLANG_LIB_SEMA_USEDDECLVISITOR_H

0 commit comments

Comments
 (0)