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


C++ CompoundStmt::size方法代码示例

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


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

示例1: 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;
}
开发者ID:ghorvath,项目名称:oclint,代码行数:11,代码来源:RedundantLocalVariableRule.cpp

示例2: VisitForStmt

    bool VisitForStmt(ForStmt *parentStmt)
    {
        Stmt *bodyStmt = parentStmt->getBody();
        ForStmt *forStmt = dyn_cast_or_null<ForStmt>(bodyStmt);
        CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(bodyStmt);
        if (!forStmt && compoundStmt && compoundStmt->size() == 1)
        {
            forStmt = dyn_cast_or_null<ForStmt>(compoundStmt->body_back());
        }
        if (forStmt)
        {
            Stmt *initStmt = parentStmt->getInit();
            Expr *incExpr = forStmt->getInc();
            if (isInnerIncMatchingOuterInit(incExpr, initStmt))
            {
                addViolation(incExpr, this);
            }
        }

        return true;
    }
开发者ID:Abioy,项目名称:oclint,代码行数:21,代码来源:JumbledIncrementerRule.cpp

示例3: removeGotosToNextLabel

//--------------------------------------------------------- 
void removeGotosToNextLabel(StmtEditor& editor, Stmt* Node)
{
  RemoveGotosToNextLabel visitor(editor);
  visit_df(Node, visitor);
  for (RemoveGotosToNextLabel::tTouchedLabels::iterator i = visitor.m_TouchedLabels.begin(), 
       e = visitor.m_TouchedLabels.end(); i != e; ++i)
  {
    if (!i->second.m_Used)
    {
      LabelStmt* LS = i->second.LS;
      assert(LS);
      CompoundStmt* CS = dyn_cast<CompoundStmt>(editor.getParent(LS));
      if (CS && CS->size() > 1 && isa<NullStmt>(LS->getSubStmt()))
      {
        editor.removeStmt(CS, LS);
      }
      else
      {
        editor.replaceStatement(LS, LS->getSubStmt());
      }
    }
  }
}
开发者ID:kevinzhang334455,项目名称:Scout,代码行数:24,代码来源:Toolbox.cpp

示例4: expandOneUsedInitDeclsToUse

//--------------------------------------------------------- 
void expandOneUsedInitDeclsToUse(StmtEditor& editor, Stmt* Node)
{
  CountVarUses visitor(editor);
  CompileTimeComputedExprTester tester;
  visit_df(Node, visitor);
  for (CountVarUses::tVarRefCountMap::iterator i = visitor.m_VarUseCount.begin(), 
       e = visitor.m_VarUseCount.end(); i != e; ++i)
  {
    if (i->second.second < 2 || 
        (i->first->getInit() && tester.Visit(i->first->getInit())))
    {
      CompoundStmt* CS = dyn_cast<CompoundStmt>(editor.getParent(i->second.first));
      if (CS && CS->size() > 1)
      {
        if (i->second.second > 0)
        {
          visit_df(Node, ExpandVariableRefs(editor, i->first));
          i->first->setInit(0); // ownership was transferred, so don't confuse anyone after us
        }
        editor.removeStmt(CS, i->second.first);
      }
    }
  }
}
开发者ID:kevinzhang334455,项目名称:Scout,代码行数:25,代码来源:Toolbox.cpp

示例5: tryAttachVP

  bool ValuePrinterSynthesizer::tryAttachVP(FunctionDecl* FD) {
    // We have to be able to mark the expression for printout. There are
    // three scenarios:
    // 0: Expression printing disabled - don't do anything just exit.
    // 1: Expression printing enabled - print no matter what.
    // 2: Expression printing auto - analyze - rely on the omitted ';' to
    //    not produce the suppress marker.
    int indexOfLastExpr = -1;
    Expr* To = utils::Analyze::GetOrCreateLastExpr(FD, &indexOfLastExpr,
                                                   /*omitDS*/false,
                                                   m_Sema);
    if (To) {
      // Update the CompoundStmt body, avoiding alloc/dealloc of all the el.
      CompoundStmt* CS = cast<CompoundStmt>(FD->getBody());
      assert(CS && "Missing body?");

      switch (getCompilationOpts().ValuePrinting) {
      case CompilationOptions::VPDisabled:
        assert(0 && "Don't wait that long. Exit early!");
        break;
      case CompilationOptions::VPEnabled:
        break;
      case CompilationOptions::VPAuto: {
        // FIXME: Propagate the flag to the nested transactions also, they
        // must have the same CO as their parents.
        getCompilationOpts().ValuePrinting = CompilationOptions::VPEnabled;
        if ((int)CS->size() > indexOfLastExpr+1
            && (*(CS->body_begin() + indexOfLastExpr + 1))
            && isa<NullStmt>(*(CS->body_begin() + indexOfLastExpr + 1))) {
          // If next is NullStmt disable VP is disabled - exit. Signal this in
          // the CO of the transaction.
          getCompilationOpts().ValuePrinting = CompilationOptions::VPDisabled;
        }
        if (getCompilationOpts().ValuePrinting
            == CompilationOptions::VPDisabled)
          return true;
      }
        break;
      }

      // We can't PushDeclContext, because we don't have scope.
      Sema::ContextRAII pushedDC(*m_Sema, FD);

      if (To) {
        // Strip the parenthesis if any
        if (ParenExpr* PE = dyn_cast<ParenExpr>(To))
          To = PE->getSubExpr();

        Expr* Result = 0;
        // if (!m_Sema->getLangOpts().CPlusPlus)
        //   Result = SynthesizeVP(To);

        if (Result)
          *(CS->body_begin()+indexOfLastExpr) = Result;
      }
      // Clear the artificial NullStmt-s
      if (!ClearNullStmts(CS)) {
        // FIXME: Why it is here? Shouldn't it be in DeclExtractor?
        // if no body remove the wrapper
        DeclContext* DC = FD->getDeclContext();
        Scope* S = m_Sema->getScopeForContext(DC);
        if (S)
          S->RemoveDecl(FD);
        DC->removeDecl(FD);
      }
    }
    else // if nothing to attach to set the CO's ValuePrinting to disabled.
      getCompilationOpts().ValuePrinting = CompilationOptions::VPDisabled;
    return true;
  }
开发者ID:dan131riley,项目名称:root,代码行数:70,代码来源:ValuePrinterSynthesizer.cpp

示例6: ActOnLambdaExpr

ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, 
                                 Scope *CurScope, 
                                 llvm::Optional<unsigned> ManglingNumber,
                                 Decl *ContextDecl,
                                 bool IsInstantiation) {
  // Collect information from the lambda scope.
  llvm::SmallVector<LambdaExpr::Capture, 4> Captures;
  llvm::SmallVector<Expr *, 4> CaptureInits;
  LambdaCaptureDefault CaptureDefault;
  CXXRecordDecl *Class;
  CXXMethodDecl *CallOperator;
  SourceRange IntroducerRange;
  bool ExplicitParams;
  bool ExplicitResultType;
  bool LambdaExprNeedsCleanups;
  llvm::SmallVector<VarDecl *, 4> ArrayIndexVars;
  llvm::SmallVector<unsigned, 4> ArrayIndexStarts;
  {
    LambdaScopeInfo *LSI = getCurLambda();
    CallOperator = LSI->CallOperator;
    Class = LSI->Lambda;
    IntroducerRange = LSI->IntroducerRange;
    ExplicitParams = LSI->ExplicitParams;
    ExplicitResultType = !LSI->HasImplicitReturnType;
    LambdaExprNeedsCleanups = LSI->ExprNeedsCleanups;
    ArrayIndexVars.swap(LSI->ArrayIndexVars);
    ArrayIndexStarts.swap(LSI->ArrayIndexStarts);
    
    // Translate captures.
    for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I) {
      LambdaScopeInfo::Capture From = LSI->Captures[I];
      assert(!From.isBlockCapture() && "Cannot capture __block variables");
      bool IsImplicit = I >= LSI->NumExplicitCaptures;

      // Handle 'this' capture.
      if (From.isThisCapture()) {
        Captures.push_back(LambdaExpr::Capture(From.getLocation(),
                                               IsImplicit,
                                               LCK_This));
        CaptureInits.push_back(new (Context) CXXThisExpr(From.getLocation(),
                                                         getCurrentThisType(),
                                                         /*isImplicit=*/true));
        continue;
      }

      VarDecl *Var = From.getVariable();
      LambdaCaptureKind Kind = From.isCopyCapture()? LCK_ByCopy : LCK_ByRef;
      Captures.push_back(LambdaExpr::Capture(From.getLocation(), IsImplicit, 
                                             Kind, Var, From.getEllipsisLoc()));
      CaptureInits.push_back(From.getCopyExpr());
    }

    switch (LSI->ImpCaptureStyle) {
    case CapturingScopeInfo::ImpCap_None:
      CaptureDefault = LCD_None;
      break;

    case CapturingScopeInfo::ImpCap_LambdaByval:
      CaptureDefault = LCD_ByCopy;
      break;

    case CapturingScopeInfo::ImpCap_LambdaByref:
      CaptureDefault = LCD_ByRef;
      break;

    case CapturingScopeInfo::ImpCap_Block:
      llvm_unreachable("block capture in lambda");
      break;
    }

    // C++11 [expr.prim.lambda]p4:
    //   If a lambda-expression does not include a
    //   trailing-return-type, it is as if the trailing-return-type
    //   denotes the following type:
    // FIXME: Assumes current resolution to core issue 975.
    if (LSI->HasImplicitReturnType) {
      //   - if there are no return statements in the
      //     compound-statement, or all return statements return
      //     either an expression of type void or no expression or
      //     braced-init-list, the type void;
      if (LSI->ReturnType.isNull()) {
        LSI->ReturnType = Context.VoidTy;
      } else {
        // C++11 [expr.prim.lambda]p4:
        //   - if the compound-statement is of the form
        //
        //       { attribute-specifier-seq[opt] return expression ; }
        //
        //     the type of the returned expression after
        //     lvalue-to-rvalue conversion (4.1), array-to-pointer
        //     conver- sion (4.2), and function-to-pointer conversion
        //     (4.3);
        //
        // Since we're accepting the resolution to a post-C++11 core
        // issue with a non-trivial extension, provide a warning (by
        // default).
        CompoundStmt *CompoundBody = cast<CompoundStmt>(Body);
        if (!(CompoundBody->size() == 1 &&
              isa<ReturnStmt>(*CompoundBody->body_begin())) &&
            !Context.hasSameType(LSI->ReturnType, Context.VoidTy))
//.........这里部分代码省略.........
开发者ID:jckarter,项目名称:clang,代码行数:101,代码来源:SemaLambda.cpp


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