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
|
###############################################################################
#
# Class: NaturalDocs::Languages::ObjC
#
###############################################################################
#
# Handle Objective-C.
#
###############################################################################
## Copyright 2008, Matthias Andreas Benkard.
##
## This package 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 2 of the License, or
## (at your option) any later version.
##
## This package 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 this package; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use integer;
package NaturalDocs::Languages::ObjC;
use base 'NaturalDocs::Languages::Simple';
use NaturalDocs::Languages;
sub OnCode
{
my ($self, $codeLines, $codeLineNumber, $topicList, $lastCommentTopicCount) = @_;
$self->SUPER::OnCode ($codeLines, $codeLineNumber, $topicList, $lastCommentTopicCount);
my $topic = $topicList->[-1];
my $line = $codeLines->[0];
if ($lastCommentTopicCount)
{
unless ($topic->Prototype())
{
my $code = join ("\n", @{$codeLines});
if ($topic->Type() eq ::TOPIC_FUNCTION())
{
if ($code =~ /\s*([-+].*)[;{]/)
{
$topic->SetPrototype($1);
}
}
elsif ($topic->Type() eq ::TOPIC_CLASS())
{
if ($code =~ /\s*(\@interface.*\n)/)
{
$topic->SetPrototype($1);
}
}
}
}
};
sub ParsePrototype
{
my ($self, $topic_type, $prototype) = @_;
$_ = $prototype;
if ($topic_type == ::TOPIC_FUNCTION and /([-+]\s*\((.*?)\)\s*)(.*)/)
{
# An Objective-C method.
my $return_type = $2;
my $p = NaturalDocs::Languages::Prototype->New ($1, "");
my $args_p = 0;
# FIXME: This doesn't work for argument types that contain commas.
# We should use a recursive-descent parser or something...
$_ = $3;
while (/(\S+)\((.*?)\)\s*(\S+)(?:(\s+(.*))?|$)/)
{
$p->AddParameter (NaturalDocs::Languages::Prototype::Parameter->New ("($2)",
$1,
$3,
undef,
undef,
undef));
$args_p = 1;
$_ = $4;
}
if ($args_p)
{
return $p;
}
else
{
return NaturalDocs::Languages::Prototype->New ($prototype, "");
}
}
elsif ($topic_type == ::TOPIC_FUNCTION and /((?:\S+\s+)?\S+\s*)\((.*)\)/)
{
# An ordinary C function.
my $p = NaturalDocs::Languages::Prototype->New ("$1 (", ")");
# FIXME: Same as the FIXME above. (It's even hairier here because
# something like “char *str” is read as a variable called “*str”
# whose type is “char”. (Actually, this isn't quite that wrong
# either, as “*str” _is_, in fact, of type char in this case -- by
# design! Still, it's hard to parse...))
$_ = $2;
while (/(.+?)\s*(\S+)\s*(?:,(.*)|$)/)
{
$p->AddParameter (NaturalDocs::Languages::Prototype::Parameter->New ($1,
undef,
$2,
undef,
undef,
undef));
$_ = $3;
}
return $p;
}
else
{
return $self->SUPER::ParsePrototype ($topic_type, $prototype);
}
};
1;
|