本文整理汇总了C++中SourceRange类的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange类的具体用法?C++ SourceRange怎么用?C++ SourceRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SourceRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bool
bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
bool ForceComplain,
bool (*IsPlausibleResult)(QualType)) {
SourceLocation Loc = E.get()->getExprLoc();
SourceRange Range = E.get()->getSourceRange();
QualType ZeroArgCallTy;
UnresolvedSet<4> Overloads;
if (isExprCallable(*E.get(), ZeroArgCallTy, Overloads) &&
!ZeroArgCallTy.isNull() &&
(!IsPlausibleResult || IsPlausibleResult(ZeroArgCallTy))) {
// At this point, we know E is potentially callable with 0
// arguments and that it returns something of a reasonable type,
// so we can emit a fixit and carry on pretending that E was
// actually a CallExpr.
SourceLocation ParenInsertionLoc =
PP.getLocForEndOfToken(Range.getEnd());
Diag(Loc, PD)
<< /*zero-arg*/ 1 << Range
<< (IsCallableWithAppend(E.get())
? FixItHint::CreateInsertion(ParenInsertionLoc, "()")
: FixItHint());
notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
// FIXME: Try this before emitting the fixit, and suppress diagnostics
// while doing so.
E = ActOnCallExpr(0, E.take(), ParenInsertionLoc,
MultiExprArg(), ParenInsertionLoc.getLocWithOffset(1));
return true;
}
if (!ForceComplain) return false;
Diag(Loc, PD) << /*not zero-arg*/ 0 << Range;
notePlausibleOverloads(*this, Loc, Overloads, IsPlausibleResult);
E = ExprError();
return true;
}
示例2: sm
std::vector<FixItHint> Qt4_QStringFromArray::fixMethodCallCall(clang::CXXMemberCallExpr *memberExpr)
{
vector<FixItHint> fixits;
if (memberExpr->getNumArgs() == 1) {
Expr *e = *(memberExpr->arg_begin());
SourceLocation start = e->getLocStart();
SourceLocation end = Lexer::getLocForEndOfToken(FixItUtils::biggestSourceLocationInStmt(sm(), e), 0, sm(), lo());
SourceRange range = { start, end };
if (range.isInvalid()) {
emitWarning(memberExpr->getLocStart(), "internal error");
return {};
}
FixItUtils::insertParentMethodCall("QString::fromLatin1", {start, end}, /*by-ref*/fixits);
} else {
emitWarning(memberExpr->getLocStart(), "internal error");
}
return fixits;
}
示例3: ASSERT
void InspectorStyleTextEditor::enableProperty(unsigned index)
{
ASSERT(m_allProperties->at(index).disabled);
unsigned disabledIndex = disabledIndexByOrdinal(index, false);
ASSERT(disabledIndex != UINT_MAX);
InspectorStyleProperty disabledProperty = m_disabledProperties->at(disabledIndex);
m_disabledProperties->remove(disabledIndex);
SourceRange removedRange;
unsigned insertedLength;
internalReplaceProperty(disabledProperty, disabledProperty.rawText, &removedRange, &insertedLength);
shiftDisabledProperties(disabledIndex, static_cast<long>(insertedLength) - static_cast<long>(removedRange.length()));
}
示例4: TransAssert
void SimplifyCommaExpr::simplifyCommaExpr(void)
{
TransAssert((TheBinaryOperator->getOpcode() == clang::BO_Comma) &&
"Non Comma Operator!");
const Expr *LHS = TheBinaryOperator->getLHS();
std::string LHSStr;
RewriteHelper->getExprString(LHS, LHSStr);
SourceRange LHSRange = LHS->getSourceRange();
SourceLocation StartLoc = LHSRange.getBegin();
SourceLocation EndLoc;
if (StartLoc.isMacroID()) {
StartLoc = SrcManager->getFileLoc(StartLoc);
EndLoc = LHSRange.getEnd();
TransAssert(EndLoc.isMacroID() && "EndLoc is not from a macro!");
LHSRange = SourceRange(StartLoc, SrcManager->getFileLoc(EndLoc));
}
EndLoc = RewriteHelper->getEndLocationUntil(LHSRange, ',');
TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
LHSStr += ";";
RewriteHelper->addStringBeforeStmt(TheStmt, LHSStr, NeedParen);
}
示例5: VisitVarDecl
bool RemoveUnusedVarAnalysisVisitor::VisitVarDecl(VarDecl *VD)
{
if (ConsumerInstance->isInIncludedFile(VD))
return true;
if (VD->isReferenced() || dyn_cast<ParmVarDecl>(VD) ||
VD->isStaticDataMember())
return true;
SourceRange VarRange = VD->getSourceRange();
if (VarRange.getEnd().isInvalid())
return true;
if (ConsumerInstance->SkippedVars.count(VD->getCanonicalDecl()))
return true;
ConsumerInstance->ValidInstanceNum++;
if (ConsumerInstance->ValidInstanceNum ==
ConsumerInstance->TransformationCounter) {
ConsumerInstance->TheVarDecl = VD;
}
return true;
}
示例6: BuiltinBug
void StackAddrEscapeChecker::EmitStackError(CheckerContext &C, const MemRegion *R,
const Expr *RetE) const {
ExplodedNode *N = C.generateSink();
if (!N)
return;
if (!BT_returnstack)
BT_returnstack.reset(
new BuiltinBug("Return of address to stack-allocated memory"));
// Generate a report for this bug.
SmallString<512> buf;
llvm::raw_svector_ostream os(buf);
SourceRange range = GenName(os, R, C.getSourceManager());
os << " returned to caller";
BugReport *report = new BugReport(*BT_returnstack, os.str(), N);
report->addRange(RetE->getSourceRange());
if (range.isValid())
report->addRange(range);
C.EmitReport(report);
}
示例7: assert
void TransformActionsImpl::commitReplace(SourceRange range,
SourceRange replacementRange) {
RangeComparison comp = CharRange::compare(replacementRange, range,
Ctx.getSourceManager(), PP);
assert(comp == Range_Contained);
if (comp != Range_Contained)
return; // Although we asserted, be extra safe for release build.
if (range.getBegin() != replacementRange.getBegin())
addRemoval(CharSourceRange::getCharRange(range.getBegin(),
replacementRange.getBegin()));
if (replacementRange.getEnd() != range.getEnd())
addRemoval(CharSourceRange::getTokenRange(
getLocForEndOfToken(replacementRange.getEnd(),
Ctx.getSourceManager(), PP),
range.getEnd()));
}
示例8: Out
void StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures(
const BlockDataRegion &B, CheckerContext &C) const {
// There is a not-too-uncommon idiom
// where a block passed to dispatch_async captures a semaphore
// and then the thread (which called dispatch_async) is blocked on waiting
// for the completion of the execution of the block
// via dispatch_semaphore_wait. To avoid false-positives (for now)
// we ignore all the blocks which have captured
// a variable of the type "dispatch_semaphore_t".
if (isSemaphoreCaptured(*B.getDecl()))
return;
for (const MemRegion *Region : getCapturedStackRegions(B, C)) {
// The block passed to dispatch_async may capture another block
// created on the stack. However, there is no leak in this situaton,
// no matter if ARC or no ARC is enabled:
// dispatch_async copies the passed "outer" block (via Block_copy)
// and if the block has captured another "inner" block,
// the "inner" block will be copied as well.
if (isa<BlockDataRegion>(Region))
continue;
ExplodedNode *N = C.generateNonFatalErrorNode();
if (!N)
continue;
if (!BT_capturedstackasync)
BT_capturedstackasync = llvm::make_unique<BuiltinBug>(
this, "Address of stack-allocated memory is captured");
SmallString<128> Buf;
llvm::raw_svector_ostream Out(Buf);
SourceRange Range = genName(Out, Region, C.getASTContext());
Out << " is captured by an asynchronously-executed block";
auto Report =
llvm::make_unique<BugReport>(*BT_capturedstackasync, Out.str(), N);
if (Range.isValid())
Report->addRange(Range);
C.emitReport(std::move(Report));
}
}
示例9: HighlightRange
void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
SourceRange Range,
const char *HighlightStart,
const char *HighlightEnd) {
SourceManager &SM = R.getSourceMgr();
const LangOptions &LangOpts = R.getLangOpts();
SourceLocation InstantiationStart = SM.getExpansionLoc(Range.getBegin());
unsigned StartLineNo = SM.getExpansionLineNumber(InstantiationStart);
SourceLocation InstantiationEnd = SM.getExpansionLoc(Range.getEnd());
unsigned EndLineNo = SM.getExpansionLineNumber(InstantiationEnd);
if (EndLineNo < StartLineNo)
return;
if (SM.getFileID(InstantiationStart) != BugFileID ||
SM.getFileID(InstantiationEnd) != BugFileID)
return;
// Compute the column number of the end.
unsigned EndColNo = SM.getExpansionColumnNumber(InstantiationEnd);
unsigned OldEndColNo = EndColNo;
if (EndColNo) {
// Add in the length of the token, so that we cover multi-char tokens.
EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM, LangOpts)-1;
}
// Highlight the range. Make the span tag the outermost tag for the
// selected range.
SourceLocation E =
InstantiationEnd.getLocWithOffset(EndColNo - OldEndColNo);
html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
}
示例10: Diag
void C2Sema::ActOnAttr(Decl* D, const char* name, SourceRange range, Expr* arg) {
#ifdef SEMA_DEBUG
std::cerr << COL_SEMA << "SEMA: attribute " << name << ANSI_NORMAL"\n";
#endif
AttrKind kind = Attr::name2kind(name);
if (kind == ATTR_UNKNOWN) {
Diag(range.getBegin(), diag::err_attribute_unknown) << name << range;
return;
}
const AttrInfo& ai = Attr::getInfo(kind);
// check if allowed for type of Decl
if (isa<TypeDecl>(D) && !ai.isAllowedInType()) {
Diag(range.getBegin(), diag::err_attribute_invalid_decl) << name << 0 << range;
return;
}
if (isa<FunctionDecl>(D) && !ai.isAllowedInFunction()) {
Diag(range.getBegin(), diag::err_attribute_invalid_decl) << name << 1 << range;
return;
}
if (isa<VarDecl>(D) && !ai.isAllowedInVar()) {
Diag(range.getBegin(), diag::err_attribute_invalid_decl) << name << 2 << range;
return;
}
// check if it requires an argument or has argument while not needing one
if (arg) {
if (!ai.requiresArgument) {
Diag(range.getBegin(), diag::err_attribute_wrong_number_arguments) << name << 0 << range;
return;
}
} else {
if (ai.requiresArgument) {
Diag(range.getBegin(), diag::err_attribute_wrong_number_arguments) << name << 1 << range;
return;
}
}
// check for duplicates
if (ast.hasAttribute(D, kind)) {
Diag(range.getBegin(), diag::warn_duplicate_attribute_exact) << name << range;
return;
}
D->setHasAttributes();
ast.addAttribute(D, new Attr(kind, range, arg));
// Fixup opaque structs; members are not public!
if (kind == ATTR_OPAQUE && isa<StructTypeDecl>(D)) {
StructTypeDecl* S = cast<StructTypeDecl>(D);
S->setOpaqueMembers();
}
}
示例11: getFunctionOuterLocStart
void RemoveUnusedFunction::removeOneFunctionDecl(const FunctionDecl *FD)
{
SourceRange FuncRange = FD->getSourceRange();
SourceLocation LocEnd = FuncRange.getEnd();
if (!FD->isInExternCContext() && !FD->isInExternCXXContext()) {
SourceLocation FuncLocStart = getFunctionOuterLocStart(FD);
LocEnd = getFunctionLocEnd(FuncLocStart, LocEnd, FD);
if (SrcManager->isWrittenInMainFile(FuncLocStart) &&
SrcManager->isWrittenInMainFile(LocEnd))
TheRewriter.RemoveText(SourceRange(FuncLocStart, LocEnd));
return;
}
const DeclContext *Ctx = FD->getLookupParent();
const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(Ctx);
if (!Linkage) {
SourceLocation FuncLocStart = getFunctionOuterLocStart(FD);
LocEnd = getFunctionLocEnd(FuncLocStart, LocEnd, FD);
TheRewriter.RemoveText(SourceRange(FuncLocStart, LocEnd));
return;
}
// cases like:
// extern "C++" { void foo(); }
// namespace { using ::foo; }
if (Linkage->hasBraces()) {
SourceLocation FuncLocStart = getFunctionOuterLocStart(FD);
TheRewriter.RemoveText(SourceRange(FuncLocStart, LocEnd));
return;
}
// cases like:
// extern "C++" void foo();
// it also handles cases such as extern "C++" template<typename T> ...
SourceLocation LocStart = Linkage->getExternLoc();
LocStart = getExtensionLocStart(LocStart);
TheRewriter.RemoveText(SourceRange(LocStart, LocEnd));
}
示例12: ProcessStmtAttributes
StmtResult Sema::ProcessStmtAttributes(Stmt *S, AttributeList *AttrList,
SourceRange Range) {
SmallVector<const Attr*, 8> Attrs;
for (const AttributeList* l = AttrList; l; l = l->getNext()) {
if (Attr *a = ProcessStmtAttribute(*this, S, *l, Range))
Attrs.push_back(a);
}
CheckForIncompatibleAttributes(*this, Attrs);
if (Attrs.empty())
return S;
return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
}
示例13: Range
RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR,
bool Merged, bool ParseAllComments) :
Range(SR), RawTextValid(false), BriefTextValid(false),
IsAttached(false), IsAlmostTrailingComment(false),
ParseAllComments(ParseAllComments) {
// Extract raw comment text, if possible.
if (SR.getBegin() == SR.getEnd() || getRawText(SourceMgr).empty()) {
Kind = RCK_Invalid;
return;
}
if (!Merged) {
// Guess comment kind.
std::pair<CommentKind, bool> K = getCommentKind(RawText, ParseAllComments);
Kind = K.first;
IsTrailingComment = K.second;
IsAlmostTrailingComment = RawText.startswith("//<") ||
RawText.startswith("/*<");
} else {
Kind = RCK_Merged;
IsTrailingComment = mergedCommentIsTrailingComment(RawText);
}
}
示例14: isInTheFuncDef
bool ReturnVoid::isInTheFuncDef(ReturnStmt *RS)
{
// The candidate function doesn't have a body
if (!FuncDefStartPos)
return false;
SourceRange RSRange = RS->getSourceRange();
SourceLocation StartLoc = RSRange.getBegin();
SourceLocation EndLoc = RSRange.getEnd();
const char *StartPos =
SrcManager->getCharacterData(StartLoc);
const char *EndPos =
SrcManager->getCharacterData(EndLoc);
(void)EndPos;
if ((StartPos > FuncDefStartPos) && (StartPos < FuncDefEndPos)) {
TransAssert((EndPos > FuncDefStartPos) && (EndPos < FuncDefEndPos) &&
"Bad return statement range!");
return true;
}
return false;
}
示例15: ProcessStmtAttributes
StmtResult Sema::ProcessStmtAttributes(Stmt *S,
const ParsedAttributesView &AttrList,
SourceRange Range) {
SmallVector<const Attr*, 8> Attrs;
for (const ParsedAttr &AL : AttrList) {
if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
Attrs.push_back(a);
}
CheckForIncompatibleAttributes(*this, Attrs);
if (Attrs.empty())
return S;
return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
}