Coverage Report

Created: 2020-03-31 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ExprOpenMP.h
Line
Count
Source (jump to first uncovered line)
1
//===--- ExprOpenMP.h - Classes for representing expressions ----*- 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
//  This file defines the Expr interface and subclasses.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_EXPROPENMP_H
14
#define LLVM_CLANG_AST_EXPROPENMP_H
15
16
#include "clang/AST/ComputeDependence.h"
17
#include "clang/AST/Expr.h"
18
19
namespace clang {
20
/// OpenMP 4.0 [2.4, Array Sections].
21
/// To specify an array section in an OpenMP construct, array subscript
22
/// expressions are extended with the following syntax:
23
/// \code
24
/// [ lower-bound : length ]
25
/// [ lower-bound : ]
26
/// [ : length ]
27
/// [ : ]
28
/// \endcode
29
/// The array section must be a subset of the original array.
30
/// Array sections are allowed on multidimensional arrays. Base language array
31
/// subscript expressions can be used to specify length-one dimensions of
32
/// multidimensional array sections.
33
/// The lower-bound and length are integral type expressions. When evaluated
34
/// they represent a set of integer values as follows:
35
/// \code
36
/// { lower-bound, lower-bound + 1, lower-bound + 2,... , lower-bound + length -
37
/// 1 }
38
/// \endcode
39
/// The lower-bound and length must evaluate to non-negative integers.
40
/// When the size of the array dimension is not known, the length must be
41
/// specified explicitly.
42
/// When the length is absent, it defaults to the size of the array dimension
43
/// minus the lower-bound.
44
/// When the lower-bound is absent it defaults to 0.
45
class OMPArraySectionExpr : public Expr {
46
  enum { BASE, LOWER_BOUND, LENGTH, END_EXPR };
47
  Stmt *SubExprs[END_EXPR];
48
  SourceLocation ColonLoc;
49
  SourceLocation RBracketLoc;
50
51
public:
52
  OMPArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, QualType Type,
53
                      ExprValueKind VK, ExprObjectKind OK,
54
                      SourceLocation ColonLoc, SourceLocation RBracketLoc)
55
      : Expr(OMPArraySectionExprClass, Type, VK, OK), ColonLoc(ColonLoc),
56
6.56k
        RBracketLoc(RBracketLoc) {
57
6.56k
    SubExprs[BASE] = Base;
58
6.56k
    SubExprs[LOWER_BOUND] = LowerBound;
59
6.56k
    SubExprs[LENGTH] = Length;
60
6.56k
    setDependence(computeDependence(this));
61
6.56k
  }
62
63
  /// Create an empty array section expression.
64
  explicit OMPArraySectionExpr(EmptyShell Shell)
65
929
      : Expr(OMPArraySectionExprClass, Shell) {}
66
67
  /// An array section can be written only as Base[LowerBound:Length].
68
69
  /// Get base of the array section.
70
19.8k
  Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
71
48.2k
  const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
72
  /// Set base of the array section.
73
929
  void setBase(Expr *E) { SubExprs[BASE] = E; }
74
75
  /// Return original type of the base expression for array section.
76
  static QualType getBaseOriginalType(const Expr *Base);
77
78
  /// Get lower bound of array section.
79
12.4k
  Expr *getLowerBound() { return cast_or_null<Expr>(SubExprs[LOWER_BOUND]); }
80
4.64k
  const Expr *getLowerBound() const {
81
4.64k
    return cast_or_null<Expr>(SubExprs[LOWER_BOUND]);
82
4.64k
  }
83
  /// Set lower bound of the array section.
84
929
  void setLowerBound(Expr *E) { SubExprs[LOWER_BOUND] = E; }
85
86
  /// Get length of array section.
87
13.5k
  Expr *getLength() { return cast_or_null<Expr>(SubExprs[LENGTH]); }
88
10.8k
  const Expr *getLength() const { return cast_or_null<Expr>(SubExprs[LENGTH]); }
89
  /// Set length of the array section.
90
929
  void setLength(Expr *E) { SubExprs[LENGTH] = E; }
91
92
14.8k
  SourceLocation getBeginLoc() const LLVM_READONLY {
93
14.8k
    return getBase()->getBeginLoc();
94
14.8k
  }
95
10.4k
  SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
96
97
12.7k
  SourceLocation getColonLoc() const { return ColonLoc; }
98
929
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
99
100
2.72k
  SourceLocation getRBracketLoc() const { return RBracketLoc; }
101
929
  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
102
103
22.3k
  SourceLocation getExprLoc() const LLVM_READONLY {
104
22.3k
    return getBase()->getExprLoc();
105
22.3k
  }
106
107
251k
  static bool classof(const Stmt *T) {
108
251k
    return T->getStmtClass() == OMPArraySectionExprClass;
109
251k
  }
110
111
2.24k
  child_range children() {
112
2.24k
    return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
113
2.24k
  }
114
115
0
  const_child_range children() const {
116
0
    return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]);
117
0
  }
118
};
119
120
/// An explicit cast in C or a C-style cast in C++, which uses the syntax
121
/// ([s1][s2]...[sn])expr. For example: @c ([3][3])f.
122
class OMPArrayShapingExpr final
123
    : public Expr,
124
      private llvm::TrailingObjects<OMPArrayShapingExpr, Expr *, SourceRange> {
125
  friend TrailingObjects;
126
  friend class ASTStmtReader;
127
  friend class ASTStmtWriter;
128
  /// Base node.
129
  SourceLocation LPLoc; /// The location of the left paren
130
  SourceLocation RPLoc; /// The location of the right paren
131
  unsigned NumDims = 0; /// Number of dimensions in the shaping expression.
132
133
  /// Construct full expression.
134
  OMPArrayShapingExpr(QualType ExprTy, Expr *Op, SourceLocation L,
135
                      SourceLocation R, ArrayRef<Expr *> Dims);
136
137
  /// Construct an empty expression.
138
  explicit OMPArrayShapingExpr(EmptyShell Shell, unsigned NumDims)
139
12
      : Expr(OMPArrayShapingExprClass, Shell), NumDims(NumDims) {}
140
141
  /// Sets the dimensions for the array shaping.
142
  void setDimensions(ArrayRef<Expr *> Dims);
143
144
  /// Sets the base expression for array shaping operation.
145
53
  void setBase(Expr *Op) { getTrailingObjects<Expr *>()[NumDims] = Op; }
146
147
  /// Sets source ranges for the brackets in the array shaping operation.
148
  void setBracketsRanges(ArrayRef<SourceRange> BR);
149
150
81
  unsigned numTrailingObjects(OverloadToken<Expr *>) const {
151
81
    // Add an extra one for the base expression.
152
81
    return NumDims + 1;
153
81
  }
154
155
0
  unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
156
0
    return NumDims;
157
0
  }
158
159
public:
160
  static OMPArrayShapingExpr *Create(const ASTContext &Context, QualType T,
161
                                     Expr *Op, SourceLocation L,
162
                                     SourceLocation R, ArrayRef<Expr *> Dims,
163
                                     ArrayRef<SourceRange> BracketRanges);
164
165
  static OMPArrayShapingExpr *CreateEmpty(const ASTContext &Context,
166
                                          unsigned NumDims);
167
168
28
  SourceLocation getLParenLoc() const { return LPLoc; }
169
12
  void setLParenLoc(SourceLocation L) { LPLoc = L; }
170
171
28
  SourceLocation getRParenLoc() const { return RPLoc; }
172
12
  void setRParenLoc(SourceLocation L) { RPLoc = L; }
173
174
82
  SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
175
1
  SourceLocation getEndLoc() const LLVM_READONLY {
176
1
    return getBase()->getEndLoc();
177
1
  }
178
179
  /// Fetches the dimensions for array shaping expression.
180
113
  ArrayRef<Expr *> getDimensions() const {
181
113
    return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumDims);
182
113
  }
183
184
  /// Fetches source ranges for the brackets os the array shaping expression.
185
28
  ArrayRef<SourceRange> getBracketsRanges() const {
186
28
    return llvm::makeArrayRef(getTrailingObjects<SourceRange>(), NumDims);
187
28
  }
188
189
  /// Fetches base expression of array shaping expression.
190
97
  Expr *getBase() { return getTrailingObjects<Expr *>()[NumDims]; }
191
5
  const Expr *getBase() const { return getTrailingObjects<Expr *>()[NumDims]; }
192
193
956
  static bool classof(const Stmt *T) {
194
956
    return T->getStmtClass() == OMPArrayShapingExprClass;
195
956
  }
196
197
  // Iterators
198
14
  child_range children() {
199
14
    Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
200
14
    return child_range(Begin, Begin + NumDims + 1);
201
14
  }
202
0
  const_child_range children() const {
203
0
    Stmt *const *Begin =
204
0
        reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
205
0
    return const_child_range(Begin, Begin + NumDims + 1);
206
0
  }
207
};
208
} // end namespace clang
209
210
#endif