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

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: updated 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..0ce3573502330a24bc29325bfda33531547812ad 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 UnionTypeWithSuffix)
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 UnionTypeWithSuffix)
specials => '@', # Specials
extendedAttributes => '$', # Extended attributes
isOptional => '$', # Is variable optional (optional T)
@@ -107,6 +107,20 @@ struct( Typedef => {
type => '$', # Type of data
});
+struct( UnionTypeWithSuffix => {
+ unionType => '$', # UnionType
+ suffix => '$', # suffix
+});
+
+struct( UnionType => {
+ unionMemberTypes => '@', # UnionMemberType[]
+});
+
+struct( UnionMemberType => {
+ unionTypeWithSuffix => '$', # UnionTypeWithSuffix
+ singleType => '$', # NonAnyType | "any" "[" "]" TypeSuffix
+});
+
# Maps 'typedef name' -> Typedef
my %typedefs = ();
@@ -1751,9 +1765,10 @@ sub parseType
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "(") {
- $self->parseUnionType();
- $self->parseTypeSuffix();
- return;
+ my $unionTypeWithSuffix = UnionTypeWithSuffix->new();
+ $unionTypeWithSuffix->unionType($self->parseUnionType());
+ $unionTypeWithSuffix->suffix($self->parseTypeSuffix());
+ return $unionTypeWithSuffix;
}
if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) {
return $self->parseSingleType();
@@ -1780,13 +1795,14 @@ 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__);
}
@@ -1796,20 +1812,23 @@ sub parseUnionMemberType
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "(") {
- $self->parseUnionType();
- $self->parseTypeSuffix();
- return;
+ my $unionMemberType = UnionMemberType->new();
+ my $unionTypeWithSuffix = UnionTypeWithSuffix->new();
+ $unionTypeWithSuffix->unionType($self->parseUnionType());
+ $unionTypeWithSuffix->suffix($self->parseTypeSuffix());
+
+ $unionMemberType->unionTypeWithSuffix($unionTypeWithSuffix);
+ return $unionMemberType;
}
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;
haraken 2013/05/15 12:09:43 Is it OK to return a string? Shouldn't parseUnionM
kojih 2013/05/16 05:22:57 now parseUnionMemberType returns UnionType or stri
}
if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1/) {
- $self->parseNonAnyType();
- return;
+ return $self->parseNonAnyType();
haraken 2013/05/15 12:09:43 Ditto. parseNonAnyType() returns nothing.
kojih 2013/05/16 05:22:57 parseNonAnyType returns string. last line of parse
}
$self->assertUnexpectedToken($next->value(), __LINE__);
}
@@ -1819,10 +1838,13 @@ sub parseUnionMemberTypes
my $self = shift;
my $next = $self->nextToken();
if ($next->value() eq "or") {
+ my @types = ();
$self->assertTokenValue($self->getToken(), "or", __LINE__);
- $self->parseUnionMemberType();
- $self->parseUnionMemberTypes();
+ push @types, $self->parseUnionMemberType();
+ push @types, $self->parseUnionMemberTypes();
+ return @types;
}
+ return ();
haraken 2013/05/15 12:09:43 Nit: You can write: my @types = (); if (...)
}
sub parseNonAnyType

Powered by Google App Engine
This is Rietveld 408576698