| OLD | NEW |
| 1 #!/usr/bin/perl -w | 1 #!/usr/bin/perl -w -I../../core/scripts |
| 2 # | 2 # |
| 3 # Copyright (C) 2005 Apple Computer, Inc. | 3 # Copyright (C) 2005 Apple Computer, Inc. |
| 4 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> | 4 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> |
| 5 # | 5 # |
| 6 # This file is part of WebKit | 6 # This file is part of WebKit |
| 7 # | 7 # |
| 8 # This library is free software; you can redistribute it and/or | 8 # This library is free software; you can redistribute it and/or |
| 9 # modify it under the terms of the GNU Library General Public | 9 # modify it under the terms of the GNU Library General Public |
| 10 # License as published by the Free Software Foundation; either | 10 # License as published by the Free Software Foundation; either |
| 11 # version 2 of the License, or (at your option) any later version. | 11 # version 2 of the License, or (at your option) any later version. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 use strict; | 31 use strict; |
| 32 | 32 |
| 33 use File::Path; | 33 use File::Path; |
| 34 use File::Basename; | 34 use File::Basename; |
| 35 use Getopt::Long; | 35 use Getopt::Long; |
| 36 use Text::ParseWords; | 36 use Text::ParseWords; |
| 37 use Cwd; | 37 use Cwd; |
| 38 | 38 |
| 39 use IDLParser; | 39 use IDLParser; |
| 40 use CodeGeneratorV8; | 40 use CodeGeneratorV8; |
| 41 use SemanticAnalyzer; |
| 41 | 42 |
| 42 my @idlDirectories; | 43 my @idlDirectories; |
| 43 my $outputDirectory; | 44 my $outputDirectory; |
| 44 my $outputHeadersDirectory; | 45 my $outputHeadersDirectory; |
| 45 my $defines; | 46 my $defines; |
| 46 my $filename; | 47 my $filename; |
| 47 my $preprocessor; | 48 my $preprocessor; |
| 48 my $verbose; | 49 my $verbose; |
| 49 my $supplementalDependencyFile; | 50 my $supplementalDependencyFile; |
| 50 my $additionalIdlFiles; | 51 my $additionalIdlFiles; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 generateEmptyHeaderAndCpp($targetInterfaceName, $outputHeadersDirectory,
$outputDirectory); | 115 generateEmptyHeaderAndCpp($targetInterfaceName, $outputHeadersDirectory,
$outputDirectory); |
| 115 exit 0; | 116 exit 0; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 # Parse the target IDL file. | 120 # Parse the target IDL file. |
| 120 my $targetParser = IDLParser->new(!$verbose); | 121 my $targetParser = IDLParser->new(!$verbose); |
| 121 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso
r); | 122 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso
r); |
| 122 | 123 |
| 123 if ($idlAttributesFile) { | 124 if ($idlAttributesFile) { |
| 124 my $idlAttributes = loadIDLAttributes($idlAttributesFile); | 125 my $semanticAnalyzer = SemanticAnalyzer->new($idlAttributesFile); |
| 125 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile)
); | 126 $semanticAnalyzer->checkIDLAttributes($targetDocument, basename($targetIdlFi
le)); |
| 126 } | 127 } |
| 127 | 128 |
| 128 foreach my $idlFile (@supplementedIdlFiles) { | 129 foreach my $idlFile (@supplementedIdlFiles) { |
| 129 next if $idlFile eq $targetIdlFile; | 130 next if $idlFile eq $targetIdlFile; |
| 130 | 131 |
| 131 my $interfaceName = fileparse(basename($idlFile), ".idl"); | 132 my $interfaceName = fileparse(basename($idlFile), ".idl"); |
| 132 my $parser = IDLParser->new(!$verbose); | 133 my $parser = IDLParser->new(!$verbose); |
| 133 my $document = $parser->Parse($idlFile, $defines, $preprocessor); | 134 my $document = $parser->Parse($idlFile, $defines, $preprocessor); |
| 134 | 135 |
| 135 foreach my $interface (@{$document->interfaces}) { | 136 foreach my $interface (@{$document->interfaces}) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 */ | 209 */ |
| 209 "; | 210 "; |
| 210 open FH, "> ${outputHeadersDirectory}/${headerName}" or die "Cannot open $he
aderName\n"; | 211 open FH, "> ${outputHeadersDirectory}/${headerName}" or die "Cannot open $he
aderName\n"; |
| 211 print FH $contents; | 212 print FH $contents; |
| 212 close FH; | 213 close FH; |
| 213 | 214 |
| 214 open FH, "> ${outputDirectory}/${cppName}" or die "Cannot open $cppName\n"; | 215 open FH, "> ${outputDirectory}/${cppName}" or die "Cannot open $cppName\n"; |
| 215 print FH $contents; | 216 print FH $contents; |
| 216 close FH; | 217 close FH; |
| 217 } | 218 } |
| 218 | |
| 219 sub loadIDLAttributes | |
| 220 { | |
| 221 my $idlAttributesFile = shift; | |
| 222 | |
| 223 my %idlAttributes; | |
| 224 open FH, "<", $idlAttributesFile or die "Couldn't open $idlAttributesFile: $
!"; | |
| 225 while (my $line = <FH>) { | |
| 226 chomp $line; | |
| 227 next if $line =~ /^\s*#/; | |
| 228 next if $line =~ /^\s*$/; | |
| 229 | |
| 230 if ($line =~ /^\s*([^=\s]*)\s*=?\s*(.*)/) { | |
| 231 my $name = $1; | |
| 232 $idlAttributes{$name} = {}; | |
| 233 if ($2) { | |
| 234 foreach my $rightValue (split /\|/, $2) { | |
| 235 $rightValue =~ s/^\s*|\s*$//g; | |
| 236 $rightValue = "VALUE_IS_MISSING" unless $rightValue; | |
| 237 $idlAttributes{$name}{$rightValue} = 1; | |
| 238 } | |
| 239 } else { | |
| 240 $idlAttributes{$name}{"VALUE_IS_MISSING"} = 1; | |
| 241 } | |
| 242 } else { | |
| 243 die "The format of " . basename($idlAttributesFile) . " is wrong: li
ne $.\n"; | |
| 244 } | |
| 245 } | |
| 246 close FH; | |
| 247 | |
| 248 return \%idlAttributes; | |
| 249 } | |
| 250 | |
| 251 sub checkIDLAttributes | |
| 252 { | |
| 253 my $idlAttributes = shift; | |
| 254 my $document = shift; | |
| 255 my $idlFile = shift; | |
| 256 | |
| 257 foreach my $interface (@{$document->interfaces}) { | |
| 258 checkIfIDLAttributesExists($idlAttributes, $interface->extendedAttribute
s, $idlFile); | |
| 259 | |
| 260 foreach my $attribute (@{$interface->attributes}) { | |
| 261 checkIfIDLAttributesExists($idlAttributes, $attribute->signature->ex
tendedAttributes, $idlFile); | |
| 262 } | |
| 263 | |
| 264 foreach my $function (@{$interface->functions}) { | |
| 265 checkIfIDLAttributesExists($idlAttributes, $function->signature->ext
endedAttributes, $idlFile); | |
| 266 foreach my $parameter (@{$function->parameters}) { | |
| 267 checkIfIDLAttributesExists($idlAttributes, $parameter->extendedA
ttributes, $idlFile); | |
| 268 } | |
| 269 } | |
| 270 } | |
| 271 } | |
| 272 | |
| 273 sub checkIfIDLAttributesExists | |
| 274 { | |
| 275 my $idlAttributes = shift; | |
| 276 my $extendedAttributes = shift; | |
| 277 my $idlFile = shift; | |
| 278 | |
| 279 my $error; | |
| 280 OUTER: for my $name (keys %$extendedAttributes) { | |
| 281 if (!exists $idlAttributes->{$name}) { | |
| 282 $error = "Unknown IDL attribute [$name] is found at $idlFile."; | |
| 283 last OUTER; | |
| 284 } | |
| 285 if ($idlAttributes->{$name}{"*"}) { | |
| 286 next; | |
| 287 } | |
| 288 for my $rightValue (split /\s*\|\s*/, $extendedAttributes->{$name}) { | |
| 289 if (!exists $idlAttributes->{$name}{$rightValue}) { | |
| 290 $error = "Unknown IDL attribute [$name=" . $extendedAttributes->
{$name} . "] is found at $idlFile."; | |
| 291 last OUTER; | |
| 292 } | |
| 293 } | |
| 294 } | |
| 295 if ($error) { | |
| 296 die "IDL ATTRIBUTE CHECKER ERROR: $error | |
| 297 If you want to add a new IDL attribute, you need to add it to bindings/scripts/I
DLAttributes.txt and add explanations to the Blink IDL document (http://chromium
.org/blink/webidl). | |
| 298 "; | |
| 299 } | |
| 300 } | |
| OLD | NEW |