本文整理汇总了C++中Stmt::getLocEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ Stmt::getLocEnd方法的具体用法?C++ Stmt::getLocEnd怎么用?C++ Stmt::getLocEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stmt
的用法示例。
在下文中一共展示了Stmt::getLocEnd方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InsertAccess
void FakeDirectiveHandler::InsertAccess(Expr * Current,
DeclRefExpr * Original,
bool Write,
vector<LocalStmtPair> WritePairs,
bool ActualVar,
string Struct) {
if (!ActualVar) return;
const Type * T = Current->getType().getTypePtr();
if (FullDirectives->IsPrivate(Original, Struct, T, Original->getLocStart())) {
return;
}
vector<LocalStmtPair>::iterator it;
CompilerInstance &CI = FullDirectives->GetCI(Current->getLocStart());
for (it = WritePairs.begin(); it != WritePairs.end(); it++) {
bool insertAfter = it->insertAfter;
Stmt * curStmt = it->stmt;
bool isBracket = false;
SourceLocation start = curStmt->getLocStart();
SourceLocation end = FindSemiAfterLocation(curStmt->getLocEnd(),
CI.getASTContext());
if (end.isInvalid()) {
end = curStmt->getLocEnd();
isBracket = true;
}
SourceLocation loc;
if (insertAfter) {
if (isBracket) {
loc = end;
} else {
loc = end.getLocWithOffset(1);
}
} else {
loc = start;
}
loc = tools::UnpackMacroLoc(loc, CI);
if (GetOrSetAccessed(loc, Current, Write)) {
continue;
}
FullDirectives->InsertDeclAccess(Original->getFoundDecl(), Write);
}
}
示例2: VisitFunctionDecl
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
Stmt *FuncBody = f->getBody();
// Type name as string
QualType QT = f->getResultType();
string TypeStr = QT.getAsString();
// Function name
DeclarationName DeclName = f->getNameInfo().getName();
string FuncName = DeclName.getAsString();
// Add comment before
stringstream SSBefore;
SSBefore << "// Begin function " << FuncName << " returning "
<< TypeStr << "\n";
SourceLocation ST = f->getSourceRange().getBegin();
TheRewriter.InsertText(ST, SSBefore.str(), true, true);
// And after
stringstream SSAfter;
SSAfter << "\n// End function " << FuncName << "\n";
ST = FuncBody->getLocEnd().getLocWithOffset(1);
TheRewriter.InsertText(ST, SSAfter.str(), true, true);
}
return true;
}
示例3: VisitFunctionDecl
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
Stmt *FuncBody = f->getBody();
// Type name as string
QualType QT = f->getResultType();
string TypeStr = QT.getAsString();
// Function name
DeclarationName DeclName = f->getNameInfo().getName();
string FuncName = DeclName.getAsString();
func_info fi;
fi.name = FuncName;
fi.return_type = TypeStr;
unsigned nbp = f->getNumParams();
for (int i = 0; i < nbp; ++i) {
//getTypeSourceInfo()->getType() and getOriginalType() is the final type. e.g. for size_t, the result may be unsigned int, but we need only size_t
//fi.argv.push_back(f->getParamDecl(i)->getTypeSourceInfo()->getType().getAsString());//->getOriginalType().getAsString());
/*
TypeLoc tl = f->getParamDecl(i)->getTypeSourceInfo()->getTypeLoc();
SourceLocation sl0 = tl.getBeginLoc();
SourceLocation sl1 = tl.getEndLoc();
const char* ptr0 = TheRewriter.getSourceMgr().getCharacterData(sl0);
const char* ptr1 = TheRewriter.getSourceMgr().getCharacterData(sl1);
*/
fi.argv.push_back(trim(decl2str_without_var(f->getParamDecl(i), &TheRewriter.getSourceMgr())));
}
mFuncInfo.push_back(fi);
#if 0
if (f->hasBody()) {
// Add comment before
stringstream SSBefore;
SSBefore << "// Begin function " << FuncName << " returning "
<< TypeStr << "\n";
SourceLocation ST = f->getSourceRange().getBegin();
TheRewriter.InsertText(ST, SSBefore.str(), true, true);
// And after
stringstream SSAfter;
SSAfter << "\n// End function " << FuncName << "\n";
ST = FuncBody->getLocEnd().getLocWithOffset(1);
TheRewriter.InsertText(ST, SSAfter.str(), true, true);
}
#endif
return true;
}
示例4: VisitFunctionDecl
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
Stmt *FuncBody = f->getBody();
// Type name as string
QualType QT = f->getReturnType();
std::string TypeStr = QT.getAsString();
// Function name
DeclarationName DeclName = f->getNameInfo().getName();
std::string FuncName = DeclName.getAsString();
// Add comment before
std::stringstream SSBefore;
SSBefore << "// Begin function " << FuncName << " returning " << TypeStr
<< "\n";
SourceLocation ST = f->getSourceRange().getBegin();
TheRewriter.InsertText(ST, SSBefore.str(), true, true);
// And after
std::stringstream SSAfter;
SSAfter << "\n// End function " << FuncName;
ST = FuncBody->getLocEnd().getLocWithOffset(1);
TheRewriter.InsertText(ST, SSAfter.str(), true, true);
int forCounter=0;
Stmt::child_iterator CI, CE = FuncBody->child_end();
for (CI = FuncBody->child_begin(); CI != CE; ++CI) {
if (*CI != 0) {
if (isa<ForStmt>(*CI))
{
forCounter++;
std::stringstream MarkerBefore;
std::stringstream MarkerAfter;
MarkerBefore<<"\nMCPROF_ZONE_ENTER(" << forCounter << ");\n";
MarkerAfter<<"\nMCPROF_ZONE_EXIT(" << forCounter << ");\n";
ForStmt *For = cast<ForStmt>(*CI);
SourceLocation ST = For->getLocStart();
TheRewriter.InsertText(ST, MarkerBefore.str(), true, false);
Stmt *ForBody = For->getBody();
SourceLocation END = ForBody->getLocEnd();
int offset = Lexer::MeasureTokenLength(END,
TheRewriter.getSourceMgr(),
TheRewriter.getLangOpts()) + 1;
SourceLocation END1 = END.getLocWithOffset(offset);
TheRewriter.InsertText(END1, MarkerAfter.str(), true, false);
// llvm::errs() << " Detected for loop number " << forCounter
// << " in function " << FuncName << "\n";
// InstrumentStmt(ForBody);
// Stmt *ForBody = CI->getBody();
// SourceLocation ST = CI->getLocStart();
// char *b = sourceManager->getCharacterData(_b)
// llvm::errs() << ST << " is location \n";
}
}
}
}
return true;
}