diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2017-09-03 18:48:43 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2017-09-03 18:48:43 +0200 |
commit | dd4f4f513c7785f14d6ce91120b8d5a0b9556540 (patch) | |
tree | 8218f89d2161d76388f8b05dbbea8f6296be3d65 /tools/pm | |
parent | ab1175dc5ea4caae38e57cbb931f1aebdfe4a6f7 (diff) | |
download | glibmm-dd4f4f513c7785f14d6ce91120b8d5a0b9556540.tar.gz |
gmmproc: Write default values of properties to generated documentation
Bug 785895
Diffstat (limited to 'tools/pm')
-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 aef38255..17e7cda1 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 62209e9d..fa27743d 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 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) = @_; |