-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NFC] Factor out common parts of ArraySections into its own class #89639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b95304b
[NFC] Factor out common parts of ArraySections into its own class
erichkeane e473961
Move to protected + clang-format
erichkeane c8a9094
Correctly initialize second-colon-loc so it prints correctly
erichkeane 9c7489e
Re-implementation: renames OMPArraySectionExpr to ArraySectionExpr
erichkeane 40e7dea
Clang-format
erichkeane 883b556
Do the requested changes to ArraySectionExpr, be more specific on the…
erichkeane bac62f3
Clang-format
erichkeane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6610,6 +6610,115 @@ class TypoExpr : public Expr { | |
|
||
}; | ||
|
||
// This is a sub-class for OpenMP and OpenACC array sections. OpenACC uses a | ||
// very small subset of the functionality, so this class only exposes the things | ||
// the two have in common. This type is not expected to be used directly, | ||
// instead it is inherited from by the OMP and OpenACC variants. | ||
// | ||
// This type does not capture a 'stride', only a lower-bound and length (plus | ||
// the base expression), but provides room via a template argument to get | ||
// additional ones. | ||
template <unsigned NumSubExprs, bool AllowNullExprs> | ||
class ArraySectionExprBase : public Expr { | ||
friend class ASTStmtReader; | ||
|
||
enum { BASE, LOWER_BOUND, LENGTH, END_EXPR = NumSubExprs }; | ||
Stmt *SubExprs[END_EXPR]; | ||
SourceLocation ColonLocFirst; | ||
SourceLocation RBracketLoc; | ||
|
||
protected: | ||
ArraySectionExprBase(StmtClass SC, Expr *Base, Expr *LowerBound, Expr *Length, | ||
QualType Type, ExprValueKind VK, ExprObjectKind OK, | ||
SourceLocation ColonLocFirst, SourceLocation RBracketLoc) | ||
: Expr(SC, Type, VK, OK), ColonLocFirst(ColonLocFirst), | ||
RBracketLoc(RBracketLoc) { | ||
setBase(Base); | ||
setLowerBound(LowerBound); | ||
setLength(Length); | ||
} | ||
|
||
explicit ArraySectionExprBase(StmtClass SC, EmptyShell Shell) | ||
: Expr(SC, Shell) {} | ||
|
||
void setSubExpr(unsigned Idx, Expr *SubExpr) { | ||
assert(Idx > LENGTH && | ||
"setting sub expression owned by ArraySectionExprBase: Should be " | ||
"using the direct 'setter' functions"); | ||
assert((SubExpr || AllowNullExprs) && "Null expression when not allowed"); | ||
SubExprs[Idx] = SubExpr; | ||
} | ||
|
||
Expr *getSubExpr(unsigned Idx) { | ||
assert(Idx > LENGTH && | ||
"getting sub expression owned by ArraySectionExprBase: Should be " | ||
"using the direct 'getter' functions"); | ||
return cast_or_null<Expr>(SubExprs[Idx]); | ||
} | ||
const Expr *getSubExpr(unsigned Idx) const { | ||
assert(Idx > LENGTH && | ||
"getting sub expression owned by ArraySectionExprBase: Should be " | ||
"using the direct 'getter' functions"); | ||
return cast_or_null<Expr>(SubExprs[Idx]); | ||
} | ||
|
||
/// Set base of the array section. | ||
void setBase(Expr *E) { | ||
assert((E || AllowNullExprs) && "Null expression when not allowed"); | ||
SubExprs[BASE] = E; | ||
} | ||
|
||
/// Set lower bound of the array section. | ||
void setLowerBound(Expr *E) { | ||
assert((E || AllowNullExprs) && "Null expression when not allowed"); | ||
SubExprs[LOWER_BOUND] = E; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
/// Set length of the array section. | ||
void setLength(Expr *E) { | ||
assert((E || AllowNullExprs) && "Null expression when not allowed"); | ||
SubExprs[LENGTH] = E; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
public: | ||
/// Get base of the array section. | ||
Expr *getBase() { return cast<Expr>(SubExprs[BASE]); } | ||
const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); } | ||
|
||
/// Get lower bound of array section. | ||
Expr *getLowerBound() { return cast_or_null<Expr>(SubExprs[LOWER_BOUND]); } | ||
const Expr *getLowerBound() const { | ||
return cast_or_null<Expr>(SubExprs[LOWER_BOUND]); | ||
} | ||
|
||
/// Get length of array section. | ||
Expr *getLength() { return cast_or_null<Expr>(SubExprs[LENGTH]); } | ||
const Expr *getLength() const { return cast_or_null<Expr>(SubExprs[LENGTH]); } | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { | ||
return getBase()->getBeginLoc(); | ||
} | ||
|
||
SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; } | ||
|
||
SourceLocation getColonLocFirst() const { return ColonLocFirst; } | ||
void setColonLocFirst(SourceLocation L) { ColonLocFirst = L; } | ||
|
||
SourceLocation getRBracketLoc() const { return RBracketLoc; } | ||
void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } | ||
|
||
SourceLocation getExprLoc() const LLVM_READONLY { | ||
return getBase()->getExprLoc(); | ||
} | ||
child_range children() { | ||
return child_range(&SubExprs[BASE], &SubExprs[END_EXPR]); | ||
} | ||
|
||
const_child_range children() const { | ||
return const_child_range(&SubExprs[BASE], &SubExprs[END_EXPR]); | ||
} | ||
}; | ||
|
||
/// Frontend produces RecoveryExprs on semantic errors that prevent creating | ||
/// other well-formed expressions. E.g. when type-checking of a binary operator | ||
/// fails, we cannot produce a BinaryOperator expression. Instead, we can choose | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make it private or protected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it protected (since I want the constructors of the inheritors to use it) and had to make
ASTStmtReader
a friend.