diff mbox

[RFC] Dejagnu patch to handle multi-line directives

Message ID d897d54e-5e05-b83b-973a-d1825fd8e76e@mentor.com
State New
Headers show

Commit Message

Tom de Vries June 10, 2017, 8:03 a.m. UTC
[ attached patch ]

On 06/10/2017 09:57 AM, Tom de Vries wrote:
> Hi,
> 
> one thing that has bothered me on a regular basis is the inability to 
> spread long dejagnu directives over multiple lines.
> 
> I've written a demonstrator patch (for the dejagnu sources) and tested 
> it by splitting this 108 chars line:
> ...
> /* { dg-additional-options "-DSTACK_SIZE=[dg-effective-target-value 
> stack_size]" { target { stack_size } } } */
> ...
> into:
> ...
> /* { dg-additional-options }
>     { dg-dc "-DSTACK_SIZE=[dg-effective-target-value stack_size]" }
>     { dg-dc { target { stack_size } } } */
> ...
> 
> Good idea to fix this?
> 
> Good idea to fix this like this?
> 
> If so, any other comments, before I suggest this at dejagnu project?
> 
> Thanks,
> - Tom
>

Comments

Segher Boessenkool June 11, 2017, 12:42 a.m. UTC | #1
Hi!
On Sat, Jun 10, 2017 at 10:03:04AM +0200, Tom de Vries wrote:
> >/* { dg-additional-options }
> >    { dg-dc "-DSTACK_SIZE=[dg-effective-target-value stack_size]" }
> >    { dg-dc { target { stack_size } } } */
> >...
> >
> >Good idea to fix this?

I like it.  What is the exact semantics though?  What directives does
this not work on?

>  proc dg-get-options { prog } {
>      set result ""
> -
> -    set tmp [grep $prog "{\[ \t\]\+dg-\[-a-z\]\+\[ \t\]\+.*\[ \t\]\+}" line]
> +    set cmd_prev ""
> +
> +    set grep_pattern [join {
> +	"{"
> +	"\[ \t\]\+"
> +	"dg-\[-a-z\]\+"
> +	"\[ \t\]\+"
> +	"(.*\[ \t\]\+)?"
> +	"}"
> +    } ""]
> +    set tmp [grep $prog $grep_pattern line]

If you use {} instead of "" you don't need all these backslashes.  If you
use expanded syntax (see "man tcl re_syntax") you can make it even more
readable (and you don't need the join) (but it is a short regexp anyway).
You might want to use \s instead of [ \t].


Segher
diff mbox

Patch

Add dg-dc support

---
 lib/dg.exp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/lib/dg.exp b/lib/dg.exp
index 7a894cb..67f46ab 100644
--- a/lib/dg.exp
+++ b/lib/dg.exp
@@ -181,15 +181,64 @@  proc dg-format-linenum { linenum } {
 # we return:
 #
 # { dg-prms-id 1 1234 } { dg-build 2 fatal "some comment" }
+#
+# Directive dg-dc (short for dg-directive-continue) can be used for multi-line
+# directives.  This:
+#
+# /* { dg-x a b c } */
+#
+# is equivalent to:
+#
+# /* { dg-x } */
+# /* { dg-dc a b } */
+# /* { dg-dc c } */
+#
+# and to:
+#
+# /* { dg-x a } */
+# /* { dg-dc b c} */
 
 proc dg-get-options { prog } {
     set result ""
-
-    set tmp [grep $prog "{\[ \t\]\+dg-\[-a-z\]\+\[ \t\]\+.*\[ \t\]\+}" line]
+    set cmd_prev ""
+
+    set grep_pattern [join {
+	"{"
+	"\[ \t\]\+"
+	"dg-\[-a-z\]\+"
+	"\[ \t\]\+"
+	"(.*\[ \t\]\+)?"
+	"}"
+    } ""]
+    set tmp [grep $prog $grep_pattern line]
     if {![string match "" $tmp]} {
+	set pattern [join {
+	    "(\[0-9\]+)"
+	    "\[ \t\]+"
+	    "{"
+	    "\[ \t\]+"
+	    "(dg-\[-a-z\]+)"
+	    "\[ \t\]+"
+	    "((.*)\[ \t\]+)?"
+	    "}"
+	    "\[^\}\]*"
+	    "(\n|$)"
+	} ""]
 	foreach i $tmp {
-	    regexp "(\[0-9\]+)\[ \t\]+{\[ \t\]+(dg-\[-a-z\]+)\[ \t\]+(.*)\[ \t\]+}\[^\}\]*(\n|$)" $i i line cmd args
-	    append result " { $cmd $line $args }"
+	    regexp $pattern $i dummy line cmd ws_args args
+	    if { "$cmd" == "dg-dc" } {
+		set args_prev "$args_prev $args"
+	    } else {
+		if { "$cmd_prev" != "" } {
+		    append result " { $cmd_prev $line_prev $args_prev }"
+		}
+		set cmd_prev $cmd
+		set line_prev $line
+		set args_prev "$args"
+	    }
+	}
+	if { "$cmd_prev" != "" } {
+	    append result " { $cmd_prev $line_prev $args_prev }"
 	}
     }
     return $result