当前位置: 首页>>代码示例>>C++>>正文


C++ Sema::getDiagnostics方法代码示例

本文整理汇总了C++中Sema::getDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C++ Sema::getDiagnostics方法的具体用法?C++ Sema::getDiagnostics怎么用?C++ Sema::getDiagnostics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sema的用法示例。


在下文中一共展示了Sema::getDiagnostics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
 }
开发者ID:agheorghiu,项目名称:root,代码行数:25,代码来源:NullDerefProtectionTransformer.cpp

示例2: CheckFallThroughForBody

/// CheckFallThroughForFunctionDef - Check that we don't fall off the end of a
/// function that should return a value.  Check that we don't fall off the end
/// of a noreturn function.  We assume that functions and blocks not marked
/// noreturn will return.
static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
                                    QualType BlockTy,
                                    const CheckFallThroughDiagnostics& CD,
                                    AnalysisContext &AC) {

    bool ReturnsVoid = false;
    bool HasNoReturn = false;

    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
        ReturnsVoid = FD->getResultType()->isVoidType();
        HasNoReturn = FD->hasAttr<NoReturnAttr>() ||
                      FD->getType()->getAs<FunctionType>()->getNoReturnAttr();
    }
    else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
        ReturnsVoid = MD->getResultType()->isVoidType();
        HasNoReturn = MD->hasAttr<NoReturnAttr>();
    }
    else if (isa<BlockDecl>(D)) {
        if (const FunctionType *FT =
                    BlockTy->getPointeeType()->getAs<FunctionType>()) {
            if (FT->getResultType()->isVoidType())
                ReturnsVoid = true;
            if (FT->getNoReturnAttr())
                HasNoReturn = true;
        }
    }

    Diagnostic &Diags = S.getDiagnostics();

    // Short circuit for compilation speed.
    if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))
        return;

    // FIXME: Function try block
    if (const CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body)) {
        switch (CheckFallThrough(AC)) {
        case UnknownFallThrough:
            break;

        case MaybeFallThrough:
            if (HasNoReturn)
                S.Diag(Compound->getRBracLoc(),
                       CD.diag_MaybeFallThrough_HasNoReturn);
            else if (!ReturnsVoid)
                S.Diag(Compound->getRBracLoc(),
                       CD.diag_MaybeFallThrough_ReturnsNonVoid);
            break;
        case AlwaysFallThrough:
            if (HasNoReturn)
                S.Diag(Compound->getRBracLoc(),
                       CD.diag_AlwaysFallThrough_HasNoReturn);
            else if (!ReturnsVoid)
                S.Diag(Compound->getRBracLoc(),
                       CD.diag_AlwaysFallThrough_ReturnsNonVoid);
            break;
        case NeverFallThroughOrReturn:
            if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn)
                S.Diag(Compound->getLBracLoc(),
                       CD.diag_NeverFallThroughOrReturn);
            break;
        case NeverFallThrough:
            break;
        }
    }
}
开发者ID:,项目名称:,代码行数:69,代码来源:


注:本文中的Sema::getDiagnostics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。