diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2017-09-08 09:15:03 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2017-09-08 09:15:03 +0200 |
commit | d5c0c7b3b2825fb5d9d889b2161239e997b2ef3f (patch) | |
tree | bfc7c5678a0d26b48f00e0730ab4097a33989840 | |
parent | d598fbecbf973ef20f201ed06beff0454c17ad1d (diff) | |
download | glibmm-d5c0c7b3b2825fb5d9d889b2161239e997b2ef3f.tar.gz |
gmmproc: Write default values of properties to generated documentation
Bug 785895
-rw-r--r-- | tools/pm/DocsParser.pm | 14 | ||||
-rw-r--r-- | tools/pm/Output.pm | 28 | ||||
-rw-r--r-- | 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 90b7859a..25dba9ea 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 0afd2a8a..f1d717e3 100644 --- a/tools/pm/Output.pm +++ b/tools/pm/Output.pm @@ -853,22 +853,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"; } @@ -916,6 +916,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 265a3f70..a5fc6184 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) = @_; |