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


C++ StmtResult类代码示例

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


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

示例1: assert

StmtResult Parser::HandlePragmaCaptured()
{
  assert(Tok.is(tok::annot_pragma_captured));
  ConsumeToken();

  if (Tok.isNot(tok::l_brace)) {
    PP.Diag(Tok, diag::err_expected_lbrace);
    return StmtError();
  }

  SourceLocation Loc = Tok.getLocation();

  ParseScope CapturedRegionScope(this, Scope::FnScope | Scope::DeclScope);
  Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_Default);

  StmtResult R = ParseCompoundStatement();
  CapturedRegionScope.Exit();

  if (R.isInvalid()) {
    Actions.ActOnCapturedRegionError();
    return StmtError();
  }

  return Actions.ActOnCapturedRegionEnd(R.get());
}
开发者ID:Hoernchen,项目名称:clang,代码行数:25,代码来源:ParsePragma.cpp

示例2: main

int main(int argc, char **argv)
{
    static const char *src =
        "a = 3\n"
        "b = 4\n"
        "c = a + b\n";

    MemoryManager manager;
    Lexer lexer(src);
    Parser parser(manager, lexer);

    StmtResult result = parser.parseStatement();
    if (result.hasError()) {
        std::cout << result.error() << std::endl;
        return 1;
    }

    //FunctionTranslator xlator(static_cast<const Ast::FnDeclStmt &>(*result.value()));

    // Program program(manager);
    // VirtualMachine virtualMachine(program);
    // virtualMachine.run(View<const char *>(argv, argv + argc));

#ifdef SNW_OS_WIN32
    std::system("pause");
#endif
    return 0;
}
开发者ID:Sojourn,项目名称:snowda,代码行数:28,代码来源:snw.cpp

示例3: VisitCompoundStmt

    bool VisitCompoundStmt(CompoundStmt* CS) {
      for(CompoundStmt::body_iterator I = CS->body_begin(), E = CS->body_end();
          I != E; ++I) {
        if (!isa<BinaryOperator>(*I))
          continue;

        const BinaryOperator* BinOp = cast<BinaryOperator>(*I);
        if (isAutoCandidate(BinOp)) {
          ASTContext& C = m_Sema->getASTContext();
          VarDecl* VD 
            = cast<VarDecl>(cast<DeclRefExpr>(BinOp->getLHS())->getDecl());
          TypeSourceInfo* ResTSI = 0;
          TypeSourceInfo* TrivialTSI 
            = C.getTrivialTypeSourceInfo(VD->getType());
          Expr* RHS = BinOp->getRHS();
          m_Sema->DeduceAutoType(TrivialTSI, RHS, ResTSI);
          VD->setTypeSourceInfo(ResTSI);
          VD->setType(ResTSI->getType());
          VD->setInit(RHS);
          Sema::DeclGroupPtrTy VDPtrTy = m_Sema->ConvertDeclToDeclGroup(VD);
          // Transform the AST into a "sane" state. Replace the binary operator
          // with decl stmt, because the binop semantically is a decl with init.
          StmtResult DS = m_Sema->ActOnDeclStmt(VDPtrTy, BinOp->getLocStart(), 
                                                BinOp->getLocEnd());
          assert(!DS.isInvalid() && "Invalid DeclStmt.");
          *I = DS.take();
        }
      }
      return true; // returning false will abort the in-depth traversal.
    }
开发者ID:My-Source,项目名称:root,代码行数:30,代码来源:AutoSynthesizer.cpp

示例4: checkCoroutineContext

StmtResult Sema::ActOnCoreturnStmt(SourceLocation Loc, Expr *E) {
  auto *Context = checkCoroutineContext(*this, Loc, "co_return");
  StmtResult Res = StmtError();

  if (Context && !Res.isInvalid())
    Context->CoroutineStmts.push_back(Res.get());
  return Res;
}
开发者ID:RichardsonAlex,项目名称:clang-1,代码行数:8,代码来源:SemaCoroutine.cpp

示例5: StmtResult

C2::StmtResult C2Sema::ActOnIfStmt(SourceLocation ifLoc,
                                   Stmt* condition, StmtResult thenStmt,
                                   SourceLocation elseLoc, StmtResult elseStmt) {
#ifdef SEMA_DEBUG
    std::cerr << COL_SEMA"SEMA: if statement at ";
    ifLoc.dump(SourceMgr);
    std::cerr << ANSI_NORMAL"\n";
#endif
    return StmtResult(new IfStmt(ifLoc, condition, thenStmt.get(), elseLoc, elseStmt.get()));
}
开发者ID:8l,项目名称:c2compiler,代码行数:10,代码来源:C2Sema.cpp

示例6: makePromiseStmt

bool CoroutineStmtBuilder::makePromiseStmt() {
  // Form a declaration statement for the promise declaration, so that AST
  // visitors can more easily find it.
  StmtResult PromiseStmt =
      S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(Fn.CoroutinePromise), Loc, Loc);
  if (PromiseStmt.isInvalid())
    return false;

  this->Promise = PromiseStmt.get();
  return true;
}
开发者ID:bgabor666,项目名称:clang,代码行数:11,代码来源:SemaCoroutine.cpp

示例7: ParsePROGRAMStmt

/// ParseMainProgram - Parse the main program.
///
///   [R1101]:
///     main-program :=
///         [program-stmt]
///           [specification-part]
///           [execution-part]
///           [internal-subprogram-part]
///           end-program-stmt
bool Parser::ParseMainProgram(std::vector<StmtResult> &Body) {
  // If the PROGRAM statement didn't have an identifier, pretend like it did for
  // the time being.
  StmtResult ProgStmt;
  if (Tok.is(tok::kw_PROGRAM)) {
    ProgStmt = ParsePROGRAMStmt();
    Body.push_back(ProgStmt);
  }

  // If the PROGRAM statement has an identifier, pass it on to the main program
  // action.
  const IdentifierInfo *IDInfo = 0;
  SMLoc NameLoc;
  if (ProgStmt.isUsable()) {
    ProgramStmt *PS = ProgStmt.takeAs<ProgramStmt>();
    IDInfo = PS->getProgramName();
    NameLoc = PS->getNameLocation();
    // FIXME: Debugging
    dump(PS);
  }

  Actions.ActOnMainProgram(IDInfo, NameLoc);

  // FIXME: Check for the specific keywords and not just absence of END or
  //        ENDPROGRAM.
  ParseStatementLabel();
  if (Tok.isNot(tok::kw_END) && Tok.isNot(tok::kw_ENDPROGRAM))
    ParseSpecificationPart(Body);

  // FIXME: Check for the specific keywords and not just absence of END or
  //        ENDPROGRAM.
  ParseStatementLabel();
  if (Tok.isNot(tok::kw_END) && Tok.isNot(tok::kw_ENDPROGRAM))
    ParseExecutionPart(Body);

  // FIXME: Debugging support.
  dump(Body);

  ParseStatementLabel();
  StmtResult EndProgStmt = ParseEND_PROGRAMStmt();
  Body.push_back(EndProgStmt);

  IDInfo = 0;
  NameLoc = SMLoc();

  if (EndProgStmt.isUsable()) {
    EndProgramStmt *EPS = EndProgStmt.takeAs<EndProgramStmt>();
    IDInfo = EPS->getProgramName();
    NameLoc = EPS->getNameLocation();
  }

  Actions.ActOnEndMainProgram(IDInfo, NameLoc);
  return EndProgStmt.isInvalid();
}
开发者ID:isanbard,项目名称:flang,代码行数:63,代码来源:Parser.cpp

示例8: ParseStatementLabel

/// ParseExecutableConstruct - Parse the executable construct.
///
///   [R213]:
///     executable-construct :=
///         action-stmt
///      or associate-construct
///      or block-construct
///      or case-construct
///      or critical-construct
///      or do-construct
///      or forall-construct
///      or if-construct
///      or select-type-construct
///      or where-construct
StmtResult Parser::ParseExecutableConstruct() {
  ParseStatementLabel();
  ParseConstructNameLabel();
  LookForExecutableStmtKeyword(StmtLabel || StmtConstructName.isUsable()?
                               false : true);

  auto Loc = Tok.getLocation();
  StmtResult SR = ParseActionStmt();
  CheckStmtOrder(Loc, SR);
  if (SR.isInvalid()) return StmtError();
  if (!SR.isUsable()) return StmtResult();

  return SR;
}
开发者ID:carlobertolli,项目名称:flang,代码行数:28,代码来源:ParseExec.cpp

示例9: assert

bool CoroutineStmtBuilder::makeOnFallthrough() {
  assert(!IsPromiseDependentType &&
         "cannot make statement while the promise type is dependent");

  // [dcl.fct.def.coroutine]/4
  // The unqualified-ids 'return_void' and 'return_value' are looked up in
  // the scope of class P. If both are found, the program is ill-formed.
  bool HasRVoid, HasRValue;
  LookupResult LRVoid =
      lookupMember(S, "return_void", PromiseRecordDecl, Loc, HasRVoid);
  LookupResult LRValue =
      lookupMember(S, "return_value", PromiseRecordDecl, Loc, HasRValue);

  StmtResult Fallthrough;
  if (HasRVoid && HasRValue) {
    // FIXME Improve this diagnostic
    S.Diag(FD.getLocation(),
           diag::err_coroutine_promise_incompatible_return_functions)
        << PromiseRecordDecl;
    S.Diag(LRVoid.getRepresentativeDecl()->getLocation(),
           diag::note_member_first_declared_here)
        << LRVoid.getLookupName();
    S.Diag(LRValue.getRepresentativeDecl()->getLocation(),
           diag::note_member_first_declared_here)
        << LRValue.getLookupName();
    return false;
  } else if (!HasRVoid && !HasRValue) {
    // FIXME: The PDTS currently specifies this case as UB, not ill-formed.
    // However we still diagnose this as an error since until the PDTS is fixed.
    S.Diag(FD.getLocation(),
           diag::err_coroutine_promise_requires_return_function)
        << PromiseRecordDecl;
    S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here)
        << PromiseRecordDecl;
    return false;
  } else if (HasRVoid) {
    // If the unqualified-id return_void is found, flowing off the end of a
    // coroutine is equivalent to a co_return with no operand. Otherwise,
    // flowing off the end of a coroutine results in undefined behavior.
    Fallthrough = S.BuildCoreturnStmt(FD.getLocation(), nullptr,
                                      /*IsImplicit*/false);
    Fallthrough = S.ActOnFinishFullStmt(Fallthrough.get());
    if (Fallthrough.isInvalid())
      return false;
  }

  this->OnFallthrough = Fallthrough.get();
  return true;
}
开发者ID:bgabor666,项目名称:clang,代码行数:49,代码来源:SemaCoroutine.cpp

示例10: while

/// ParseExecutionPart - Parse the execution part.
///
///   [R208]:
///     execution-part :=
///         executable-construct
///           [ execution-part-construct ] ...
bool Parser::ParseExecutionPart(std::vector<StmtResult> &Body) {
  bool HadError = false;
  while (true) {
    StmtResult SR = ParseExecutableConstruct();
    if (SR.isInvalid()) {
      LexToEndOfStatement();
      HadError = true;
    } else if (!SR.isUsable()) {
      break;
    }
    Body.push_back(SR);
  }

  return HadError;
}
开发者ID:isanbard,项目名称:flang,代码行数:21,代码来源:Parser.cpp

示例11: CheckStmtOrder

void Parser::CheckStmtOrder(SourceLocation Loc, StmtResult SR) {
  auto S = SR.get();
  if(SR.isUsable()) {
    if(Actions.InsideWhereConstruct(S))
      Actions.CheckValidWhereStmtPart(S);
  }

  if(PrevStmtWasSelectCase) {
    PrevStmtWasSelectCase = false;
    if(SR.isUsable() && (isa<SelectionCase>(S) ||
       (isa<ConstructPartStmt>(S) &&
        cast<ConstructPartStmt>(S)->getConstructStmtClass() == ConstructPartStmt::EndSelectStmtClass)))
      return;
    Diag.Report(SR.isUsable()? S->getLocation() : Loc,
                diag::err_expected_case_or_end_select);
  }
  if(SR.isUsable() && isa<SelectCaseStmt>(S))
    PrevStmtWasSelectCase = true;
}
开发者ID:carlobertolli,项目名称:flang,代码行数:19,代码来源:ParseExec.cpp

示例12: Fix

 void Fix(CompoundStmt* CS) {
   if (!CS->size())
     return;
   typedef llvm::SmallVector<Stmt*, 32> Statements;
   Statements Stmts;
   Stmts.append(CS->body_begin(), CS->body_end());
   for (Statements::iterator I = Stmts.begin(); I != Stmts.end(); ++I) {
     if (!TraverseStmt(*I) && !m_HandledDecls.count(m_FoundDRE->getDecl())) {
       Sema::DeclGroupPtrTy VDPtrTy 
         = m_Sema->ConvertDeclToDeclGroup(m_FoundDRE->getDecl());
       StmtResult DS = m_Sema->ActOnDeclStmt(VDPtrTy, 
                                             m_FoundDRE->getLocStart(), 
                                             m_FoundDRE->getLocEnd());
       assert(!DS.isInvalid() && "Invalid DeclStmt.");
       I = Stmts.insert(I, DS.take());
       m_HandledDecls.insert(m_FoundDRE->getDecl());
     }
   }
   CS->setStmts(m_Sema->getASTContext(), Stmts.data(), Stmts.size());
 }
开发者ID:aamedina,项目名称:cling,代码行数:20,代码来源:AutoSynthesizer.cpp

示例13: castForMoving

bool CoroutineStmtBuilder::makeParamMoves() {
  for (auto *paramDecl : FD.parameters()) {
    auto Ty = paramDecl->getType();
    if (Ty->isDependentType())
      continue;

    // No need to copy scalars, llvm will take care of them.
    if (Ty->getAsCXXRecordDecl()) {
      if (!paramDecl->getIdentifier())
        continue;

      ExprResult ParamRef =
          S.BuildDeclRefExpr(paramDecl, paramDecl->getType(),
                             ExprValueKind::VK_LValue, Loc); // FIXME: scope?
      if (ParamRef.isInvalid())
        return false;

      Expr *RCast = castForMoving(S, ParamRef.get());

      auto D = buildVarDecl(S, Loc, Ty, paramDecl->getIdentifier()->getName());

      S.AddInitializerToDecl(D, RCast, /*DirectInit=*/true);

      // Convert decl to a statement.
      StmtResult Stmt = S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(D), Loc, Loc);
      if (Stmt.isInvalid())
        return false;

      ParamMovesVector.push_back(Stmt.get());
    }
  }

  // Convert to ArrayRef in CtorArgs structure that builder inherits from.
  ParamMoves = ParamMovesVector;
  return true;
}
开发者ID:bgabor666,项目名称:clang,代码行数:36,代码来源:SemaCoroutine.cpp

示例14: actOnCoroutineBodyStart

static bool actOnCoroutineBodyStart(Sema &S, Scope *SC, SourceLocation KWLoc,
                                    StringRef Keyword) {
  if (!checkCoroutineContext(S, KWLoc, Keyword))
    return false;
  auto *ScopeInfo = S.getCurFunction();
  assert(ScopeInfo->CoroutinePromise);

  // If we have existing coroutine statements then we have already built
  // the initial and final suspend points.
  if (!ScopeInfo->NeedsCoroutineSuspends)
    return true;

  ScopeInfo->setNeedsCoroutineSuspends(false);

  auto *Fn = cast<FunctionDecl>(S.CurContext);
  SourceLocation Loc = Fn->getLocation();
  // Build the initial suspend point
  auto buildSuspends = [&](StringRef Name) mutable -> StmtResult {
    ExprResult Suspend =
        buildPromiseCall(S, ScopeInfo->CoroutinePromise, Loc, Name, None);
    if (Suspend.isInvalid())
      return StmtError();
    Suspend = buildOperatorCoawaitCall(S, SC, Loc, Suspend.get());
    if (Suspend.isInvalid())
      return StmtError();
    Suspend = S.BuildResolvedCoawaitExpr(Loc, Suspend.get(),
                                         /*IsImplicit*/ true);
    Suspend = S.ActOnFinishFullExpr(Suspend.get());
    if (Suspend.isInvalid()) {
      S.Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required)
          << ((Name == "initial_suspend") ? 0 : 1);
      S.Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword;
      return StmtError();
    }
    return cast<Stmt>(Suspend.get());
  };

  StmtResult InitSuspend = buildSuspends("initial_suspend");
  if (InitSuspend.isInvalid())
    return true;

  StmtResult FinalSuspend = buildSuspends("final_suspend");
  if (FinalSuspend.isInvalid())
    return true;

  ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());

  return true;
}
开发者ID:bgabor666,项目名称:clang,代码行数:49,代码来源:SemaCoroutine.cpp

示例15: StmtResult

/// ParseSAVEStmt - Parse the SAVE statement.
///
///   [R543]:
///     save-stmt :=
///         SAVE [ [::] saved-entity-list ]
Parser::StmtResult Parser::ParseSAVEStmt() {
  // Check if this is an assignment.
  if (IsNextToken(tok::equal))
    return StmtResult();

  auto Loc = ConsumeToken();
  if(Tok.isAtStartOfStatement())
    return Actions.ActOnSAVE(Context, Loc, StmtLabel);

  bool IsSaveStmt = ConsumeIfPresent(tok::coloncolon);
  SmallVector<Stmt *,8> StmtList;
  bool ListParsedOk = true;

  auto IDLoc = Tok.getLocation();
  auto II = Tok.getIdentifierInfo();
  StmtResult Stmt;
  if(ConsumeIfPresent(tok::slash)) {
    IDLoc = Tok.getLocation();
    II = Tok.getIdentifierInfo();
    if(ExpectAndConsume(tok::identifier)) {
      if(!ExpectAndConsume(tok::slash))
        ListParsedOk = false;
      Stmt = Actions.ActOnSAVECommonBlock(Context, Loc, IDLoc, II);
    }
    else ListParsedOk = false;
  }
  else if(ExpectAndConsume(tok::identifier)) {
    if(!IsSaveStmt && Features.FixedForm && (IsPresent(tok::equal) || IsPresent(tok::l_paren)))
      return ReparseAmbiguousAssignmentStatement();
    Stmt = Actions.ActOnSAVE(Context, Loc, IDLoc, II, nullptr);
  } else ListParsedOk = false;

  if(Stmt.isUsable())
    StmtList.push_back(Stmt.get());
  if(ListParsedOk) {
    while(ConsumeIfPresent(tok::comma)) {
      IDLoc = Tok.getLocation();
      II = Tok.getIdentifierInfo();
      if(ConsumeIfPresent(tok::slash)) {
        IDLoc = Tok.getLocation();
        II = Tok.getIdentifierInfo();
        if(!ExpectAndConsume(tok::identifier)) {
          ListParsedOk = false;
          break;
        }
        if(!ExpectAndConsume(tok::slash)) {
          ListParsedOk = false;
          break;
        }
        Stmt = Actions.ActOnSAVECommonBlock(Context, Loc, IDLoc, II);
      }
      else if(ExpectAndConsume(tok::identifier))
        Stmt = Actions.ActOnSAVE(Context, Loc, IDLoc, II, nullptr);
      else {
        ListParsedOk = false;
        break;
      }

      if(Stmt.isUsable())
        StmtList.push_back(Stmt.get());
    }
  }

  if(ListParsedOk) ExpectStatementEnd();
  else SkipUntilNextStatement();

  return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel);
}
开发者ID:carlobertolli,项目名称:flang,代码行数:73,代码来源:ParseSpecStmt.cpp


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