当前位置: 首页>>代码示例>>C++>>正文


C++ StringRef::startswith方法代码示例

本文整理汇总了C++中StringRef::startswith方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::startswith方法的具体用法?C++ StringRef::startswith怎么用?C++ StringRef::startswith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringRef的用法示例。


在下文中一共展示了StringRef::startswith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDarwinNumber

/// getDarwinNumber - Parse the 'darwin number' out of the specific target
/// triple.  For example, if we have darwin8.5 return 8,5,0.  If any entry is
/// not defined, return 0's.  This requires that the triple have an OSType of
/// darwin before it is called.
void Triple::getDarwinNumber(unsigned &Maj, unsigned &Min,
                             unsigned &Revision) const {
  assert(getOS() == Darwin && "Not a darwin target triple!");
  StringRef OSName = getOSName();
  assert(OSName.startswith("darwin") && "Unknown darwin target triple!");
  
  // Strip off "darwin".
  OSName = OSName.substr(6);
  
  Maj = Min = Revision = 0;

  if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
    return;

  // The major version is the first digit.
  Maj = EatNumber(OSName);
  if (OSName.empty()) return;
  
  // Handle minor version: 10.4.9 -> darwin8.9.
  if (OSName[0] != '.')
    return;
  
  // Eat the '.'.
  OSName = OSName.substr(1);

  if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
    return;
  
  Min = EatNumber(OSName);
  if (OSName.empty()) return;

  // Handle revision darwin8.9.1
  if (OSName[0] != '.')
    return;
  
  // Eat the '.'.
  OSName = OSName.substr(1);
  
  if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
    return;

  Revision = EatNumber(OSName);
}
开发者ID:aaasz,项目名称:SHP,代码行数:47,代码来源:Triple.cpp

示例2: assert

static const ProtocolDescriptor *
_searchProtocolRecords(ProtocolMetadataPrivateState &C,
                       const llvm::StringRef protocolName){
  for (auto &section : C.SectionsToScan.snapshot()) {
    for (const auto &record : section) {
      if (auto protocol = record.Protocol.getPointer()) {
        // Drop the "S$" prefix from the protocol record. It's not used in
        // the type itself.
        StringRef foundProtocolName = protocol->Name;
        assert(foundProtocolName.startswith("$S"));
        foundProtocolName = foundProtocolName.drop_front(2);
        if (foundProtocolName == protocolName)
          return protocol;
      }
    }
  }

  return nullptr;
}
开发者ID:XLsn0wKit,项目名称:swift,代码行数:19,代码来源:MetadataLookup.cpp

示例3: parseVersionFromName

static void parseVersionFromName(StringRef Name, unsigned &Major,
                                 unsigned &Minor, unsigned &Micro) {
  // Any unset version defaults to 0.
  Major = Minor = Micro = 0;

  // Parse up to three components.
  unsigned *Components[3] = {&Major, &Minor, &Micro};
  for (unsigned i = 0; i != 3; ++i) {
    if (Name.empty() || Name[0] < '0' || Name[0] > '9')
      break;

    // Consume the leading number.
    *Components[i] = EatNumber(Name);

    // Consume the separator, if present.
    if (Name.startswith("."))
      Name = Name.substr(1);
  }
}
开发者ID:pasaulais,项目名称:llvm-leg,代码行数:19,代码来源:Triple.cpp

示例4: hasAttribute

int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope,
                        const IdentifierInfo *Attr, const TargetInfo &Target,
                        const LangOptions &LangOpts) {
  StringRef Name = Attr->getName();
  // Normalize the attribute name, __foo__ becomes foo.
  if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__"))
    Name = Name.substr(2, Name.size() - 4);

  // Normalize the scope name, but only for gnu and clang attributes.
  StringRef ScopeName = Scope ? Scope->getName() : "";
  if (ScopeName == "__gnu__")
    ScopeName = "gnu";
  else if (ScopeName == "_Clang")
    ScopeName = "clang";

#include "clang/Basic/AttrHasAttributeImpl.inc"

  return 0;
}
开发者ID:CTSRD-CHERI,项目名称:clang,代码行数:19,代码来源:Attributes.cpp

示例5: GetVersionFromSimulatorDefine

/// \brief Parse the simulator version define:
/// __IPHONE_OS_VERSION_MIN_REQUIRED=([0-9])([0-9][0-9])([0-9][0-9])
// and return the grouped values as integers, e.g:
//   __IPHONE_OS_VERSION_MIN_REQUIRED=40201
// will return Major=4, Minor=2, Micro=1.
static bool GetVersionFromSimulatorDefine(StringRef define,
        unsigned &Major, unsigned &Minor,
        unsigned &Micro) {
    assert(define.startswith(SimulatorVersionDefineName()));
    StringRef name, version;
    llvm::tie(name, version) = define.split('=');
    if (version.empty())
        return false;
    std::string verstr = version.str();
    char *end;
    unsigned num = (unsigned) strtol(verstr.c_str(), &end, 10);
    if (*end != '\0')
        return false;
    Major = num / 10000;
    num = num % 10000;
    Minor = num / 100;
    Micro = num % 100;
    return true;
}
开发者ID:avakar,项目名称:clang,代码行数:24,代码来源:ARCMT.cpp

示例6: LexSingleQuote

/// LexSingleQuote: Integer: 'b'
AsmToken AsmLexer::LexSingleQuote() {
    int CurChar = getNextChar();

    if (CurChar == '\\')
        CurChar = getNextChar();

    if (CurChar == EOF)
        return ReturnError(TokStart, "unterminated single quote");

    CurChar = getNextChar();

    if (CurChar != '\'')
        return ReturnError(TokStart, "single quote way too long");

    // The idea here being that 'c' is basically just an integral
    // constant.
    StringRef Res = StringRef(TokStart,CurPtr - TokStart);
    long long Value;

    if (Res.startswith("\'\\")) {
        char theChar = Res[2];
        switch (theChar) {
        default:
            Value = theChar;
            break;
        case '\'':
            Value = '\'';
            break;
        case 't':
            Value = '\t';
            break;
        case 'n':
            Value = '\n';
            break;
        case 'b':
            Value = '\b';
            break;
        }
    } else
        Value = TokStart[1];

    return AsmToken(AsmToken::Integer, Res, Value);
}
开发者ID:james-boulton,项目名称:llvm-m68k,代码行数:44,代码来源:AsmLexer.cpp

示例7: ToHeader

error_code Archive::Child::getName(StringRef &Result) const {
  StringRef name = ToHeader(Data.data())->getName();
  // Check if it's a special name.
  if (name[0] == '/') {
    if (name.size() == 1) { // Linker member.
      Result = name;
      return object_error::success;
    }
    if (name.size() == 2 && name[1] == '/') { // String table.
      Result = name;
      return object_error::success;
    }
    // It's a long name.
    // Get the offset.
    APInt offset;
    name.substr(1).getAsInteger(10, offset);
    const char *addr = Parent->StringTable->Data.begin()
                       + sizeof(ArchiveMemberHeader)
                       + offset.getZExtValue();
    // Verify it.
    if (Parent->StringTable == Parent->end_children()
        || addr < (Parent->StringTable->Data.begin()
                   + sizeof(ArchiveMemberHeader))
        || addr > (Parent->StringTable->Data.begin()
                   + sizeof(ArchiveMemberHeader)
                   + Parent->StringTable->getSize()))
      return object_error::parse_failed;
    Result = addr;
    return object_error::success;
  } else if (name.startswith("#1/")) {
    APInt name_size;
    name.substr(3).getAsInteger(10, name_size);
    Result = Data.substr(0, name_size.getZExtValue());
    return object_error::success;
  }
  // It's a simple name.
  if (name[name.size() - 1] == '/')
    Result = name.substr(0, name.size() - 1);
  else
    Result = name;
  return object_error::success;
}
开发者ID:groue,项目名称:llvm,代码行数:42,代码来源:Archive.cpp

示例8: handleIns

void StatsComputer::handleIns(FunInfo &funInfo, const Instruction &ins) {
  if (const CallInst *CI = dyn_cast<const CallInst>(&ins)) {
    if (CI->isInlineAsm()) {
#ifdef DEBUG_ASM
      errs() << "ASM: in " << ins.getParent()->getParent()->getName() << " ";
      CI->print(errs());
      CI->getParent()->print(errs());
      errs() << "\n";
#endif
      funInfo.setHasAsm();
    } else {
      Function *called = CI->getCalledFunction();
      if (called) {
        StringRef calledName = called->getName();
        if (calledName.startswith("llvm.") ||
            calledName.equals("__assert_fail") ||
            calledName.equals("__kmalloc") || calledName.equals("kfree") ||
            isLockingFun(calledName))
          return;
        if (called->isDeclaration()) {
#ifdef DEBUG_EXT
          errs() << "EXT1 " << ins.getParent()->getParent()->getName() << " to "
                 << called->getName() << "\n";
#endif
          funInfo.setHasExternalCall();
        }
      } else {
#ifdef DEBUG_EXT
        errs() << "EXT2 " << ins.getParent()->getParent()->getName() << " to ";
        ins.print(errs());
        errs() << '\n';
#endif
        funInfo.setHasExternalCall();
      }
      funInfo.setHasCall();
    }
  } else if (const StoreInst *SI = dyn_cast<const StoreInst>(&ins)) {
    const Value *LHS = SI->getPointerOperand();
    if (LHS->hasName() && LHS->getName().startswith("__ai_state"))
      funInfo.setHasLock();
  }
}
开发者ID:Justme0,项目名称:LLVMSlicer,代码行数:42,代码来源:ModStats.cpp

示例9: Type

Type
ASTBuilder::createBuiltinType(StringRef builtinName,
                              StringRef mangledName) {
  if (builtinName.startswith(BUILTIN_TYPE_NAME_PREFIX)) {
    SmallVector<ValueDecl *, 1> decls;

    ModuleDecl::AccessPathTy accessPath;
    StringRef strippedName =
          builtinName.drop_front(strlen(BUILTIN_TYPE_NAME_PREFIX));
    Ctx.TheBuiltinModule->lookupValue(accessPath,
                                      Ctx.getIdentifier(strippedName),
                                      NLKind::QualifiedLookup,
                                      decls);
    
    if (decls.size() == 1 && isa<TypeDecl>(decls[0]))
      return cast<TypeDecl>(decls[0])->getDeclaredInterfaceType();
  }

  return Type();
}
开发者ID:amraboelela,项目名称:swift,代码行数:20,代码来源:ASTDemangler.cpp

示例10: Parent

Archive::Child::Child(const Archive *Parent, const char *Start)
    : Parent(Parent) {
  if (!Start)
    return;

  const ArchiveMemberHeader *Header =
      reinterpret_cast<const ArchiveMemberHeader *>(Start);
  Data = StringRef(Start, sizeof(ArchiveMemberHeader) + Header->getSize());

  // Setup StartOfFile and PaddingBytes.
  StartOfFile = sizeof(ArchiveMemberHeader);
  // Don't include attached name.
  StringRef Name = Header->getName();
  if (Name.startswith("#1/")) {
    uint64_t NameSize;
    if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
      llvm_unreachable("Long name length is not an integer");
    StartOfFile += NameSize;
  }
}
开发者ID:Xmister,项目名称:llvm-onex,代码行数:20,代码来源:Archive.cpp

示例11: assert

static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
  assert(F && "Illegal to upgrade a non-existent Function.");

  // Quickly eliminate it, if it's not a candidate.
  StringRef Name = F->getName();
  if (Name.size() <= 8 || !Name.startswith("llvm."))
    return false;
  Name = Name.substr(5); // Strip off "llvm."

  switch (Name[0]) {
  default: break;
  // SOMEDAY: Add some.
  }

  //  This may not belong here. This function is effectively being overloaded 
  //  to both detect an intrinsic which needs upgrading, and to provide the 
  //  upgraded form of the intrinsic. We should perhaps have two separate 
  //  functions for this.
  return false;
}
开发者ID:Bootz,项目名称:multicore-opimization,代码行数:20,代码来源:AutoUpgrade.cpp

示例12: sanitizeCompilerArgs

static void sanitizeCompilerArgs(ArrayRef<const char *> Args,
                                 SmallVectorImpl<const char *> &NewArgs) {
  for (const char *CArg : Args) {
    StringRef Arg = CArg;
    if (Arg.startswith("-j"))
      continue;
    if (Arg == "-c")
      continue;
    if (Arg == "-v")
      continue;
    if (Arg == "-Xfrontend")
      continue;
    if (Arg == "-embed-bitcode")
      continue;
    if (Arg == "-enable-bridging-pch" ||
        Arg == "-disable-bridging-pch")
      continue;
    NewArgs.push_back(CArg);
  }
}
开发者ID:randomstep,项目名称:swift,代码行数:20,代码来源:SwiftASTManager.cpp

示例13: parseInputFilenamesFile

static void parseInputFilenamesFile(MemoryBuffer *Buffer,
                                    WeightedFileVector &WFV) {
  if (!Buffer)
    return;

  SmallVector<StringRef, 8> Entries;
  StringRef Data = Buffer->getBuffer();
  Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
  for (const StringRef &FileWeightEntry : Entries) {
    StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
    // Skip comments.
    if (SanitizedEntry.startswith("#"))
      continue;
    // If there's no comma, it's an unweighted profile.
    else if (SanitizedEntry.find(',') == StringRef::npos)
      addWeightedInput(WFV, {SanitizedEntry, 1});
    else
      addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
  }
}
开发者ID:ralic,项目名称:llvm,代码行数:20,代码来源:llvm-profdata.cpp

示例14: StringRef

ErrorOr<StringRef> Archive::Child::getName() const {
  StringRef name = getRawName();
  // Check if it's a special name.
  if (name[0] == '/') {
    if (name.size() == 1) // Linker member.
      return name;
    if (name.size() == 2 && name[1] == '/') // String table.
      return name;
    // It's a long name.
    // Get the offset.
    std::size_t offset;
    if (name.substr(1).rtrim(' ').getAsInteger(10, offset))
      llvm_unreachable("Long name offset is not an integer");

    // Verify it.
    if (offset >= Parent->StringTable.size())
      return object_error::parse_failed;
    const char *addr = Parent->StringTable.begin() + offset;

    // GNU long file names end with a "/\n".
    if (Parent->kind() == K_GNU || Parent->kind() == K_MIPS64) {
      StringRef::size_type End = StringRef(addr).find('\n');
      return StringRef(addr, End - 1);
    }
    return StringRef(addr);
  } else if (name.startswith("#1/")) {
    uint64_t name_size;
    if (name.substr(3).rtrim(' ').getAsInteger(10, name_size))
      llvm_unreachable("Long name length is not an ingeter");
    return Data.substr(Header.getSizeOf(), name_size).rtrim('\0');
  } else {
    // It is not a long name so trim the blanks at the end of the name.
    if (name[name.size() - 1] != '/') {
      return name.rtrim(' ');
    }
  }
  // It's a simple name.
  if (name[name.size() - 1] == '/')
    return name.substr(0, name.size() - 1);
  return name;
}
开发者ID:clockmaker002,项目名称:llvm,代码行数:41,代码来源:Archive.cpp

示例15: ConvertBackendLocation

/// InlineAsmDiagHandler2 - This function is invoked when the backend hits an
/// error parsing inline asm.  The SMDiagnostic indicates the error relative to
/// the temporary memory buffer that the inline asm parser has set up.
void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
                                            SourceLocation LocCookie) {
  // There are a couple of different kinds of errors we could get here.  First,
  // we re-format the SMDiagnostic in terms of a clang diagnostic.

  // Strip "error: " off the start of the message string.
  StringRef Message = D.getMessage();
  if (Message.startswith("error: "))
    Message = Message.substr(7);

  // If the SMDiagnostic has an inline asm source location, translate it.
  FullSourceLoc Loc;
  if (D.getLoc() != SMLoc())
    Loc = ConvertBackendLocation(D, Context->getSourceManager());
  

  // If this problem has clang-level source location information, report the
  // issue as being an error in the source with a note showing the instantiated
  // code.
  if (LocCookie.isValid()) {
    Diags.Report(LocCookie, diag::err_fe_inline_asm).AddString(Message);
    
    if (D.getLoc().isValid()) {
      DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
      // Convert the SMDiagnostic ranges into SourceRange and attach them
      // to the diagnostic.
      for (unsigned i = 0, e = D.getRanges().size(); i != e; ++i) {
        std::pair<unsigned, unsigned> Range = D.getRanges()[i];
        unsigned Column = D.getColumnNo();
        B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
                         Loc.getLocWithOffset(Range.second - Column));
      }
    }
    return;
  }
  
  // Otherwise, report the backend error as occurring in the generated .s file.
  // If Loc is invalid, we still need to report the error, it just gets no
  // location info.
  Diags.Report(Loc, diag::err_fe_inline_asm).AddString(Message);
}
开发者ID:bhushan23,项目名称:clang,代码行数:44,代码来源:CodeGenAction.cpp


注:本文中的StringRef::startswith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。