Skip to content

Commit f3063d5

Browse files
committed
Add support for _When
1 parent 981ee4a commit f3063d5

File tree

19 files changed

+1612
-1416
lines changed

19 files changed

+1612
-1416
lines changed

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
24722472
DEF_TRAVERSE_STMT(ReturnStmt, {})
24732473
DEF_TRAVERSE_STMT(SwitchStmt, {})
24742474
DEF_TRAVERSE_STMT(WhileStmt, {})
2475+
DEF_TRAVERSE_STMT(WhenStmt, {})
24752476

24762477
DEF_TRAVERSE_STMT(ConstantExpr, {})
24772478

clang/include/clang/AST/Stmt.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,61 @@ class IfStmt final
24092409
}
24102410
};
24112411

2412+
/// WhenStmt - This represents a '_When' stmt.
2413+
class WhenStmt : public Stmt, private llvm::TrailingObjects<WhenStmt, Stmt *> {
2414+
SourceLocation WhenLoc;
2415+
Expr *Condition;
2416+
bool IsAccept;
2417+
IdentifierInfo *VarName;
2418+
Stmt *Body;
2419+
2420+
/*
2421+
* WhenStmt is followed by several trailing objects, some of which optional.
2422+
* Note that it would be more convenient to put the optional trailing objects
2423+
* at the end but this would change the order in children().
2424+
* The trailing objects are in order:
2425+
*
2426+
* * A "Stmt *" for the condition.
2427+
* Always present. This is in fact an "Expr *".
2428+
*
2429+
* * A "Stmt *" for the body.
2430+
* Always present.
2431+
*/
2432+
enum {
2433+
NumMandatoryStmtPtr = 2
2434+
};
2435+
2436+
public:
2437+
// WhenStmt(SourceLocation Loc, Expr *Cond, bool Accept, IdentifierInfo *Var, Stmt *BodyStmt)
2438+
WhenStmt(SourceLocation Loc, Expr *Cond, Stmt *BodyStmt)
2439+
: Stmt(Stmt::WhenStmtClass), WhenLoc(Loc), Condition(Cond),
2440+
Body(BodyStmt) {}
2441+
// IsAccept(Accept), VarName(Var), Body(BodyStmt) {}
2442+
2443+
explicit WhenStmt(EmptyShell Empty)
2444+
: Stmt(Stmt::WhenStmtClass) {}
2445+
2446+
// static WhenStmt* Create(const ASTContext &Ctx, SourceLocation Loc, Expr *Cond, bool Accept, IdentifierInfo *Var, Stmt *BodyStmt);
2447+
static WhenStmt* Create(const ASTContext &Ctx, SourceLocation Loc, Expr *Cond, Stmt *BodyStmt);
2448+
static WhenStmt* CreateEmpty(const ASTContext &Ctx);
2449+
2450+
SourceLocation getBeginLoc() const { return WhenLoc; }
2451+
SourceLocation getEndLoc() const { return Body ? Body->getEndLoc() : WhenLoc; }
2452+
child_range children() { return child_range(&Body, &Body + 1); }
2453+
static bool classof(const Stmt *S) { return S->getStmtClass() == WhenStmtClass; }
2454+
2455+
bool isAccept() const { return IsAccept; }
2456+
IdentifierInfo *getVarName() const { return VarName; }
2457+
Expr *getCondition() const { return Condition; }
2458+
void setCondition(Expr *Cond) { Condition = Cond; }
2459+
Stmt *getBody() const { return Body; }
2460+
void setBody(Stmt *B) { Body = B; }
2461+
2462+
SourceLocation getWhenLoc() const { return WhenLoc; }
2463+
SourceLocation setWhenLoc(SourceLocation Loc) { return WhenLoc = Loc; }
2464+
2465+
};
2466+
24122467
/// SwitchStmt - This represents a 'switch' stmt.
24132468
class SwitchStmt final : public Stmt,
24142469
private llvm::TrailingObjects<SwitchStmt, Stmt *> {

clang/include/clang/Basic/StmtNodes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def CaseStmt : StmtNode<SwitchCase>;
2525
def DefaultStmt : StmtNode<SwitchCase>;
2626
def CapturedStmt : StmtNode<Stmt>;
2727

28+
// uC++ Statements
29+
def WhenStmt : StmtNode<Stmt>;
30+
2831
// Statements that might produce a value (for example, as the last non-null
2932
// statement in a GNU statement-expression).
3033
def ValueStmt : StmtNode<Stmt, 1>;

0 commit comments

Comments
 (0)