本文整理汇总了C++中StringRef::end方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::end方法的具体用法?C++ StringRef::end怎么用?C++ StringRef::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
/// fields in this structure. If the constraint string is not understood,
/// return true, otherwise return false.
bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
InlineAsm::ConstraintInfoVector &ConstraintsSoFar) {
StringRef::iterator I = Str.begin(), E = Str.end();
unsigned multipleAlternativeCount = Str.count('|') + 1;
unsigned multipleAlternativeIndex = 0;
ConstraintCodeVector *pCodes = &Codes;
// Initialize
isMultipleAlternative = multipleAlternativeCount > 1;
if (isMultipleAlternative) {
multipleAlternatives.resize(multipleAlternativeCount);
pCodes = &multipleAlternatives[0].Codes;
}
Type = isInput;
isEarlyClobber = false;
MatchingInput = -1;
isCommutative = false;
isIndirect = false;
currentAlternativeIndex = 0;
// Parse prefixes.
if (*I == '~') {
Type = isClobber;
++I;
// '{' must immediately follow '~'.
if (I != E && *I != '{')
return true;
} else if (*I == '=') {
++I;
Type = isOutput;
}
if (*I == '*') {
isIndirect = true;
++I;
}
if (I == E) return true; // Just a prefix, like "==" or "~".
// Parse the modifiers.
bool DoneWithModifiers = false;
while (!DoneWithModifiers) {
switch (*I) {
default:
DoneWithModifiers = true;
break;
case '&': // Early clobber.
if (Type != isOutput || // Cannot early clobber anything but output.
isEarlyClobber) // Reject &&&&&&
return true;
isEarlyClobber = true;
break;
case '%': // Commutative.
if (Type == isClobber || // Cannot commute clobbers.
isCommutative) // Reject %%%%%
return true;
isCommutative = true;
break;
case '#': // Comment.
case '*': // Register preferencing.
return true; // Not supported.
}
if (!DoneWithModifiers) {
++I;
if (I == E) return true; // Just prefixes and modifiers!
}
}
// Parse the various constraints.
while (I != E) {
if (*I == '{') { // Physical register reference.
// Find the end of the register name.
StringRef::iterator ConstraintEnd = std::find(I+1, E, '}');
if (ConstraintEnd == E) return true; // "{foo"
pCodes->push_back(StringRef(I, ConstraintEnd+1 - I));
I = ConstraintEnd+1;
} else if (isdigit(static_cast<unsigned char>(*I))) { // Matching Constraint
// Maximal munch numbers.
StringRef::iterator NumStart = I;
while (I != E && isdigit(static_cast<unsigned char>(*I)))
++I;
pCodes->push_back(StringRef(NumStart, I - NumStart));
unsigned N = atoi(pCodes->back().c_str());
// Check that this is a valid matching constraint!
if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput||
Type != isInput)
return true; // Invalid constraint number.
// If Operand N already has a matching input, reject this. An output
// can't be constrained to the same value as multiple inputs.
if (isMultipleAlternative) {
if (multipleAlternativeIndex >=
ConstraintsSoFar[N].multipleAlternatives.size())
return true;
InlineAsm::SubConstraintInfo &scInfo =
//.........这里部分代码省略.........
示例2: EmitBytes
void MCObjectStreamer::EmitBytes(StringRef Data) {
MCLineEntry::Make(this, getCurrentSection().first);
getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
}
示例3: getRelocationType
error_code
MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const {
StringRef res;
uint64_t RType;
getRelocationType(Rel, RType);
unsigned Arch = this->getArch();
switch (Arch) {
case Triple::x86: {
static const char *const Table[] = {
"GENERIC_RELOC_VANILLA",
"GENERIC_RELOC_PAIR",
"GENERIC_RELOC_SECTDIFF",
"GENERIC_RELOC_PB_LA_PTR",
"GENERIC_RELOC_LOCAL_SECTDIFF",
"GENERIC_RELOC_TLV" };
if (RType > 5)
res = "Unknown";
else
res = Table[RType];
break;
}
case Triple::x86_64: {
static const char *const Table[] = {
"X86_64_RELOC_UNSIGNED",
"X86_64_RELOC_SIGNED",
"X86_64_RELOC_BRANCH",
"X86_64_RELOC_GOT_LOAD",
"X86_64_RELOC_GOT",
"X86_64_RELOC_SUBTRACTOR",
"X86_64_RELOC_SIGNED_1",
"X86_64_RELOC_SIGNED_2",
"X86_64_RELOC_SIGNED_4",
"X86_64_RELOC_TLV" };
if (RType > 9)
res = "Unknown";
else
res = Table[RType];
break;
}
case Triple::arm: {
static const char *const Table[] = {
"ARM_RELOC_VANILLA",
"ARM_RELOC_PAIR",
"ARM_RELOC_SECTDIFF",
"ARM_RELOC_LOCAL_SECTDIFF",
"ARM_RELOC_PB_LA_PTR",
"ARM_RELOC_BR24",
"ARM_THUMB_RELOC_BR22",
"ARM_THUMB_32BIT_BRANCH",
"ARM_RELOC_HALF",
"ARM_RELOC_HALF_SECTDIFF" };
if (RType > 9)
res = "Unknown";
else
res = Table[RType];
break;
}
case Triple::ppc: {
static const char *const Table[] = {
"PPC_RELOC_VANILLA",
"PPC_RELOC_PAIR",
"PPC_RELOC_BR14",
"PPC_RELOC_BR24",
"PPC_RELOC_HI16",
"PPC_RELOC_LO16",
"PPC_RELOC_HA16",
"PPC_RELOC_LO14",
"PPC_RELOC_SECTDIFF",
"PPC_RELOC_PB_LA_PTR",
"PPC_RELOC_HI16_SECTDIFF",
"PPC_RELOC_LO16_SECTDIFF",
"PPC_RELOC_HA16_SECTDIFF",
"PPC_RELOC_JBSR",
"PPC_RELOC_LO14_SECTDIFF",
"PPC_RELOC_LOCAL_SECTDIFF" };
if (RType > 15)
res = "Unknown";
else
res = Table[RType];
break;
}
case Triple::UnknownArch:
res = "Unknown";
break;
}
Result.append(res.begin(), res.end());
return object_error::success;
}
示例4: EmitBytes
void MCObjectStreamer::EmitBytes(StringRef Data) {
MCLineEntry::Make(this, getCurrentSection().first);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getContents().append(Data.begin(), Data.end());
}
示例5: SearchPathRef
/// LookupFile - Lookup the specified file in this search path, returning it
/// if it exists or returning null if not.
const FileEntry *DirectoryLookup::LookupFile(
StringRef &Filename,
HeaderSearch &HS,
SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath,
ModuleMap::KnownHeader *SuggestedModule,
bool &InUserSpecifiedSystemFramework,
bool &HasBeenMapped,
SmallVectorImpl<char> &MappedName) const {
InUserSpecifiedSystemFramework = false;
HasBeenMapped = false;
SmallString<1024> TmpDir;
if (isNormalDir()) {
// Concatenate the requested file onto the directory.
TmpDir = getDir()->getName();
llvm::sys::path::append(TmpDir, Filename);
if (SearchPath != NULL) {
StringRef SearchPathRef(getDir()->getName());
SearchPath->clear();
SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
}
if (RelativePath != NULL) {
RelativePath->clear();
RelativePath->append(Filename.begin(), Filename.end());
}
return getFileAndSuggestModule(HS, TmpDir.str(), getDir(),
isSystemHeaderDirectory(),
SuggestedModule);
}
if (isFramework())
return DoFrameworkLookup(Filename, HS, SearchPath, RelativePath,
SuggestedModule, InUserSpecifiedSystemFramework);
assert(isHeaderMap() && "Unknown directory lookup");
const HeaderMap *HM = getHeaderMap();
SmallString<1024> Path;
StringRef Dest = HM->lookupFilename(Filename, Path);
if (Dest.empty())
return 0;
const FileEntry *Result;
// Check if the headermap maps the filename to a framework include
// ("Foo.h" -> "Foo/Foo.h"), in which case continue header lookup using the
// framework include.
if (llvm::sys::path::is_relative(Dest)) {
MappedName.clear();
MappedName.append(Dest.begin(), Dest.end());
Filename = StringRef(MappedName.begin(), MappedName.size());
HasBeenMapped = true;
Result = HM->LookupFile(Filename, HS.getFileMgr());
} else {
Result = HS.getFileMgr().getFile(Dest);
}
if (Result) {
if (SearchPath != NULL) {
StringRef SearchPathRef(getName());
SearchPath->clear();
SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
}
if (RelativePath != NULL) {
RelativePath->clear();
RelativePath->append(Filename.begin(), Filename.end());
}
}
return Result;
}
示例6: EvaluateValue
//.........这里部分代码省略.........
Result.Val.setIsUnsigned(Literal.isUnsigned);
// Detect overflow based on whether the value is signed. If signed
// and if the value is too large, emit a warning "integer constant is so
// large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
// is 64-bits.
if (!Literal.isUnsigned && Result.Val.isNegative()) {
// Don't warn for a hex literal: 0x8000..0 shouldn't warn.
if (ValueLive && Literal.getRadix() != 16)
PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed);
Result.Val.setIsUnsigned(true);
}
}
// Consume the token.
Result.setRange(PeekTok.getLocation());
PP.LexNonComment(PeekTok);
return false;
}
case tok::char_constant: // 'x'
case tok::wide_char_constant: // L'x'
case tok::utf16_char_constant: // u'x'
case tok::utf32_char_constant: { // U'x'
// Complain about, and drop, any ud-suffix.
if (PeekTok.hasUDSuffix())
PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*character*/0;
SmallString<32> CharBuffer;
bool CharInvalid = false;
StringRef ThisTok = PP.getSpelling(PeekTok, CharBuffer, &CharInvalid);
if (CharInvalid)
return true;
CharLiteralParser Literal(ThisTok.begin(), ThisTok.end(),
PeekTok.getLocation(), PP, PeekTok.getKind());
if (Literal.hadError())
return true; // A diagnostic was already emitted.
// Character literals are always int or wchar_t, expand to intmax_t.
const TargetInfo &TI = PP.getTargetInfo();
unsigned NumBits;
if (Literal.isMultiChar())
NumBits = TI.getIntWidth();
else if (Literal.isWide())
NumBits = TI.getWCharWidth();
else if (Literal.isUTF16())
NumBits = TI.getChar16Width();
else if (Literal.isUTF32())
NumBits = TI.getChar32Width();
else
NumBits = TI.getCharWidth();
// Set the width.
llvm::APSInt Val(NumBits);
// Set the value.
Val = Literal.getValue();
// Set the signedness. UTF-16 and UTF-32 are always unsigned
if (!Literal.isUTF16() && !Literal.isUTF32())
Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned);
if (Result.Val.getBitWidth() > Val.getBitWidth()) {
Result.Val = Val.extend(Result.Val.getBitWidth());
} else {
assert(Result.Val.getBitWidth() == Val.getBitWidth() &&
"intmax_t smaller than char/wchar_t?");
Result.Val = Val;
示例7: AnalyzeAsmString
/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
/// it into pieces. If the asm string is erroneous, emit errors and return
/// true, otherwise return false.
unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
const ASTContext &C, unsigned &DiagOffs) const {
StringRef Str = getAsmString()->getString();
const char *StrStart = Str.begin();
const char *StrEnd = Str.end();
const char *CurPtr = StrStart;
// "Simple" inline asms have no constraints or operands, just convert the asm
// string to escape $'s.
if (isSimple()) {
std::string Result;
for (; CurPtr != StrEnd; ++CurPtr) {
switch (*CurPtr) {
case '$':
Result += "$$";
break;
default:
Result += *CurPtr;
break;
}
}
Pieces.push_back(AsmStringPiece(Result));
return 0;
}
// CurStringPiece - The current string that we are building up as we scan the
// asm string.
std::string CurStringPiece;
bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
unsigned LastAsmStringToken = 0;
unsigned LastAsmStringOffset = 0;
while (1) {
// Done with the string?
if (CurPtr == StrEnd) {
if (!CurStringPiece.empty())
Pieces.push_back(AsmStringPiece(CurStringPiece));
return 0;
}
char CurChar = *CurPtr++;
switch (CurChar) {
case '$': CurStringPiece += "$$"; continue;
case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
case '%':
break;
default:
CurStringPiece += CurChar;
continue;
}
// Escaped "%" character in asm string.
if (CurPtr == StrEnd) {
// % at end of string is invalid (no escape).
DiagOffs = CurPtr-StrStart-1;
return diag::err_asm_invalid_escape;
}
// Handle escaped char and continue looping over the asm string.
char EscapedChar = *CurPtr++;
switch (EscapedChar) {
default:
break;
case '%': // %% -> %
case '{': // %{ -> {
case '}': // %} -> }
CurStringPiece += EscapedChar;
continue;
case '=': // %= -> Generate a unique ID.
CurStringPiece += "${:uid}";
continue;
}
// Otherwise, we have an operand. If we have accumulated a string so far,
// add it to the Pieces list.
if (!CurStringPiece.empty()) {
Pieces.push_back(AsmStringPiece(CurStringPiece));
CurStringPiece.clear();
}
// Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
// don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
const char *Begin = CurPtr - 1; // Points to the character following '%'.
const char *Percent = Begin - 1; // Points to '%'.
if (isLetter(EscapedChar)) {
if (CurPtr == StrEnd) { // Premature end.
DiagOffs = CurPtr-StrStart-1;
return diag::err_asm_invalid_escape;
}
EscapedChar = *CurPtr++;
}
//.........这里部分代码省略.........
示例8: EmitBytes
void MCPureStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
// TODO: This is exactly the same as WinCOFFStreamer. Consider merging into
// MCObjectStreamer.
getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
}
示例9: if
/// Parse - Analyze the specified string (e.g. "==&{eax}") and fill in the
/// fields in this structure. If the constraint string is not understood,
/// return true, otherwise return false.
bool InlineAsm::ConstraintInfo::Parse(const StringRef &Str,
std::vector<InlineAsm::ConstraintInfo> &ConstraintsSoFar) {
StringRef::iterator I = Str.begin(), E = Str.end();
// Initialize
Type = isInput;
isEarlyClobber = false;
MatchingInput = -1;
isCommutative = false;
isIndirect = false;
// Parse prefixes.
if (*I == '~') {
Type = isClobber;
++I;
} else if (*I == '=') {
++I;
Type = isOutput;
}
if (*I == '*') {
isIndirect = true;
++I;
}
if (I == E) return true; // Just a prefix, like "==" or "~".
// Parse the modifiers.
bool DoneWithModifiers = false;
while (!DoneWithModifiers) {
switch (*I) {
default:
DoneWithModifiers = true;
break;
case '&': // Early clobber.
if (Type != isOutput || // Cannot early clobber anything but output.
isEarlyClobber) // Reject &&&&&&
return true;
isEarlyClobber = true;
break;
case '%': // Commutative.
if (Type == isClobber || // Cannot commute clobbers.
isCommutative) // Reject %%%%%
return true;
isCommutative = true;
break;
case '#': // Comment.
case '*': // Register preferencing.
return true; // Not supported.
}
if (!DoneWithModifiers) {
++I;
if (I == E) return true; // Just prefixes and modifiers!
}
}
// Parse the various constraints.
while (I != E) {
if (*I == '{') { // Physical register reference.
// Find the end of the register name.
StringRef::iterator ConstraintEnd = std::find(I+1, E, '}');
if (ConstraintEnd == E) return true; // "{foo"
Codes.push_back(std::string(I, ConstraintEnd+1));
I = ConstraintEnd+1;
} else if (isdigit(*I)) { // Matching Constraint
// Maximal munch numbers.
StringRef::iterator NumStart = I;
while (I != E && isdigit(*I))
++I;
Codes.push_back(std::string(NumStart, I));
unsigned N = atoi(Codes.back().c_str());
// Check that this is a valid matching constraint!
if (N >= ConstraintsSoFar.size() || ConstraintsSoFar[N].Type != isOutput||
Type != isInput)
return true; // Invalid constraint number.
// If Operand N already has a matching input, reject this. An output
// can't be constrained to the same value as multiple inputs.
if (ConstraintsSoFar[N].hasMatchingInput())
return true;
// Note that operand #n has a matching input.
ConstraintsSoFar[N].MatchingInput = ConstraintsSoFar.size();
} else {
// Single letter constraint.
Codes.push_back(std::string(I, I+1));
++I;
}
}
return false;
}
示例10: verifyFile
//.........这里部分代码省略.........
size_t MinusLoc = FixItStr.find('-');
if (MinusLoc == StringRef::npos) {
addError(FixItStr.data(), "expected '-' in fix-it verification");
continue;
}
StringRef StartColStr = FixItStr.slice(0, MinusLoc);
StringRef AfterMinus = FixItStr.substr(MinusLoc+1);
size_t EqualLoc = AfterMinus.find('=');
if (EqualLoc == StringRef::npos) {
addError(AfterMinus.data(),
"expected '=' after '-' in fix-it verification");
continue;
}
StringRef EndColStr = AfterMinus.slice(0, EqualLoc);
StringRef AfterEqual = AfterMinus.substr(EqualLoc+1);
ExpectedFixIt FixIt;
FixIt.StartLoc = StartColStr.data()-2;
FixIt.EndLoc = FixItStr.data()+EndLoc;
if (StartColStr.getAsInteger(10, FixIt.StartCol)) {
addError(StartColStr.data(),
"invalid column number in fix-it verification");
continue;
}
if (EndColStr.getAsInteger(10, FixIt.EndCol)) {
addError(EndColStr.data(),
"invalid column number in fix-it verification");
continue;
}
// Translate literal "\\n" into '\n', inefficiently.
StringRef fixItText = AfterEqual.slice(0, EndLoc);
for (const char *current = fixItText.begin(), *end = fixItText.end();
current != end; /* in loop */) {
if (*current == '\\' && current + 1 < end) {
if (current[1] == 'n') {
FixIt.Text += '\n';
current += 2;
} else { // Handle \}, \\, etc.
FixIt.Text += current[1];
current += 2;
}
} else {
FixIt.Text += *current++;
}
}
Expected.Fixits.push_back(FixIt);
}
Expected.ExpectedEnd = ExtraChecks.data();
// Don't include trailing whitespace in the expected-foo{{}} range.
while (isspace(Expected.ExpectedEnd[-1]))
--Expected.ExpectedEnd;
// Add the diagnostic the expected number of times.
for (; Count; --Count)
ExpectedDiagnostics.push_back(Expected);
}
// Make sure all the expected diagnostics appeared.
std::reverse(ExpectedDiagnostics.begin(), ExpectedDiagnostics.end());
示例11: OptionInfos
OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos)
: OptionInfos(_OptionInfos),
NumOptionInfos(_NumOptionInfos),
TheInputOptionID(0),
TheUnknownOptionID(0),
FirstSearchableIndex(0)
{
// Explicitly zero initialize the error to work around a bug in array
// value-initialization on MinGW with gcc 4.3.5.
// Find start of normal options.
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
unsigned Kind = getInfo(i + 1).Kind;
if (Kind == Option::InputClass) {
assert(!TheInputOptionID && "Cannot have multiple input options!");
TheInputOptionID = getInfo(i + 1).ID;
} else if (Kind == Option::UnknownClass) {
assert(!TheUnknownOptionID && "Cannot have multiple unknown options!");
TheUnknownOptionID = getInfo(i + 1).ID;
} else if (Kind != Option::GroupClass) {
FirstSearchableIndex = i;
break;
}
}
assert(FirstSearchableIndex != 0 && "No searchable options?");
#ifndef NDEBUG
// Check that everything after the first searchable option is a
// regular option class.
for (unsigned i = FirstSearchableIndex, e = getNumOptions(); i != e; ++i) {
Option::OptionClass Kind = (Option::OptionClass) getInfo(i + 1).Kind;
assert((Kind != Option::InputClass && Kind != Option::UnknownClass &&
Kind != Option::GroupClass) &&
"Special options should be defined first!");
}
// Check that options are in order.
for (unsigned i = FirstSearchableIndex+1, e = getNumOptions(); i != e; ++i) {
if (!(getInfo(i) < getInfo(i + 1))) {
getOption(i).dump();
getOption(i + 1).dump();
llvm_unreachable("Options are not in order!");
}
}
#endif
// Build prefixes.
for (unsigned i = FirstSearchableIndex+1, e = getNumOptions(); i != e; ++i) {
if (const char *const *P = getInfo(i).Prefixes) {
for (; *P != 0; ++P) {
PrefixesUnion.insert(*P);
}
}
}
// Build prefix chars.
for (llvm::StringSet<>::const_iterator I = PrefixesUnion.begin(),
E = PrefixesUnion.end(); I != E; ++I) {
StringRef Prefix = I->getKey();
for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
C != CE; ++C)
if (std::find(PrefixChars.begin(), PrefixChars.end(), *C)
== PrefixChars.end())
PrefixChars.push_back(*C);
}
}
示例12: parseDirectiveSection
/// parseDirectiveSection:
/// ::= .section identifier (',' identifier)*
bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
SMLoc Loc = getLexer().getLoc();
StringRef SectionName;
if (getParser().parseIdentifier(SectionName))
return Error(Loc, "expected identifier after '.section' directive");
// Verify there is a following comma.
if (!getLexer().is(AsmToken::Comma))
return TokError("unexpected token in '.section' directive");
std::string SectionSpec = SectionName;
SectionSpec += ",";
// Add all the tokens until the end of the line, ParseSectionSpecifier will
// handle this.
StringRef EOL = getLexer().LexUntilEndOfStatement();
SectionSpec.append(EOL.begin(), EOL.end());
Lex();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.section' directive");
Lex();
StringRef Segment, Section;
unsigned StubSize;
unsigned TAA;
bool TAAParsed;
std::string ErrorStr =
MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section,
TAA, TAAParsed, StubSize);
if (!ErrorStr.empty())
return Error(Loc, ErrorStr);
// Issue a warning if the target is not powerpc and Section is a *coal* section.
Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();
Triple::ArchType ArchTy = TT.getArch();
if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
StringRef NonCoalSection = StringSwitch<StringRef>(Section)
.Case("__textcoal_nt", "__text")
.Case("__const_coal", "__const")
.Case("__datacoal_nt", "__data")
.Default(Section);
if (!Section.equals(NonCoalSection)) {
StringRef SectionVal(Loc.getPointer());
size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
SMRange(BLoc, ELoc));
getParser().Note(Loc, "change section name to \"" + NonCoalSection +
"\"", SMRange(BLoc, ELoc));
}
}
// FIXME: Arch specific.
bool isText = Segment == "__TEXT"; // FIXME: Hack.
getStreamer().SwitchSection(getContext().getMachOSection(
Segment, Section, TAA, StubSize,
isText ? SectionKind::getText() : SectionKind::getData()));
return false;
}
示例13: AnalyzeAsmString
/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
/// it into pieces. If the asm string is erroneous, emit errors and return
/// true, otherwise return false.
unsigned AsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
ASTContext &C, unsigned &DiagOffs) const {
StringRef Str = getAsmString()->getString();
const char *StrStart = Str.begin();
const char *StrEnd = Str.end();
const char *CurPtr = StrStart;
// "Simple" inline asms have no constraints or operands, just convert the asm
// string to escape $'s.
if (isSimple()) {
std::string Result;
for (; CurPtr != StrEnd; ++CurPtr) {
switch (*CurPtr) {
case '$':
Result += "$$";
break;
default:
Result += *CurPtr;
break;
}
}
Pieces.push_back(AsmStringPiece(Result));
return 0;
}
// CurStringPiece - The current string that we are building up as we scan the
// asm string.
std::string CurStringPiece;
bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
while (1) {
// Done with the string?
if (CurPtr == StrEnd) {
if (!CurStringPiece.empty())
Pieces.push_back(AsmStringPiece(CurStringPiece));
return 0;
}
char CurChar = *CurPtr++;
switch (CurChar) {
case '$': CurStringPiece += "$$"; continue;
case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
case '%':
break;
default:
CurStringPiece += CurChar;
continue;
}
// Escaped "%" character in asm string.
if (CurPtr == StrEnd) {
// % at end of string is invalid (no escape).
DiagOffs = CurPtr-StrStart-1;
return diag::err_asm_invalid_escape;
}
char EscapedChar = *CurPtr++;
if (EscapedChar == '%') { // %% -> %
// Escaped percentage sign.
CurStringPiece += '%';
continue;
}
if (EscapedChar == '=') { // %= -> Generate an unique ID.
CurStringPiece += "${:uid}";
continue;
}
// Otherwise, we have an operand. If we have accumulated a string so far,
// add it to the Pieces list.
if (!CurStringPiece.empty()) {
Pieces.push_back(AsmStringPiece(CurStringPiece));
CurStringPiece.clear();
}
// Handle %x4 and %x[foo] by capturing x as the modifier character.
char Modifier = '\0';
if (isalpha(EscapedChar)) {
if (CurPtr == StrEnd) { // Premature end.
DiagOffs = CurPtr-StrStart-1;
return diag::err_asm_invalid_escape;
}
Modifier = EscapedChar;
EscapedChar = *CurPtr++;
}
if (isdigit(EscapedChar)) {
// %n - Assembler operand n
unsigned N = 0;
--CurPtr;
while (CurPtr != StrEnd && isdigit(*CurPtr))
N = N*10 + ((*CurPtr++)-'0');
//.........这里部分代码省略.........
示例14: isValidCIdentifier
// Returns true if S is valid as a C language identifier.
bool elf::isValidCIdentifier(StringRef S) {
return !S.empty() && isAlpha(S[0]) &&
std::all_of(S.begin() + 1, S.end(), isAlnum);
}
示例15: HandlePiece
void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID,
const PathDiagnosticPiece& P,
unsigned num, unsigned max) {
// For now, just draw a box above the line in question, and emit the
// warning.
FullSourceLoc Pos = P.getLocation().asLocation();
if (!Pos.isValid())
return;
SourceManager &SM = R.getSourceMgr();
assert(&Pos.getManager() == &SM && "SourceManagers are different!");
std::pair<FileID, unsigned> LPosInfo = SM.getDecomposedExpansionLoc(Pos);
if (LPosInfo.first != BugFileID)
return;
const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
const char* FileStart = Buf->getBufferStart();
// Compute the column number. Rewind from the current position to the start
// of the line.
unsigned ColNo = SM.getColumnNumber(LPosInfo.first, LPosInfo.second);
const char *TokInstantiationPtr =Pos.getExpansionLoc().getCharacterData();
const char *LineStart = TokInstantiationPtr-ColNo;
// Compute LineEnd.
const char *LineEnd = TokInstantiationPtr;
const char* FileEnd = Buf->getBufferEnd();
while (*LineEnd != '\n' && LineEnd != FileEnd)
++LineEnd;
// Compute the margin offset by counting tabs and non-tabs.
unsigned PosNo = 0;
for (const char* c = LineStart; c != TokInstantiationPtr; ++c)
PosNo += *c == '\t' ? 8 : 1;
// Create the html for the message.
const char *Kind = nullptr;
switch (P.getKind()) {
case PathDiagnosticPiece::Call:
llvm_unreachable("Calls should already be handled");
case PathDiagnosticPiece::Event:
Kind = "Event";
break;
case PathDiagnosticPiece::ControlFlow:
Kind = "Control";
break;
// Setting Kind to "Control" is intentional.
case PathDiagnosticPiece::Macro:
Kind = "Control";
break;
}
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
os << "\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\"";
if (num == max)
os << "EndPath";
else
os << "Path" << num;
os << "\" class=\"msg";
if (Kind)
os << " msg" << Kind;
os << "\" style=\"margin-left:" << PosNo << "ex";
// Output a maximum size.
if (!isa<PathDiagnosticMacroPiece>(P)) {
// Get the string and determining its maximum substring.
const std::string& Msg = P.getString();
unsigned max_token = 0;
unsigned cnt = 0;
unsigned len = Msg.size();
for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I)
switch (*I) {
default:
++cnt;
continue;
case ' ':
case '\t':
case '\n':
if (cnt > max_token) max_token = cnt;
cnt = 0;
}
if (cnt > max_token)
max_token = cnt;
// Determine the approximate size of the message bubble in em.
unsigned em;
const unsigned max_line = 120;
if (max_token >= max_line)
em = max_token / 2;
//.........这里部分代码省略.........