Skip to content

Commit 15f9f86

Browse files
committed
Add support for bool literals.
1 parent 6f1eb67 commit 15f9f86

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ void *SwiftStringLiteralExpr_create(void *ctx, const char *_Nullable string,
9999
void *SwiftIntegerLiteralExpr_create(void *ctx, const char *_Nullable string,
100100
long len, void *TokenLoc);
101101

102-
void *SwiftVarDecl_create(void *ctx, const char *_Nullable name,
102+
void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc);
103+
104+
void *SwiftVarDecl_create(void *ctx, const char *_Nullable name,
103105
void *loc, _Bool isStatic, _Bool isLet, void *dc);
104106

105107
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, void *_Nullable elseLoc,

lib/AST/CASTBridging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ void *SwiftIntegerLiteralExpr_create(void *ctx, const char *_Nullable string,
124124
*(SourceLoc *)&TokenLoc);
125125
}
126126

127+
void *SwiftBooleanLiteralExpr_create(void *ctx, bool value, void *TokenLoc) {
128+
ASTContext &Context = *static_cast<ASTContext *>(ctx);
129+
return new (Context) BooleanLiteralExpr(value, *(SourceLoc *)&TokenLoc);
130+
}
131+
127132
void *SwiftVarDecl_create(void *ctx, const char *_Nullable nameId,
128133
void *loc, bool isStatic, bool isLet, void *dc) {
129134
ASTContext &Context = *static_cast<ASTContext *>(ctx);

lib/ASTGen/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ASTGen/Sources/ASTGen/Literals.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ extension ASTGenVisitor {
2121
return SwiftIntegerLiteralExpr_create(ctx, id, buf.count, loc)
2222
}
2323
}
24+
25+
public func visit(_ node: BooleanLiteralExprSyntax) -> UnsafeMutableRawPointer {
26+
let loc = self.base.advanced(by: node.position.utf8Offset).raw
27+
let value = node.booleanLiteral == .trueKeyword()
28+
return SwiftBooleanLiteralExpr_create(ctx, value, loc)
29+
}
2430
}

0 commit comments

Comments
 (0)