lib/Sema/DerivedConformanceCodingKey.cpp
/// Sets the body of the given function to `self.init(rawValue:)`, passing along
/// the parameter of the given constructor.
///
/// \param initDecl The constructor whose body to set.
Sets the body of the given function to `self.init(rawValue:)`, passing along
the parameter of the given constructor.

\param initDecl The constructor whose body to set.
Sets the body of the given function to ` self . init ( rawValue : ) ` passing along the parameter of the given constructor . \ param initDecl The constructor whose body to set .
static void deriveRawValueInit(AbstractFunctionDecl *initDecl, void *) {
  auto *parentDC = initDecl->getDeclContext();
  auto &C = parentDC->getASTContext();
  auto *valueParam = initDecl->getParameters()->get(0);
  auto *valueParamExpr = new (C) DeclRefExpr(ConcreteDeclRef(valueParam),
                                             DeclNameLoc(), true);
  auto *rawValueDecl = new (C) ParamDecl(
      VarDecl::Specifier::Default, SourceLoc(), SourceLoc(), C.Id_rawValue,
      SourceLoc(), C.Id_rawValue, parentDC);
  rawValueDecl->setInterfaceType(C.getIntDecl()->getDeclaredType());
  rawValueDecl->setImplicit();
  auto *paramList = ParameterList::createWithoutLoc(rawValueDecl);
  DeclName ctorName(C, DeclBaseName::createConstructor(), paramList);
  auto *selfRef = DerivedConformance::createSelfDeclRef(initDecl);
  auto *initExpr = new (C) UnresolvedDotExpr(selfRef, SourceLoc(), ctorName,
                                             DeclNameLoc(), true);
  Expr *args[1] = {valueParamExpr};
  Identifier argLabels[1] = {C.Id_rawValue};
  auto *callExpr = CallExpr::createImplicit(C, initExpr, C.AllocateCopy(args),
                                            C.AllocateCopy(argLabels));
  auto *body = BraceStmt::create(C, SourceLoc(), ASTNode(callExpr),
                                 SourceLoc());
  initDecl->setBody(body);
}
static void deriveRawValueInit ( AbstractFunctionDecl * initDecl , void * ) { auto * parentDC = initDecl -> getDeclContext ( ) ; auto & C = parentDC -> getASTContext ( ) ; auto * valueParam = initDecl -> getParameters ( ) -> get ( 0 ) ; auto * valueParamExpr = new ( C ) DeclRefExpr ( ConcreteDeclRef ( valueParam ) , DeclNameLoc ( ) , true ) ; auto * rawValueDecl = new ( C ) ParamDecl ( VarDecl :: Specifier :: Default , SourceLoc ( ) , SourceLoc ( ) , C . Id_rawValue , SourceLoc ( ) , C . Id_rawValue , parentDC ) ; rawValueDecl -> setInterfaceType ( C . getIntDecl ( ) -> getDeclaredType ( ) ) ; rawValueDecl -> setImplicit ( ) ; auto * paramList = ParameterList :: createWithoutLoc ( rawValueDecl ) ; DeclName ctorName ( C , DeclBaseName :: createConstructor ( ) , paramList ) ; auto * selfRef = DerivedConformance :: createSelfDeclRef ( initDecl ) ; auto * initExpr = new ( C ) UnresolvedDotExpr ( selfRef , SourceLoc ( ) , ctorName , DeclNameLoc ( ) , true ) ; Expr * args [ 1 ] = { valueParamExpr } ; Identifier argLabels [ 1 ] = { C . Id_rawValue } ; auto * callExpr = CallExpr :: createImplicit ( C , initExpr , C . AllocateCopy ( args ) , C . AllocateCopy ( argLabels ) ) ; auto * body = BraceStmt :: create ( C , SourceLoc ( ) , ASTNode ( callExpr ) , SourceLoc ( ) ) ; initDecl -> setBody ( body ) ; }
Sets the body of the given function to `self.init(rawValue:)`, passing along
the parameter of the given constructor.
Sets the body of the given function to ` self . init ( rawValue : ) ` passing along the parameter of the given constructor .
// Get the param from init({string,int}Value:). self is the first param in the // list; stringValue is the second. /*Implicit=*/ // rawValue param to init(rawValue:) // init(rawValue:) constructor name // self.init(rawValue:) expr /*Implicit=*/ // Bind the value param in self.init(rawValue: {string,int}Value).