本文整理汇总了C++中StringLiteral::getStrData方法的典型用法代码示例。如果您正苦于以下问题:C++ StringLiteral::getStrData方法的具体用法?C++ StringLiteral::getStrData怎么用?C++ StringLiteral::getStrData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringLiteral
的用法示例。
在下文中一共展示了StringLiteral::getStrData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseObjCStringLiteral
Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
ExprTy **strings,
unsigned NumStrings) {
StringLiteral **Strings = reinterpret_cast<StringLiteral**>(strings);
// Most ObjC strings are formed out of a single piece. However, we *can*
// have strings formed out of multiple @ strings with multiple pptokens in
// each one, e.g. @"foo" "bar" @"baz" "qux" which need to be turned into one
// StringLiteral for ObjCStringLiteral to hold onto.
StringLiteral *S = Strings[0];
// If we have a multi-part string, merge it all together.
if (NumStrings != 1) {
// Concatenate objc strings.
llvm::SmallString<128> StrBuf;
llvm::SmallVector<SourceLocation, 8> StrLocs;
for (unsigned i = 0; i != NumStrings; ++i) {
S = Strings[i];
// ObjC strings can't be wide.
if (S->isWide()) {
Diag(S->getLocStart(), diag::err_cfstring_literal_not_string_constant)
<< S->getSourceRange();
return true;
}
// Get the string data.
StrBuf.append(S->getStrData(), S->getStrData()+S->getByteLength());
// Get the locations of the string tokens.
StrLocs.append(S->tokloc_begin(), S->tokloc_end());
}
// Create the aggregate string with the appropriate content and location
// information.
S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(), false,
Context.getPointerType(Context.CharTy),
&StrLocs[0], StrLocs.size());
}
// Verify that this composite string is acceptable for ObjC strings.
if (CheckObjCString(S))
return true;
// Initialize the constant string interface lazily. This assumes
// the NSString interface is seen in this translation unit. Note: We
// don't use NSConstantString, since the runtime team considers this
// interface private (even though it appears in the header files).
QualType Ty = Context.getObjCConstantStringInterface();
if (!Ty.isNull()) {
Ty = Context.getObjCObjectPointerType(Ty);
} else if (getLangOptions().NoConstantCFStrings) {
IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLocs[0],
LookupOrdinaryName);
if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
Context.setObjCConstantStringInterface(StrIF);
Ty = Context.getObjCConstantStringInterface();
Ty = Context.getObjCObjectPointerType(Ty);
} else {
// If there is no NSConstantString interface defined then treat this
// as error and recover from it.
Diag(S->getLocStart(), diag::err_no_nsconstant_string_class) << NSIdent
<< S->getSourceRange();
Ty = Context.getObjCIdType();
}
} else {
IdentifierInfo *NSIdent = &Context.Idents.get("NSString");
NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLocs[0],
LookupOrdinaryName);
if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
Context.setObjCConstantStringInterface(StrIF);
Ty = Context.getObjCConstantStringInterface();
Ty = Context.getObjCObjectPointerType(Ty);
} else {
// If there is no NSString interface defined then treat constant
// strings as untyped objects and let the runtime figure it out later.
Ty = Context.getObjCIdType();
}
}
return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]);
}