Beispiel #1
0
DeclarationName::DeclarationName(Selector Sel) {
    if (!Sel.getAsOpaquePtr()) {
        Ptr = 0;
        return;
    }

    switch (Sel.getNumArgs()) {
    case 0:
        Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
        assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
        Ptr |= StoredObjCZeroArgSelector;
        break;

    case 1:
        Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
        assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
        Ptr |= StoredObjCOneArgSelector;
        break;

    default:
        Ptr = Sel.InfoPtr & ~Selector::ArgFlags;
        assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector");
        Ptr |= StoredDeclarationNameExtra;
        break;
    }
}
/// \brief Get a GlobalSelector for the ASTContext-specific selector.
GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) {
  if (Sel.isNull())
    return GlobalSelector();

  ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl);

  llvm::SmallVector<IdentifierInfo *, 8> Ids;
  for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs();
         i != e; ++i) {
    IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i);
    IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName(),
                                               II->getName() + II->getLength());
    Ids.push_back(GlobII);
  }

  Selector GlobSel = ProgImpl.getSelectors().getSelector(Sel.getNumArgs(),
                                                         Ids.data());
  return GlobalSelector(GlobSel.getAsOpaquePtr());
}