本文整理汇总了C++中SourceLocation::isInvalid方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceLocation::isInvalid方法的具体用法?C++ SourceLocation::isInvalid怎么用?C++ SourceLocation::isInvalid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceLocation
的用法示例。
在下文中一共展示了SourceLocation::isInvalid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: migrateRef
void XCTMigrator::migrateRef(NamedDecl *D, SourceLocation Loc) {
if (!D || Loc.isInvalid())
return;
llvm::DenseMap<IdentifierInfo *, IdentifierInfo *>::iterator DI =
DeclsMap.find(D->getDeclName().getAsIdentifierInfo());
if (DI == DeclsMap.end())
return;
if (!isFromSenTestInclude(D->getLocation()) || isFromSenTestInclude(Loc))
return;
assert(DI->second);
edit::Commit commit(Editor);
commit.replace(Loc, DI->second->getName());
Editor.commit(commit);
}
示例2: lfort_getLocationForOffset
CXSourceLocation lfort_getLocationForOffset(CXProgram tu,
CXFile file,
unsigned offset) {
if (!tu || !file)
return lfort_getNullLocation();
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->PgmData);
SourceLocation SLoc
= CXXUnit->getLocation(static_cast<const FileEntry *>(file), offset);
if (SLoc.isInvalid())
return lfort_getNullLocation();
return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
}
示例3: parseModuleReferences
// Parses module references in the given lines. Returns the module references,
// and a pointer to the first "main code" line if that is adjacent to the
// affected lines of module references, nullptr otherwise.
std::pair<SmallVector<JsModuleReference, 16>, AnnotatedLine*>
parseModuleReferences(const AdditionalKeywords &Keywords,
SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
SmallVector<JsModuleReference, 16> References;
SourceLocation Start;
AnnotatedLine *FirstNonImportLine = nullptr;
bool AnyImportAffected = false;
for (auto Line : AnnotatedLines) {
Current = Line->First;
LineEnd = Line->Last;
skipComments();
if (Start.isInvalid() || References.empty())
// After the first file level comment, consider line comments to be part
// of the import that immediately follows them by using the previously
// set Start.
Start = Line->First->Tok.getLocation();
if (!Current) {
// Only comments on this line. Could be the first non-import line.
FirstNonImportLine = Line;
continue;
}
JsModuleReference Reference;
Reference.Range.setBegin(Start);
if (!parseModuleReference(Keywords, Reference)) {
if (!FirstNonImportLine)
FirstNonImportLine = Line; // if no comment before.
break;
}
FirstNonImportLine = nullptr;
AnyImportAffected = AnyImportAffected || Line->Affected;
Reference.Range.setEnd(LineEnd->Tok.getEndLoc());
DEBUG({
llvm::dbgs() << "JsModuleReference: {"
<< "is_export: " << Reference.IsExport
<< ", cat: " << Reference.Category
<< ", url: " << Reference.URL
<< ", prefix: " << Reference.Prefix;
for (size_t i = 0; i < Reference.Symbols.size(); ++i)
llvm::dbgs() << ", " << Reference.Symbols[i].Symbol << " as "
<< Reference.Symbols[i].Alias;
llvm::dbgs() << ", text: " << getSourceText(Reference.Range);
llvm::dbgs() << "}\n";
});
References.push_back(Reference);
Start = SourceLocation();
}
示例4: addUsage
static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures,
const IdentifierNamingCheck::NamingCheckId &Decl,
SourceRange Range, SourceManager *SourceMgr = nullptr) {
// Do nothing if the provided range is invalid.
if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
return;
// If we have a source manager, use it to convert to the spelling location for
// performing the fix. This is necessary because macros can map the same
// spelling location to different source locations, and we only want to fix
// the token once, before it is expanded by the macro.
SourceLocation FixLocation = Range.getBegin();
if (SourceMgr)
FixLocation = SourceMgr->getSpellingLoc(FixLocation);
if (FixLocation.isInvalid())
return;
// Try to insert the identifier location in the Usages map, and bail out if it
// is already in there
auto &Failure = Failures[Decl];
if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
return;
if (!Failure.ShouldFix)
return;
// Check if the range is entirely contained within a macro argument.
SourceLocation MacroArgExpansionStartForRangeBegin;
SourceLocation MacroArgExpansionStartForRangeEnd;
bool RangeIsEntirelyWithinMacroArgument =
SourceMgr &&
SourceMgr->isMacroArgExpansion(Range.getBegin(),
&MacroArgExpansionStartForRangeBegin) &&
SourceMgr->isMacroArgExpansion(Range.getEnd(),
&MacroArgExpansionStartForRangeEnd) &&
MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd;
// Check if the range contains any locations from a macro expansion.
bool RangeContainsMacroExpansion = RangeIsEntirelyWithinMacroArgument ||
Range.getBegin().isMacroID() ||
Range.getEnd().isMacroID();
bool RangeCanBeFixed =
RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion;
Failure.ShouldFix = RangeCanBeFixed;
}
示例5: PrintIncludeStack
void TextDiagnosticPrinter::
PrintIncludeStack(SourceLocation Loc, const SourceManager &SM) {
if (Loc.isInvalid()) return;
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
if (PLoc.isInvalid())
return;
// Print out the other include frames first.
PrintIncludeStack(PLoc.getIncludeLoc(), SM);
if (DiagOpts->ShowLocation)
OS << "In file included from " << PLoc.getFilename()
<< ':' << PLoc.getLine() << ":\n";
else
OS << "In included file:\n";
}
示例6: emitIncludeStackRecursively
/// \brief Helper to recursivly walk up the include stack and print each layer
/// on the way back down.
void TextDiagnostic::emitIncludeStackRecursively(SourceLocation Loc) {
if (Loc.isInvalid())
return;
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
if (PLoc.isInvalid())
return;
// Emit the other include frames first.
emitIncludeStackRecursively(PLoc.getIncludeLoc());
if (DiagOpts.ShowLocation)
OS << "In file included from " << PLoc.getFilename()
<< ':' << PLoc.getLine() << ":\n";
else
OS << "In included file:\n";
}
示例7: checkReset
void MakeSmartPtrCheck::checkReset(SourceManager &SM,
const CXXMemberCallExpr *Reset,
const CXXNewExpr *New) {
const auto *Expr = cast<MemberExpr>(Reset->getCallee());
SourceLocation OperatorLoc = Expr->getOperatorLoc();
SourceLocation ResetCallStart = Reset->getExprLoc();
SourceLocation ExprStart = Expr->getLocStart();
SourceLocation ExprEnd =
Lexer::getLocForEndOfToken(Expr->getLocEnd(), 0, SM, getLangOpts());
bool InMacro = ExprStart.isMacroID();
if (InMacro && IgnoreMacros) {
return;
}
// There are some cases where we don't have operator ("." or "->") of the
// "reset" expression, e.g. call "reset()" method directly in the subclass of
// "std::unique_ptr<>". We skip these cases.
if (OperatorLoc.isInvalid()) {
return;
}
auto Diag = diag(ResetCallStart, "use %0 instead")
<< MakeSmartPtrFunctionName;
// Disable the fix in macros.
if (InMacro) {
return;
}
if (!replaceNew(Diag, New, SM)) {
return;
}
Diag << FixItHint::CreateReplacement(
CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
(llvm::Twine(" = ") + MakeSmartPtrFunctionName + "<" +
GetNewExprName(New, SM, getLangOpts()) + ">")
.str());
if (Expr->isArrow())
Diag << FixItHint::CreateInsertion(ExprStart, "*");
insertHeader(Diag, SM.getFileID(OperatorLoc));
}
示例8: handleReference
bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
CXCursor Cursor,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E,
CXIdxEntityRefKind Kind) {
if (!CB.indexEntityReference)
return false;
if (!D)
return false;
if (Loc.isInvalid())
return false;
if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D))
return false;
if (isNotFromSourceFile(D->getLocation()))
return false;
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
return false;
if (shouldSuppressRefs()) {
if (markEntityOccurrenceInFile(D, Loc))
return false; // already occurred.
}
ScratchAlloc SA(*this);
EntityInfo RefEntity, ParentEntity;
getEntityInfo(D, RefEntity, SA);
if (!RefEntity.USR)
return false;
getEntityInfo(Parent, ParentEntity, SA);
ContainerInfo Container;
getContainerInfo(DC, Container);
CXIdxEntityRefInfo Info = { Kind,
Cursor,
getIndexLoc(Loc),
&RefEntity,
Parent ? &ParentEntity : nullptr,
&Container };
CB.indexEntityReference(ClientData, &Info);
return true;
}
示例9: EmitOptimizationRemark
void BackendConsumer::EmitOptimizationRemark(
const llvm::DiagnosticInfoOptimizationRemarkBase &D, unsigned DiagID) {
// We only support remarks.
assert(D.getSeverity() == llvm::DS_Remark);
SourceManager &SourceMgr = Context->getSourceManager();
FileManager &FileMgr = SourceMgr.getFileManager();
StringRef Filename;
unsigned Line, Column;
D.getLocation(&Filename, &Line, &Column);
SourceLocation DILoc;
const FileEntry *FE = FileMgr.getFile(Filename);
if (FE && Line > 0) {
// If -gcolumn-info was not used, Column will be 0. This upsets the
// source manager, so pass 1 if Column is not set.
DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
}
// If a location isn't available, try to approximate it using the associated
// function definition. We use the definition's right brace to differentiate
// from diagnostics that genuinely relate to the function itself.
FullSourceLoc Loc(DILoc, SourceMgr);
if (Loc.isInvalid())
if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
Loc = FD->getASTContext().getFullLoc(FD->getBodyRBrace());
Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName())
<< D.getMsg().str();
if (Line == 0)
// If we could not extract a source location for the diagnostic,
// inform the user how they can get source locations back.
//
// FIXME: We should really be generating !srcloc annotations when
// -Rpass is used. !srcloc annotations need to be emitted in
// approximately the same spots as !dbg nodes.
Diags.Report(Loc, diag::note_fe_backend_optimization_remark_missing_loc);
else if (DILoc.isInvalid())
// If we were not able to translate the file:line:col information
// back to a SourceLocation, at least emit a note stating that
// we could not translate this location. This can happen in the
// case of #line directives.
Diags.Report(Loc, diag::note_fe_backend_optimization_remark_invalid_loc)
<< Filename << Line << Column;
}
示例10: rewriteToNSEnumDecl
static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
const TypedefDecl *TypedefDcl,
const NSAPI &NS, edit::Commit &commit,
bool IsNSIntegerType) {
std::string ClassString =
IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, ";
ClassString += TypedefDcl->getIdentifier()->getName();
ClassString += ')';
SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
commit.replace(R, ClassString);
SourceLocation EndOfTypedefLoc = TypedefDcl->getLocEnd();
EndOfTypedefLoc = trans::findLocationAfterSemi(EndOfTypedefLoc, NS.getASTContext());
if (!EndOfTypedefLoc.isInvalid()) {
commit.remove(SourceRange(TypedefDcl->getLocStart(), EndOfTypedefLoc));
return true;
}
return false;
}
示例11: TraverseMemberExpr
/// \brief If the member expression is operator-> (overloaded or not) on
/// IndexVar, include it as a valid usage and prune the traversal.
///
/// For example, given
/// \code
/// struct Foo { int bar(); int x; };
/// vector<Foo> v;
/// \endcode
/// the following uses will be considered convertible:
/// \code
/// for (vector<Foo>::iterator i = v.begin(), e = v.end(); i != e; ++i) {
/// int b = i->bar();
/// int k = i->x + 1;
/// }
/// \endcode
/// though
/// \code
/// for (vector<Foo>::iterator i = v.begin(), e = v.end(); i != e; ++i) {
/// int k = i.insert(1);
/// }
/// for (vector<Foo>::iterator i = v.begin(), e = v.end(); i != e; ++i) {
/// int b = e->bar();
/// }
/// \endcode
/// will not.
bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
const Expr *Base = Member->getBase();
const DeclRefExpr *Obj = getDeclRef(Base);
const Expr *ResultExpr = Member;
QualType ExprType;
if (const CXXOperatorCallExpr *Call =
dyn_cast<CXXOperatorCallExpr>(Base->IgnoreParenImpCasts())) {
// If operator->() is a MemberExpr containing a CXXOperatorCallExpr, then
// the MemberExpr does not have the expression we want. We therefore catch
// that instance here.
// For example, if vector<Foo>::iterator defines operator->(), then the
// example `i->bar()` at the top of this function is a CXXMemberCallExpr
// referring to `i->` as the member function called. We want just `i`, so
// we take the argument to operator->() as the base object.
if(Call->getOperator() == OO_Arrow) {
assert(Call->getNumArgs() == 1 &&
"Operator-> takes more than one argument");
Obj = getDeclRef(Call->getArg(0));
ResultExpr = Obj;
ExprType = Call->getCallReturnType();
}
}
if (Member->isArrow() && Obj && exprReferencesVariable(IndexVar, Obj)) {
if (ExprType.isNull())
ExprType = Obj->getType();
assert(ExprType->isPointerType() && "Operator-> returned non-pointer type");
// FIXME: This works around not having the location of the arrow operator.
// Consider adding OperatorLoc to MemberExpr?
SourceLocation ArrowLoc =
Lexer::getLocForEndOfToken(Base->getExprLoc(), 0,
Context->getSourceManager(),
Context->getLangOpts());
// If something complicated is happening (i.e. the next token isn't an
// arrow), give up on making this work.
if (!ArrowLoc.isInvalid()) {
Usages.push_back(Usage(ResultExpr, /*IsArrow=*/true,
SourceRange(Base->getExprLoc(), ArrowLoc)));
return true;
}
}
return TraverseStmt(Member->getBase());
}
示例12: OptimizationRemarkHandler
void BackendConsumer::OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationRemark &D) {
// We only support remarks.
assert(D.getSeverity() == llvm::DS_Remark);
// Optimization remarks are active only if -Rpass=regexp is given and the
// regular expression pattern in 'regexp' matches the name of the pass
// name in \p D.
if (CodeGenOpts.OptimizationRemarkPattern &&
CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName())) {
SourceManager &SourceMgr = Context->getSourceManager();
FileManager &FileMgr = SourceMgr.getFileManager();
StringRef Filename;
unsigned Line, Column;
D.getLocation(&Filename, &Line, &Column);
SourceLocation Loc;
const FileEntry *FE = FileMgr.getFile(Filename);
if (FE && Line > 0) {
// If -gcolumn-info was not used, Column will be 0. This upsets the
// source manager, so if Column is not set, set it to 1.
if (Column == 0)
Column = 1;
Loc = SourceMgr.translateFileLineCol(FE, Line, Column);
}
Diags.Report(Loc, diag::remark_fe_backend_optimization_remark)
<< AddFlagValue(D.getPassName()) << D.getMsg().str();
if (Line == 0)
// If we could not extract a source location for the diagnostic,
// inform the user how they can get source locations back.
//
// FIXME: We should really be generating !srcloc annotations when
// -Rpass is used. !srcloc annotations need to be emitted in
// approximately the same spots as !dbg nodes.
Diags.Report(diag::note_fe_backend_optimization_remark_missing_loc);
else if (Loc.isInvalid())
// If we were not able to translate the file:line:col information
// back to a SourceLocation, at least emit a note stating that
// we could not translate this location. This can happen in the
// case of #line directives.
Diags.Report(diag::note_fe_backend_optimization_remark_invalid_loc)
<< Filename << Line << Column;
}
}
示例13: WriteSourceLocation
static void WriteSourceLocation(llvm::raw_ostream &OS,
SourceManager *SM,
SourceLocation Location) {
if (!SM || Location.isInvalid()) {
// If we don't have a source manager or this location is invalid,
// just write an invalid location.
WriteUnsigned(OS, 0);
WriteUnsigned(OS, 0);
WriteUnsigned(OS, 0);
return;
}
Location = SM->getInstantiationLoc(Location);
std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location);
WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName());
WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second));
WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second));
}
示例14: emitImportStackRecursively
/// \brief Helper to recursivly walk up the import stack and print each layer
/// on the way back down.
void DiagnosticRenderer::emitImportStackRecursively(SourceLocation Loc,
StringRef ModuleName,
const SourceManager &SM) {
if (Loc.isInvalid()) {
return;
}
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
if (PLoc.isInvalid())
return;
// Emit the other import frames first.
std::pair<SourceLocation, StringRef> NextImportLoc
= SM.getModuleImportLoc(Loc);
emitImportStackRecursively(NextImportLoc.first, NextImportLoc.second, SM);
// Emit the inclusion text/note.
emitImportLocation(Loc, PLoc, ModuleName, SM);
}
示例15: AddLocToRecord
void SDiagsWriter::AddLocToRecord(SourceLocation Loc,
RecordDataImpl &Record,
unsigned TokSize) {
if (Loc.isInvalid()) {
// Emit a "sentinel" location.
Record.push_back((unsigned)0); // File.
Record.push_back((unsigned)0); // Line.
Record.push_back((unsigned)0); // Column.
Record.push_back((unsigned)0); // Offset.
return;
}
SourceManager &SM = Diags.getSourceManager();
Loc = SM.getSpellingLoc(Loc);
Record.push_back(getEmitFile(Loc));
Record.push_back(SM.getSpellingLineNumber(Loc));
Record.push_back(SM.getSpellingColumnNumber(Loc)+TokSize);
Record.push_back(SM.getFileOffset(Loc));
}