本文整理汇总了C++中CompoundStmt类的典型用法代码示例。如果您正苦于以下问题:C++ CompoundStmt类的具体用法?C++ CompoundStmt怎么用?C++ CompoundStmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompoundStmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unrollRecordAssigns
//---------------------------------------------------------
void unrollRecordAssigns(StmtEditor& editor, Stmt* S)
{
const RecordType *RT;
for (stmt_iterator<BinaryOperator> i = stmt_ibegin(S),
e = stmt_iend(S); i != e;)
{
BinaryOperator* BO = *i;
if (BO->getOpcode() == BO_Assign &&
(RT = BO->getType()->getAsStructureType()) != 0 &&
editor.getStatementOfExpression(BO) == BO) // ensures top level assign
{
CompoundStmt* CS = editor.ensureCompoundParent(BO);
std::vector<Stmt*> compoundStmts(CS->child_begin(), CS->child_end());
std::vector<Stmt*>::iterator insertPos =
std::find(compoundStmts.begin(), compoundStmts.end(), BO);
assert(insertPos != compoundStmts.end());
insertPos = compoundStmts.erase(insertPos);
RecordAssignUnroller unroller(editor, RT->getDecl(), BO);
compoundStmts.insert(insertPos,
unroller.compoundStmts.begin(), unroller.compoundStmts.end());
editor.replaceStmts(CS, &compoundStmts[0], compoundStmts.size());
i = stmt_ibegin(S);
}
else
{
++i;
}
}
}
示例2: apply
void UnreachableCodeRule::apply(
CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet)
{
Stmt *stmt = CursorHelper::getStmt(node);
if (stmt)
{
CompoundStmt *compoundStmt = dyn_cast<CompoundStmt>(stmt);
if (compoundStmt)
{
bool hasBreakPoint = false;
for (CompoundStmt::body_iterator body = compoundStmt->body_begin(),
bodyEnd = compoundStmt->body_end();
body != bodyEnd;
body++)
{
if (hasBreakPoint)
{
Violation violation(node, this);
violationSet.addViolation(violation);
return;
}
else
{
Stmt *bodyStmt = (Stmt *)*body;
hasBreakPoint = isBreakPoint(bodyStmt, parentNode);
}
}
}
}
}
示例3: shouldProceed
bool shouldProceed(void *S, void *T) {
using namespace clang;
Sema *Sem = (Sema *)S;
DiagnosticsEngine& Diag = Sem->getDiagnostics();
cling::Transaction* Trans = (cling::Transaction*)T;
// Here we will cheat a bit and assume that the warning came from the last
// stmt, which will be in the 90% of the cases.
CompoundStmt* CS = cast<CompoundStmt>(Trans->getWrapperFD()->getBody());
// Skip the NullStmts.
SourceLocation Loc = CS->getLocStart();
for(CompoundStmt::const_reverse_body_iterator I = CS->body_rbegin(),
E = CS->body_rend(); I != E; ++I)
if (!isa<NullStmt>(*I)) {
Loc = (*I)->getLocStart();
break;
}
Diag.Report(Loc, diag::warn_null_ptr_deref);
if (isatty(fileno(stdin))) {
int input = getchar();
getchar();
if (input == 'y' || input == 'Y')
return false;
}
return true;
}
示例4: VisitSwitchStmt
bool VisitSwitchStmt(SwitchStmt *switchStmt)
{
CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(switchStmt->getBody());
if (compoundStmt)
{
bool breakFound = true;
for (CompoundStmt::body_iterator body = compoundStmt->body_begin(),
bodyEnd = compoundStmt->body_end(); body != bodyEnd; body++)
{
Stmt *bodyStmt = dyn_cast<Stmt>(*body);
if (isBreakingPoint(bodyStmt))
{
breakFound = true;
continue;
}
if (isSwitchCase(bodyStmt))
{
if (!breakFound)
{
addViolation(switchStmt, this);
break;
}
FindingBreak findingBreak;
breakFound = findingBreak.findBreak(dyn_cast<SwitchCase>(bodyStmt));
}
}
if (!breakFound)
{
addViolation(switchStmt, this);
}
}
return true;
}
示例5: UnwrapStmtList
Stmt *TransformWCR::MergeWCRsAndMakeCompoundStmt(StmtVector &Body) {
StmtVector Stmts;
UnwrapStmtList(Stmts, Body);
#if 1
return NewCompoundStmt(Stmts);
#else
StmtVector NewBody;
for (unsigned i = 0, e = Stmts.size(); i < e; i++) {
CompoundStmt *CS = dyn_cast<CompoundStmt>(Stmts[i]);
if (CS && CS->isWCR() && !isLandPad(CS)) {
// Check if the next stmt is a WCR.
while (i + 1 < e) {
CompoundStmt *nextCS = dyn_cast<CompoundStmt>(Stmts[i+1]);
if (nextCS && nextCS->isWCR() && !isLandPad(CS)) {
CS = MergeConsecutiveWCRs(CS, nextCS);
i++;
} else break;
}
NewBody.push_back(CS);
} else {
NewBody.push_back(Stmts[i]);
}
}
return NewCompoundStmt(NewBody);
#endif
}
示例6: removeInnerAssigns
//---------------------------------------------------------
void removeInnerAssigns(StmtEditor& editor, Stmt* S)
{
for (stmt_iterator<BinaryOperator> i = stmt_ibegin(S),
e = stmt_iend(S); i != e;)
{
if (i->getOpcode() == BO_Assign &&
isa<Expr>(editor.getParent(*i)))
{
Stmt* exprStmt = editor.getStatementOfExpression(*i);
CompoundStmt* CS = editor.ensureCompoundParent(exprStmt);
std::vector<Stmt*> compoundStmts(CS->child_begin(), CS->child_end());
std::vector<Stmt*>::iterator insertPos =
std::find(compoundStmts.begin(), compoundStmts.end(), exprStmt);
assert(insertPos != compoundStmts.end());
compoundStmts.insert(insertPos, *i);
editor.replaceStatement(*i, selectInnerAssignResult(*i));
editor.replaceStmts(CS, &compoundStmts[0], compoundStmts.size());
i = stmt_ibegin(S);
}
else
{
++i;
}
}
}
示例7: new
Stmt *TransformVector::VisitDoStmt(DoStmt *Node) {
// Body
Stmt *Body = Node->getBody();
CompoundStmt *CS = dyn_cast<CompoundStmt>(Body);
if (!CS) {
// Convert a single stmt Body into a compound stmt.
SourceLocation loc;
CS = new (ASTCtx) CompoundStmt(ASTCtx, &Body, 1, loc, loc);
}
Node->setBody(TransformStmt(CS));
// Cond
Expr *Cond = Node->getCond();
if (Cond->getType()->isVectorType()) {
DeclVector DeclVec;
Node->setCond(ConvertVecLiteralInExpr(DeclVec, Cond));
if (DeclVec.size() > 0) {
CS = dyn_cast<CompoundStmt>(Node->getBody());
StmtVector StmtVec;
CompoundStmt::body_iterator I, E;
for (I = CS->body_begin(), E = CS->body_end(); I != E; ++I) {
StmtVec.push_back(*I);
}
PushBackDeclStmts(StmtVec, DeclVec);
CS->setStmts(ASTCtx, StmtVec.data(), StmtVec.size());
}
} else {
Node->setCond(TransformExpr(Cond));
}
return Node;
}
示例8: getTransaction
void ReturnSynthesizer::Transform() {
if (!getTransaction()->getCompilationOpts().ResultEvaluation)
return;
FunctionDecl* FD = getTransaction()->getWrapperFD();
int foundAtPos = -1;
Expr* lastExpr = utils::Analyze::GetOrCreateLastExpr(FD, &foundAtPos,
/*omitDS*/false,
m_Sema);
if (lastExpr) {
QualType RetTy = lastExpr->getType();
if (!RetTy->isVoidType() && RetTy.isTriviallyCopyableType(*m_Context)) {
// Change the void function's return type
// We can't PushDeclContext, because we don't have scope.
Sema::ContextRAII pushedDC(*m_Sema, FD);
FunctionProtoType::ExtProtoInfo EPI;
QualType FnTy
= m_Context->getFunctionType(RetTy, llvm::ArrayRef<QualType>(), EPI);
FD->setType(FnTy);
CompoundStmt* CS = cast<CompoundStmt>(FD->getBody());
assert(CS && "Missing body?");
// Change it to a return stmt (Avoid dealloc/alloc of all el.)
*(CS->body_begin() + foundAtPos)
= m_Sema->ActOnReturnStmt(lastExpr->getExprLoc(),
lastExpr).take();
}
} else if (foundAtPos >= 0) {
// check for non-void return statement
CompoundStmt* CS = cast<CompoundStmt>(FD->getBody());
Stmt* CSS = *(CS->body_begin() + foundAtPos);
if (ReturnStmt* RS = dyn_cast<ReturnStmt>(CSS)) {
if (Expr* RetV = RS->getRetValue()) {
QualType RetTy = RetV->getType();
// Any return statement will have been "healed" by Sema
// to correspond to the original void return type of the
// wrapper, using a ImplicitCastExpr 'void' <ToVoid>.
// Remove that.
if (RetTy->isVoidType()) {
ImplicitCastExpr* VoidCast = dyn_cast<ImplicitCastExpr>(RetV);
if (VoidCast) {
RS->setRetValue(VoidCast->getSubExpr());
RetTy = VoidCast->getSubExpr()->getType();
}
}
if (!RetTy->isVoidType()
&& RetTy.isTriviallyCopyableType(*m_Context)) {
Sema::ContextRAII pushedDC(*m_Sema, FD);
FunctionProtoType::ExtProtoInfo EPI;
QualType FnTy
= m_Context->getFunctionType(RetTy, llvm::ArrayRef<QualType>(),
EPI);
FD->setType(FnTy);
} // not returning void
} // have return value
} // is a return statement
} // have a statement
}
示例9: assert
CompoundStmt *TransformWCR::getWCR(int id) {
for (WCRSetTy::iterator I = WCRs.begin(), E = WCRs.end(); I != E; ++I) {
CompoundStmt *WCR = *I;
if (WCR->getWCRID() == id) return WCR;
}
assert(0 && "Invalid WCR ID");
return 0;
}
示例10: isLexicalEmpty
bool EmptyIfStatementRule::isLexicalEmpty(Stmt *stmt)
{
if (stmt)
{
CompoundStmt *compoundStmt = dyn_cast<CompoundStmt>(stmt);
return isa<NullStmt>(stmt) || (compoundStmt && compoundStmt->body_empty());
}
return false;
}
示例11: SerializeStmtList
//---------------------------------------------------------------------------
void TransformWCR::SerializeStmtList(StmtVector &Stmts, CompoundStmt *SL) {
for (CompoundStmt::body_iterator I = SL->body_begin(), E = SL->body_end();
I != E; ++I) {
CompoundStmt *CS = dyn_cast<CompoundStmt>(*I);
if (CS && CS->isStmtList())
SerializeStmtList(Stmts, CS);
else
Stmts.push_back(*I);
}
ASTCtx.Deallocate(SL);
}
示例12: extractFromDeclStmt
NamedDecl* RedundantLocalVariableRule::extractFromDeclStmt(Stmt *stmt) {
CompoundStmt *compoundStmt = dyn_cast<CompoundStmt>(stmt);
if (compoundStmt && compoundStmt->size() >= 2) {
Stmt *lastSecondStmt = (Stmt *)*(compoundStmt->body_end() - 2);
DeclStmt *declStmt = dyn_cast<DeclStmt>(lastSecondStmt);
if (declStmt && declStmt->isSingleDecl()) {
return dyn_cast<NamedDecl>(declStmt->getSingleDecl());
}
}
return NULL;
}
示例13: WCRs
////////////////////////////////////////////////////////////////////////////
/// Printing functions for debugging
////////////////////////////////////////////////////////////////////////////
void TransformWCR::printWCRs() {
OS << "All WCRs(" << WCRs.size() << ") = { ";
for (WCRSetTy::iterator I = WCRs.begin(), E = WCRs.end(); I != E; ++I) {
if (I != WCRs.begin()) OS << ", ";
CompoundStmt *WCR = *I;
OS << "W" << WCR->getWCRID();
if (isLandPad(WCR)) OS << "(LP)";
}
OS << " }\n";
OS.flush();
}
示例14: applyDecl
void applyDecl(Decl *decl)
{
if (decl->hasBody() &&
!isCppMethodDeclLocatedInCppRecordDecl(dyn_cast<CXXMethodDecl>(decl)))
{
CompoundStmt *compoundStmt = dyn_cast<CompoundStmt>(decl->getBody());
int length = getLineCount(compoundStmt->getSourceRange(), _carrier->getSourceManager());
int threshold = RuleConfiguration::intForKey("LONG_METHOD", 50);
if (length > threshold)
{
string description = "Method with " +
toString<int>(length) + " lines exceeds limit of " + toString<int>(threshold);
addViolation(decl, this, description);
}
}
}
示例15: TraverseStmt
bool RNFStatementVisitor::VisitStmtExpr(StmtExpr *SE)
{
CompoundStmt *CS = SE->getSubStmt();
if (ConsumerInstance->CallExprQueue.empty()) {
TraverseStmt(CS);
return false;
}
CallExpr *CallE = ConsumerInstance->CallExprQueue.back();
CurrentStmt = CallE;
for (clang::CompoundStmt::body_iterator I = CS->body_begin(),
E = CS->body_end(); I != E; ++I) {
TraverseStmt(*I);
}
return false;
}