aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/Syntax/BuildTree.cpp
diff options
context:
space:
mode:
authorSirraide <aeternalmail@gmail.com>2025-09-02 18:37:19 +0200
committerGitHub <noreply@github.com>2025-09-02 16:37:19 +0000
commite4a1b5f36e71c8c382bdd531867c5f6eb3f7deac (patch)
tree5ed6131d9d0abadc4e4726509c3c01cdf264600d /clang/lib/Tooling/Syntax/BuildTree.cpp
parent83f390859e186d22af8aa32135d7993079ed4666 (diff)
downloadllvm-e4a1b5f36e71c8c382bdd531867c5f6eb3f7deac.zip
llvm-e4a1b5f36e71c8c382bdd531867c5f6eb3f7deac.tar.gz
llvm-e4a1b5f36e71c8c382bdd531867c5f6eb3f7deac.tar.bz2
[Clang] [C2y] Implement N3355 ‘Named Loops’ (#152870)
This implements support for [named loops](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm) for C2y. When parsing a `LabelStmt`, we create the `LabeDecl` early before we parse the substatement; this label is then passed down to `ParseWhileStatement()` and friends, which then store it in the loop’s (or switch statement’s) `Scope`; when we encounter a `break/continue` statement, we perform a lookup for the label (and error if it doesn’t exist), and then walk the scope stack and check if there is a scope whose preceding label is the target label, which identifies the jump target. The feature is only supported in C2y mode, though a cc1-only option exists for testing (`-fnamed-loops`), which is mostly intended to try and make sure that we don’t have to refactor this entire implementation when/if we start supporting it in C++. --------- Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
Diffstat (limited to 'clang/lib/Tooling/Syntax/BuildTree.cpp')
-rw-r--r--clang/lib/Tooling/Syntax/BuildTree.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 546161c..b75f8ff 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1482,16 +1482,14 @@ public:
}
bool WalkUpFromContinueStmt(ContinueStmt *S) {
- Builder.markChildToken(S->getContinueLoc(),
- syntax::NodeRole::IntroducerKeyword);
+ Builder.markChildToken(S->getKwLoc(), syntax::NodeRole::IntroducerKeyword);
Builder.foldNode(Builder.getStmtRange(S),
new (allocator()) syntax::ContinueStatement, S);
return true;
}
bool WalkUpFromBreakStmt(BreakStmt *S) {
- Builder.markChildToken(S->getBreakLoc(),
- syntax::NodeRole::IntroducerKeyword);
+ Builder.markChildToken(S->getKwLoc(), syntax::NodeRole::IntroducerKeyword);
Builder.foldNode(Builder.getStmtRange(S),
new (allocator()) syntax::BreakStatement, S);
return true;