OLD | NEW |
1 # | 1 # |
2 # WebKit IDL parser | 2 # WebKit IDL parser |
3 # | 3 # |
4 # Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org> | 4 # Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org> |
5 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> | 5 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> |
6 # Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 6 # Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> | 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> |
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. | 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. |
9 # | 9 # |
10 # This library is free software; you can redistribute it and/or | 10 # This library is free software; you can redistribute it and/or |
11 # modify it under the terms of the GNU Library General Public | 11 # modify it under the terms of the GNU Library General Public |
12 # License as published by the Free Software Foundation; either | 12 # License as published by the Free Software Foundation; either |
13 # version 2 of the License, or (at your option) any later version. | 13 # version 2 of the License, or (at your option) any later version. |
14 # | 14 # |
15 # This library is distributed in the hope that it will be useful, | 15 # This library is distributed in the hope that it will be useful, |
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 # Library General Public License for more details. | 18 # Library General Public License for more details. |
19 # | 19 # |
20 # You should have received a copy of the GNU Library General Public License | 20 # You should have received a copy of the GNU Library General Public License |
21 # along with this library; see the file COPYING.LIB. If not, write to | 21 # along with this library; see the file COPYING.LIB. If not, write to |
22 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 # Boston, MA 02110-1301, USA. | 23 # Boston, MA 02110-1301, USA. |
24 # | 24 # |
25 | 25 |
26 package CodeGenerator; | 26 package CodeGenerator; |
27 | 27 |
28 use strict; | 28 use strict; |
29 | 29 |
| 30 use File::Basename; |
30 use File::Find; | 31 use File::Find; |
31 | 32 |
32 my $useDocument = ""; | 33 my $useDocument = ""; |
33 my $useOutputDir = ""; | 34 my $useOutputDir = ""; |
34 my $useOutputHeadersDir = ""; | 35 my $useOutputHeadersDir = ""; |
35 my $useDirectories = ""; | 36 my $useDirectories = ""; |
36 my $preprocessor; | 37 my $preprocessor; |
37 my $defines = ""; | 38 my $defines = ""; |
38 my $verbose = 0; | 39 my $verbose = 0; |
39 | 40 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 foreach my $function (@{$currentInterface->functions}) { | 236 foreach my $function (@{$currentInterface->functions}) { |
236 if ($function->signature->name eq $functionName) { | 237 if ($function->signature->name eq $functionName) { |
237 $indexer = $function->signature; | 238 $indexer = $function->signature; |
238 return 'prune'; | 239 return 'prune'; |
239 } | 240 } |
240 } | 241 } |
241 }); | 242 }); |
242 return $indexer; | 243 return $indexer; |
243 } | 244 } |
244 | 245 |
245 sub IDLFileForInterface | 246 sub PopulateIDLFiles { |
246 { | |
247 my $object = shift; | 247 my $object = shift; |
248 my $interfaceName = shift; | |
249 | 248 |
250 unless ($idlFiles) { | 249 unless ($idlFiles) { |
251 my $sourceRoot = $ENV{SOURCE_ROOT}; | 250 my $sourceRoot = $ENV{SOURCE_ROOT}; |
252 my @directories = map { $_ = "$sourceRoot/$_" if $sourceRoot && -d "$sou
rceRoot/$_"; $_ } @$useDirectories; | 251 my @directories = map { $_ = "$sourceRoot/$_" if $sourceRoot && -d "$sou
rceRoot/$_"; $_ } @$useDirectories; |
253 push(@directories, "."); | 252 push(@directories, "."); |
254 | 253 |
255 $idlFiles = { }; | 254 $idlFiles = { }; |
256 | 255 |
257 my $wanted = sub { | 256 my $wanted = sub { |
258 $idlFiles->{$1} = $File::Find::name if /^([A-Z].*)\.idl$/; | 257 $idlFiles->{$1} = $File::Find::name if /^([A-Z].*)\.idl$/; |
259 $File::Find::prune = 1 if /^\../; | 258 $File::Find::prune = 1 if /^\../; |
260 }; | 259 }; |
261 find($wanted, @directories); | 260 find($wanted, @directories); |
262 } | 261 } |
| 262 } |
| 263 |
| 264 # As per Web IDL specification, for each interface that is a non-callback interf
ace that is |
| 265 # not declared with the [NoInterfaceObject] extended attribute, a corresponding
property must |
| 266 # exist on the ECMAScript global object. |
| 267 sub GenerateDOMWindowConstructorAttributes |
| 268 { |
| 269 my $object = shift; |
| 270 |
| 271 $object->PopulateIDLFiles(); |
| 272 |
| 273 my @normalAttributes; |
| 274 my @enabledAtRuntimeAttributes; |
| 275 my @enabledPerContextAttributes; |
| 276 |
| 277 foreach my $idlFile (values $idlFiles) { |
| 278 my $interfaceName = fileparse(basename($idlFile), ".idl"); |
| 279 # Ignore test IDL files. |
| 280 next if $interfaceName =~ /^Test/; |
| 281 |
| 282 # Optimization: we avoid full Web IDL parsing since we are merely intere
sted |
| 283 # in the interface / exception's extended attributes. |
| 284 my $parser = IDLParser->new(1); |
| 285 my $extendedAttributes = $parser->ParseOnlyExtendedAttributes($idlFile,
$defines, $preprocessor); |
| 286 |
| 287 next if ($extendedAttributes->{"NoInterfaceObject"} || $extendedAttribut
es->{"Callback"}); |
| 288 |
| 289 my $attribute = domAttribute->new(); |
| 290 $attribute->type("attribute"); |
| 291 $attribute->signature(domSignature->new()); |
| 292 $attribute->signature->type("${interfaceName}Constructor"); |
| 293 |
| 294 if ($extendedAttributes->{"InterfaceName"}) { |
| 295 $attribute->signature->name($extendedAttributes->{"InterfaceName"}); |
| 296 } else { |
| 297 $attribute->signature->name($interfaceName); |
| 298 } |
| 299 |
| 300 # In addition to the regular property, for every [NamedConstructor] exte
nded attribute on an interface, |
| 301 # a corresponding property MUST exist on the ECMAScript global object. |
| 302 my $namedConstructorAttribute; |
| 303 if ($extendedAttributes->{"NamedConstructor"}) { |
| 304 $namedConstructorAttribute = domAttribute->new(); |
| 305 $namedConstructorAttribute->type("attribute"); |
| 306 $namedConstructorAttribute->signature(domSignature->new()); |
| 307 $namedConstructorAttribute->signature->type("${interfaceName}Constru
ctorConstructor"); |
| 308 my $constructorName = (keys $extendedAttributes->{"NamedConstructor"
})[0]; |
| 309 $namedConstructorAttribute->signature->name($constructorName); |
| 310 } |
| 311 |
| 312 my $attrExtendedAttributeList = {}; |
| 313 if ($extendedAttributes->{"Conditional"}) { |
| 314 $attrExtendedAttributeList->{"Conditional"} = $extendedAttributes->{
"Conditional"}; |
| 315 } |
| 316 if ($extendedAttributes->{"EnabledAtRuntime"}) { |
| 317 $attrExtendedAttributeList->{"EnabledAtRuntime"} = $extendedAttribut
es->{"EnabledAtRuntime"}; |
| 318 push(@enabledAtRuntimeAttributes, $attribute); |
| 319 push(@enabledAtRuntimeAttributes, $namedConstructorAttribute) if $na
medConstructorAttribute; |
| 320 } elsif ($extendedAttributes->{"EnabledPerContext"}) { |
| 321 $attrExtendedAttributeList->{"EnabledPerContext"} = $extendedAttribu
tes->{"EnabledPerContext"}; |
| 322 push(@enabledPerContextAttributes, $attribute); |
| 323 push(@enabledPerContextAttributes, $namedConstructorAttribute) if $n
amedConstructorAttribute; |
| 324 } else { |
| 325 push(@normalAttributes, $attribute); |
| 326 push(@normalAttributes, $namedConstructorAttribute) if $namedConstru
ctorAttribute; |
| 327 } |
| 328 $attribute->signature->extendedAttributes($attrExtendedAttributeList); |
| 329 $namedConstructorAttribute->signature->extendedAttributes($attrExtendedA
ttributeList) if $namedConstructorAttribute; |
| 330 } |
| 331 |
| 332 return (\@normalAttributes, \@enabledAtRuntimeAttributes, \@enabledPerContex
tAttributes); |
| 333 } |
| 334 |
| 335 sub IDLFileForInterface |
| 336 { |
| 337 my $object = shift; |
| 338 my $interfaceName = shift; |
| 339 |
| 340 $object->PopulateIDLFiles(); |
263 | 341 |
264 return $idlFiles->{$interfaceName}; | 342 return $idlFiles->{$interfaceName}; |
265 } | 343 } |
266 | 344 |
267 sub ParseInterface | 345 sub ParseInterface |
268 { | 346 { |
269 my $object = shift; | 347 my $object = shift; |
270 my $interfaceName = shift; | 348 my $interfaceName = shift; |
271 | 349 |
272 return undef if $interfaceName eq 'Object'; | 350 return undef if $interfaceName eq 'Object'; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { | 840 if ($currentInterface->extendedAttributes->{$extendedAttribute}) { |
763 $found = 1; | 841 $found = 1; |
764 } | 842 } |
765 return 1 if $found; | 843 return 1 if $found; |
766 }, 0); | 844 }, 0); |
767 | 845 |
768 return $found; | 846 return $found; |
769 } | 847 } |
770 | 848 |
771 1; | 849 1; |
OLD | NEW |