本文整理汇总了C++中SourceRange::getBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange::getBegin方法的具体用法?C++ SourceRange::getBegin怎么用?C++ SourceRange::getBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceRange
的用法示例。
在下文中一共展示了SourceRange::getBegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addLocationRange
//---------------------------------------------------------
void DocumentXML::addLocationRange(const SourceRange& R)
{
PresumedLoc PStartLoc = addLocation(R.getBegin());
if (R.getBegin() != R.getEnd())
{
SourceManager& SM = Ctx->getSourceManager();
SourceLocation SpellingLoc = SM.getSpellingLoc(R.getEnd());
if (!SpellingLoc.isInvalid())
{
PresumedLoc PLoc = SM.getPresumedLoc(SpellingLoc);
if (PStartLoc.isInvalid() ||
strcmp(PLoc.getFilename(), PStartLoc.getFilename()) != 0) {
addToMap(SourceFiles, PLoc.getFilename(), ID_FILE);
addAttribute("endfile", PLoc.getFilename());
addAttribute("endline", PLoc.getLine());
addAttribute("endcol", PLoc.getColumn());
} else if (PLoc.getLine() != PStartLoc.getLine()) {
addAttribute("endline", PLoc.getLine());
addAttribute("endcol", PLoc.getColumn());
} else {
addAttribute("endcol", PLoc.getColumn());
}
}
}
}
示例2: storeReplacement
void WhitespaceManager::storeReplacement(const SourceRange &Range,
StringRef Text) {
unsigned WhitespaceLength = SourceMgr.getFileOffset(Range.getEnd()) -
SourceMgr.getFileOffset(Range.getBegin());
// Don't create a replacement, if it does not change anything.
if (StringRef(SourceMgr.getCharacterData(Range.getBegin()),
WhitespaceLength) == Text)
return;
Replaces.insert(tooling::Replacement(
SourceMgr, CharSourceRange::getCharRange(Range), Text));
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_clang,代码行数:11,代码来源:WhitespaceManager.cpp
示例3: make_pair
std::pair<unsigned, unsigned>
PreprocessingRecord::findLocalPreprocessedEntitiesInRange(
SourceRange Range) const {
if (Range.isInvalid())
return std::make_pair(0,0);
assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
unsigned Begin = findBeginLocalPreprocessedEntity(Range.getBegin());
unsigned End = findEndLocalPreprocessedEntity(Range.getEnd());
return std::make_pair(Begin, End);
}
示例4: ReplaceText
bool Rewriter::ReplaceText(SourceRange range, SourceRange replacementRange) {
if (!isRewritable(range.getBegin())) return true;
if (!isRewritable(range.getEnd())) return true;
if (replacementRange.isInvalid()) return true;
SourceLocation start = range.getBegin();
unsigned origLength = getRangeSize(range);
unsigned newLength = getRangeSize(replacementRange);
FileID FID;
unsigned newOffs = getLocationOffsetAndFileID(replacementRange.getBegin(),
FID);
StringRef MB = SourceMgr->getBufferData(FID);
return ReplaceText(start, origLength, MB.substr(newOffs, newLength));
}
示例5: HighlightRange
/// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
/// any characters in LineNo that intersect the SourceRange.
void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
SourceManager& SourceMgr,
unsigned LineNo,
std::string &CaratLine,
const std::string &SourceLine) {
assert(CaratLine.size() == SourceLine.size() &&
"Expect a correspondence between source and carat line!");
if (!R.isValid()) return;
unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
if (StartLineNo > LineNo) return; // No intersection.
unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
if (EndLineNo < LineNo) return; // No intersection.
// Compute the column number of the start.
unsigned StartColNo = 0;
if (StartLineNo == LineNo) {
StartColNo = SourceMgr.getLogicalColumnNumber(R.getBegin());
if (StartColNo) --StartColNo; // Zero base the col #.
}
// Pick the first non-whitespace column.
while (StartColNo < SourceLine.size() &&
(SourceLine[StartColNo] == ' ' || SourceLine[StartColNo] == '\t'))
++StartColNo;
// Compute the column number of the end.
unsigned EndColNo = CaratLine.size();
if (EndLineNo == LineNo) {
EndColNo = SourceMgr.getLogicalColumnNumber(R.getEnd());
if (EndColNo) {
--EndColNo; // Zero base the col #.
// Add in the length of the token, so that we cover multi-char tokens.
EndColNo += Lexer::MeasureTokenLength(R.getEnd(), SourceMgr);
} else {
EndColNo = CaratLine.size();
}
}
// Pick the last non-whitespace column.
while (EndColNo-1 &&
(SourceLine[EndColNo-1] == ' ' || SourceLine[EndColNo-1] == '\t'))
--EndColNo;
// Fill the range with ~'s.
assert(StartColNo <= EndColNo && "Invalid range!");
for (unsigned i = StartColNo; i != EndColNo; ++i)
CaratLine[i] = '~';
}
示例6: SrcClass
/// TryStaticMemberPointerUpcast - Tests whether a conversion according to
/// C++ 5.2.9p9 is valid:
///
/// An rvalue of type "pointer to member of D of type cv1 T" can be
/// converted to an rvalue of type "pointer to member of B of type cv2 T",
/// where B is a base class of D [...].
///
TryStaticCastResult
TryStaticMemberPointerUpcast(Sema &Self, QualType SrcType, QualType DestType,
const SourceRange &OpRange)
{
const MemberPointerType *SrcMemPtr = SrcType->getAsMemberPointerType();
if (!SrcMemPtr)
return TSC_NotApplicable;
const MemberPointerType *DestMemPtr = DestType->getAsMemberPointerType();
if (!DestMemPtr)
return TSC_NotApplicable;
// T == T, modulo cv
if (Self.Context.getCanonicalType(
SrcMemPtr->getPointeeType().getUnqualifiedType()) !=
Self.Context.getCanonicalType(DestMemPtr->getPointeeType().
getUnqualifiedType()))
return TSC_NotApplicable;
// B base of D
QualType SrcClass(SrcMemPtr->getClass(), 0);
QualType DestClass(DestMemPtr->getClass(), 0);
BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
/*DetectVirtual=*/true);
if (!Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
return TSC_NotApplicable;
}
// B is a base of D. But is it an allowed base? If not, it's a hard error.
if (Paths.isAmbiguous(DestClass)) {
Paths.clear();
Paths.setRecordingPaths(true);
bool StillOkay = Self.IsDerivedFrom(SrcClass, DestClass, Paths);
assert(StillOkay);
StillOkay = StillOkay;
std::string PathDisplayStr = Self.getAmbiguousPathsDisplayString(Paths);
Self.Diag(OpRange.getBegin(), diag::err_ambiguous_memptr_conv)
<< 1 << SrcClass << DestClass << PathDisplayStr << OpRange;
return TSC_Failed;
}
if (const RecordType *VBase = Paths.getDetectedVirtual()) {
Self.Diag(OpRange.getBegin(), diag::err_memptr_conv_via_virtual)
<< SrcClass << DestClass << QualType(VBase, 0) << OpRange;
return TSC_Failed;
}
// FIXME: Test accessibility.
return TSC_Success;
}
示例7: getAsString
/// \brief Get a StringRef representing a SourceRange.
static StringRef getAsString(const MatchFinder::MatchResult &Result,
SourceRange R) {
const SourceManager &SM = *Result.SourceManager;
// Don't even try to resolve macro or include contraptions. Not worth emitting
// a fixit for.
if (R.getBegin().isMacroID() ||
!SM.isWrittenInSameFile(R.getBegin(), R.getEnd()))
return StringRef();
const char *Begin = SM.getCharacterData(R.getBegin());
const char *End = SM.getCharacterData(Lexer::getLocForEndOfToken(
R.getEnd(), 0, SM, Result.Context->getLangOpts()));
return StringRef(Begin, End - Begin);
}
示例8: removeLastNamespaceFromUsingDecl
void RemoveNamespace::removeLastNamespaceFromUsingDecl(
const UsingDirectiveDecl *D, const NamespaceDecl *ND)
{
SourceLocation IdLocStart = D->getIdentLocation();
SourceRange DeclSourceRange = D->getSourceRange();
SourceLocation DeclLocStart = DeclSourceRange.getBegin();
const char *IdStartBuf = SrcManager->getCharacterData(IdLocStart);
const char *DeclStartBuf = SrcManager->getCharacterData(DeclLocStart);
unsigned Count = 0;
int Offset = 0;
while (IdStartBuf != DeclStartBuf) {
if (*IdStartBuf != ':') {
IdStartBuf--;
Offset--;
continue;
}
Count++;
if (Count == 2) {
break;
}
Offset--;
IdStartBuf--;
}
TransAssert((Count == 2) && "Bad NestedNamespaceSpecifier!");
TransAssert((Offset < 0) && "Bad Offset Value!");
IdLocStart = IdLocStart.getLocWithOffset(Offset);
TheRewriter.RemoveText(IdLocStart,
ND->getNameAsString().length() - Offset);
}
示例9: removeOneInitExpr
void RemoveUnusedStructField::removeOneInitExpr(const Expr *E)
{
TransAssert(NumFields && "NumFields cannot be zero!");
if (NumFields == 1) {
RewriteHelper->replaceExpr(E, "");
return;
}
SourceRange ExpRange = E->getSourceRange();
SourceLocation StartLoc = ExpRange.getBegin();
SourceLocation EndLoc = ExpRange.getEnd();
if (IsFirstField) {
EndLoc = RewriteHelper->getEndLocationUntil(ExpRange, ',');
TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
return;
}
const char *Buf = SrcManager->getCharacterData(StartLoc);
int Offset = 0;
while (*Buf != ',') {
Buf--;
Offset--;
}
StartLoc = StartLoc.getLocWithOffset(Offset);
TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
}
示例10: dumpSourceRange
void ASTDumper::dumpSourceRange(SourceRange R) {
// Can't translate locations if a SourceManager isn't available.
if (!SM)
return;
OS << " <";
dumpLocation(R.getBegin());
if (R.getBegin() != R.getEnd()) {
OS << ", ";
dumpLocation(R.getEnd());
}
OS << ">";
// <t2.c:123:421[blah], t2.c:412:321>
}
示例11: rewriteFuncDecl
bool RVASTVisitor::rewriteFuncDecl(FunctionDecl *FD)
{
DeclarationNameInfo NameInfo = FD->getNameInfo();
SourceLocation NameInfoStartLoc = NameInfo.getBeginLoc();
SourceRange FuncDefRange = FD->getSourceRange();
SourceLocation FuncStartLoc = FuncDefRange.getBegin();
const char *FuncStartBuf =
ConsumerInstance->SrcManager->getCharacterData(FuncStartLoc);
const char *NameInfoStartBuf =
ConsumerInstance->SrcManager->getCharacterData(NameInfoStartLoc);
if (FuncStartBuf == NameInfoStartBuf)
return true;
int Offset = NameInfoStartBuf - FuncStartBuf;
NameInfoStartBuf--;
while ((*NameInfoStartBuf == '(') || (*NameInfoStartBuf == ' ') ||
(*NameInfoStartBuf == '\t') || (*NameInfoStartBuf == '\n')) {
Offset--;
NameInfoStartBuf--;
}
TransAssert(Offset >= 0);
ConsumerInstance->Rewritten = true;
return !(ConsumerInstance->TheRewriter.ReplaceText(FuncStartLoc,
Offset, "void "));
}
示例12: removeRecordDecls
// ISSUE: we will have bad transformation for the case below:
// typedef struct S;
// S *s;
// ==>
// typedef
// int *s;
// This is bad because we don't catch the implicit declaration of struct S.
// But hopefully peephole pass will remove the keyword typedef,
// then we will be fine.
void EmptyStructToInt::removeRecordDecls(void)
{
for (RecordDecl::redecl_iterator I = TheRecordDecl->redecls_begin(),
E = TheRecordDecl->redecls_end(); I != E; ++I) {
const RecordDecl *RD = dyn_cast<RecordDecl>(*I);
SourceRange Range = RD->getSourceRange();
SourceLocation LocEnd = Range.getEnd();
SourceLocation SemiLoc =
Lexer::findLocationAfterToken(LocEnd,
tok::semi,
*SrcManager,
Context->getLangOpts(),
/*SkipTrailingWhitespaceAndNewLine=*/true);
// handle cases such as
// struct S {} s;
if (SemiLoc.isInvalid()) {
if (!RD->isThisDeclarationADefinition())
return;
SourceLocation RBLoc = RD->getRBraceLoc();
if (RBLoc.isInvalid())
return;
RewriteHelper->removeTextFromLeftAt(SourceRange(RBLoc, RBLoc),
'{', RBLoc);
Rewritten = true;
}
else {
LocEnd = RewriteHelper->getEndLocationUntil(Range, ';');
TheRewriter.RemoveText(SourceRange(Range.getBegin(), LocEnd));
Rewritten = true;
}
}
}
示例13: MacroExpands
void ExpandModularHeadersPPCallbacks::MacroExpands(const Token &MacroNameTok,
const MacroDefinition &,
SourceRange Range,
const MacroArgs *) {
// FIME: Figure out whether it's the right location to parse to.
parseToLocation(Range.getBegin());
}
示例14:
/// Tests whether a conversion according to N2844 is valid.
TryStaticCastResult
TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType,
const SourceRange &OpRange)
{
// N2844 5.2.9p3: An lvalue of type "cv1 T1" can be cast to type "rvalue
// reference to cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
const RValueReferenceType *R = DestType->getAsRValueReferenceType();
if (!R)
return TSC_NotApplicable;
if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid)
return TSC_NotApplicable;
// Because we try the reference downcast before this function, from now on
// this is the only cast possibility, so we issue an error if we fail now.
bool DerivedToBase;
if (Self.CompareReferenceRelationship(SrcExpr->getType(), R->getPointeeType(),
DerivedToBase) <
Sema::Ref_Compatible_With_Added_Qualification) {
Self.Diag(OpRange.getBegin(), diag::err_bad_lvalue_to_rvalue_cast)
<< SrcExpr->getType() << R->getPointeeType() << OpRange;
return TSC_Failed;
}
// FIXME: Similar to CheckReferenceInit, we actually need more AST annotation
// than nothing.
return TSC_Success;
}
示例15: checkPreObjCMessage
void NSAutoreleasePoolChecker::checkPreObjCMessage(ObjCMessage msg,
CheckerContext &C) const {
const Expr *receiver = msg.getInstanceReceiver();
if (!receiver)
return;
// FIXME: Enhance with value-tracking information instead of consulting
// the type of the expression.
const ObjCObjectPointerType* PT =
receiver->getType()->getAs<ObjCObjectPointerType>();
if (!PT)
return;
const ObjCInterfaceDecl *OD = PT->getInterfaceDecl();
if (!OD)
return;
if (!OD->getIdentifier()->getName().equals("NSAutoreleasePool"))
return;
if (releaseS.isNull())
releaseS = GetNullarySelector("release", C.getASTContext());
// Sending 'release' message?
if (msg.getSelector() != releaseS)
return;
SourceRange R = msg.getSourceRange();
C.getBugReporter().EmitBasicReport("Use -drain instead of -release",
"API Upgrade (Apple)",
"Use -drain instead of -release when using NSAutoreleasePool "
"and garbage collection", R.getBegin(), &R, 1);
}