kernel-doc (0ff555192a8d20385d49d1c420e2e8d409b3c0da) | kernel-doc (a1d94aa5560dc6b06baf30ae477115b51dc25461) |
---|---|
1#!/usr/bin/perl -w 2 3use strict; 4 5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 7## Copyright (C) 2001 Simon Huggins ## 8## Copyright (C) 2005-2008 Randy Dunlap ## --- 275 unchanged lines hidden (view full) --- 284my $doc_content = $doc_com.'(.*)'; 285my $doc_block = $doc_com.'DOC:\s*(.*)?'; 286 287my %constants; 288my %parameterdescs; 289my @parameterlist; 290my %sections; 291my @sectionlist; | 1#!/usr/bin/perl -w 2 3use strict; 4 5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 7## Copyright (C) 2001 Simon Huggins ## 8## Copyright (C) 2005-2008 Randy Dunlap ## --- 275 unchanged lines hidden (view full) --- 284my $doc_content = $doc_com.'(.*)'; 285my $doc_block = $doc_com.'DOC:\s*(.*)?'; 286 287my %constants; 288my %parameterdescs; 289my @parameterlist; 290my %sections; 291my @sectionlist; |
292my $sectcheck; 293my $struct_actual; |
|
292 293my $contents = ""; 294my $section_default = "Description"; # default section 295my $section_intro = "Introduction"; 296my $section = $section_default; 297my $section_context = "Context"; 298 299my $undescribed = "-- undescribed --"; --- 73 unchanged lines hidden (view full) --- 373 if ($name =~ m/$type_constant/) { 374 $name = $1; 375# print STDERR "constant section '$1' = '$contents'\n"; 376 $constants{$name} = $contents; 377 } elsif ($name =~ m/$type_param/) { 378# print STDERR "parameter def '$1' = '$contents'\n"; 379 $name = $1; 380 $parameterdescs{$name} = $contents; | 294 295my $contents = ""; 296my $section_default = "Description"; # default section 297my $section_intro = "Introduction"; 298my $section = $section_default; 299my $section_context = "Context"; 300 301my $undescribed = "-- undescribed --"; --- 73 unchanged lines hidden (view full) --- 375 if ($name =~ m/$type_constant/) { 376 $name = $1; 377# print STDERR "constant section '$1' = '$contents'\n"; 378 $constants{$name} = $contents; 379 } elsif ($name =~ m/$type_param/) { 380# print STDERR "parameter def '$1' = '$contents'\n"; 381 $name = $1; 382 $parameterdescs{$name} = $contents; |
383 $sectcheck = $sectcheck . $name . " "; |
|
381 } elsif ($name eq "@\.\.\.") { 382# print STDERR "parameter def '...' = '$contents'\n"; 383 $name = "..."; 384 $parameterdescs{$name} = $contents; | 384 } elsif ($name eq "@\.\.\.") { 385# print STDERR "parameter def '...' = '$contents'\n"; 386 $name = "..."; 387 $parameterdescs{$name} = $contents; |
388 $sectcheck = $sectcheck . $name . " "; |
|
385 } else { 386# print STDERR "other section '$name' = '$contents'\n"; 387 if (defined($sections{$name}) && ($sections{$name} ne "")) { 388 print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; 389 ++$errors; 390 } 391 $sections{$name} = $contents; 392 push @sectionlist, $name; --- 1007 unchanged lines hidden (view full) --- 1400 1401sub dump_union($$) { 1402 dump_struct(@_); 1403} 1404 1405sub dump_struct($$) { 1406 my $x = shift; 1407 my $file = shift; | 389 } else { 390# print STDERR "other section '$name' = '$contents'\n"; 391 if (defined($sections{$name}) && ($sections{$name} ne "")) { 392 print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; 393 ++$errors; 394 } 395 $sections{$name} = $contents; 396 push @sectionlist, $name; --- 1007 unchanged lines hidden (view full) --- 1404 1405sub dump_union($$) { 1406 dump_struct(@_); 1407} 1408 1409sub dump_struct($$) { 1410 my $x = shift; 1411 my $file = shift; |
1412 my $nested; |
|
1408 1409 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) { 1410 $declaration_name = $2; 1411 my $members = $3; 1412 1413 # ignore embedded structs or unions | 1413 1414 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) { 1415 $declaration_name = $2; 1416 my $members = $3; 1417 1418 # ignore embedded structs or unions |
1414 $members =~ s/{.*}//g; | 1419 $members =~ s/({.*})//g; 1420 $nested = $1; |
1415 1416 # ignore members marked private: 1417 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos; 1418 $members =~ s/\/\*.*?private:.*//gos; 1419 # strip comments: 1420 $members =~ s/\/\*.*?\*\///gos; | 1421 1422 # ignore members marked private: 1423 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos; 1424 $members =~ s/\/\*.*?private:.*//gos; 1425 # strip comments: 1426 $members =~ s/\/\*.*?\*\///gos; |
1427 $nested =~ s/\/\*.*?\*\///gos; |
|
1421 1422 create_parameterlist($members, ';', $file); | 1428 1429 create_parameterlist($members, ';', $file); |
1430 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); |
|
1423 1424 output_declaration($declaration_name, 1425 'struct', 1426 {'struct' => $declaration_name, 1427 'module' => $modulename, 1428 'parameterlist' => \@parameterlist, 1429 'parameterdescs' => \%parameterdescs, 1430 'parametertypes' => \%parametertypes, --- 69 unchanged lines hidden (view full) --- 1500 }); 1501 } 1502 else { 1503 print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 1504 ++$errors; 1505 } 1506} 1507 | 1431 1432 output_declaration($declaration_name, 1433 'struct', 1434 {'struct' => $declaration_name, 1435 'module' => $modulename, 1436 'parameterlist' => \@parameterlist, 1437 'parameterdescs' => \%parameterdescs, 1438 'parametertypes' => \%parametertypes, --- 69 unchanged lines hidden (view full) --- 1508 }); 1509 } 1510 else { 1511 print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 1512 ++$errors; 1513 } 1514} 1515 |
1516sub save_struct_actual($) { 1517 my $actual = shift; 1518 1519 # strip all spaces from the actual param so that it looks like one string item 1520 $actual =~ s/\s*//g; 1521 $struct_actual = $struct_actual . $actual . " "; 1522} 1523 |
|
1508sub create_parameterlist($$$) { 1509 my $args = shift; 1510 my $splitter = shift; 1511 my $file = shift; 1512 my $type; 1513 my $param; 1514 1515 # temporarily replace commas inside function pointer definition --- 16 unchanged lines hidden (view full) --- 1532 push_parameter($arg, "", $file); 1533 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1534 # pointer-to-function 1535 $arg =~ tr/#/,/; 1536 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 1537 $param = $1; 1538 $type = $arg; 1539 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; | 1524sub create_parameterlist($$$) { 1525 my $args = shift; 1526 my $splitter = shift; 1527 my $file = shift; 1528 my $type; 1529 my $param; 1530 1531 # temporarily replace commas inside function pointer definition --- 16 unchanged lines hidden (view full) --- 1548 push_parameter($arg, "", $file); 1549 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1550 # pointer-to-function 1551 $arg =~ tr/#/,/; 1552 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 1553 $param = $1; 1554 $type = $arg; 1555 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
1556 save_struct_actual($param); |
|
1540 push_parameter($param, $type, $file); 1541 } elsif ($arg) { 1542 $arg =~ s/\s*:\s*/:/g; 1543 $arg =~ s/\s*\[/\[/g; 1544 1545 my @args = split('\s*,\s*', $arg); 1546 if ($args[0] =~ m/\*/) { 1547 $args[0] =~ s/(\*+)\s*/ $1/; --- 8 unchanged lines hidden (view full) --- 1556 @first_arg = split('\s+', shift @args); 1557 } 1558 1559 unshift(@args, pop @first_arg); 1560 $type = join " ", @first_arg; 1561 1562 foreach $param (@args) { 1563 if ($param =~ m/^(\*+)\s*(.*)/) { | 1557 push_parameter($param, $type, $file); 1558 } elsif ($arg) { 1559 $arg =~ s/\s*:\s*/:/g; 1560 $arg =~ s/\s*\[/\[/g; 1561 1562 my @args = split('\s*,\s*', $arg); 1563 if ($args[0] =~ m/\*/) { 1564 $args[0] =~ s/(\*+)\s*/ $1/; --- 8 unchanged lines hidden (view full) --- 1573 @first_arg = split('\s+', shift @args); 1574 } 1575 1576 unshift(@args, pop @first_arg); 1577 $type = join " ", @first_arg; 1578 1579 foreach $param (@args) { 1580 if ($param =~ m/^(\*+)\s*(.*)/) { |
1581 save_struct_actual($2); |
|
1564 push_parameter($2, "$type $1", $file); 1565 } 1566 elsif ($param =~ m/(.*?):(\d+)/) { 1567 if ($type ne "") { # skip unnamed bit-fields | 1582 push_parameter($2, "$type $1", $file); 1583 } 1584 elsif ($param =~ m/(.*?):(\d+)/) { 1585 if ($type ne "") { # skip unnamed bit-fields |
1586 save_struct_actual($1); |
|
1568 push_parameter($1, "$type:$2", $file) 1569 } 1570 } 1571 else { | 1587 push_parameter($1, "$type:$2", $file) 1588 } 1589 } 1590 else { |
1591 save_struct_actual($param); |
|
1572 push_parameter($param, $type, $file); 1573 } 1574 } 1575 } 1576 } 1577} 1578 1579sub push_parameter($$$) { --- 49 unchanged lines hidden (view full) --- 1629 ++$warnings; 1630 } 1631 } 1632 1633 push @parameterlist, $param; 1634 $parametertypes{$param} = $type; 1635} 1636 | 1592 push_parameter($param, $type, $file); 1593 } 1594 } 1595 } 1596 } 1597} 1598 1599sub push_parameter($$$) { --- 49 unchanged lines hidden (view full) --- 1649 ++$warnings; 1650 } 1651 } 1652 1653 push @parameterlist, $param; 1654 $parametertypes{$param} = $type; 1655} 1656 |
1657sub check_sections($$$$$$) { 1658 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 1659 my @sects = split ' ', $sectcheck; 1660 my @prms = split ' ', $prmscheck; 1661 my $err; 1662 my ($px, $sx); 1663 my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1664 1665 foreach $sx (0 .. $#sects) { 1666 $err = 1; 1667 foreach $px (0 .. $#prms) { 1668 $prm_clean = $prms[$px]; 1669 $prm_clean =~ s/\[.*\]//; 1670 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//; 1671 ##$prm_clean =~ s/^\**//; 1672 if ($prm_clean eq $sects[$sx]) { 1673 $err = 0; 1674 last; 1675 } 1676 } 1677 if ($err) { 1678 if ($decl_type eq "function") { 1679 print STDERR "Warning(${file}:$.): " . 1680 "Excess function parameter " . 1681 "'$sects[$sx]' " . 1682 "description in '$decl_name'\n"; 1683 ++$warnings; 1684 } else { 1685 if ($nested !~ m/\Q$sects[$sx]\E/) { 1686 print STDERR "Warning(${file}:$.): " . 1687 "Excess struct/union/enum/typedef member " . 1688 "'$sects[$sx]' " . 1689 "description in '$decl_name'\n"; 1690 ++$warnings; 1691 } 1692 } 1693 } 1694 } 1695} 1696 |
|
1637## 1638# takes a function prototype and the name of the current file being 1639# processed and spits out all the details stored in the global 1640# arrays/hashes. 1641sub dump_function($$) { 1642 my $prototype = shift; 1643 my $file = shift; 1644 --- 49 unchanged lines hidden (view full) --- 1694 1695 create_parameterlist($args, ',', $file); 1696 } else { 1697 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; 1698 ++$errors; 1699 return; 1700 } 1701 | 1697## 1698# takes a function prototype and the name of the current file being 1699# processed and spits out all the details stored in the global 1700# arrays/hashes. 1701sub dump_function($$) { 1702 my $prototype = shift; 1703 my $file = shift; 1704 --- 49 unchanged lines hidden (view full) --- 1754 1755 create_parameterlist($args, ',', $file); 1756 } else { 1757 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; 1758 ++$errors; 1759 return; 1760 } 1761 |
1762 my $prms = join " ", @parameterlist; 1763 check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 1764 |
|
1702 output_declaration($declaration_name, 1703 'function', 1704 {'function' => $declaration_name, 1705 'module' => $modulename, 1706 'functiontype' => $return_type, 1707 'parameterlist' => \@parameterlist, 1708 'parameterdescs' => \%parameterdescs, 1709 'parametertypes' => \%parametertypes, --- 42 unchanged lines hidden (view full) --- 1752sub reset_state { 1753 $function = ""; 1754 %constants = (); 1755 %parameterdescs = (); 1756 %parametertypes = (); 1757 @parameterlist = (); 1758 %sections = (); 1759 @sectionlist = (); | 1765 output_declaration($declaration_name, 1766 'function', 1767 {'function' => $declaration_name, 1768 'module' => $modulename, 1769 'functiontype' => $return_type, 1770 'parameterlist' => \@parameterlist, 1771 'parameterdescs' => \%parameterdescs, 1772 'parametertypes' => \%parametertypes, --- 42 unchanged lines hidden (view full) --- 1815sub reset_state { 1816 $function = ""; 1817 %constants = (); 1818 %parameterdescs = (); 1819 %parametertypes = (); 1820 @parameterlist = (); 1821 %sections = (); 1822 @sectionlist = (); |
1823 $sectcheck = ""; 1824 $struct_actual = ""; |
|
1760 $prototype = ""; 1761 1762 $state = 0; 1763} 1764 1765sub process_state3_function($$) { 1766 my $x = shift; 1767 my $file = shift; --- 306 unchanged lines hidden --- | 1825 $prototype = ""; 1826 1827 $state = 0; 1828} 1829 1830sub process_state3_function($$) { 1831 my $x = shift; 1832 my $file = shift; --- 306 unchanged lines hidden --- |