lib/ClangImporter/ImportDecl.cpp
// Build the rawValue getter for an imported NS_ENUM.
//   enum NSSomeEnum: RawType {
//     var rawValue: RawType {
//       return Builtin.reinterpretCast(self)
//     }
//   }
// Unlike a standard init(rawValue:) enum initializer, this does a reinterpret
// cast in order to preserve unknown or future cases from C.
Build the rawValue getter for an imported NS_ENUM.
enum NSSomeEnum: RawType {
var rawValue: RawType {
return Builtin.reinterpretCast(self)
}
}
Unlike a standard init(rawValue:) enum initializer, this does a reinterpret
cast in order to preserve unknown or future cases from C.
Build the rawValue getter for an imported NS_ENUM . enum NSSomeEnum : RawType { var rawValue : RawType { return Builtin . reinterpretCast ( self ) } } Unlike a standard init ( rawValue : ) enum initializer this does a reinterpret cast in order to preserve unknown or future cases from C .
static FuncDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
                                        EnumDecl *enumDecl,
                                        VarDecl *rawValueDecl) {
  ASTContext &C = Impl.SwiftContext;
  auto selfDecl = ParamDecl::createSelf(SourceLoc(), enumDecl);
  ParameterList *params[] = {
    ParameterList::createWithoutLoc(selfDecl),
    ParameterList::createEmpty(C)
  };
  auto getterDecl =
    FuncDecl::create(C, SourceLoc(), StaticSpellingKind::None, SourceLoc(),
                     DeclName(), SourceLoc(), SourceLoc(), SourceLoc(), nullptr,
                     Type(), params,
                     TypeLoc::withoutLoc(enumDecl->getRawType()), enumDecl);
  getterDecl->setImplicit();
  getterDecl->setType(ParameterList::getFullType(enumDecl->getRawType(),
                                                 params));
  getterDecl->setBodyResultType(enumDecl->getRawType());
  getterDecl->setAccessibility(Accessibility::Public);
  rawValueDecl->makeComputed(SourceLoc(), getterDecl, nullptr, nullptr,
                             SourceLoc());
  if (Impl.hasFinishedTypeChecking())
    return getterDecl;
  auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(), true);
  auto reinterpretCast
    = cast<FuncDecl>(getBuiltinValueDecl(C, C.getIdentifier("reinterpretCast")));
  auto reinterpretCastRef
    = new (C) DeclRefExpr(reinterpretCast, DeclNameLoc(),  true);
  auto reinterpreted = new (C) CallExpr(reinterpretCastRef, selfRef,
                                         true);
  auto ret = new (C) ReturnStmt(SourceLoc(), reinterpreted);
  auto body = BraceStmt::create(C, SourceLoc(), ASTNode(ret), SourceLoc(),
                                 true);
  getterDecl->setBody(body);
  C.addExternalDecl(getterDecl);
  return getterDecl;
}
static FuncDecl * makeEnumRawValueGetter ( ClangImporter :: Implementation & Impl , EnumDecl * enumDecl , VarDecl * rawValueDecl ) { ASTContext & C = Impl . SwiftContext ; auto selfDecl = ParamDecl :: createSelf ( SourceLoc ( ) , enumDecl ) ; ParameterList * params [ ] = { ParameterList :: createWithoutLoc ( selfDecl ) , ParameterList :: createEmpty ( C ) } ; auto getterDecl = FuncDecl :: create ( C , SourceLoc ( ) , StaticSpellingKind :: None , SourceLoc ( ) , DeclName ( ) , SourceLoc ( ) , SourceLoc ( ) , SourceLoc ( ) , nullptr , Type ( ) , params , TypeLoc :: withoutLoc ( enumDecl -> getRawType ( ) ) , enumDecl ) ; getterDecl -> setImplicit ( ) ; getterDecl -> setType ( ParameterList :: getFullType ( enumDecl -> getRawType ( ) , params ) ) ; getterDecl -> setBodyResultType ( enumDecl -> getRawType ( ) ) ; getterDecl -> setAccessibility ( Accessibility :: Public ) ; rawValueDecl -> makeComputed ( SourceLoc ( ) , getterDecl , nullptr , nullptr , SourceLoc ( ) ) ; if ( Impl . hasFinishedTypeChecking ( ) ) return getterDecl ; auto selfRef = new ( C ) DeclRefExpr ( selfDecl , DeclNameLoc ( ) , true ) ; auto reinterpretCast = cast < FuncDecl > ( getBuiltinValueDecl ( C , C . getIdentifier ( " " ) ) ) ; auto reinterpretCastRef = new ( C ) DeclRefExpr ( reinterpretCast , DeclNameLoc ( ) , true ) ; auto reinterpreted = new ( C ) CallExpr ( reinterpretCastRef , selfRef , true ) ; auto ret = new ( C ) ReturnStmt ( SourceLoc ( ) , reinterpreted ) ; auto body = BraceStmt :: create ( C , SourceLoc ( ) , ASTNode ( ret ) , SourceLoc ( ) , true ) ; getterDecl -> setBody ( body ) ; C . addExternalDecl ( getterDecl ) ; return getterDecl ; }
Build the rawValue getter for an imported NS_ENUM.
Build the rawValue getter for an imported NS_ENUM .
// Don't bother synthesizing the body if we've already finished type-checking. /*implicit*/ /*implicit*/ /*implicit*/ /*implicit*/