[glibmm] gmmproc: Write default values of properties to generated documentation



commit dd4f4f513c7785f14d6ce91120b8d5a0b9556540
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Sep 3 18:48:43 2017 +0200

    gmmproc: Write default values of properties to generated documentation
    
    Bug 785895

 tools/pm/DocsParser.pm |   14 ++++++++++++++
 tools/pm/Output.pm     |   28 ++++++++++++++++++++++++----
 tools/pm/Property.pm   |   10 +++++++++-
 3 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/tools/pm/DocsParser.pm b/tools/pm/DocsParser.pm
index aef3825..17e7cda 100644
--- a/tools/pm/DocsParser.pm
+++ b/tools/pm/DocsParser.pm
@@ -390,6 +390,20 @@ sub lookup_documentation($$$;$)
   return $text;
 }
 
+# void convert_value_to_cpp(\$text)
+# Converts e.g. a property's default value.
+sub convert_value_to_cpp($)
+{
+  my ($text) = @_;
+
+  $$text =~ s"\bFALSE\b"<tt>false</tt>"g;
+  $$text =~ s"\bTRUE\b"<tt>true</tt>"g;
+  $$text =~ s"\bNULL\b"<tt>nullptr</tt>"g;
+
+  # Enumerator names
+  $$text =~ s/\b([A-Z]+)_([A-Z\d_]+)\b/&DocsParser::substitute_enumerator_name($1, $2)/eg;
+}
+
 # void remove_example_code($obj_name, \$text)
 # Removes example code from the text of docs (passed by reference).
 sub remove_example_code($$)
diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm
index 62209e9..fa27743 100644
--- a/tools/pm/Output.pm
+++ b/tools/pm/Output.pm
@@ -876,22 +876,22 @@ sub output_wrap_any_property($$$$$$$$$$)
   my $proxy_suffix = "";
 
   # Read/Write:
-  if($objProperty->get_construct_only() eq 1)
+  if ($objProperty->get_construct_only())
   {
     # construct-only functions can be read, but not written.
     $proxy_suffix = "_ReadOnly";
 
-    if($objProperty->get_readable() ne 1)
+    if (!$objProperty->get_readable())
     {
       $self->output_wrap_failed($name, "attempt to wrap write-only and construct-only property.");
       return;
     }
   }
-  elsif($objProperty->get_readable() ne 1)
+  elsif (!$objProperty->get_readable())
   {
     $proxy_suffix = "_WriteOnly";
   }
-  elsif($objProperty->get_writable() ne 1)
+  elsif (!$objProperty->get_writable())
   {
     $proxy_suffix = "_ReadOnly";
   }
@@ -939,6 +939,26 @@ sub output_wrap_any_property($$$$$$$$$$)
     }
   }
 
+  # Default value, if available:
+  my $default_value = $objProperty->get_default_value();
+  if (defined($default_value))
+  {
+    DocsParser::convert_value_to_cpp(\$default_value);
+
+    # Add double quotes around a string value.
+    if ($objProperty->get_type() eq "GParamString")
+    {
+      $default_value = "\"" . $default_value . "\"";
+    }
+    $default_value = "Default value: $default_value";
+    add_m4_quotes(\$default_value);
+    if ($documentation ne "")
+    {
+      $documentation .= "\n   *\n   * ";
+    }
+    $documentation .= $default_value;
+  }
+
   #Declaration:
   if($deprecated ne "")
   {
diff --git a/tools/pm/Property.pm b/tools/pm/Property.pm
index 265a3f7..a5fc618 100644
--- a/tools/pm/Property.pm
+++ b/tools/pm/Property.pm
@@ -27,6 +27,7 @@ our @EXPORT_OK;
 #       bool writable;
 #       bool construct_only;
 #       bool deprecated; # optional
+#       string default_value; # optional
 #       string docs;
 #    }
 
@@ -48,10 +49,11 @@ sub new
   $$self{writable} = ($1 eq "#t")       if ($def =~ s/\(writable (\S+)\)//);
   $$self{construct_only} = ($1 eq "#t") if ($def =~ s/\(construct-only (\S+)\)//);
   $$self{deprecated} = ($1 eq "#t")     if ($def =~ s/\(deprecated (\S+)\)//);
+  $$self{default_value} = $1            if ($def =~ s/\(default-value "(.*?)"\)//);
   $$self{entity_type} = 'property';
 
   # Property documentation:
-  my $propertydocs = $1                     if ($def =~ s/\(docs "([^"]*)"\)//);
+  my $propertydocs = $1                 if ($def =~ s/\(docs "([^"]*)"\)//);
   # Add a full-stop if there is not one already:
   if(defined($propertydocs))
   {
@@ -118,6 +120,12 @@ sub get_deprecated($)
   return $$self{deprecated}; # undef, 0 or 1
 }
 
+sub get_default_value($)
+{
+  my ($self) = @_;
+  return $$self{default_value}; # undef or a string (possibly empty)
+}
+
 sub get_docs($$)
 {
   my ($self, $deprecation_docs, $newin) = @_;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]