c2c/Parser/Parser.cpp
// ParseCondition - A condition is used inside If/While/Switch statemnts
//   and can be either a VarDecl (wrapped in DeclStmt) or an Expr
//   returns false on error. See clang ParseCXXCondition()
A condition is used inside If/While/Switch statemnts
and can be either a VarDecl (wrapped in DeclStmt) or an Expr
returns false on error.
A condition is used inside If / While / Switch statemnts and can be either a VarDecl ( wrapped in DeclStmt ) or an Expr returns false on error .
bool Parser::ParseCondition(C2::StmtResult& Res) {
    LOG_FUNC
    if (ExpectAndConsume(tok::l_paren)) return false;
    bool isDecl = isDeclaration();
    if (isDecl) {
        Res = ParseDeclaration(false, false);
        if (Res.isInvalid()) return false;
        assert(dyncast<DeclStmt>(Res.get()) && "expect DeclStmt");
        DeclStmt* DS = cast<DeclStmt>(Res.get());
        VarDecl* VD = DS->getDecl();
        if (!VD->getInitValue()) {
            Diag(Tok, diag::err_expected_init_in_condition);
            return false;
        }
    } else {
        ExprResult CondExp = ParseExpression();
        Res = StmtResult(CondExp.get());
        if (Res.isInvalid()) return false;
    }
    if (ExpectAndConsume(tok::r_paren)) return false;
    return true;
}
bool Parser :: ParseCondition ( C2 :: StmtResult & Res ) { LOG_FUNC if ( ExpectAndConsume ( tok :: l_paren ) ) return false ; bool isDecl = isDeclaration ( ) ; if ( isDecl ) { Res = ParseDeclaration ( false , false ) ; if ( Res . isInvalid ( ) ) return false ; assert ( dyncast < DeclStmt > ( Res . get ( ) ) && " " ) ; DeclStmt * DS = cast < DeclStmt > ( Res . get ( ) ) ; VarDecl * VD = DS -> getDecl ( ) ; if ( ! VD -> getInitValue ( ) ) { Diag ( Tok , diag :: err_expected_init_in_condition ) ; return false ; } } else { ExprResult CondExp = ParseExpression ( ) ; Res = StmtResult ( CondExp . get ( ) ) ; if ( Res . isInvalid ( ) ) return false ; } if ( ExpectAndConsume ( tok :: r_paren ) ) return false ; return true ; }
ParseCondition - A condition is used inside If/While/Switch statemnts
and can be either a VarDecl (wrapped in DeclStmt) or an Expr
returns false on error.
ParseCondition - A condition is used inside If / While / Switch statemnts and can be either a VarDecl ( wrapped in DeclStmt ) or an Expr returns false on error .
// must have initializer