~ubuntu-branches/ubuntu/karmic/glibmm2.4/karmic

« back to all changes in this revision

Viewing changes to tools/pm/WrapParser.pm

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-09-22 11:12:24 UTC
  • mfrom: (1.2.41 upstream)
  • Revision ID: james.westby@ubuntu.com-20090922111224-p1r8bxw835x23l07
Tags: 2.22.1-0ubuntu1
* New upstream release (LP: #434371)
  - Fix KeyFile build with exceptions disabled
  - Re-enable input file line markers in gmmproc
  - Fix broken test for empty _WRAP_METHOD argument
  - Allow the C documentation to be overridden
  - Slightly clean up gross Perl code in gmmproc.in
  - Correctly quote the extracted comment for M4
  - Enable verbose output of autoreconf
  - Do not complain about missing docs_override.xml
  - Support Automake silent rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
    if ($token eq "_WRAP_GERROR") { $self->on_wrap_gerror(); next;}
123
123
    if ($token eq "_IMPLEMENTS_INTERFACE") { $self->on_implements_interface(); next;}
124
124
 
125
 
    my $prefix_class = "_CLASS_"; # e.g. _CLASS_GTKOBJECT
126
 
    my $token_prefix = substr($token, 0, length($prefix_class));
127
 
    if ($token_prefix eq $prefix_class)
 
125
    if ($token =~ m/\A_CLASS_/s)
128
126
    {
129
127
      $self->on_class($token);
130
128
      next;
175
173
    # skip empty tokens
176
174
    next if ( !defined($_) or $_ eq "" );
177
175
 
178
 
    # eat line statements. TODO: e.g.?
179
 
    if ( /^#l (\S+)\n/)
 
176
    # eat line statements
 
177
    if (m/^#l (\S+)\n/)
180
178
    {
181
179
      $$self{line_num} = $1;
182
180
      next;
183
181
    }
184
182
 
185
 
    # eat file statements. TODO: e.g.?
186
 
    if ( /^#f (\S+)\n/)
 
183
    # eat file statements
 
184
    if (m/^#f (\S+)\n/)
187
185
    {
188
186
      $$self{filename} = $1;
189
187
      next;
211
209
    {
212
210
      shift @tokens;
213
211
    }
214
 
    # eat line statements. TODO: e.g.?
 
212
    # eat line statements
215
213
    elsif ( /^#l (\S+)\n/)
216
214
    {
217
215
      $$self{line_num} = $1;
218
216
      shift @tokens;
219
217
    }
220
 
    # eat file statements. TODO: e.g.?
 
218
    # eat file statements
221
219
    elsif ( /^#f (\S+)\n/)
222
220
    {
223
221
      $$self{filename} = $1;
236
234
sub tokens_remaining($)
237
235
{
238
236
  my ($self) = @_;
239
 
  return scalar(@tokens)!=0;
 
237
  return $#tokens >= 0;
240
238
}
241
239
 
242
240
 
339
337
      # can print it if the next real token is not _WRAP_SIGNAL
340
338
      my @whitespace;
341
339
      my $next_token = $self->peek_token();
342
 
      while ($next_token =~ /^\s*$/)
 
340
      while ($next_token !~ /\S/)
343
341
      {
344
342
        push(@whitespace, $self->extract_token());
345
343
        $next_token = $self->peek_token();
358
356
      }
359
357
      else
360
358
      {
361
 
        # Something else then signal follows, so close comment normally
 
359
        # Something other than signal follows, so close comment normally
362
360
        $objOutputter->append("/");
363
 
        # And append whitespace we ignored so far
 
361
        # And append whitespace we ignored so far
364
362
        $objOutputter->append(join("", @whitespace));
365
 
        # Do not extract the token so that parse_and_build_output() will
366
 
        # process it.
 
363
        # Do not extract the token so that parse_and_build_output() will
 
364
        # process it.
367
365
      }
368
366
 
369
367
      last;
432
430
 
433
431
  # we need to peek ahead to figure out what type of namespace 
434
432
  # declaration this is.
435
 
  while ( $number < scalar(@tokens) )
 
433
  while ( $number <= $#tokens )
436
434
  {
437
435
    $token = $tokens[$number];
438
436
    $number++;
524
522
  
525
523
  # When we hit _CLASS, we walk backwards through the output to find "class"
526
524
  my $token;
527
 
  while ( scalar(@{$$objOutputter{out}}) > 0)
 
525
  while ( scalar(@{$$objOutputter{out}}))
528
526
  {
529
527
    $token = pop @{$$objOutputter{out}};
530
528
    unshift(@back, $token);
596
594
  $objOutputter->append("}"); #We append it here instead of after we return, so that we can end the namespace after it.
597
595
 
598
596
  $self->on_end_namespace()
599
 
    if ( (scalar(@{$$self{in_namespace}}) > 0) && (@{$$self{in_namespace}}[0] == $$self{level}) );
 
597
    if ( scalar(@{$$self{in_namespace}}) && (@{$$self{in_namespace}}[0] == $$self{level}) );
600
598
 
601
599
  $$self{level}--;
602
600
}
716
714
{
717
715
  my ($self, $srcdir, $source) = @_;
718
716
 
719
 
  my $line;
720
 
  my @in;
 
717
  my $lineno = 1;
 
718
  my @in = ();
721
719
 
722
720
  if ( ! -r "${srcdir}/${source}.hg")
723
721
  {
724
722
    print "Unable to find header file $srcdir/$source.hg\n";
725
 
    exit(-1); 
 
723
    exit(1);
726
724
  }
727
725
 
728
726
  # Read header file:
729
727
  open(FILE, "${srcdir}/${source}.hg");
730
 
#  push(@in, "#f ${source}.hg\n"); #TODO: What does #f do?
731
 
  $line = 1;
 
728
  push(@in, "#f ${source}.hg\n");
732
729
  while (<FILE>)
733
730
    {
734
 
#      push(@in, "#l $line\n"); #TODO: What does #l do?
 
731
      push(@in, "#l $lineno\n");
735
732
      push(@in, $_);
736
 
      $line++;
 
733
      ++$lineno;
737
734
    }
738
735
  close(FILE);
739
 
  push(@in, "\n_SECTION(SECTION_SRC_CUSTOM)\n");
 
736
  push(@in, "\n", "_SECTION(SECTION_SRC_CUSTOM)\n");
740
737
 
741
738
  # Source file is optional.
742
739
  if ( -r "${srcdir}/${source}.ccg")
743
740
  {
744
741
    open(FILE, "${srcdir}/${source}.ccg");
745
 
    $line = 1;
746
 
#    push(@in, "#f ${source}.ccg\n"); #TODO: What does #f do?
 
742
    $lineno = 1;
 
743
    push(@in, "#f ${source}.ccg\n");
747
744
    while (<FILE>)
748
745
      {
749
 
#        push(@in, "#l $line\n"); #TODO: What does #l do?
 
746
        push(@in, "#l $lineno\n");
750
747
        push(@in, $_);
751
 
        $line++;
 
748
        ++$lineno;
752
749
      }
753
750
    close(FILE);
754
751
  }
793
790
  my $filename = $$self{filename};
794
791
  my $line_num = $$self{line_num};
795
792
 
796
 
  if (!(scalar(@tokens)))
 
793
  unless (scalar(@tokens))
797
794
  {
798
795
    print STDERR "$filename:$line_num:hit eof in _WRAP\n";
799
796
    return 0; #EOF
802
799
  return 1; # No EOF
803
800
}
804
801
 
 
802
# Look back for a Doxygen comment.  If there is one,
 
803
# remove it from the output and return it as a string.
 
804
sub extract_preceding_documentation ($)
 
805
{
 
806
  my ($self) = @_;
 
807
  my $outputter = $$self{objOutputter};
 
808
  my $out = \@{$$outputter{out}};
 
809
 
 
810
  my $comment = '';
 
811
 
 
812
  if ($#$out >= 2)
 
813
  {
 
814
    # steal the last three tokens
 
815
    my @back = splice(@$out, -3);
 
816
    local $_ = join('', @back);
 
817
 
 
818
    # Check for /*[*!] ... */ or //[/!] comments.  The closing */ _must_
 
819
    # be the last token of the previous line.  Apart from this restriction,
 
820
    # anything else should work, including multi-line comments.
 
821
 
 
822
    if (m#\A/\s*\*(?:\*`|`!)(.+)'\*/\s*\z#s or m#\A\s*//`[/!](.+)'\s*\z#s)
 
823
    {
 
824
      $comment = '`' . $1;
 
825
      $comment =~ s/\s*$/'/;
 
826
    }
 
827
    else
 
828
    {
 
829
      # restore stolen tokens
 
830
      push(@$out, @back);
 
831
    }
 
832
  }
 
833
 
 
834
  return $comment;
 
835
}
 
836
 
805
837
# void on_wrap_method()
806
838
sub on_wrap_method($)
807
839
{
808
840
  my ($self) = @_;
809
841
  my $objOutputter = $$self{objOutputter};
810
842
 
811
 
  if( !($self->check_for_eof()) )
812
 
  {
813
 
   return;
814
 
  }
 
843
  return unless ($self->check_for_eof());
815
844
 
816
845
  my $filename = $$self{filename};
817
846
  my $line_num = $$self{line_num};
818
847
 
 
848
  my $commentblock = $self->extract_preceding_documentation();
819
849
  my $str = $self->extract_bracketed_text();
820
850
  my @args = string_split_commas($str);
821
851
 
822
852
  my $entity_type = "method";
823
853
 
824
 
  if (!$$self{in_class})
 
854
  unless ($$self{in_class})
825
855
    {
826
856
      print STDERR "$filename:$line_num:_WRAP macro encountered outside class\n";
827
857
      return;
832
862
 
833
863
  # handle first argument
834
864
  my $argCppMethodDecl = $args[0];
835
 
  if ($argCppMethodDecl =~ /^\S+$/ ) #Checks that it's not empty and that it contains no whitespace.
 
865
  if ($argCppMethodDecl !~ m/\S/s)
836
866
  {
837
 
    print STDERR "$filename:$line_num:_WRAP can't handle unspecified method $argCppMethodDecl\n";
 
867
    print STDERR "$filename:$line_num:_WRAP_METHOD: missing prototype\n";
838
868
    return;
839
869
  }
840
 
  else
841
 
  {
842
 
    #Parse the method decaration and build an object that holds the details:
843
 
    $objCppfunc = &Function::new($argCppMethodDecl, $self);
844
 
  }
845
870
 
 
871
  #Parse the method decaration and build an object that holds the details:
 
872
  $objCppfunc = &Function::new($argCppMethodDecl, $self);
846
873
 
847
874
  # handle second argument:
848
875
 
851
878
 
852
879
  #Get the c function's details:
853
880
 
854
 
  #Checks that it's not empty and that it contains no whitespace.
855
 
  if ($argCFunctionName =~ /^\S+$/ )
 
881
  # Checks that it's not empty and that it contains no whitespace.
 
882
  if ($argCFunctionName =~ m/^\S+$/s)
856
883
  {
857
884
    #c-name. e.g. gtk_clist_set_column_title
858
885
    $objCfunc = GtkDefs::lookup_function($argCFunctionName);
868
895
  $$objCfunc{deprecated} = "";
869
896
  my $deprecation_docs = "";
870
897
  my $ifdef;
871
 
  while(scalar(@args) > 2) # If the optional ref/err/deprecated arguments are there.
 
898
  while($#args >= 2) # If the optional ref/err/deprecated arguments are there.
872
899
  {
873
900
    my $argRef = string_trim(pop @args);
874
901
    #print "debug arg=$argRef\n";
899
926
    }
900
927
  }
901
928
 
902
 
  my $commentblock = "";
903
 
  $commentblock = DocsParser::lookup_documentation($argCFunctionName, $deprecation_docs);
 
929
  if ($commentblock ne '')
 
930
  {
 
931
    $commentblock = '  /**' . $commentblock . "\n   */\n";
 
932
  }
 
933
  else
 
934
  {
 
935
    $commentblock = DocsParser::lookup_documentation($argCFunctionName, $deprecation_docs);
 
936
  }
904
937
 
905
938
  $objOutputter->output_wrap_meth($filename, $line_num, $objCppfunc, $objCfunc, $argCppMethodDecl, $commentblock, $ifdef);
906
939
}
911
944
  my ($self) = @_;
912
945
  my $objOutputter = $$self{objOutputter};
913
946
 
914
 
  if( !($self->check_for_eof()) )
915
 
  {
916
 
   return;
917
 
  }
 
947
  return unless ($self->check_for_eof());
918
948
 
919
949
  my $filename = $$self{filename};
920
950
  my $line_num = $$self{line_num};
936
966
  my $argCFunctionName = $args[0];
937
967
  $argCFunctionName = string_trim($argCFunctionName);
938
968
 
939
 
  #Get the c function's details:
 
969
  # Get the C function's details:
940
970
 
941
 
  #Checks that it's not empty and that it contains no whitespace.
942
 
  if ($argCFunctionName =~ /^\S+$/ ) 
 
971
  # Checks that it's not empty or contains whitespace
 
972
  if ($argCFunctionName =~ m/^\S+$/s)
943
973
  {
944
974
    #c-name. e.g. gtk_clist_set_column_title
945
975
    $objCfunc = GtkDefs::lookup_function($argCFunctionName);
952
982
  }
953
983
 
954
984
  # Extra ref needed?
955
 
  while(scalar(@args) > 1) # If the optional ref/err arguments are there.
 
985
  while($#args >= 1) # If the optional ref/err arguments are there.
956
986
  {
957
987
    my $argRef = string_trim(pop @args);
958
988
    if($argRef eq "errthrow")
996
1026
 
997
1027
  # handle first argument
998
1028
  my $argCppMethodDecl = $args[0];
999
 
  if ($argCppMethodDecl =~ /^\S+$/ ) #Checks that it's not empty and that it contains no whitespace.
 
1029
  if ($argCppMethodDecl !~ m/\S/s)
1000
1030
    {
1001
 
      print STDERR "$filename:$line_num:_WRAP_CTOR can't handle unspecified method $argCppMethodDecl\n";
 
1031
      print STDERR "$filename:$line_num:_WRAP_CTOR: missing prototype\n";
1002
1032
      return;
1003
1033
    }
1004
 
  else
1005
 
    {
1006
 
      #Parse the method decaration and build an object that holds the details:
1007
 
      $objCppfunc = &Function::new_ctor($argCppMethodDecl, $self);
1008
 
    }
1009
1034
 
 
1035
  #Parse the method decaration and build an object that holds the details:
 
1036
  $objCppfunc = &Function::new_ctor($argCppMethodDecl, $self);
1010
1037
 
1011
1038
  # handle second argument:
1012
1039
 
1013
1040
  my $argCFunctionName = $args[1];
1014
1041
  $argCFunctionName = string_trim($argCFunctionName);
1015
1042
 
1016
 
  #Get the c function's details:
1017
 
  if ($argCFunctionName =~ /^\S+$/ ) #Checks that it's not empty and that it contains no whitespace.
 
1043
  #Get the C function's details:
 
1044
  if ($argCFunctionName =~ m/^\S+$/s)
1018
1045
  {
1019
1046
    $objCfunc = GtkDefs::lookup_function($argCFunctionName); #c-name. e.g. gtk_clist_set_column_title
1020
1047
    if(!$objCfunc) #If the lookup failed:
1047
1074
 
1048
1075
  # Extra stuff needed?
1049
1076
  my $ifdef; 
1050
 
  while(scalar(@args) > 1) # If the optional ref/err/deprecated arguments are there.
 
1077
  while($#args >= 1) # If the optional ref/err/deprecated arguments are there.
1051
1078
  {
1052
1079
        my $argRef = string_trim(pop @args);
1053
1080
    if($argRef =~ /^ifdef(.*)/) #If ifdef is at the start.
1098
1125
  my $bRefreturn = 0;
1099
1126
  my $ifdef;
1100
1127
  
1101
 
  while(scalar(@args) > 2) # If optional arguments are there.
 
1128
  while($#args >= 2) # If optional arguments are there.
1102
1129
  {
1103
1130
    my $argRef = string_trim(pop @args);
1104
1131
    if($argRef eq "custom_default_handler")
1155
1182
  my $ifdef = "";
1156
1183
 
1157
1184
  # Extra ref needed?
1158
 
  while(scalar(@args) > 2) # If the optional ref/err arguments are there.
 
1185
  while($#args >= 2) # If the optional ref/err arguments are there.
1159
1186
  {
1160
1187
    my $argRef = string_trim(pop @args);
1161
1188
 
1177
1204
{
1178
1205
  my ($self) = @_;
1179
1206
 
1180
 
  return if(!$self->check_for_eof());
 
1207
  return unless ($self->check_for_eof());
1181
1208
 
1182
1209
  my $outputter = $$self{objOutputter};
1183
 
  my $out = \@{$$outputter{out}};
1184
 
 
1185
 
  # Look back for a Doxygen comment for this _WRAP_ENUM.  If there is one,
1186
 
  # remove it from the output and pass it to the m4 _ENUM macro instead.
1187
 
  my $comment = "";
1188
 
 
1189
 
  if(scalar(@$out) >= 2)
1190
 
  {
1191
 
    # steal the last two tokens
1192
 
    my @back = splice(@$out, -2);
1193
 
    local $_ = $back[0];
1194
 
 
1195
 
    # Check for /*[*!] ... */ or //[/!] comments.  The closing */ _must_
1196
 
    # be the last token of the previous line.  Apart from this restriction,
1197
 
    # anything else should work, including multi-line comments.
1198
 
 
1199
 
    if($back[1] eq "\n" && (m#^/\*`[*!](.+)'\*/#s || m#^//`[/!](.+)'$#))
1200
 
    {
1201
 
      $comment = $1;
1202
 
      $comment =~ s/\s+$//;
1203
 
    }
1204
 
    else
1205
 
    {
1206
 
      # restore stolen tokens
1207
 
      push(@$out, @back);
1208
 
    }
1209
 
  }
 
1210
  my $comment = $self->extract_preceding_documentation();
1210
1211
 
1211
1212
  # get the arguments
1212
1213
  my @args = string_split_commas($self->extract_bracketed_text());
1224
1225
{
1225
1226
  my ($self) = @_;
1226
1227
 
1227
 
  return if(!$self->check_for_eof());
 
1228
  return unless ($self->check_for_eof());
1228
1229
 
1229
1230
  # get the arguments
1230
1231
  my @args = string_split_commas($self->extract_bracketed_text());
1244
1245
  my ($self) = @_;
1245
1246
  my $objOutputter = $$self{objOutputter};
1246
1247
 
1247
 
  if( !($self->check_for_eof()) )
1248
 
  {
1249
 
    return;
1250
 
  }
 
1248
  return unless ($self->check_for_eof());
1251
1249
 
1252
1250
  my $str = $self->extract_bracketed_text();
1253
1251
  my @args = string_split_commas($str);
1260
1258
  #Convert the property name to a canonical form, as it is inside gobject.
1261
1259
  #Otherwise, gobject might not recognise the name, 
1262
1260
  #and we will not recognise the property name when we get notification that the value changes.
1263
 
  $argPropertyName =~ s/_/-/g; #g means replace all.
 
1261
  $argPropertyName =~ tr/_/-/;
1264
1262
 
1265
1263
  my $argCppType = $args[1];
1266
1264
  $argCppType = string_trim($argCppType);
1279
1277
 
1280
1278
  #Some checks:
1281
1279
 
1282
 
 
1283
 
  if (!$$self{in_class})
 
1280
  unless ($$self{in_class})
1284
1281
  {
1285
1282
    print STDERR "$filename:$line_num: $macro_name macro encountered outside class\n";
1286
 
    return;
 
1283
    return 1;
1287
1284
  }
1288
 
 
1289
 
  if ($CppDecl =~ /^\S+$/ ) #If it's not empty and it contains no whitespace.
 
1285
  if ($CppDecl !~ m/\S/s)
1290
1286
  {
1291
 
    print STDERR "$filename:$line_num:$macro_name can't handle unspecified entity $CppDecl\n";
1292
 
    return;
 
1287
    print STDERR "$filename:$line_num:$macro_name: missing prototype\n";
 
1288
    return 1;
1293
1289
  }
1294
 
 
1295
 
 
 
1290
  return '';
1296
1291
}
1297
1292
 
1298
1293
# void output_wrap($CppDecl, $signal_name, $filename, $line_num, $bCustomDefaultHandler, $bNoDefaultHandler, $bCustomCCallback, $bRefreturn)
1302
1297
  my ($self, $CppDecl, $signal_name, $filename, $line_num, $bCustomDefaultHandler, $bNoDefaultHandler, $bCustomCCallback, $bRefreturn, $ifdef, $merge_doxycomment_with_previous) = @_;
1303
1298
  
1304
1299
  #Some checks:
1305
 
  $self->output_wrap_check($CppDecl, $signal_name, $filename, $line_num, "WRAP_SIGNAL");
1306
 
 
 
1300
  return if ($self->output_wrap_check($CppDecl, $signal_name,
 
1301
                                      $filename, $line_num, "_WRAP_SIGNAL"));
1307
1302
  # handle first argument
1308
1303
 
1309
1304
  #Parse the method decaration and build an object that holds the details:
1317
1312
  my $objOutputter = $$self{objOutputter};
1318
1313
 
1319
1314
  #Get the c function's details:
1320
 
  if ($signal_name ne "" ) #If it's not empty and it contains no whitespace.
 
1315
  if ($signal_name ne '')
1321
1316
  {
1322
1317
    $objCSignal = GtkDefs::lookup_signal($$self{c_class}, $signal_name);
1323
1318
 
1350
1345
  my ($self, $CppDecl, $vfunc_name, $refreturn, $refreturn_ctype, $filename, $line_num, $ifdef) = @_;
1351
1346
 
1352
1347
  #Some checks:
1353
 
  $self->output_wrap_check($CppDecl, $vfunc_name, $filename, $line_num, "VFUNC");
 
1348
  return if ($self->output_wrap_check($CppDecl, $vfunc_name, $filename, $line_num, '_WRAP_VFUNC'));
1354
1349
 
1355
1350
  # handle first argument
1356
1351
 
1364
1359
  my $objOutputter = $$self{objOutputter};
1365
1360
 
1366
1361
  #Get the c function's details:
1367
 
  if ($vfunc_name =~ /^\S+$/ ) #If it's not empty and it contains no whitespace.
 
1362
  if ($vfunc_name =~ m/^\S+$/s) # if it's not empty and contains no whitespace
1368
1363
  {
1369
1364
    $objCVfunc = GtkDefs::lookup_signal($$self{c_class},$vfunc_name);
1370
1365
    if(!$objCVfunc) #If the lookup failed:
1408
1403
  my ($self) = @_;
1409
1404
  my $objOutputter = $$self{objOutputter};
1410
1405
 
1411
 
  if( !($self->check_for_eof()) )
1412
 
  {
1413
 
   return;
1414
 
  }
 
1406
  return unless ($self->check_for_eof());
1415
1407
 
1416
1408
  my $filename = $$self{filename};
1417
1409
  my $line_num = $$self{line_num};
1427
1419
      return;
1428
1420
    }
1429
1421
 
1430
 
  my $objCfunc;
1431
1422
  my $objCppfunc;
1432
1423
 
1433
1424
  # handle first argument
1434
1425
  my $argCppMethodDecl = $args[0];
1435
 
  if ($argCppMethodDecl =~ /^\S+$/ ) #Checks that it's not empty and that it contains no whitespace.
 
1426
  if ($argCppMethodDecl !~ m/\S/s)
1436
1427
  {
1437
 
    print STDERR "$filename:$line_num:_WRAP can't handle unspecified method $argCppMethodDecl\n";
 
1428
    print STDERR "$filename:$line_num:_WRAP_CORBA_METHOD: missing prototype\n";
1438
1429
    return;
1439
1430
  }
1440
 
  else
1441
 
  {
1442
 
    #Parse the method decaration and build an object that holds the details:
1443
 
    $objCppfunc = &Function::new($argCppMethodDecl, $self);
1444
 
  }
1445
1431
 
 
1432
  # Parse the method decaration and build an object that holds the details:
 
1433
  $objCppfunc = &Function::new($argCppMethodDecl, $self);
1446
1434
  $objOutputter->output_wrap_corba_method($filename, $line_num, $objCppfunc);
1447
1435
}
1448
1436