Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # | 1 # |
| 2 # KDOM IDL parser | 2 # KDOM IDL parser |
| 3 # | 3 # |
| 4 # Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org> | 4 # Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org> |
| 5 # | 5 # |
| 6 # This library is free software; you can redistribute it and/or | 6 # This library is free software; you can redistribute it and/or |
| 7 # modify it under the terms of the GNU Library General Public | 7 # modify it under the terms of the GNU Library General Public |
| 8 # License as published by the Free Software Foundation; either | 8 # License as published by the Free Software Foundation; either |
| 9 # version 2 of the License, or (at your option) any later version. | 9 # version 2 of the License, or (at your option) any later version. |
| 10 # | 10 # |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 use constant StringToken => 0; | 29 use constant StringToken => 0; |
| 30 use constant IntegerToken => 1; | 30 use constant IntegerToken => 1; |
| 31 use constant FloatToken => 2; | 31 use constant FloatToken => 2; |
| 32 use constant IdentifierToken => 3; | 32 use constant IdentifierToken => 3; |
| 33 use constant OtherToken => 4; | 33 use constant OtherToken => 4; |
| 34 use constant EmptyToken => 5; | 34 use constant EmptyToken => 5; |
| 35 | 35 |
| 36 # Used to represent a parsed IDL document | 36 # Used to represent a parsed IDL document |
| 37 struct( idlDocument => { | 37 struct( idlDocument => { |
| 38 fileName => '$', # file name | |
| 39 callbackFunctions => '@', | |
| 40 enumerations => '@', # All parsed enumerations | |
| 38 interfaces => '@', # All parsed interfaces | 41 interfaces => '@', # All parsed interfaces |
| 39 enumerations => '@', # All parsed enumerations | 42 }); |
| 40 fileName => '$', # file name | 43 |
| 44 struct( CallbackFunction => { | |
|
haraken
2013/06/10 09:11:03
Nit: CallbackFunction => callbackFunction
| |
| 45 name => '$', | |
| 46 returnType => '$', | |
|
haraken
2013/06/10 09:11:03
Nit: Use 'type' for consistency with other data st
| |
| 47 arguments => '@', | |
|
haraken
2013/06/10 09:11:03
Nit: Use 'parameters' for consistency with other d
| |
| 41 }); | 48 }); |
| 42 | 49 |
| 43 # Used to represent 'interface' blocks | 50 # Used to represent 'interface' blocks |
| 44 struct( domInterface => { | 51 struct( domInterface => { |
| 45 name => '$', # Class identifier | 52 name => '$', # Class identifier |
| 46 parents => '@', # List of strings | 53 parents => '@', # List of strings |
| 47 constants => '@', # List of 'domConstant' | 54 constants => '@', # List of 'domConstant' |
| 48 functions => '@', # List of 'domFunction' | 55 functions => '@', # List of 'domFunction' |
| 49 attributes => '@', # List of 'domAttribute' | 56 attributes => '@', # List of 'domAttribute' |
| 50 extendedAttributes => '$', # Extended attributes | 57 extendedAttributes => '$', # Extended attributes |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 }; | 208 }; |
| 202 die $@ . " in $fileName" if $@; | 209 die $@ . " in $fileName" if $@; |
| 203 | 210 |
| 204 my $document = idlDocument->new(); | 211 my $document = idlDocument->new(); |
| 205 $document->fileName($fileName); | 212 $document->fileName($fileName); |
| 206 foreach my $definition (@definitions) { | 213 foreach my $definition (@definitions) { |
| 207 if (ref($definition) eq "domInterface") { | 214 if (ref($definition) eq "domInterface") { |
| 208 push(@{$document->interfaces}, $definition); | 215 push(@{$document->interfaces}, $definition); |
| 209 } elsif (ref($definition) eq "domEnum") { | 216 } elsif (ref($definition) eq "domEnum") { |
| 210 push(@{$document->enumerations}, $definition); | 217 push(@{$document->enumerations}, $definition); |
| 218 } elsif (ref($definition) eq "CallbackFunction") { | |
| 219 push(@{$document->callbackFunctions}, $definition); | |
| 211 } else { | 220 } else { |
| 212 die "Unrecognized IDL definition kind: \"" . ref($definition) . "\"" ; | 221 die "Unrecognized IDL definition kind: \"" . ref($definition) . "\"" ; |
| 213 } | 222 } |
| 214 } | 223 } |
| 215 return $document; | 224 return $document; |
| 216 } | 225 } |
| 217 | 226 |
| 218 sub nextToken | 227 sub nextToken |
| 219 { | 228 { |
| 220 my $self = shift; | 229 my $self = shift; |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 return \@values; # empty list (end of enumeration-values) | 812 return \@values; # empty list (end of enumeration-values) |
| 804 } | 813 } |
| 805 | 814 |
| 806 sub parseCallbackRest | 815 sub parseCallbackRest |
| 807 { | 816 { |
| 808 my $self = shift; | 817 my $self = shift; |
| 809 my $extendedAttributeList = shift; | 818 my $extendedAttributeList = shift; |
| 810 | 819 |
| 811 my $next = $self->nextToken(); | 820 my $next = $self->nextToken(); |
| 812 if ($next->type() == IdentifierToken) { | 821 if ($next->type() == IdentifierToken) { |
| 813 $self->assertTokenType($self->getToken(), IdentifierToken); | 822 my $callback = CallbackFunction->new(); |
| 823 my $name = $self->getToken(); | |
| 824 $self->assertTokenType($name, IdentifierToken); | |
| 825 $callback->name($name->value()); | |
| 814 $self->assertTokenValue($self->getToken(), "=", __LINE__); | 826 $self->assertTokenValue($self->getToken(), "=", __LINE__); |
| 815 $self->parseReturnType(); | 827 $callback->returnType($self->parseReturnType()); |
| 816 $self->assertTokenValue($self->getToken(), "(", __LINE__); | 828 $self->assertTokenValue($self->getToken(), "(", __LINE__); |
| 817 $self->parseArgumentList(); | 829 $callback->arguments($self->parseArgumentList()); |
| 818 $self->assertTokenValue($self->getToken(), ")", __LINE__); | 830 $self->assertTokenValue($self->getToken(), ")", __LINE__); |
| 819 $self->assertTokenValue($self->getToken(), ";", __LINE__); | 831 $self->assertTokenValue($self->getToken(), ";", __LINE__); |
| 820 return; | 832 return $callback; |
| 821 } | 833 } |
| 822 $self->assertUnexpectedToken($next->value(), __LINE__); | 834 $self->assertUnexpectedToken($next->value(), __LINE__); |
| 823 } | 835 } |
| 824 | 836 |
| 825 sub parseTypedef | 837 sub parseTypedef |
| 826 { | 838 { |
| 827 my $self = shift; | 839 my $self = shift; |
| 828 my $extendedAttributeList = shift; | 840 my $extendedAttributeList = shift; |
| 829 die "Extended attributes are not applicable to typedefs themselves: " . $sel f->{Line} if %{$extendedAttributeList}; | 841 die "Extended attributes are not applicable to typedefs themselves: " . $sel f->{Line} if %{$extendedAttributeList}; |
| 830 | 842 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1331 { | 1343 { |
| 1332 my $self = shift; | 1344 my $self = shift; |
| 1333 my $extendedAttributeList = shift; | 1345 my $extendedAttributeList = shift; |
| 1334 | 1346 |
| 1335 my $next = $self->nextToken(); | 1347 my $next = $self->nextToken(); |
| 1336 if ($next->type() == IdentifierToken || $next->value() eq "(") { | 1348 if ($next->type() == IdentifierToken || $next->value() eq "(") { |
| 1337 my $newDataNode = domFunction->new(); | 1349 my $newDataNode = domFunction->new(); |
| 1338 $newDataNode->signature(domSignature->new()); | 1350 $newDataNode->signature(domSignature->new()); |
| 1339 my $name = $self->parseOptionalIdentifier(); | 1351 my $name = $self->parseOptionalIdentifier(); |
| 1340 $newDataNode->signature->name($name); | 1352 $newDataNode->signature->name($name); |
| 1341 $self->assertTokenValue($self->getToken(), "(", $name, __LINE__); | 1353 $self->assertTokenValue($self->getToken(), "(", __LINE__); |
| 1342 push(@{$newDataNode->parameters}, @{$self->parseArgumentList()}); | 1354 push(@{$newDataNode->parameters}, @{$self->parseArgumentList()}); |
| 1343 $self->assertTokenValue($self->getToken(), ")", __LINE__); | 1355 $self->assertTokenValue($self->getToken(), ")", __LINE__); |
| 1344 $self->assertTokenValue($self->getToken(), ";", __LINE__); | 1356 $self->assertTokenValue($self->getToken(), ";", __LINE__); |
| 1345 $newDataNode->signature->extendedAttributes($extendedAttributeList); | 1357 $newDataNode->signature->extendedAttributes($extendedAttributeList); |
| 1346 return $newDataNode; | 1358 return $newDataNode; |
| 1347 } | 1359 } |
| 1348 $self->assertUnexpectedToken($next->value(), __LINE__); | 1360 $self->assertUnexpectedToken($next->value(), __LINE__); |
| 1349 } | 1361 } |
| 1350 | 1362 |
| 1351 sub parseOptionalIdentifier | 1363 sub parseOptionalIdentifier |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2225 $customConstructor->{overloadedIndex} = $index++; | 2237 $customConstructor->{overloadedIndex} = $index++; |
| 2226 push(@{$interface->customConstructors}, $customConstructor); | 2238 push(@{$interface->customConstructors}, $customConstructor); |
| 2227 } | 2239 } |
| 2228 delete $extendedAttributeList->{"CustomConstructors"}; | 2240 delete $extendedAttributeList->{"CustomConstructors"}; |
| 2229 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; | 2241 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; |
| 2230 } | 2242 } |
| 2231 $interface->extendedAttributes($extendedAttributeList); | 2243 $interface->extendedAttributes($extendedAttributeList); |
| 2232 } | 2244 } |
| 2233 | 2245 |
| 2234 1; | 2246 1; |
| OLD | NEW |