"Fossies" - the Fresh Open Source Software Archive

Member "darktable-2.6.3/tools/introspection/parser.pl" (20 Oct 2019, 3523 Bytes) of package /linux/misc/darktable-2.6.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "parser.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 #  This file is part of darktable,
    3 #  copyright (c) 2013-2014 tobias ellinghaus.
    4 #
    5 #  darktable is free software: you can redistribute it and/or modify
    6 #  it under the terms of the GNU General Public License as published by
    7 #  the Free Software Foundation, either version 3 of the License, or
    8 #  (at your option) any later version.
    9 #
   10 #  darktable is distributed in the hope that it will be useful,
   11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 #  GNU General Public License for more details.
   14 #
   15 #  You should have received a copy of the GNU General Public License
   16 #  along with darktable.  If not, see <http://www.gnu.org/licenses/>.
   17 
   18 # 0 -- print nothing
   19 # 1 -- print errors
   20 # 2 -- print warnings
   21 # 3 -- print debug info
   22 our $ERROR_LEVEL = 0;
   23 
   24 use strict;
   25 use warnings;
   26 
   27 use FindBin;
   28 use lib "$FindBin::RealBin";
   29 
   30 use scanner;
   31 use parser;
   32 use ast;
   33 use code_gen;
   34 
   35 my $base_dir = $ARGV[0];
   36 my $input_file = $ARGV[1];
   37 my $output_file = $ARGV[2];
   38 
   39 if(!defined($base_dir) or !defined($input_file) or !defined($output_file))
   40 {
   41   print STDERR "usage: parse.pl <base dir> <input file> <output_file>\n";
   42   exit(1);
   43 }
   44 
   45 # set the directory where to look for #includes
   46 $scanner::folder = $base_dir;
   47 
   48 read_file($input_file);
   49 
   50 # dump_tokens(); exit 1;
   51 
   52 my %types;
   53 my $version = -1;
   54 my $params_type;
   55 
   56 while()
   57 {
   58   @token = get_token();
   59   last if($token[$P_TYPE] == $T_NONE);
   60   if(istypedef(\@token))
   61   {
   62     my $ast = parse();
   63     if(defined($ast))
   64     {
   65       $ast->fix_types(\%types);
   66   #     $ast->print_tree(0);
   67   #     print "===========\n";
   68       $types{$ast->{name}} = \$ast;
   69     }
   70   }
   71   elsif(isdtmoduleintrospection(\@token))
   72   {
   73     ($version, $params_type) = parse_dt_module_introspection();
   74   }
   75 }
   76 
   77 open my $OUT, '>', $output_file;
   78 
   79 if(defined($params_type))
   80 {
   81   # needed for variable metadata like min, max, default and description
   82   parse_comments();
   83 
   84   my $code_generated = 0;
   85   my $params = $types{$params_type};
   86   if(defined($params) && $$params->check_tree())
   87   {
   88     $code_generated = code_gen::print_code($OUT, $$params, $input_file, $version, $params_type);
   89   }
   90 
   91   if(!$code_generated)
   92   {
   93     print STDERR "error: can't generate introspection data for type `$params_type'.\n";
   94     code_gen::print_fallback($OUT, $input_file, $version, $params_type);
   95   }
   96 }
   97 else
   98 {
   99   my $source_file_name = $input_file;
  100   if($input_file =~ /([^\/]*)$/) { $source_file_name = $1; }
  101   print STDERR "no introspection requested for $source_file_name.\n";
  102   print $OUT "/* no introspection requested for $source_file_name */\n#include \"$input_file\"\n";
  103 }
  104 
  105 close $OUT;
  106 
  107 ################# some debug functions #################
  108 
  109 # sub print_token
  110 # {
  111 #   my $token = shift;
  112 #   print @$token[0]." : ".@$token[1]." : ".@$token[2]." : ".@$token[3]."\n";
  113 # }
  114 #
  115 # sub dump_tokens
  116 # {
  117 #   while()
  118 #   {
  119 #     my @token = get_token();
  120 #     last if($token[$P_TYPE] == $T_NONE);
  121 #     print_token(\@token);
  122 #   }
  123 # }
  124 #
  125 # sub dump_comments
  126 # {
  127 #   my $lineno = 0;
  128 #   foreach(@comments)
  129 #   {
  130 #     if(defined($_))
  131 #     {
  132 #       print "$lineno:\n";
  133 #       my %line = %{$_};
  134 #       foreach(@{$line{raw}})
  135 #       {
  136 #         print "  ".$_."\n";
  137 #       }
  138 #     }
  139 #     $lineno++;
  140 #   }
  141 # }
  142 
  143 # modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
  144 # vim: shiftwidth=2 expandtab tabstop=2 cindent
  145 # kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;