| 1 | |||
| 2 | package CORBA::XPIDL::CheckVisitor; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | our $VERSION = '0.20'; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $proto = shift; | ||
| 11 | my $class = ref($proto) || $proto; | ||
| 12 | my $self = {}; | ||
| 13 | bless $self, $class; | ||
| 14 | my ($parser, $typelib, $mode) = @_; | ||
| 15 | $self->{symbtab} = $parser->YYData->{symbtab}; | ||
| 16 | $self->{typelib} = $typelib; | ||
| 17 | $self->{mode} = $mode; | ||
| 18 | $self->{parser} = $parser; | ||
| 19 | $self->{num_key} = 'check_xp'; | ||
| 20 | return $self; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub _get_defn { | ||
| 24 | my $self = shift; | ||
| 25 | my ($defn) = @_; | ||
| 26 | if (ref $defn) { | ||
| 27 | return $defn; | ||
| 28 | } | ||
| 29 | else { | ||
| 30 | return $self->{symbtab}->Lookup($defn); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | sub _get_effective_type { | ||
| 35 | my $self = shift; | ||
| 36 | my ($type) = @_; | ||
| 37 | $type = $self->_get_defn($type); | ||
| 38 | # while ( $type->isa('TypeDeclarator') | ||
| 39 | # and ! exists $type->{array_size} ) { | ||
| 40 | while ($type->isa('TypeDeclarator')) { | ||
| 41 | $type = $self->_get_defn($type->{type}); | ||
| 42 | } | ||
| 43 | return $type; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub _verify_type_fits_version { | ||
| 47 | my $self = shift; | ||
| 48 | my ($type, $node) = @_; | ||
| 49 | |||
| 50 | if ($self->{typelib} eq '1.1') { | ||
| 51 | # XPIDL Version 1.1 checks | ||
| 52 | |||
| 53 | # utf8string, cstring, and astring types are not supported | ||
| 54 | if ( $type->hasProperty('utf8string') | ||
| 55 | or $type->hasProperty('cstring') | ||
| 56 | or $type->hasProperty('astring') ) { | ||
| 57 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 58 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 59 | $self->{parser}->Error( | ||
| 60 | "Cannot use [utf8string], [cstring] and [astring] " . | ||
| 61 | "types when generating version 1.1 typelibs.\n" | ||
| 62 | ); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _check_param_attribute { | ||
| 68 | my $self = shift; | ||
| 69 | my ($method, $param, $label) = @_; | ||
| 70 | my $prop = $param->getProperty($label); | ||
| 71 | return unless (defined $prop); | ||
| 72 | $self->{parser}->YYData->{filename} = $method->{filename}; | ||
| 73 | $self->{parser}->YYData->{lineno} = $method->{lineno}; | ||
| 74 | foreach (@{$method->{list_param}}) { | ||
| 75 | if ($_->{idf} eq $prop) { | ||
| 76 | if ($param == $_) { | ||
| 77 | $self->{parser}->Error( | ||
| 78 | "attribute [$label($prop)] refers to it's own parameter.\n" | ||
| 79 | ); | ||
| 80 | } | ||
| 81 | my $type = $self->_get_defn($_->{type}); | ||
| 82 | if ($label eq 'iid_is') { | ||
| 83 | # require IID type | ||
| 84 | unless ($type->hasProperty('nsid')) { | ||
| 85 | $self->{parser}->Error( | ||
| 86 | "target \"$prop\" of [$label($prop)] attribute " . | ||
| 87 | "must be of IID type.\n" | ||
| 88 | ); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | elsif ($label eq 'size_is' or $label eq 'length_is') { | ||
| 92 | # require PRUint32 type | ||
| 93 | $type = $self->_get_effective_type($type); | ||
| 94 | unless ($type->isa('IntegerType') and $type->{value} eq 'unsigned long') { | ||
| 95 | $self->{parser}->Error( | ||
| 96 | "target \"$prop\" of [$label($prop)] attribute " . | ||
| 97 | "must be of unsigned long (or PRUint32) type.\n" | ||
| 98 | ); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | $self->{parser}->Error( | ||
| 105 | "attribute [$label($prop)] refers to missing " . | ||
| 106 | "parameter \"$prop\".\n" | ||
| 107 | ); | ||
| 108 | } | ||
| 109 | |||
| 110 | # | ||
| 111 | # 3.5 OMG IDL Specification | ||
| 112 | # | ||
| 113 | |||
| 114 | sub visitSpecification { | ||
| 115 | my $self = shift; | ||
| 116 | my ($node) = @_; | ||
| 117 | foreach (@{$node->{list_decl}}) { | ||
| 118 | $self->_get_defn($_)->visit($self, $node); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | # | ||
| 123 | # 3.7 Module Declaration | ||
| 124 | # | ||
| 125 | |||
| 126 | sub visitModules { | ||
| 127 | my $self = shift; | ||
| 128 | my ($node) = @_; | ||
| 129 | unless (exists $node->{$self->{num_key}}) { | ||
| 130 | $node->{$self->{num_key}} = 0; | ||
| 131 | } | ||
| 132 | my $module = ${$node->{list_decl}}[$node->{$self->{num_key}}]; | ||
| 133 | $module->visit($self); | ||
| 134 | $node->{$self->{num_key}} ++; | ||
| 135 | } | ||
| 136 | |||
| 137 | sub visitModule { | ||
| 138 | my $self = shift; | ||
| 139 | my ($node) = @_; | ||
| 140 | foreach (@{$node->{list_decl}}) { | ||
| 141 | $self->_get_defn($_)->visit($self, $node); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | # | ||
| 146 | # 3.8 Interface Declaration | ||
| 147 | # | ||
| 148 | |||
| 149 | sub visitRegularInterface { | ||
| 150 | my $self = shift; | ||
| 151 | my ($node) = @_; | ||
| 152 | |||
| 153 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 154 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 155 | my $iid = $node->getProperty('uuid'); | ||
| 156 | if (defined $iid) { | ||
| 157 | if (length($iid) == 36) { | ||
| 158 | $self->{parser}->Error("cannot parse IID $iid.\n") | ||
| 159 | unless ($iid =~ /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/); | ||
| 160 | } | ||
| 161 | else { | ||
| 162 | $self->{parser}->Error("IID $iid is the wrong length.\n"); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | else { | ||
| 166 | unless ($self->{mode} eq 'java') { | ||
| 167 | $self->{parser}->Error( | ||
| 168 | "interface '$node->{idf}' lacks a uuid attribute.\n" | ||
| 169 | ); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | if (exists $node->{inheritance}) { | ||
| 174 | unless (scalar(@{$node->{inheritance}->{list_interface}}) == 1) { | ||
| 175 | unless ($self->{mode} eq 'java') { | ||
| 176 | $self->{parser}->Error( | ||
| 177 | "multiple inheritance is not supported by xpidl.\n" | ||
| 178 | ); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | # If we have the scriptable attribute then make sure all of our direct | ||
| 183 | # parents have it as well. | ||
| 184 | # NOTE: We don't recurse since all interfaces will fall through here | ||
| 185 | if ($node->hasProperty('scriptable')) { | ||
| 186 | foreach (@{$node->{inheritance}->{list_interface}}) { | ||
| 187 | my $base = $self->_get_defn($_); | ||
| 188 | unless ($base->hasProperty('scriptable')) { | ||
| 189 | $self->{parser}->Warning( | ||
| 190 | "'$node->{idf}' is scriptable but inherits from " . | ||
| 191 | "the non-scriptable interface '$base->{idf}'.\n" | ||
| 192 | ); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | foreach (@{$node->{list_decl}}) { | ||
| 199 | $self->_get_defn($_)->visit($self, $node); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | sub visitAbstractInterface { | ||
| 204 | my $self = shift; | ||
| 205 | my ($node) = @_; | ||
| 206 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 207 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 208 | $self->{parser}->Error("abstract interface not supported.\n"); | ||
| 209 | } | ||
| 210 | |||
| 211 | sub visitLocalInterface { | ||
| 212 | my $self = shift; | ||
| 213 | my ($node) = @_; | ||
| 214 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 215 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 216 | $self->{parser}->Error("local interface not supported.\n"); | ||
| 217 | } | ||
| 218 | |||
| 219 | sub visitForwardRegularInterface { | ||
| 220 | # empty | ||
| 221 | } | ||
| 222 | |||
| 223 | sub visitForwardAbstractInterface { | ||
| 224 | shift->visitAbstractInterface(@_); | ||
| 225 | } | ||
| 226 | |||
| 227 | sub visitForwardLocalInterface { | ||
| 228 | shift->visitLocalInterface(@_); | ||
| 229 | } | ||
| 230 | |||
| 231 | # 3.9 Value Declaration | ||
| 232 | # | ||
| 233 | |||
| 234 | sub visitValue { | ||
| 235 | my $self = shift; | ||
| 236 | my ($node) = @_; | ||
| 237 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 238 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 239 | $self->{parser}->Error("valuetype not supported.\n"); | ||
| 240 | } | ||
| 241 | |||
| 242 | sub visitForwardValue { | ||
| 243 | # empty | ||
| 244 | } | ||
| 245 | |||
| 246 | # | ||
| 247 | # 3.10 Constant Declaration | ||
| 248 | # | ||
| 249 | |||
| 250 | sub visitConstant { | ||
| 251 | my $self = shift; | ||
| 252 | my ($node, $parent) = @_; | ||
| 253 | |||
| 254 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 255 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 256 | unless ($parent->isa('RegularInterface')) { | ||
| 257 | $self->{parser}->Error( | ||
| 258 | "const declaration '$node->{idf}' outside interface.\n" | ||
| 259 | ); | ||
| 260 | } | ||
| 261 | |||
| 262 | my $type = $self->_get_effective_type($node->{type}); | ||
| 263 | if ( ! $type->isa('IntegerType') ) { | ||
| 264 | # and ! $type->isa('CharType') | ||
| 265 | # and ! $type->isa('WideCharType') | ||
| 266 | # and ! $type->isa('OctetType') ) { | ||
| 267 | $self->{parser}->Error( | ||
| 268 | "const declaration '$node->{idf}' must be of type short or long.\n" | ||
| 269 | ); | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | sub visitExpression { | ||
| 274 | # empty | ||
| 275 | } | ||
| 276 | |||
| 277 | # | ||
| 278 | # 3.11 Type Declaration | ||
| 279 | # | ||
| 280 | |||
| 281 | sub visitTypeDeclarators { | ||
| 282 | my $self = shift; | ||
| 283 | my ($node) = @_; | ||
| 284 | |||
| 285 | my $type = $self->_get_effective_type($node->{type}); | ||
| 286 | if ($type->isa('SequenceType')) { | ||
| 287 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 288 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 289 | $self->{parser}->Warning("sequences not supported, ignored.\n"); | ||
| 290 | return; | ||
| 291 | } | ||
| 292 | |||
| 293 | foreach (@{$node->{list_decl}}) { | ||
| 294 | $self->_get_defn($_)->visit($self); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | sub visitTypeDeclarator { | ||
| 299 | my $self = shift; | ||
| 300 | my ($node) = @_; | ||
| 301 | |||
| 302 | my $type = $self->_get_defn($node->{type}); | ||
| 303 | $type->visit($self); | ||
| 304 | } | ||
| 305 | |||
| 306 | sub visitNativeType { | ||
| 307 | my $self = shift; | ||
| 308 | my ($node) = @_; | ||
| 309 | |||
| 310 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 311 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 312 | # require that native declarations give a native type | ||
| 313 | unless (exists $node->{native}) { | ||
| 314 | $self->{parser}->Error( | ||
| 315 | "``native $node->{idf};'' needs C++ type: " . | ||
| 316 | "``native $node->{idf}(<C++ type>);''\n" | ||
| 317 | ); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | # | ||
| 322 | # 3.11.1 Basic Types | ||
| 323 | # | ||
| 324 | |||
| 325 | sub visitBasicType { | ||
| 326 | # empty | ||
| 327 | } | ||
| 328 | |||
| 329 | sub visitValueBaseType { | ||
| 330 | my $self = shift; | ||
| 331 | my ($node) = @_; | ||
| 332 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 333 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 334 | $self->{parser}->Error("ValueBase not supported.\n"); | ||
| 335 | } | ||
| 336 | |||
| 337 | # | ||
| 338 | # 3.11.2 Constructed Types | ||
| 339 | # | ||
| 340 | # 3.11.2.1 Structures | ||
| 341 | # | ||
| 342 | |||
| 343 | sub visitStructType { | ||
| 344 | my $self = shift; | ||
| 345 | my ($node) = @_; | ||
| 346 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 347 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 348 | $self->{parser}->Warning("structs not supported, struct '$node->{idf}' ignored\n"); | ||
| 349 | } | ||
| 350 | |||
| 351 | # 3.11.2.2 Discriminated Unions | ||
| 352 | # | ||
| 353 | |||
| 354 | sub visitUnionType { | ||
| 355 | my $self = shift; | ||
| 356 | my ($node) = @_; | ||
| 357 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 358 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 359 | $self->{parser}->Warning("unions not supported, union '$node->{idf}' ignored\n"); | ||
| 360 | } | ||
| 361 | |||
| 362 | sub visitForwardStructType { | ||
| 363 | # empty | ||
| 364 | } | ||
| 365 | |||
| 366 | sub visitForwardUnionType { | ||
| 367 | # empty | ||
| 368 | } | ||
| 369 | |||
| 370 | # 3.11.2.4 Enumerations | ||
| 371 | # | ||
| 372 | |||
| 373 | sub visitEnumType { | ||
| 374 | my $self = shift; | ||
| 375 | my ($node) = @_; | ||
| 376 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 377 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 378 | $self->{parser}->Warning("enums not supported, enum '$node->{idf}' ignored\n"); | ||
| 379 | } | ||
| 380 | |||
| 381 | # | ||
| 382 | # 3.11.3 Template Types | ||
| 383 | # | ||
| 384 | |||
| 385 | sub visitStringType { | ||
| 386 | # empty | ||
| 387 | } | ||
| 388 | |||
| 389 | sub visitWideStringType { | ||
| 390 | # empty | ||
| 391 | } | ||
| 392 | |||
| 393 | sub visitFixedPtType { | ||
| 394 | my $self = shift; | ||
| 395 | my ($node) = @_; | ||
| 396 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 397 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 398 | $self->{parser}->Error("fixed not supported.\n"); | ||
| 399 | } | ||
| 400 | |||
| 401 | sub visitFixedPtConstType { | ||
| 402 | my $self = shift; | ||
| 403 | my ($node) = @_; | ||
| 404 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 405 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 406 | $self->{parser}->Error("fixed not supported.\n"); | ||
| 407 | } | ||
| 408 | |||
| 409 | # | ||
| 410 | # 3.12 Exception Declaration | ||
| 411 | # | ||
| 412 | |||
| 413 | sub visitException { | ||
| 414 | shift->visitStructType(@_); | ||
| 415 | } | ||
| 416 | |||
| 417 | # | ||
| 418 | # 3.13 Operation Declaration | ||
| 419 | # | ||
| 420 | |||
| 421 | sub visitOperation { | ||
| 422 | my $self = shift; | ||
| 423 | my ($node, $parent) = @_; | ||
| 424 | |||
| 425 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 426 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 427 | |||
| 428 | # We don't support attributes named IID, conflicts with static GetIID | ||
| 429 | # member. The conflict is due to certain compilers (VC++) choosing a | ||
| 430 | # different vtable order, placing GetIID at the beginning regardless | ||
| 431 | # of it's placement | ||
| 432 | if ($node->{idf} eq 'GetIID') { | ||
| 433 | $self->{parser}->Error( | ||
| 434 | "Methods named GetIID not supported, causes vtable " . | ||
| 435 | "ordering problems.\n" | ||
| 436 | ); | ||
| 437 | } | ||
| 438 | |||
| 439 | # Decide if the interface was marked [scriptable] | ||
| 440 | my $scriptable_interface = $parent->hasProperty('scriptable'); | ||
| 441 | |||
| 442 | # Require that any method in an interface marked as [scriptable], that | ||
| 443 | # *isn't* scriptable because it refers to some native type, be marked | ||
| 444 | # [noscript] or [notxpcom]. | ||
| 445 | # | ||
| 446 | # Also check that iid_is points to nsid, and length_is, size_is points | ||
| 447 | # to unsigned long. | ||
| 448 | my $notxpcom = $node->hasProperty('notxpcom'); | ||
| 449 | my $scriptable_method = $scriptable_interface && !$notxpcom && !$node->hasProperty('noscript'); | ||
| 450 | |||
| 451 | my $seen_retval; | ||
| 452 | my $last = 1; | ||
| 453 | foreach (reverse @{$node->{list_param}}) { | ||
| 454 | if ($_->isa('Ellipsis')) { | ||
| 455 | $self->{parser}->Error("varargs are not currently supported.\n"); | ||
| 456 | } | ||
| 457 | else { | ||
| 458 | my $type = $self->_get_effective_type($_->{type}); | ||
| 459 | if ($type->isa('SequenceType')) { | ||
| 460 | $self->{parser}->Error("sequences not supported.\n"); | ||
| 461 | } | ||
| 462 | |||
| 463 | # Reject this method if it should be scriptable and some parameter is | ||
| 464 | # native that isn't marked with either nsid, domstring, utf8string, | ||
| 465 | # cstring, astring or iid_is. | ||
| 466 | if ( $scriptable_method and $type->isa('NativeType') ) { | ||
| 467 | if ( ! $type->hasProperty('nsid') | ||
| 468 | and ! $_->hasProperty('iid_is') | ||
| 469 | and ! $type->hasProperty('domstring') | ||
| 470 | and ! $type->hasProperty('utf8string') | ||
| 471 | and ! $type->hasProperty('cstring') | ||
| 472 | and ! $type->hasProperty('astring') ) { | ||
| 473 | $self->{parser}->Error( | ||
| 474 | "methods in [scriptable] interfaces that are " . | ||
| 475 | "non-scriptable because they refer to native " . | ||
| 476 | "types (parameter '$_->{idf}') must be marked " . | ||
| 477 | "[noscript].\n" | ||
| 478 | ); | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | # nsid's parameters that aren't ptr's or ref's are not currently | ||
| 483 | # supported in xpcom or non-xpcom (marked with [notxpcom]) methods | ||
| 484 | # as input parameters | ||
| 485 | if ( !$notxpcom and $_->{attr} ne 'in') { | ||
| 486 | if ( $type->hasProperty('nsid') | ||
| 487 | and ! $type->hasProperty('ptr') | ||
| 488 | and ! $type->hasProperty('ref') ) { | ||
| 489 | $self->{parser}->Error( | ||
| 490 | "Feature currently not supported: " . | ||
| 491 | "parameter '$_->{idf}' is of type nsid and " . | ||
| 492 | "must be marked either [ptr] or [ref] " . | ||
| 493 | "or method '$node->{idf}' must be marked [notxpcom]" . | ||
| 494 | " and must not be an input parameter.\n" | ||
| 495 | ); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | # Sanity checks on return values. | ||
| 500 | if ($_->hasProperty('retval')) { | ||
| 501 | unless ($last) { | ||
| 502 | $self->{parser}->Error( | ||
| 503 | "only the last parameter can be marked [retval].\n" | ||
| 504 | ); | ||
| 505 | } | ||
| 506 | unless ($self->_get_defn($node->{type})->isa('VoidType')) { | ||
| 507 | $self->{parser}->Error( | ||
| 508 | "can't have [retval] with non-void return type.\n" | ||
| 509 | ); | ||
| 510 | } | ||
| 511 | # In case XPConnect relaxes the retval-is-last restriction. | ||
| 512 | if ($seen_retval) { | ||
| 513 | $self->{parser}->Error( | ||
| 514 | "can't have more than one [retval] parameter.\n" | ||
| 515 | ); | ||
| 516 | } | ||
| 517 | $seen_retval = 1; | ||
| 518 | } | ||
| 519 | |||
| 520 | # Confirm that [shared] attributes are only used with string, wstring, | ||
| 521 | # or native (but not nsid, domstring, utf8string, cstring or astring) | ||
| 522 | # and can't be used with [array]. | ||
| 523 | if ($_->hasProperty('shared')) { | ||
| 524 | if ($_->hasProperty('array')) { | ||
| 525 | $self->{parser}->Error( | ||
| 526 | "[shared] parameter '$_->{idf}' cannot " . | ||
| 527 | "be of array type.\n" | ||
| 528 | ); | ||
| 529 | } | ||
| 530 | |||
| 531 | unless ( $type->isa('StringType') | ||
| 532 | or $type->isa('WideStringType') | ||
| 533 | or ( $type->isa('NativeType') | ||
| 534 | and ! $type->hasProperty('nsid') | ||
| 535 | and ! $type->hasProperty('domstring') | ||
| 536 | and ! $type->hasProperty('utf8string') | ||
| 537 | and ! $type->hasProperty('cstring') | ||
| 538 | and ! $type->hasProperty('astring') ) ) { | ||
| 539 | $self->{parser}->Error( | ||
| 540 | "[shared] parameter '$_->{idf}' must be of type " . | ||
| 541 | "string, wstring or native.\n" | ||
| 542 | ); | ||
| 543 | } | ||
| 544 | } | ||
| 545 | |||
| 546 | # inout is not allowed with "domstring", "UTF8String", "CString" | ||
| 547 | # and "AString" types | ||
| 548 | if ( $_->{attr} eq 'inout' and $type->isa('NativeType') ) { | ||
| 549 | if ( $type->hasProperty('domstring') | ||
| 550 | or $type->hasProperty('utf8string') | ||
| 551 | or $type->hasProperty('cstring') | ||
| 552 | or $type->hasProperty('astring') ) { | ||
| 553 | $self->{parser}->Error( | ||
| 554 | "[domstring], [utf8string], [cstring], [astring] " . | ||
| 555 | "types cannot be used as inout parameters" | ||
| 556 | ); | ||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | # arrays of domstring, utf8string, cstring, astring types not allowed | ||
| 561 | if ( $_->hasProperty('array') and $type->isa('NativeType') ) { | ||
| 562 | if ( $type->hasProperty('domstring') | ||
| 563 | or $type->hasProperty('utf8string') | ||
| 564 | or $type->hasProperty('cstring') | ||
| 565 | or $type->hasProperty('astring') ) { | ||
| 566 | $self->{parser}->Error( | ||
| 567 | "[domstring], [utf8string], [cstring], [astring] " . | ||
| 568 | "types cannot be used in array parameters.\n" | ||
| 569 | ); | ||
| 570 | } | ||
| 571 | } | ||
| 572 | |||
| 573 | $self->_check_param_attribute($node, $_, 'iid_is'); | ||
| 574 | $self->_check_param_attribute($node, $_, 'length_is'); | ||
| 575 | $self->_check_param_attribute($node, $_, 'size_is'); | ||
| 576 | |||
| 577 | # Run additional error checks on the return type if targetting an | ||
| 578 | # older version of XPConnect. | ||
| 579 | $self->_verify_type_fits_version($type, $node); | ||
| 580 | } | ||
| 581 | $last = 0; | ||
| 582 | } | ||
| 583 | |||
| 584 | my $type = $self->_get_effective_type($node->{type}); | ||
| 585 | if ($type->isa('SequenceType')) { | ||
| 586 | $self->{parser}->Error("sequences not supported.\n"); | ||
| 587 | } | ||
| 588 | |||
| 589 | return if ($type->isa('VoidType')); | ||
| 590 | |||
| 591 | # XXX q: can return type be nsid? | ||
| 592 | # Native return type? | ||
| 593 | if ( $scriptable_method and $type->isa('NativeType') ) { | ||
| 594 | if ( ! $type->hasProperty('nsid') | ||
| 595 | and ! $type->hasProperty('domstring') | ||
| 596 | and ! $type->hasProperty('utf8string') | ||
| 597 | and ! $type->hasProperty('cstring') | ||
| 598 | and ! $type->hasProperty('astring') ) { | ||
| 599 | $self->{parser}->Error( | ||
| 600 | "methods in [scriptable] interfaces that are " . | ||
| 601 | "non-scriptable because they return native " . | ||
| 602 | "types must be marked [noscript].\n" | ||
| 603 | ); | ||
| 604 | } | ||
| 605 | } | ||
| 606 | |||
| 607 | # nsid's parameters that aren't ptr's or ref's are not currently | ||
| 608 | # supported in xpcom | ||
| 609 | if (!$notxpcom) { | ||
| 610 | if ( $type->hasProperty('nsid') | ||
| 611 | and ! $type->hasProperty('ptr') | ||
| 612 | and ! $type->hasProperty('ref') ) { | ||
| 613 | $self->{parser}->Error( | ||
| 614 | "Feature currently not supported: " . | ||
| 615 | "return value is of type nsid and " . | ||
| 616 | "must be marked either [ptr] or [ref], " . | ||
| 617 | "or else method '$node->{idf}' must be marked [notxpcom].\n" | ||
| 618 | ); | ||
| 619 | } | ||
| 620 | } | ||
| 621 | |||
| 622 | # Run additional error checks on the return type if targetting an | ||
| 623 | # older version of XPConnect. | ||
| 624 | $self->_verify_type_fits_version($type, $node); | ||
| 625 | } | ||
| 626 | |||
| 627 | # | ||
| 628 | # 3.14 Attribute Declaration | ||
| 629 | # | ||
| 630 | |||
| 631 | sub visitAttributes { | ||
| 632 | my $self = shift; | ||
| 633 | my ($node, $parent) = @_; | ||
| 634 | |||
| 635 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 636 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 637 | |||
| 638 | my $type = $self->_get_effective_type($node->{type}); | ||
| 639 | if ($type->isa('SequenceType')) { | ||
| 640 | $self->{parser}->Error("sequences not supported.\n"); | ||
| 641 | } | ||
| 642 | # if (scalar(@{$node->{list_decl}}) > 1) { | ||
| 643 | # $self->{parser}->Warning("multiple attributes in a single declaration aren't currently supported by xpidl.\n"); | ||
| 644 | # } | ||
| 645 | foreach (@{$node->{list_decl}}) { | ||
| 646 | $self->_get_defn($_)->visit($self, $parent); | ||
| 647 | } | ||
| 648 | } | ||
| 649 | |||
| 650 | sub visitAttribute { | ||
| 651 | my $self = shift; | ||
| 652 | my ($node, $parent) = @_; | ||
| 653 | |||
| 654 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 655 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 656 | |||
| 657 | # We don't support attributes named IID, conflicts with static GetIID | ||
| 658 | # member. The conflict is due to certain compilers (VC++) choosing a | ||
| 659 | # different vtable order, placing GetIID at the beginning regardless | ||
| 660 | # of it's placement | ||
| 661 | if ($node->{idf} eq 'IID') { | ||
| 662 | $self->{parser}->Error( | ||
| 663 | "Attributes named IID not supported, causes vtable " . | ||
| 664 | "ordering problems.\n" | ||
| 665 | ); | ||
| 666 | } | ||
| 667 | |||
| 668 | # If the interface isn't scriptable, or the attribute is marked noscript, | ||
| 669 | # there's no need to check. | ||
| 670 | return unless ($parent->hasProperty('scriptable')); | ||
| 671 | return if ($node->hasProperty('noscript')); | ||
| 672 | |||
| 673 | # If it should be scriptable, check that the type is non-native. nsid, | ||
| 674 | # domstring, utf8string, cstring, astring are exempted. | ||
| 675 | my $type = $self->_get_effective_type($node->{type}); | ||
| 676 | |||
| 677 | if ($type->isa('NativeType')) { | ||
| 678 | if ( ! $type->hasProperty('nsid') | ||
| 679 | and ! $type->hasProperty('domstring') | ||
| 680 | and ! $type->hasProperty('utf8string') | ||
| 681 | and ! $type->hasProperty('cstring') | ||
| 682 | and ! $type->hasProperty('astring') ) { | ||
| 683 | $self->{parser}->Error( | ||
| 684 | "attributes in [scriptable] interfaces that are " . | ||
| 685 | "non-scriptable because they refer to native " . | ||
| 686 | "types must be marked [noscript].\n" | ||
| 687 | ); | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 691 | # We currently don't support properties of type nsid that aren't | ||
| 692 | # pointers or references, unless they are marked [notxpcom] and | ||
| 693 | # must be read-only | ||
| 694 | if ( ! $node->hasProperty('notxpcom') | ||
| 695 | or !exists $node->{modifier}) { # readonly | ||
| 696 | if ( $type->hasProperty('nsid') | ||
| 697 | and ! $type->hasProperty('ptr') | ||
| 698 | and ! $type->hasProperty('ref') ) { | ||
| 699 | $self->{parser}->Error( | ||
| 700 | "Feature not currently supported: " . | ||
| 701 | "attributes with a type of nsid must be marked " . | ||
| 702 | "either [ptr] or [ref], or " . | ||
| 703 | "else must be marked [notxpcom] " . | ||
| 704 | "and must be read-only.\n" | ||
| 705 | ); | ||
| 706 | } | ||
| 707 | } | ||
| 708 | |||
| 709 | # Run additional error checks on the attribute type if targetting an | ||
| 710 | # older version of XPConnect. | ||
| 711 | $self->_verify_type_fits_version($type, $node); | ||
| 712 | } | ||
| 713 | |||
| 714 | # | ||
| 715 | # 3.15 Repository Identity Related Declarations | ||
| 716 | # | ||
| 717 | |||
| 718 | sub visitTypeId { | ||
| 719 | # empty | ||
| 720 | } | ||
| 721 | |||
| 722 | sub visitTypePrefix { | ||
| 723 | # empty | ||
| 724 | } | ||
| 725 | |||
| 726 | # | ||
| 727 | # XPIDL | ||
| 728 | # | ||
| 729 | |||
| 730 | sub visitCodeFragment { | ||
| 731 | my $self = shift; | ||
| 732 | my ($node, $parent) = @_; | ||
| 733 | |||
| 734 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 735 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 736 | if ($parent->isa('BaseInterface')) { | ||
| 737 | $self->{parser}->Warning( | ||
| 738 | "\%\%{ .. \%\%} code fragment within interface " . | ||
| 739 | "ignored when generating NS_DECL_$parent->{idf} macro; " . | ||
| 740 | "if the code fragment contains method declarations, " . | ||
| 741 | "the macro probably isn't complete.\n" | ||
| 742 | ); | ||
| 743 | } | ||
| 744 | if ($self->{mode} eq 'header') { | ||
| 745 | my @code = split /\n/, $node->{value}; | ||
| 746 | my $lang = shift @code; | ||
| 747 | unless ($lang =~ /^\s*C\+\+/) { | ||
| 748 | $self->{parser}->YYData->{filename} = $node->{filename}; | ||
| 749 | $self->{parser}->YYData->{lineno} = $node->{lineno}; | ||
| 750 | $self->{parser}->Warning( | ||
| 751 | "ignoring '\%\%{$lang' escape. " . | ||
| 752 | "(Use '\%\%{C++' to escape verbatim C++ code).\n" | ||
| 753 | ); | ||
| 754 | } | ||
| 755 | } | ||
| 756 | } | ||
| 757 | |||
| 758 | 1; | ||
| 759 |