Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: Source/bindings/scripts/IDLParser.pm

Issue 15076011: Support union return type for anonymous named/indexed getter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/IDLParser.pm
diff --git a/Source/bindings/scripts/IDLParser.pm b/Source/bindings/scripts/IDLParser.pm
index 177f3e919b1d9c2be73f0bd92942f328ad1bf95c..0bd6928bd38e1fd88d7aa1e0225fa07bc9a07e5f 100644
--- a/Source/bindings/scripts/IDLParser.pm
+++ b/Source/bindings/scripts/IDLParser.pm
@@ -64,7 +64,7 @@ struct( domFunction => {
# Used to represent domInterface contents (name of attribute, signature)
struct( domAttribute => {
- type => '$', # Attribute type (including namespace)
+ type => '$', # Attribute type (including namespace) (string or UnionType)
isStatic => '$',
isReadOnly => '$',
signature => '$', # Attribute signature
@@ -75,7 +75,7 @@ struct( domAttribute => {
# Used to represent a map of 'variable name' <-> 'variable type'
struct( domSignature => {
name => '$', # Variable name
- type => '$', # Variable type
+ type => '$', # Variable type (string or UnionType)
specials => '@', # Specials
extendedAttributes => '$', # Extended attributes
isOptional => '$', # Is variable optional (optional T)
@@ -107,6 +107,10 @@ struct( Typedef => {
type => '$', # Type of data
});
+struct( UnionType => {
+ unionMemberTypes => '@', # (UnionType or string)[]
+});
+
# Maps 'typedef name' -> Typedef
my %typedefs = ();
@@ -1751,9 +1755,10 @@ sub parseType
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "(") {
- $self->parseUnionType();
- $self->parseTypeSuffix();
- return;
+ my $unionType = $self->parseUnionType();
+ my $suffix = $self->parseTypeSuffix();
+ die "Suffix after UnionType is not supported." if $suffix ne "";
+ return $unionType;
}
if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) {
return $self->parseSingleType();
@@ -1780,36 +1785,38 @@ sub parseUnionType
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "(") {
+ my $unionType = UnionType->new();
$self->assertTokenValue($self->getToken(), "(", __LINE__);
- $self->parseUnionMemberType();
+ push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType();
$self->assertTokenValue($self->getToken(), "or", __LINE__);
- $self->parseUnionMemberType();
- $self->parseUnionMemberTypes();
+ push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType();
+ push @{$unionType->unionMemberTypes}, $self->parseUnionMemberTypes();
$self->assertTokenValue($self->getToken(), ")", __LINE__);
- return;
+ return $unionType;
}
$self->assertUnexpectedToken($next->value(), __LINE__);
}
+# Returns UnionType or string
sub parseUnionMemberType
{
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "(") {
- $self->parseUnionType();
- $self->parseTypeSuffix();
- return;
+ my $unionType = $self->parseUnionType();
+ my $suffix = $self->parseTypeSuffix();
+ die "Suffix after UnionType is not supported." if $suffix ne "";
+ return $unionType;
}
if ($next->value() eq "any") {
- $self->assertTokenValue($self->getToken(), "any", __LINE__);
- $self->assertTokenValue($self->getToken(), "[", __LINE__);
- $self->assertTokenValue($self->getToken(), "]", __LINE__);
- $self->parseTypeSuffix();
- return;
+ my $type = $self->assertTokenValue($self->getToken(), "any", __LINE__);
+ $type .= $self->assertTokenValue($self->getToken(), "[", __LINE__);
+ $type .= $self->assertTokenValue($self->getToken(), "]", __LINE__);
+ $type .= $self->parseTypeSuffix();
+ return $type;
}
if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1/) {
- $self->parseNonAnyType();
- return;
+ return $self->parseNonAnyType();
}
$self->assertUnexpectedToken($next->value(), __LINE__);
}
@@ -1817,12 +1824,14 @@ sub parseUnionMemberType
sub parseUnionMemberTypes
{
my $self = shift;
+ my @types = ();
my $next = $self->nextToken();
if ($next->value() eq "or") {
$self->assertTokenValue($self->getToken(), "or", __LINE__);
- $self->parseUnionMemberType();
- $self->parseUnionMemberTypes();
+ push @types, $self->parseUnionMemberType();
+ push @types, $self->parseUnionMemberTypes();
}
+ return @types;
}
sub parseNonAnyType

Powered by Google App Engine
This is Rietveld 408576698