c2c/Parser/Parser.cpp
/// ParseParenExpression - This parses the unit that starts with a '(' token,
/// based on what is allowed by ExprType.  The actual thing parsed is returned
/// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
/// not the parsed cast-expression.
///
/// \verbatim
///       primary-expression: [C99 6.5.1]
///         '(' expression ')'
/// [GNU]   '(' compound-statement ')'      (if !ParenExprOnly)
///       postfix-expression: [C99 6.5.2]
///         '(' type-name ')' '{' initializer-list '}'
///         '(' type-name ')' '{' initializer-list ',' '}'
///       cast-expression: [C99 6.5.4]
///         '(' type-name ')' cast-expression
/// \endverbatim
This parses the unit that starts with a '(' token,
based on what is allowed by ExprType.  The actual thing parsed is returned
in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
not the parsed cast-expression.


This parses the unit that starts with a ' ( ' token based on what is allowed by ExprType . The actual thing parsed is returned in ExprType . If stopIfCastExpr is true it will only return the parsed type not the parsed cast - expression .
C2::ExprResult
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
                               bool isTypeCast, SourceLocation &RParenLoc)
{
    LOG_FUNC
    assert(Tok.is(tok::l_paren) && "Not a paren expr!");
    SourceLocation OpenLoc = ConsumeToken();
#if 1
    ExprType = SimpleExpr; 
    ExprResult Result = ParseExpression();
    if (Result.isInvalid()) {
        SkipUntil(tok::r_paren);
        return ExprError();
    }
    if (Tok.is(tok::r_paren)) {
        Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get());
    }
    RParenLoc = Tok.getLocation();
    ExpectAndConsume(tok::r_paren);
#else
    ExprResult Result(true);
    if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
        TODO;
#if 0
        Diag(Tok, diag::ext_gnu_statement_expr);
        Actions.ActOnStartStmtExpr();
        StmtResult Stmt(ParseCompoundStatement(true));
        ExprType = CompoundStmt;
        if (!Stmt.isInvalid()) {
            Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.take(), Tok.getLocation());
        } else {
            Actions.ActOnStmtExprError();
        }
#endif
    } else if (ExprType >= CompoundLiteral && isDeclaration()) {
        ExprResult type = ParseTypeSpecifier(true);
        if (type.isInvalid()) return ExprError();
        RParenLoc = Tok.getLocation();
        if (ExpectAndConsume(tok::r_paren)) return ExprError();
        if (Tok.is(tok::l_brace)) {
            TODO;
        }
        if (ExprType == CastExpr) {
            if (stopIfCastExpr) {
                TODO;
            }
            Result = ParseCastExpression(false,
                     false,
                     IsTypeCast);
            return Result;
        }
        Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
        return ExprError();
    } else if (isTypeCast) {
        TODO;
    } else {
        Result = ParseExpression();
        ExprType = SimpleExpr;
        if (!Result.isInvalid() && Tok.is(tok::r_paren)) {
            Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get());
        }
    }
    if (Result.isInvalid()) {
        SkipUntil(tok::r_paren);
        return ExprError();
    }
    RParenLoc = Tok.getLocation();
    ExpectAndConsume(tok::r_paren);
#endif
    return Result;
}
C2 :: ExprResult Parser :: ParseParenExpression ( ParenParseOption & ExprType , bool stopIfCastExpr , bool isTypeCast , SourceLocation & RParenLoc ) { LOG_FUNC assert ( Tok . is ( tok :: l_paren ) && " " ) ; SourceLocation OpenLoc = ConsumeToken ( ) ; #if 1 ExprType = SimpleExpr ; ExprResult Result = ParseExpression ( ) ; if ( Result . isInvalid ( ) ) { SkipUntil ( tok :: r_paren ) ; return ExprError ( ) ; } if ( Tok . is ( tok :: r_paren ) ) { Result = Actions . ActOnParenExpr ( OpenLoc , Tok . getLocation ( ) , Result . get ( ) ) ; } RParenLoc = Tok . getLocation ( ) ; ExpectAndConsume ( tok :: r_paren ) ; #else ExprResult Result ( true ) ; if ( ExprType >= CompoundStmt && Tok . is ( tok :: l_brace ) ) { TODO ; #if 0 Diag ( Tok , diag :: ext_gnu_statement_expr ) ; Actions . ActOnStartStmtExpr ( ) ; StmtResult Stmt ( ParseCompoundStatement ( true ) ) ; ExprType = CompoundStmt ; if ( ! Stmt . isInvalid ( ) ) { Result = Actions . ActOnStmtExpr ( OpenLoc , Stmt . take ( ) , Tok . getLocation ( ) ) ; } else { Actions . ActOnStmtExprError ( ) ; } #endif } else if ( ExprType >= CompoundLiteral && isDeclaration ( ) ) { ExprResult type = ParseTypeSpecifier ( true ) ; if ( type . isInvalid ( ) ) return ExprError ( ) ; RParenLoc = Tok . getLocation ( ) ; if ( ExpectAndConsume ( tok :: r_paren ) ) return ExprError ( ) ; if ( Tok . is ( tok :: l_brace ) ) { TODO ; } if ( ExprType == CastExpr ) { if ( stopIfCastExpr ) { TODO ; } Result = ParseCastExpression ( false , false , IsTypeCast ) ; return Result ; } Diag ( Tok , diag :: err_expected_lbrace_in_compound_literal ) ; return ExprError ( ) ; } else if ( isTypeCast ) { TODO ; } else { Result = ParseExpression ( ) ; ExprType = SimpleExpr ; if ( ! Result . isInvalid ( ) && Tok . is ( tok :: r_paren ) ) { Result = Actions . ActOnParenExpr ( OpenLoc , Tok . getLocation ( ) , Result . get ( ) ) ; } } if ( Result . isInvalid ( ) ) { SkipUntil ( tok :: r_paren ) ; return ExprError ( ) ; } RParenLoc = Tok . getLocation ( ) ; ExpectAndConsume ( tok :: r_paren ) ; #endif return Result ; }
ParseParenExpression - This parses the unit that starts with a '(' token,
based on what is allowed by ExprType.
ParseParenExpression - This parses the unit that starts with a ' ( ' token based on what is allowed by ExprType .
// TODO remove type (not needed in C2) // Match the ')'. // NOTE: this is the Clang C parsing, where () can also be casts etc // None of these cases should fall through with an invalid Result // unless they've already reported an error. // If the substmt parsed correctly, build the AST node. // TODO remove this. C-style casts // Otherwise, this is a compound literal expression or cast expression. // We parsed '(' type-name ')' and the thing after it wasn't a '{'. // Parse the cast-expression that follows it next. // TODO: For cast expression with CastTy. /*isUnaryExpression=*/ /*isAddressOfOperand=*/ /*isTypeCast=*/ // Match the ')'.