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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 # Used to represent 'interface' blocks | 43 # Used to represent 'interface' blocks |
| 44 struct( domInterface => { | 44 struct( domInterface => { |
| 45 name => '$', # Class identifier | 45 name => '$', # Class identifier |
| 46 parents => '@', # List of strings | 46 parents => '@', # List of strings |
| 47 constants => '@', # List of 'domConstant' | 47 constants => '@', # List of 'domConstant' |
| 48 functions => '@', # List of 'domFunction' | 48 functions => '@', # List of 'domFunction' |
| 49 attributes => '@', # List of 'domAttribute' | 49 attributes => '@', # List of 'domAttribute' |
| 50 extendedAttributes => '$', # Extended attributes | 50 extendedAttributes => '$', # Extended attributes |
| 51 constructors => '@', # Constructors, list of 'domFunction' | 51 constructors => '@', # Constructors, list of 'domFunction' |
| 52 customConstructors => '@', # Custom constructors, list of 'domFunction' | |
| 52 isException => '$', # Used for exception interfaces | 53 isException => '$', # Used for exception interfaces |
| 53 }); | 54 }); |
| 54 | 55 |
| 55 # Used to represent domInterface contents (name of method, signature) | 56 # Used to represent domInterface contents (name of method, signature) |
| 56 struct( domFunction => { | 57 struct( domFunction => { |
| 57 isStatic => '$', | 58 isStatic => '$', |
| 58 signature => '$', # Return type/Object name/extended attributes | 59 signature => '$', # Return type/Object name/extended attributes |
| 59 parameters => '@', # List of 'domSignature' | 60 parameters => '@', # List of 'domSignature' |
| 60 }); | 61 }); |
| 61 | 62 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 foreach my $constant (@{$definition->constants}) { | 369 foreach my $constant (@{$definition->constants}) { |
| 369 if (exists $typedefs{$constant->type}) { | 370 if (exists $typedefs{$constant->type}) { |
| 370 my $typedef = $typedefs{$constant->type}; | 371 my $typedef = $typedefs{$constant->type}; |
| 371 $self->assertNoExtendedAttributesInTypedef($constant->type, __LINE__); | 372 $self->assertNoExtendedAttributesInTypedef($constant->type, __LINE__); |
| 372 $constant->type($typedef->type); | 373 $constant->type($typedef->type); |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 foreach my $attribute (@{$definition->attributes}) { | 376 foreach my $attribute (@{$definition->attributes}) { |
| 376 $self->applyTypedefsForSignature($attribute->signature); | 377 $self->applyTypedefsForSignature($attribute->signature); |
| 377 } | 378 } |
| 378 foreach my $function (@{$definition->functions}, @{$definition->cons tructors}) { | 379 foreach my $function (@{$definition->functions}, @{$definition->cons tructors}, @{$definition->customConstructors}) { |
| 379 $self->applyTypedefsForSignature($function->signature); | 380 $self->applyTypedefsForSignature($function->signature); |
| 380 foreach my $signature (@{$function->parameters}) { | 381 foreach my $signature (@{$function->parameters}) { |
| 381 $self->applyTypedefsForSignature($signature); | 382 $self->applyTypedefsForSignature($signature); |
| 382 } | 383 } |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 sub applyTypedefsForSignature | 389 sub applyTypedefsForSignature |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 $newDataNode->signature->isNullable(1); | 1143 $newDataNode->signature->isNullable(1); |
| 1143 } else { | 1144 } else { |
| 1144 $newDataNode->signature->isNullable(0); | 1145 $newDataNode->signature->isNullable(0); |
| 1145 } | 1146 } |
| 1146 # Remove all "?" in the type declaration, e.g. "double?" -> "double". | 1147 # Remove all "?" in the type declaration, e.g. "double?" -> "double". |
| 1147 $newDataNode->signature->type(typeRemoveNullableSuffix($type)); | 1148 $newDataNode->signature->type(typeRemoveNullableSuffix($type)); |
| 1148 my $token = $self->getToken(); | 1149 my $token = $self->getToken(); |
| 1149 $self->assertTokenType($token, IdentifierToken); | 1150 $self->assertTokenType($token, IdentifierToken); |
| 1150 $newDataNode->signature->name($token->value()); | 1151 $newDataNode->signature->name($token->value()); |
| 1151 $self->assertTokenValue($self->getToken(), ";", __LINE__); | 1152 $self->assertTokenValue($self->getToken(), ";", __LINE__); |
| 1153 # CustomConstructor may also be used on attributes. | |
|
haraken
2013/04/16 11:58:27
Where can it happen?
do-not-use
2013/04/16 12:02:23
It is used in DOMWindow.idl for:
[CustomConstructo
haraken
2013/04/16 12:05:44
ah....
Actually I do want to remove the [CustomCo
| |
| 1154 if (defined $extendedAttributeList->{"CustomConstructors"}) { | |
| 1155 delete $extendedAttributeList->{"CustomConstructors"}; | |
| 1156 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; | |
| 1157 } | |
| 1152 $newDataNode->signature->extendedAttributes($extendedAttributeList); | 1158 $newDataNode->signature->extendedAttributes($extendedAttributeList); |
| 1153 return $newDataNode; | 1159 return $newDataNode; |
| 1154 } | 1160 } |
| 1155 $self->assertUnexpectedToken($next->value(), __LINE__); | 1161 $self->assertUnexpectedToken($next->value(), __LINE__); |
| 1156 } | 1162 } |
| 1157 | 1163 |
| 1158 sub parseInherit | 1164 sub parseInherit |
| 1159 { | 1165 { |
| 1160 my $self = shift; | 1166 my $self = shift; |
| 1161 my $next = $self->nextToken(); | 1167 my $next = $self->nextToken(); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 my $attr = shift; | 1515 my $attr = shift; |
| 1510 | 1516 |
| 1511 for my $key (keys %{$attr}) { | 1517 for my $key (keys %{$attr}) { |
| 1512 if ($key eq "Constructor") { | 1518 if ($key eq "Constructor") { |
| 1513 push(@{$extendedAttributeList->{"Constructors"}}, $attr->{$key}); | 1519 push(@{$extendedAttributeList->{"Constructors"}}, $attr->{$key}); |
| 1514 } elsif ($key eq "Constructors") { | 1520 } elsif ($key eq "Constructors") { |
| 1515 my @constructors = @{$attr->{$key}}; | 1521 my @constructors = @{$attr->{$key}}; |
| 1516 foreach my $constructor (@constructors) { | 1522 foreach my $constructor (@constructors) { |
| 1517 push(@{$extendedAttributeList->{"Constructors"}}, $constructor); | 1523 push(@{$extendedAttributeList->{"Constructors"}}, $constructor); |
| 1518 } | 1524 } |
| 1525 } elsif ($key eq "CustomConstructor") { | |
| 1526 push(@{$extendedAttributeList->{"CustomConstructors"}}, $attr->{$key }); | |
| 1527 } elsif ($key eq "CustomConstructors") { | |
| 1528 my @customConstructors = @{$attr->{$key}}; | |
| 1529 foreach my $customConstructor (@customConstructors) { | |
| 1530 push(@{$extendedAttributeList->{"CustomConstructors"}}, $customC onstructor); | |
| 1531 } | |
| 1519 } else { | 1532 } else { |
| 1520 $extendedAttributeList->{$key} = $attr->{$key}; | 1533 $extendedAttributeList->{$key} = $attr->{$key}; |
| 1521 } | 1534 } |
| 1522 } | 1535 } |
| 1523 } | 1536 } |
| 1524 | 1537 |
| 1525 sub parseExtendedAttributeList | 1538 sub parseExtendedAttributeList |
| 1526 { | 1539 { |
| 1527 my $self = shift; | 1540 my $self = shift; |
| 1528 my $next = $self->nextToken(); | 1541 my $next = $self->nextToken(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 $attrs->{$name} = $self->parseArgumentList(); | 1608 $attrs->{$name} = $self->parseArgumentList(); |
| 1596 $self->assertTokenValue($self->getToken(), ")", __LINE__); | 1609 $self->assertTokenValue($self->getToken(), ")", __LINE__); |
| 1597 return $attrs; | 1610 return $attrs; |
| 1598 } | 1611 } |
| 1599 if ($next->value() eq "=") { | 1612 if ($next->value() eq "=") { |
| 1600 $self->assertTokenValue($self->getToken(), "=", __LINE__); | 1613 $self->assertTokenValue($self->getToken(), "=", __LINE__); |
| 1601 $attrs->{$name} = $self->parseExtendedAttributeRest2(); | 1614 $attrs->{$name} = $self->parseExtendedAttributeRest2(); |
| 1602 return $attrs; | 1615 return $attrs; |
| 1603 } | 1616 } |
| 1604 | 1617 |
| 1605 if ($name eq "Constructor") { | 1618 if ($name eq "Constructor" || $name eq "CustomConstructor") { |
| 1606 $attrs->{$name} = []; | 1619 $attrs->{$name} = []; |
| 1607 } else { | 1620 } else { |
| 1608 $attrs->{$name} = "VALUE_IS_MISSING"; | 1621 $attrs->{$name} = "VALUE_IS_MISSING"; |
| 1609 } | 1622 } |
| 1610 return $attrs; | 1623 return $attrs; |
| 1611 } | 1624 } |
| 1612 | 1625 |
| 1613 sub parseExtendedAttributeRest2 | 1626 sub parseExtendedAttributeRest2 |
| 1614 { | 1627 { |
| 1615 my $self = shift; | 1628 my $self = shift; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 $self->assertUnexpectedToken($next->value(), __LINE__); | 2104 $self->assertUnexpectedToken($next->value(), __LINE__); |
| 2092 } | 2105 } |
| 2093 | 2106 |
| 2094 sub parseInterfaceOld | 2107 sub parseInterfaceOld |
| 2095 { | 2108 { |
| 2096 my $self = shift; | 2109 my $self = shift; |
| 2097 my $next = $self->nextToken(); | 2110 my $next = $self->nextToken(); |
| 2098 if ($next->value() eq "interface") { | 2111 if ($next->value() eq "interface") { |
| 2099 my $interface = domInterface->new(); | 2112 my $interface = domInterface->new(); |
| 2100 $self->assertTokenValue($self->getToken(), "interface", __LINE__); | 2113 $self->assertTokenValue($self->getToken(), "interface", __LINE__); |
| 2101 my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty( ); | 2114 my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty( 1); |
|
haraken
2013/04/16 11:58:27
What is this change for?
do-not-use
2013/04/16 12:02:23
My bad. Forgot to remove this local change.
| |
| 2102 my $token = $self->getToken(); | 2115 my $token = $self->getToken(); |
| 2103 $self->assertTokenType($token, IdentifierToken); | 2116 $self->assertTokenType($token, IdentifierToken); |
| 2104 $interface->name($token->value()); | 2117 $interface->name($token->value()); |
| 2105 $interface->isException(0); | 2118 $interface->isException(0); |
| 2106 push(@{$interface->parents}, @{$self->parseInheritance()}); | 2119 push(@{$interface->parents}, @{$self->parseInheritance()}); |
| 2107 $self->assertTokenValue($self->getToken(), "{", __LINE__); | 2120 $self->assertTokenValue($self->getToken(), "{", __LINE__); |
| 2108 my $interfaceMembers = $self->parseInterfaceMembers(); | 2121 my $interfaceMembers = $self->parseInterfaceMembers(); |
| 2109 $self->assertTokenValue($self->getToken(), "}", __LINE__); | 2122 $self->assertTokenValue($self->getToken(), "}", __LINE__); |
| 2110 $self->assertTokenValue($self->getToken(), ";", __LINE__); | 2123 $self->assertTokenValue($self->getToken(), ";", __LINE__); |
| 2111 applyMemberList($interface, $interfaceMembers); | 2124 applyMemberList($interface, $interfaceMembers); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2446 $newDataNode->signature(domSignature->new()); | 2459 $newDataNode->signature(domSignature->new()); |
| 2447 $newDataNode->signature->name("NamedConstructor"); | 2460 $newDataNode->signature->name("NamedConstructor"); |
| 2448 $newDataNode->signature->extendedAttributes($extendedAttributeList); | 2461 $newDataNode->signature->extendedAttributes($extendedAttributeList); |
| 2449 my %attributes = %{$extendedAttributeList->{"NamedConstructor"}}; | 2462 my %attributes = %{$extendedAttributeList->{"NamedConstructor"}}; |
| 2450 my @attributeKeys = keys (%attributes); | 2463 my @attributeKeys = keys (%attributes); |
| 2451 my $constructorName = $attributeKeys[0]; | 2464 my $constructorName = $attributeKeys[0]; |
| 2452 push(@{$newDataNode->parameters}, @{$attributes{$constructorName}}); | 2465 push(@{$newDataNode->parameters}, @{$attributes{$constructorName}}); |
| 2453 $extendedAttributeList->{"NamedConstructor"} = $constructorName; | 2466 $extendedAttributeList->{"NamedConstructor"} = $constructorName; |
| 2454 push(@{$interface->constructors}, $newDataNode); | 2467 push(@{$interface->constructors}, $newDataNode); |
| 2455 } | 2468 } |
| 2469 if (defined $extendedAttributeList->{"CustomConstructors"}) { | |
| 2470 my @customConstructorParams = @{$extendedAttributeList->{"CustomConstruc tors"}}; | |
| 2471 my $index = (@customConstructorParams == 1) ? 0 : 1; | |
| 2472 foreach my $param (@customConstructorParams) { | |
| 2473 my $customConstructor = domFunction->new(); | |
| 2474 $customConstructor->signature(domSignature->new()); | |
| 2475 $customConstructor->signature->name("CustomConstructor"); | |
| 2476 $customConstructor->signature->extendedAttributes($extendedAttribute List); | |
| 2477 $customConstructor->parameters($param); | |
| 2478 $customConstructor->{overloadedIndex} = $index++; | |
| 2479 push(@{$interface->customConstructors}, $customConstructor); | |
| 2480 } | |
| 2481 delete $extendedAttributeList->{"CustomConstructors"}; | |
| 2482 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; | |
| 2483 } | |
| 2456 $interface->extendedAttributes($extendedAttributeList); | 2484 $interface->extendedAttributes($extendedAttributeList); |
| 2457 } | 2485 } |
| 2458 | 2486 |
| 2459 1; | 2487 1; |
| OLD | NEW |