File: parser.pl

package info (click to toggle)
darktable 4.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 52,960 kB
  • sloc: ansic: 329,632; cpp: 90,717; xml: 18,803; lisp: 12,673; sh: 3,478; javascript: 3,264; perl: 1,888; python: 1,082; ruby: 972; makefile: 536; asm: 46; sql: 38; awk: 21
file content (146 lines) | stat: -rwxr-xr-x 3,562 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
#  This file is part of darktable,
#  copyright (c) 2013-2020 tobias ellinghaus.
#
#  darktable is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  darktable is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with darktable.  If not, see <http://www.gnu.org/licenses/>.

# 0 -- print nothing
# 1 -- print errors
# 2 -- print warnings
# 3 -- print debug info
our $ERROR_LEVEL = 0;

use strict;
use warnings;

use FindBin;
use lib "$FindBin::RealBin";

use scanner;
use parser;
use ast;
use code_gen;

my $base_dir = $ARGV[0];
my $input_file = $ARGV[1];
my $output_file = $ARGV[2];

if(!defined($base_dir) or !defined($input_file) or !defined($output_file))
{
  print STDERR "usage: parse.pl <base dir> <input file> <output_file>\n";
  exit(1);
}

# set the directory where to look for #includes
$scanner::folder = $base_dir;

read_file($input_file);

# dump_tokens(); exit 1;

my %types;
my $version = -1;
my $params_type;

while()
{
  @token = get_token();
  last if($token[$P_TYPE] == $T_NONE);
  if(istypedef(\@token))
  {
    my $ast = parse();
    if(defined($ast))
    {
      $ast->fix_types(\%types);
  #     $ast->print_tree(0);
  #     print "===========\n";
      $types{$ast->{name}} = \$ast;
    }
  }
  elsif(isdtmoduleintrospection(\@token))
  {
    ($version, $params_type) = parse_dt_module_introspection();
  }
}

#dump_comments(); #exit 1;

open my $OUT, '>', $output_file;

if(defined($params_type))
{
  # needed for variable metadata like min, max, default and description
  parse_comments();

  my $code_generated = 0;
  my $params = $types{$params_type};
  if(defined($params) && $$params->check_tree())
  {
    $code_generated = code_gen::print_code($OUT, $$params, $input_file, $version, $params_type);
  }

  if(!$code_generated)
  {
    print STDERR "error: can't generate introspection data for type `$params_type'.\n";
    code_gen::print_fallback($OUT, $input_file, $version, $params_type);
  }
}
else
{
  my $source_file_name = $input_file;
  if($input_file =~ /([^\/]*)$/) { $source_file_name = $1; }
  print STDERR "no introspection requested for $source_file_name.\n";
  print $OUT "/* no introspection requested for $source_file_name */\n#include \"$input_file\"\n";
}

close $OUT;

################# some debug functions #################

sub print_token
{
  my $token = shift;
  print @$token[0]." : ".@$token[1]." : ".@$token[2]." : ".@$token[3]."\n";
}

sub dump_tokens
{
  while()
  {
    my @token = get_token();
    last if($token[$P_TYPE] == $T_NONE);
    print_token(\@token);
  }
}

sub dump_comments
{
  foreach my $filename (keys(%comments))
  {
    print "$filename\n";
    while (my ($lineno, $line) = each(@{$comments{$filename}}))
    {
      next unless defined($line);
      print "   $lineno:\n";
      foreach(@{%{$line}{raw}})
      {
        print "     ".$_."\n";
      }
    }
  }
}

# modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
# vim: shiftwidth=2 expandtab tabstop=2 cindent
# kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;