lib/ClangImporter/ImportDecl.cpp
/// Finish the given protocol conformance (for an imported type)
/// by filling in any missing witnesses.
Finish the given protocol conformance (for an imported type)
by filling in any missing witnesses.
Finish the given protocol conformance ( for an imported type ) by filling in any missing witnesses .
void ClangImporter::Implementation::finishProtocolConformance(
    NormalProtocolConformance *conformance) {
  for (auto req : conformance->getProtocol()->getMembers()) {
    auto valueReq = dyn_cast<ValueDecl>(req);
    if (!valueReq)
      continue;
    if (!conformance->hasWitness(valueReq)) {
      if (auto func = dyn_cast<AbstractFunctionDecl>(valueReq)){
        auto Attrs = func->getAttrs();
        if (Attrs.hasAttribute<OptionalAttr>()) {
          conformance->setWitness(valueReq, ConcreteDeclRef());
          continue;
        }
      }
      conformance->setWitness(valueReq, valueReq);
    } else {
      auto witness = conformance->getWitness(valueReq, nullptr).getDecl();
      if (auto ctor = dyn_cast_or_null<ConstructorDecl>(witness)) {
        if (!ctor->getAttrs().hasAttribute<RequiredAttr>()) {
          ctor->getAttrs().add(
            new (SwiftContext) RequiredAttr(true));
        }
      }
    }
  }
  conformance->setState(ProtocolConformanceState::Complete);
}
void ClangImporter :: Implementation :: finishProtocolConformance ( NormalProtocolConformance * conformance ) { for ( auto req : conformance -> getProtocol ( ) -> getMembers ( ) ) { auto valueReq = dyn_cast < ValueDecl > ( req ) ; if ( ! valueReq ) continue ; if ( ! conformance -> hasWitness ( valueReq ) ) { if ( auto func = dyn_cast < AbstractFunctionDecl > ( valueReq ) ) { auto Attrs = func -> getAttrs ( ) ; if ( Attrs . hasAttribute < OptionalAttr > ( ) ) { conformance -> setWitness ( valueReq , ConcreteDeclRef ( ) ) ; continue ; } } conformance -> setWitness ( valueReq , valueReq ) ; } else { auto witness = conformance -> getWitness ( valueReq , nullptr ) . getDecl ( ) ; if ( auto ctor = dyn_cast_or_null < ConstructorDecl > ( witness ) ) { if ( ! ctor -> getAttrs ( ) . hasAttribute < RequiredAttr > ( ) ) { ctor -> getAttrs ( ) . add ( new ( SwiftContext ) RequiredAttr ( true ) ) ; } } } } conformance -> setState ( ProtocolConformanceState :: Complete ) ; }
Finish the given protocol conformance (for an imported type)
by filling in any missing witnesses.
Finish the given protocol conformance ( for an imported type ) by filling in any missing witnesses .
// Create witnesses for requirements not already met. // For an optional requirement, record an empty witness: // we'll end up querying this at runtime. // An initializer that conforms to a requirement is required. /*implicit=*/