lib/Sema/DerivedConformanceCodingKey.cpp
/// Returns whether the given enum is eligible for CodingKey synthesis.
Returns whether the given enum is eligible for CodingKey synthesis.
Returns whether the given enum is eligible for CodingKey synthesis .
static bool canSynthesizeCodingKey(DerivedConformance &derived) {
  auto enumDecl = cast<EnumDecl>(derived.Nominal);
  derived.TC.validateDecl(enumDecl);
  Type rawType = enumDecl->getRawType();
  if (rawType) {
    auto *parentDC = derived.getConformanceContext();
    rawType = parentDC->mapTypeIntoContext(rawType);
    auto &C = derived.TC.Context;
    auto *nominal = rawType->getCanonicalType()->getAnyNominal();
    if (nominal != C.getStringDecl() && nominal != C.getIntDecl())
      return false;
  }
  auto inherited = enumDecl->getInherited();
  if (!inherited.empty() && inherited.front().wasValidated() &&
      inherited.front().isError())
    return false;
  return true;
}
static bool canSynthesizeCodingKey ( DerivedConformance & derived ) { auto enumDecl = cast < EnumDecl > ( derived . Nominal ) ; derived . TC . validateDecl ( enumDecl ) ; Type rawType = enumDecl -> getRawType ( ) ; if ( rawType ) { auto * parentDC = derived . getConformanceContext ( ) ; rawType = parentDC -> mapTypeIntoContext ( rawType ) ; auto & C = derived . TC . Context ; auto * nominal = rawType -> getCanonicalType ( ) -> getAnyNominal ( ) ; if ( nominal != C . getStringDecl ( ) && nominal != C . getIntDecl ( ) ) return false ; } auto inherited = enumDecl -> getInherited ( ) ; if ( ! inherited . empty ( ) && inherited . front ( ) . wasValidated ( ) && inherited . front ( ) . isError ( ) ) return false ; return true ; }
Returns whether the given enum is eligible for CodingKey synthesis.
Returns whether the given enum is eligible for CodingKey synthesis .
// Validate the enum and its raw type. // If the enum has a raw type (optional), it must be String or Int. // If it meets all of those requirements, we can synthesize CodingKey // conformance.