Let me start by saying that I think the patch is generally ok, especially considering the advice that's already been given. That said...

+++ b/gcc/c/c-array-notation.c
@@ -0,0 +1,3121 @@

So, like, are we going to need to replicate 3000 lines to add array notation to c++ too? How much of this are we going to be able to share?

While I don't think we should make the array notation global, we might be able to share the code via c-family/. The Ideal way I think would be via c-gimplify, in which we don't expand the array notation until later. But even if delaying the expansion causes other problems that I havn't thought about, just placing the common expansion logic in the shared directory would be better.

+  for (ii = 0; ii < rank ; ii++)
+    {
+      /* This will create the if statement label.  */
+      if_stmt_label[ii] = build_decl (location, LABEL_DECL, NULL_TREE,
+                                     void_type_node);
+      DECL_CONTEXT (if_stmt_label[ii]) = current_function_decl;
+      DECL_ARTIFICIAL (if_stmt_label[ii]) = 0;
+      DECL_IGNORED_P (if_stmt_label[ii]) = 1;
+
+      /* This label statement will point to the loop body.  */
+      body_label[ii] = build_decl (location, LABEL_DECL, NULL_TREE,
+                                  void_type_node);
+      DECL_CONTEXT (body_label[ii]) = current_function_decl;
+      DECL_ARTIFICIAL (body_label[ii]) = 0;
+      DECL_IGNORED_P (body_label[ii]) = 1;
+      body_label_expr[ii] = build1 (LABEL_EXPR, void_type_node, body_label[ii])
;
+
+      /* This will create the exit label, i.e. where the while loop will branch
+        out of.  */
+      exit_label[ii] = build_decl (location, LABEL_DECL, NULL_TREE,
+                                  void_type_node);
+      DECL_CONTEXT (exit_label[ii]) = current_function_decl;
+      DECL_ARTIFICIAL (exit_label[ii]) = 0;
+      DECL_IGNORED_P (exit_label[ii]) = 1;
+      exit_label_expr[ii] = build1 (LABEL_EXPR, void_type_node, 
exit_label[ii]);
+    }

Is there any particular reason why you're open-coding the loop expansion instead of using existing infrastructure like c_finish_loop?

Yes, the specific example of c_finish_loop goes against the c++ sharing, but it's fairly easy to add new interfaces to c-common.h that are implemented in the two front ends.



r~

Reply via email to