optgen: make more sanity checks for enums.
authorMartin Liska <mliska@suse.cz>
Tue, 5 May 2020 14:13:46 +0000 (16:13 +0200)
committerMartin Liska <mliska@suse.cz>
Tue, 5 May 2020 14:13:46 +0000 (16:13 +0200)
* opt-functions.awk (opt_args_non_empty): New function.
* opt-read.awk: Use the function for various option arguments.

gcc/ChangeLog
gcc/opt-functions.awk
gcc/opt-read.awk

index cbdc5504cadbc58d419702db59682e7c0d0a9da2..5f18676d4cd8510b6f0385e867ed309bbb182bef 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-05  Martin Liska  <mliska@suse.cz>
+
+       * opt-functions.awk (opt_args_non_empty): New function.
+       * opt-read.awk: Use the function for various option arguments.
+
 2020-05-05  Martin Liska  <mliska@suse.cz>
 
        PR driver/94330
index 2f0442dc5633a0ca7e3e86c523f333d0ff847b66..b4952b893159f63a4eb0a24a92266db4b1dd8633 100644 (file)
@@ -72,6 +72,16 @@ function opt_args(name, flags)
        return flags
 }
 
+# If FLAGS contains a "NAME(...argument...)" flag, return the value
+# of the argument.  Print error message otherwise.
+function opt_args_non_empty(name, flags, description)
+{
+       args = opt_args(name, flags)
+       if (args == "")
+               print "#error Empty option argument '" name "' during parsing of: " flags
+       return args
+}
+
 # Return the Nth comma-separated element of S.  Return the empty string
 # if S does not contain N elements.
 function nth_arg(n, s)
index a2e16f29aff359f3d7f31d75e107c92fe832efa0..9bb9dfcf6caa7caeb68d513d0debf84e7c162d91 100644 (file)
@@ -81,8 +81,8 @@ BEGIN {
                }
                else if ($1 == "Enum") {
                        props = $2
-                       name = opt_args("Name", props)
-                       type = opt_args("Type", props)
+                       name = opt_args_non_empty("Name", props)
+                       type = opt_args_non_empty("Type", props)
                        unknown_error = opt_args("UnknownError", props)
                        enum_names[n_enums] = name
                        enum_type[name] = type
@@ -93,9 +93,9 @@ BEGIN {
                }
                else if ($1 == "EnumValue")  {
                        props = $2
-                       enum_name = opt_args("Enum", props)
-                       string = opt_args("String", props)
-                       value = opt_args("Value", props)
+                       enum_name = opt_args_non_empty("Enum", props)
+                       string = opt_args_non_empty("String", props)
+                       value = opt_args_non_empty("Value", props)
                        val_flags = "0"
                        val_flags = val_flags \
                          test_flag("Canonical", props, "| CL_ENUM_CANONICAL") \