本文整理汇总了C++中SourceRange::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange::isValid方法的具体用法?C++ SourceRange::isValid怎么用?C++ SourceRange::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceRange
的用法示例。
在下文中一共展示了SourceRange::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeNamespace
void RemoveNamespace::removeNamespace(const NamespaceDecl *ND)
{
// Remove the right brace first
SourceLocation StartLoc = ND->getRBraceLoc();
if (StartLoc.isValid())
TheRewriter.RemoveText(StartLoc, 1);
// Then remove name and the left brace
StartLoc = ND->getBeginLoc();
TransAssert(StartLoc.isValid() && "Invalid Namespace LocStart!");
const char *StartBuf = SrcManager->getCharacterData(StartLoc);
SourceRange NDRange = ND->getSourceRange();
SourceLocation EndLoc;
if (NDRange.isValid()) {
int RangeSize = TheRewriter.getRangeSize(NDRange);
TransAssert((RangeSize != -1) && "Bad Namespace Range!");
std::string NDStr(StartBuf, RangeSize);
size_t Pos = NDStr.find('{');
TransAssert((Pos != std::string::npos) && "Cannot find LBrace!");
EndLoc = StartLoc.getLocWithOffset(Pos);
}
else {
EndLoc = RewriteHelper->getEndLocationUntil(StartLoc, '{');
}
TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
}
示例2: MakeCXCursor
CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
SourceRange RegionOfInterest,
bool FirstInDeclGroup) {
assert(D && TU && "Invalid arguments!");
CXCursorKind K = getCursorKindForDecl(D);
if (K == CXCursor_ObjCClassMethodDecl ||
K == CXCursor_ObjCInstanceMethodDecl) {
int SelectorIdIndex = -1;
// Check if cursor points to a selector id.
if (RegionOfInterest.isValid() &&
RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
SmallVector<SourceLocation, 16> SelLocs;
cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
SmallVectorImpl<SourceLocation>::iterator
I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
if (I != SelLocs.end())
SelectorIdIndex = I - SelLocs.begin();
}
CXCursor C = { K, SelectorIdIndex,
{ D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }
};
return C;
}
CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
return C;
}
示例3: HandleComment
bool ClangDocHTML::HandleComment(Preprocessor &PP, SourceRange Comment)
{
if(Comment.isValid())
{
if(astConsumer->sourceManager->isInSystemHeader(Comment.getBegin()))
{
return false;
}
/*
bool bInvalid = false;
const char *cbegin = astConsumer->sourceManager->getCharacterData(Comment.getBegin(), &bInvalid);
const char *cend = astConsumer->sourceManager->getCharacterData(Comment.getEnd(), &bInvalid);
llvm::StringRef string = llvm::StringRef(cbegin, cend-cbegin);*/
//Decl *decl = 0;
/*if(string.startswith("///<"))
{
decl = lastDecl;
decl->print(*Out);
}*/
commentsList.push_back(Comment);
//lastComment = commentsByDecl.insert(CommentsByDeclPair(decl, string) );
//*Out << string << "<br/>\n";
}
return false;
}
示例4: make_pair
/// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
/// that source range \arg R encompasses.
std::pair<int, int>
PreprocessingRecord::getPreprocessedEntitiesInRangeSlow(SourceRange Range) {
assert(Range.isValid());
assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
std::pair<unsigned, unsigned>
Local = findLocalPreprocessedEntitiesInRange(Range);
// Check if range spans local entities.
if (!ExternalSource || SourceMgr.isLocalSourceLocation(Range.getBegin()))
return std::make_pair(Local.first, Local.second);
std::pair<unsigned, unsigned>
Loaded = ExternalSource->findPreprocessedEntitiesInRange(Range);
// Check if range spans local entities.
if (Loaded.first == Loaded.second)
return std::make_pair(Local.first, Local.second);
unsigned TotalLoaded = LoadedPreprocessedEntities.size();
// Check if range spans loaded entities.
if (Local.first == Local.second)
return std::make_pair(int(Loaded.first)-TotalLoaded,
int(Loaded.second)-TotalLoaded);
// Range spands loaded and local entities.
return std::make_pair(int(Loaded.first)-TotalLoaded, Local.second);
}
示例5: removeOuterClass
void RemoveUnusedOuterClass::removeOuterClass()
{
TransAssert(TheCXXRDDef && "NULL Base CXXRD!");
SourceLocation LocStart = TheCXXRDDef->getLocStart();
SourceLocation LocEnd =
RewriteHelper->getEndLocationUntil(LocStart, '{');
TransAssert(LocEnd.isValid() && "Invalid Location!");
TheRewriter.RemoveText(SourceRange(LocStart, LocEnd));
const DeclContext *Ctx = dyn_cast<DeclContext>(TheCXXRDDef);
for (DeclContext::decl_iterator I = Ctx->decls_begin(),
E = Ctx->decls_end(); I != E; ++I) {
if ((*I)->isImplicit())
continue;
const AccessSpecDecl *AS = dyn_cast<AccessSpecDecl>(*I);
if (!AS)
continue;
TheRewriter.RemoveText(AS->getSourceRange());
}
SourceRange BracRange = TheCXXRDDef->getBraceRange();
TransAssert(BracRange.isValid() && "Invalid brace range!");
TheRewriter.RemoveText(BracRange);
}
示例6: PathDiagnosticRange
PathDiagnosticRange
PathDiagnosticLocation::genRange(LocationOrAnalysisDeclContext LAC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
switch (K) {
case SingleLocK:
return PathDiagnosticRange(SourceRange(Loc,Loc), true);
case RangeK:
break;
case StmtK: {
const Stmt *S = asStmt();
switch (S->getStmtClass()) {
default:
break;
case Stmt::DeclStmtClass: {
const DeclStmt *DS = cast<DeclStmt>(S);
if (DS->isSingleDecl()) {
// Should always be the case, but we'll be defensive.
return SourceRange(DS->getLocStart(),
DS->getSingleDecl()->getLocation());
}
break;
}
// FIXME: Provide better range information for different
// terminators.
case Stmt::IfStmtClass:
case Stmt::WhileStmtClass:
case Stmt::DoStmtClass:
case Stmt::ForStmtClass:
case Stmt::ChooseExprClass:
case Stmt::IndirectGotoStmtClass:
case Stmt::SwitchStmtClass:
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
SourceLocation L = getValidSourceLocation(S, LAC);
return SourceRange(L, L);
}
}
SourceRange R = S->getSourceRange();
if (R.isValid())
return R;
break;
}
case DeclK:
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
return MD->getSourceRange();
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
if (Stmt *Body = FD->getBody())
return Body->getSourceRange();
}
else {
SourceLocation L = D->getLocation();
return PathDiagnosticRange(SourceRange(L, L), true);
}
}
return SourceRange(Loc,Loc);
}
示例7: removeTypedefs
void ReplaceSimpleTypedef::removeTypedefs()
{
for (TypedefDecl::redecl_iterator I = TheTypedefDecl->redecls_begin(),
E = TheTypedefDecl->redecls_end(); I != E; ++I) {
SourceRange Range = (*I)->getSourceRange();
if (Range.isValid()) {
RewriteHelper->removeTextUntil(Range, ';');
Rewritten = true;
}
}
}
示例8: Node
TypeRefinementContext::TypeRefinementContext(ASTContext &Ctx, IntroNode Node,
TypeRefinementContext *Parent,
SourceRange SrcRange,
const AvailabilityContext &Info)
: Node(Node), SrcRange(SrcRange), AvailabilityInfo(Info) {
if (Parent) {
assert(SrcRange.isValid());
Parent->addChild(this);
assert(Info.isContainedIn(Parent->getAvailabilityInfo()));
}
Ctx.addDestructorCleanup(Children);
}
示例9: check
void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
const CXXConstructorDecl *Ctor =
Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
// Do not be confused: isExplicit means 'explicit' keyword is present,
// isImplicit means that it's a compiler-generated constructor.
if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted() ||
Ctor->getNumParams() == 0 || Ctor->getMinRequiredArguments() > 1)
return;
bool takesInitializerList = isStdInitializerList(
Ctor->getParamDecl(0)->getType().getNonReferenceType());
if (Ctor->isExplicit() &&
(Ctor->isCopyOrMoveConstructor() || takesInitializerList)) {
auto isKWExplicit = [](const Token &Tok) {
return Tok.is(tok::raw_identifier) &&
Tok.getRawIdentifier() == "explicit";
};
SourceRange ExplicitTokenRange =
FindToken(*Result.SourceManager, Result.Context->getLangOpts(),
Ctor->getOuterLocStart(), Ctor->getLocEnd(), isKWExplicit);
StringRef ConstructorDescription;
if (Ctor->isMoveConstructor())
ConstructorDescription = "move";
else if (Ctor->isCopyConstructor())
ConstructorDescription = "copy";
else
ConstructorDescription = "initializer-list";
DiagnosticBuilder Diag =
diag(Ctor->getLocation(),
"%0 constructor should not be declared explicit")
<< ConstructorDescription;
if (ExplicitTokenRange.isValid()) {
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(ExplicitTokenRange));
}
return;
}
if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() ||
takesInitializerList)
return;
bool SingleArgument =
Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
SourceLocation Loc = Ctor->getLocation();
diag(Loc,
"%0 must be marked explicit to avoid unintentional implicit conversions")
<< (SingleArgument
? "single-argument constructors"
: "constructors that are callable with a single argument")
<< FixItHint::CreateInsertion(Loc, "explicit ");
}
示例10: reportUnmatchedWait
/**
* Report there's no matching nonblocking call for request var used by wait.
*
* @param callExpr
* @param requestVar
* @param node
*/
void MPIBugReporter::reportUnmatchedWait(
const CallEvent &callEvent, const clang::ento::MemRegion *requestRegion,
const ExplodedNode *const node) const {
std::string errorText{"Request '" + util::variableName(requestRegion) +
"' has no matching nonblocking call. "};
auto bugReport =
llvm::make_unique<BugReport>(*unmatchedWaitBugType_, errorText, node);
bugReport->addRange(callEvent.getSourceRange());
SourceRange r = util::sourceRange(requestRegion);
if (r.isValid()) bugReport->addRange(r);
bugReporter_.emitReport(std::move(bugReport));
}
示例11: 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] = '~';
}
示例12: copyBaseClassDecls
// ISSUE: directly copying decls could bring in name conflicts
void RemoveBaseClass::copyBaseClassDecls(void)
{
if (!getNumExplicitDecls(TheBaseClass))
return;
SourceRange BracRange = TheBaseClass->getBraceRange();
TransAssert(BracRange.isValid() && "Invalid RBraceLoc!");
SourceLocation StartLoc = BracRange.getBegin();
SourceLocation EndLoc = BracRange.getEnd().getLocWithOffset(-1);
std::string DeclsStr =
TheRewriter.getRewrittenText(SourceRange(StartLoc, EndLoc));
TransAssert(!DeclsStr.empty() && "Empty DeclsStr!");
SourceLocation InsertLoc = TheDerivedClass->getBraceRange().getEnd();
TheRewriter.InsertTextBefore(InsertLoc, DeclsStr);
}
示例13: reportMissingWait
/**
* Report a missing wait for a nonblocking call.
*
* @param requestVar
* @param node
*/
void MPIBugReporter::reportMissingWait(const RequestVar &requestVar,
const ExplodedNode *const node) const {
std::string lineNo{lineNumber(requestVar.lastUser_)};
std::string lastUser =
requestVar.lastUser_->getCalleeIdentifier()->getName();
std::string errorText{
"'" + lastUser + "' in line " + lineNo + ", using request '" +
requestVar.variableName() +
"', has no matching wait in the scope of this function. "};
auto bugReport =
llvm::make_unique<BugReport>(*missingWaitBugType_, errorText, node);
bugReport->addRange(requestVar.lastUser_->getSourceRange());
SourceRange r = util::sourceRange(requestVar.memRegion_);
if (r.isValid()) bugReport->addRange(r);
bugReporter_.emitReport(std::move(bugReport));
}
示例14: reportDoubleWait
/**
* Report duplicate request use by waits.
*
* @param observedCall
* @param requestVar
* @param node
*/
void MPIBugReporter::reportDoubleWait(const CallEvent &observedCall,
const RequestVar &requestVar,
const ExplodedNode *const node) const {
std::string lineNo{lineNumber(requestVar.lastUser_)};
std::string lastUser =
requestVar.lastUser_->getCalleeIdentifier()->getName();
std::string errorText{"Request '" + requestVar.variableName() +
"' is already waited upon by '" + lastUser +
"' in line " + lineNo + ". "};
auto bugReport =
llvm::make_unique<BugReport>(*doubleWaitBugType_, errorText, node);
bugReport->addRange(observedCall.getSourceRange());
bugReport->addRange(requestVar.lastUser_->getSourceRange());
SourceRange r = util::sourceRange(requestVar.memRegion_);
if (r.isValid()) bugReport->addRange(r);
bugReporter_.emitReport(std::move(bugReport));
}
示例15: dumpTemplateArgument
void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
IndentScope Indent(*this);
OS << "TemplateArgument";
if (R.isValid())
dumpSourceRange(R);
switch (A.getKind()) {
case TemplateArgument::Null:
OS << " null";
break;
case TemplateArgument::Type:
OS << " type";
dumpType(A.getAsType());
break;
case TemplateArgument::Declaration:
OS << " decl";
dumpDeclRef(A.getAsDecl());
break;
case TemplateArgument::NullPtr:
OS << " nullptr";
break;
case TemplateArgument::Integral:
OS << " integral " << A.getAsIntegral();
break;
case TemplateArgument::Template:
OS << " template ";
A.getAsTemplate().dump(OS);
break;
case TemplateArgument::TemplateExpansion:
OS << " template expansion";
A.getAsTemplateOrTemplatePattern().dump(OS);
break;
case TemplateArgument::Expression:
OS << " expr";
dumpStmt(A.getAsExpr());
break;
case TemplateArgument::Pack:
OS << " pack";
for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
I != E; ++I)
dumpTemplateArgument(*I);
break;
}
}