On 06/27/2013 02:36 PM, Iyer, Balaji V wrote:
I looked through the patch again. I was able to get rid of the first if-statement in cp_parser_postfix_open_square_expression function. I think now it looks exactly as you requested.
Much better, thanks.
+ /* Sometimes, it type-casts certain functions to void. Unwrap it. */ + if (VOID_TYPE_P (TREE_TYPE (t)) && TREE_CODE (t) == CONVERT_EXPR) + t = TREE_OPERAND (t, 0);
If something is typecast to void, we shouldn't need to keep it in a temporary; we should be able to just pass it directly to finish_expr_stmt and then replace other occurrences with void_zero_node. When are you encountering this?
+ if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == POINTER_TYPE) + { + error_at (loc, "start-index and length fields necessary for " + "using array notation in pointers or records"); + return error_mark_node; + }
I'd turn this around and for anything that isn't an array, say that the [:] notation can only be used with arrays. In particular it almost never makes sense to check for RECORD_TYPE specifically.
if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == POINTER_TYPE) TREE_TYPE (array_ntn_expr) = TREE_TYPE (type); else TREE_TYPE (array_ntn_expr) = type;
So the type of an ARRAY_NOTATION_EXPR where the "array" is a class object is that same class? That seems wrong.
+ bool saved_colon_corrects = parser->colon_corrects_to_scope_p;
Let's declare this just before you change parser->colon_corrects_to_scope_p.
+ if (!*init_index || *init_index == error_mark_node) + cp_parser_skip_to_end_of_statement (parser); + length_index = cp_parser_expression (parser, false, NULL);
It doesn't make sense to skip to the end of the statement and then try to keep parsing the stuff you just skipped over.
+ bool saved_colon_corrects = parser->colon_corrects_to_scope_p; + parser->colon_corrects_to_scope_p = false; + if (flag_enable_cilkplus + && cp_lexer_peek_token (parser->lexer)->type == CPP_COLON) + { + error_at (cp_lexer_peek_token (parser->lexer)->location, + "braced list index is not allowed with array " + "notation"); + cp_parser_skip_to_end_of_statement (parser); + return error_mark_node; + } + parser->colon_corrects_to_scope_p = saved_colon_corrects;
You don't need to mess with colon_corrects_to_scope_p here; it doesn't affect the peek.
Jason