77#include " swift/AST/GenericParamList.h"
88#include " swift/AST/Identifier.h"
99#include " swift/AST/ParameterList.h"
10+ #include " swift/AST/Pattern.h"
1011#include " swift/AST/Stmt.h"
1112#include " swift/AST/TypeRepr.h"
1213
@@ -139,11 +140,20 @@ void *SwiftBooleanLiteralExpr_create(void *ctx, bool value, void *TokenLoc) {
139140}
140141
141142void *SwiftVarDecl_create (void *ctx, BridgedIdentifier _Nullable nameId,
142- void *loc, bool isStatic, bool isLet, void *dc) {
143+ void *initExpr, void *loc, bool isStatic, bool isLet,
144+ void *dc) {
143145 ASTContext &Context = *static_cast <ASTContext *>(ctx);
144- return new (Context) VarDecl (
146+ auto name = (UnresolvedDeclRefExpr *)nameId;
147+ auto sourceLoc = getSourceLocFromPointer (loc);
148+ auto varDecl = new (Context) VarDecl (
145149 isStatic, isLet ? VarDecl::Introducer::Let : VarDecl::Introducer::Var,
146- getSourceLocFromPointer (loc), Identifier::getFromOpaquePointer (nameId),
150+ sourceLoc, name->getName ().getBaseIdentifier (),
151+ reinterpret_cast <DeclContext *>(dc));
152+ auto pattern = NamedPattern::createImplicit (Context, varDecl);
153+ return PatternBindingDecl::create (
154+ Context, sourceLoc,
155+ isStatic ? StaticSpellingKind::KeywordStatic : StaticSpellingKind::None,
156+ sourceLoc, pattern, sourceLoc, (Expr *)initExpr,
147157 reinterpret_cast <DeclContext *>(dc));
148158}
149159
@@ -164,12 +174,16 @@ void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements,
164174 void *rbloc) {
165175 llvm::SmallVector<ASTNode, 6 > nodes;
166176 for (auto node : getArrayRef<ASTNodeBridged>(elements)) {
167- if (node.isExpr ) {
177+ if (node.kind == ASTNodeKindExpr ) {
168178 auto expr = (Expr *)node.ptr ;
169179 nodes.push_back (expr);
170- } else {
180+ } else if (node. kind == ASTNodeKindStmt) {
171181 auto stmt = (Stmt *)node.ptr ;
172182 nodes.push_back (stmt);
183+ } else {
184+ assert (node.kind == ASTNodeKindDecl);
185+ auto decl = (Decl *)node.ptr ;
186+ nodes.push_back (decl);
173187 }
174188 }
175189
@@ -183,13 +197,17 @@ void *ParamDecl_create(void *ctx, void *loc, void *_Nullable argLoc,
183197 BridgedIdentifier _Nullable argName,
184198 void *_Nullable paramLoc,
185199 BridgedIdentifier _Nullable paramName,
186- void *declContext) {
200+ void *_Nullable type, void * declContext) {
187201 ASTContext &Context = *static_cast <ASTContext *>(ctx);
188- return new (Context) ParamDecl (
202+ if (!paramName)
203+ paramName = argName;
204+ auto paramDecl = new (Context) ParamDecl (
189205 getSourceLocFromPointer (loc), getSourceLocFromPointer (argLoc),
190206 Identifier::getFromOpaquePointer (argName),
191207 getSourceLocFromPointer (paramLoc),
192208 Identifier::getFromOpaquePointer (paramName), (DeclContext *)declContext);
209+ paramDecl->setTypeRepr ((TypeRepr *)type);
210+ return paramDecl;
193211}
194212
195213void *FuncDecl_create (void *ctx, void *staticLoc, bool isStatic, void *funcLoc,
0 commit comments