@@ -290,145 +290,8 @@ case PatternKind::ID: foundRefutablePattern = true; break;
290
290
return foundRefutablePattern;
291
291
}
292
292
293
- Pattern *Pattern::clone (ASTContext &context) const {
294
- Pattern *result;
295
- switch (getKind ()) {
296
- case PatternKind::Any: {
297
- result = new (context) AnyPattern (cast<AnyPattern>(this )->getLoc ());
298
- break ;
299
- }
300
-
301
- case PatternKind::Named: {
302
- auto named = cast<NamedPattern>(this );
303
- VarDecl *var = new (context) VarDecl (!named->getDecl ()->isInstanceMember (),
304
- named->getDecl ()->isLet (),
305
- named->getLoc (),
306
- named->getBoundName (),
307
- named->getDecl ()->hasType ()
308
- ? named->getDecl ()->getType ()
309
- : Type (),
310
- named->getDecl ()->getDeclContext ());
311
-
312
- if (var->isImplicit ())
313
- var->setImplicit ();
314
- result = new (context) NamedPattern (var);
315
- break ;
316
- }
317
-
318
- case PatternKind::Paren: {
319
- auto paren = cast<ParenPattern>(this );
320
- result = new (context) ParenPattern (paren->getLParenLoc (),
321
- paren->getSubPattern ()->clone (context),
322
- paren->getRParenLoc ());
323
- break ;
324
- }
325
-
326
- case PatternKind::Tuple: {
327
- auto tuple = cast<TuplePattern>(this );
328
- SmallVector<TuplePatternElt, 2 > elts;
329
- elts.reserve (tuple->getNumElements ());
330
- for (const auto &elt : tuple->getElements ()) {
331
- auto eltPattern = elt.getPattern ()->clone (context);
332
- elts.push_back (TuplePatternElt (elt.getLabel (), elt.getLabelLoc (),
333
- eltPattern));
334
- }
335
-
336
- result = TuplePattern::create (context, tuple->getLParenLoc (), elts,
337
- tuple->getRParenLoc ());
338
- break ;
339
- }
340
-
341
- case PatternKind::Typed: {
342
- auto typed = cast<TypedPattern>(this );
343
- auto subP = typed->getSubPattern ()->clone (context);
344
- result = new (context) TypedPattern (subP,
345
- typed->getTypeLoc ().clone (context));
346
- break ;
347
- }
348
-
349
- case PatternKind::Is: {
350
- auto isa = cast<IsPattern>(this );
351
- result = new (context) IsPattern (isa->getLoc (),
352
- isa->getCastTypeLoc ().clone (context),
353
- isa->getSubPattern ()->clone (context),
354
- isa->getCastKind ());
355
- break ;
356
- }
357
-
358
- case PatternKind::NominalType: {
359
- auto nom = cast<NominalTypePattern>(this );
360
- SmallVector<NominalTypePattern::Element, 4 > elts;
361
- for (const auto &elt : nom->getElements ()) {
362
- elts.push_back (NominalTypePattern::Element (elt.getPropertyLoc (),
363
- elt.getPropertyName (),
364
- elt.getProperty (),
365
- elt.getColonLoc (),
366
- elt.getSubPattern ()->clone (context)));
367
- }
368
-
369
- result = NominalTypePattern::create (nom->getCastTypeLoc ().clone (context),
370
- nom->getLParenLoc (),
371
- elts,
372
- nom->getRParenLoc (), context);
373
- break ;
374
- }
375
-
376
- case PatternKind::EnumElement: {
377
- auto oof = cast<EnumElementPattern>(this );
378
- Pattern *sub = nullptr ;
379
- if (oof->hasSubPattern ())
380
- sub = oof->getSubPattern ()->clone (context);
381
- result = new (context) EnumElementPattern (oof->getParentType ()
382
- .clone (context),
383
- oof->getLoc (),
384
- oof->getNameLoc (),
385
- oof->getName (),
386
- oof->getElementDecl (),
387
- sub);
388
- break ;
389
- }
390
-
391
- case PatternKind::OptionalSome: {
392
- auto osp = cast<OptionalSomePattern>(this );
393
- auto *sub = osp->getSubPattern ()->clone (context);
394
- auto *r = new (context) OptionalSomePattern (sub, osp->getQuestionLoc ());
395
- r->setElementDecl (osp->getElementDecl ());
396
- result = r;
397
- break ;
398
- }
399
-
400
- case PatternKind::Bool: {
401
- auto bp = cast<BoolPattern>(this );
402
- result = new (context) BoolPattern (bp->getNameLoc (), bp->getValue ());
403
- break ;
404
- }
405
-
406
- case PatternKind::Expr: {
407
- auto expr = cast<ExprPattern>(this );
408
- result = new (context) ExprPattern (expr->getSubExpr (),
409
- expr->isResolved (),
410
- expr->getMatchExpr (),
411
- expr->getMatchVar ());
412
- break ;
413
- }
414
-
415
- case PatternKind::Var: {
416
- auto var = cast<VarPattern>(this );
417
- auto subP = var->getSubPattern ()->clone (context);
418
- result = new (context) VarPattern (var->getLoc (), var->isLet (), subP);
419
- }
420
- }
421
-
422
- if (hasType ())
423
- result->setType (getType ());
424
- if (isImplicit ())
425
- result->setImplicit ();
426
-
427
- return result;
428
- }
429
-
430
293
// / Standard allocator for Patterns.
431
- void *Pattern::operator new (size_t numBytes, ASTContext &C) {
294
+ void *Pattern::operator new (size_t numBytes, const ASTContext &C) {
432
295
return C.Allocate (numBytes, alignof (Pattern));
433
296
}
434
297
0 commit comments