File indexing completed on 2026-05-10 08:36:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_AST_EXPROPENMP_H
0014 #define LLVM_CLANG_AST_EXPROPENMP_H
0015
0016 #include "clang/AST/ComputeDependence.h"
0017 #include "clang/AST/Expr.h"
0018
0019 namespace clang {
0020
0021
0022 class OMPArrayShapingExpr final
0023 : public Expr,
0024 private llvm::TrailingObjects<OMPArrayShapingExpr, Expr *, SourceRange> {
0025 friend TrailingObjects;
0026 friend class ASTStmtReader;
0027 friend class ASTStmtWriter;
0028
0029 SourceLocation LPLoc;
0030 SourceLocation RPLoc;
0031 unsigned NumDims = 0;
0032
0033
0034 OMPArrayShapingExpr(QualType ExprTy, Expr *Op, SourceLocation L,
0035 SourceLocation R, ArrayRef<Expr *> Dims);
0036
0037
0038 explicit OMPArrayShapingExpr(EmptyShell Shell, unsigned NumDims)
0039 : Expr(OMPArrayShapingExprClass, Shell), NumDims(NumDims) {}
0040
0041
0042 void setDimensions(ArrayRef<Expr *> Dims);
0043
0044
0045 void setBase(Expr *Op) { getTrailingObjects<Expr *>()[NumDims] = Op; }
0046
0047
0048 void setBracketsRanges(ArrayRef<SourceRange> BR);
0049
0050 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
0051
0052 return NumDims + 1;
0053 }
0054
0055 unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
0056 return NumDims;
0057 }
0058
0059 public:
0060 static OMPArrayShapingExpr *Create(const ASTContext &Context, QualType T,
0061 Expr *Op, SourceLocation L,
0062 SourceLocation R, ArrayRef<Expr *> Dims,
0063 ArrayRef<SourceRange> BracketRanges);
0064
0065 static OMPArrayShapingExpr *CreateEmpty(const ASTContext &Context,
0066 unsigned NumDims);
0067
0068 SourceLocation getLParenLoc() const { return LPLoc; }
0069 void setLParenLoc(SourceLocation L) { LPLoc = L; }
0070
0071 SourceLocation getRParenLoc() const { return RPLoc; }
0072 void setRParenLoc(SourceLocation L) { RPLoc = L; }
0073
0074 SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
0075 SourceLocation getEndLoc() const LLVM_READONLY {
0076 return getBase()->getEndLoc();
0077 }
0078
0079
0080 ArrayRef<Expr *> getDimensions() const {
0081 return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumDims);
0082 }
0083
0084
0085 ArrayRef<SourceRange> getBracketsRanges() const {
0086 return llvm::ArrayRef(getTrailingObjects<SourceRange>(), NumDims);
0087 }
0088
0089
0090 Expr *getBase() { return getTrailingObjects<Expr *>()[NumDims]; }
0091 const Expr *getBase() const { return getTrailingObjects<Expr *>()[NumDims]; }
0092
0093 static bool classof(const Stmt *T) {
0094 return T->getStmtClass() == OMPArrayShapingExprClass;
0095 }
0096
0097
0098 child_range children() {
0099 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
0100 return child_range(Begin, Begin + NumDims + 1);
0101 }
0102 const_child_range children() const {
0103 Stmt *const *Begin =
0104 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
0105 return const_child_range(Begin, Begin + NumDims + 1);
0106 }
0107 };
0108
0109
0110
0111 struct OMPIteratorHelperData {
0112
0113 VarDecl *CounterVD = nullptr;
0114
0115
0116 Expr *Upper = nullptr;
0117
0118
0119 Expr *Update = nullptr;
0120
0121 Expr *CounterUpdate = nullptr;
0122 };
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 class OMPIteratorExpr final
0149 : public Expr,
0150 private llvm::TrailingObjects<OMPIteratorExpr, Decl *, Expr *,
0151 SourceLocation, OMPIteratorHelperData> {
0152 public:
0153
0154 struct IteratorRange {
0155 Expr *Begin = nullptr;
0156 Expr *End = nullptr;
0157 Expr *Step = nullptr;
0158 };
0159
0160 struct IteratorDefinition {
0161 Decl *IteratorDecl = nullptr;
0162 IteratorRange Range;
0163 SourceLocation AssignmentLoc;
0164 SourceLocation ColonLoc, SecondColonLoc;
0165 };
0166
0167 private:
0168 friend TrailingObjects;
0169 friend class ASTStmtReader;
0170 friend class ASTStmtWriter;
0171
0172
0173 enum class RangeExprOffset {
0174 Begin = 0,
0175 End = 1,
0176 Step = 2,
0177 Total = 3,
0178 };
0179
0180
0181 enum class RangeLocOffset {
0182 AssignLoc = 0,
0183 FirstColonLoc = 1,
0184 SecondColonLoc = 2,
0185 Total = 3,
0186 };
0187
0188 SourceLocation IteratorKwLoc;
0189
0190 SourceLocation LPLoc;
0191
0192 SourceLocation RPLoc;
0193
0194 unsigned NumIterators = 0;
0195
0196 OMPIteratorExpr(QualType ExprTy, SourceLocation IteratorKwLoc,
0197 SourceLocation L, SourceLocation R,
0198 ArrayRef<IteratorDefinition> Data,
0199 ArrayRef<OMPIteratorHelperData> Helpers);
0200
0201
0202 explicit OMPIteratorExpr(EmptyShell Shell, unsigned NumIterators)
0203 : Expr(OMPIteratorExprClass, Shell), NumIterators(NumIterators) {}
0204
0205
0206 void setIteratorDeclaration(unsigned I, Decl *D);
0207
0208
0209
0210 void setAssignmentLoc(unsigned I, SourceLocation Loc);
0211
0212
0213
0214 void setIteratorRange(unsigned I, Expr *Begin, SourceLocation ColonLoc,
0215 Expr *End, SourceLocation SecondColonLoc, Expr *Step);
0216
0217
0218 void setHelper(unsigned I, const OMPIteratorHelperData &D);
0219
0220 unsigned numTrailingObjects(OverloadToken<Decl *>) const {
0221 return NumIterators;
0222 }
0223
0224 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
0225 return NumIterators * static_cast<int>(RangeExprOffset::Total);
0226 }
0227
0228 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
0229 return NumIterators * static_cast<int>(RangeLocOffset::Total);
0230 }
0231
0232 public:
0233 static OMPIteratorExpr *Create(const ASTContext &Context, QualType T,
0234 SourceLocation IteratorKwLoc, SourceLocation L,
0235 SourceLocation R,
0236 ArrayRef<IteratorDefinition> Data,
0237 ArrayRef<OMPIteratorHelperData> Helpers);
0238
0239 static OMPIteratorExpr *CreateEmpty(const ASTContext &Context,
0240 unsigned NumIterators);
0241
0242 SourceLocation getLParenLoc() const { return LPLoc; }
0243 void setLParenLoc(SourceLocation L) { LPLoc = L; }
0244
0245 SourceLocation getRParenLoc() const { return RPLoc; }
0246 void setRParenLoc(SourceLocation L) { RPLoc = L; }
0247
0248 SourceLocation getIteratorKwLoc() const { return IteratorKwLoc; }
0249 void setIteratorKwLoc(SourceLocation L) { IteratorKwLoc = L; }
0250 SourceLocation getBeginLoc() const LLVM_READONLY { return IteratorKwLoc; }
0251 SourceLocation getEndLoc() const LLVM_READONLY { return RPLoc; }
0252
0253
0254 Decl *getIteratorDecl(unsigned I);
0255 const Decl *getIteratorDecl(unsigned I) const {
0256 return const_cast<OMPIteratorExpr *>(this)->getIteratorDecl(I);
0257 }
0258
0259
0260 IteratorRange getIteratorRange(unsigned I);
0261 const IteratorRange getIteratorRange(unsigned I) const {
0262 return const_cast<OMPIteratorExpr *>(this)->getIteratorRange(I);
0263 }
0264
0265
0266 SourceLocation getAssignLoc(unsigned I) const;
0267
0268
0269 SourceLocation getColonLoc(unsigned I) const;
0270
0271
0272 SourceLocation getSecondColonLoc(unsigned I) const;
0273
0274
0275 unsigned numOfIterators() const { return NumIterators; }
0276
0277
0278 OMPIteratorHelperData &getHelper(unsigned I);
0279 const OMPIteratorHelperData &getHelper(unsigned I) const;
0280
0281 static bool classof(const Stmt *T) {
0282 return T->getStmtClass() == OMPIteratorExprClass;
0283 }
0284
0285
0286 child_range children() {
0287 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
0288 return child_range(
0289 Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
0290 }
0291 const_child_range children() const {
0292 Stmt *const *Begin =
0293 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
0294 return const_child_range(
0295 Begin, Begin + NumIterators * static_cast<int>(RangeExprOffset::Total));
0296 }
0297 };
0298
0299 }
0300
0301 #endif