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

Side by Side 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 unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 # Used to represent domInterface contents (name of method, signature) 58 # Used to represent domInterface contents (name of method, signature)
59 struct( domFunction => { 59 struct( domFunction => {
60 isStatic => '$', 60 isStatic => '$',
61 signature => '$', # Return type/Object name/extended attributes 61 signature => '$', # Return type/Object name/extended attributes
62 parameters => '@', # List of 'domSignature' 62 parameters => '@', # List of 'domSignature'
63 }); 63 });
64 64
65 # Used to represent domInterface contents (name of attribute, signature) 65 # Used to represent domInterface contents (name of attribute, signature)
66 struct( domAttribute => { 66 struct( domAttribute => {
67 type => '$', # Attribute type (including namespace) 67 type => '$', # Attribute type (including namespace) (string or UnionTypeWithSuffix)
68 isStatic => '$', 68 isStatic => '$',
69 isReadOnly => '$', 69 isReadOnly => '$',
70 signature => '$', # Attribute signature 70 signature => '$', # Attribute signature
71 getterExceptions => '@', # Possibly raised exceptions. 71 getterExceptions => '@', # Possibly raised exceptions.
72 setterExceptions => '@', # Possibly raised exceptions. 72 setterExceptions => '@', # Possibly raised exceptions.
73 }); 73 });
74 74
75 # Used to represent a map of 'variable name' <-> 'variable type' 75 # Used to represent a map of 'variable name' <-> 'variable type'
76 struct( domSignature => { 76 struct( domSignature => {
77 name => '$', # Variable name 77 name => '$', # Variable name
78 type => '$', # Variable type 78 type => '$', # Variable type (string or UnionTypeWithSuffix)
79 specials => '@', # Specials 79 specials => '@', # Specials
80 extendedAttributes => '$', # Extended attributes 80 extendedAttributes => '$', # Extended attributes
81 isOptional => '$', # Is variable optional (optional T) 81 isOptional => '$', # Is variable optional (optional T)
82 isNullable => '$', # Is variable type Nullable (T?) 82 isNullable => '$', # Is variable type Nullable (T?)
83 isVariadic => '$' # Is variable variadic (long... numbers) 83 isVariadic => '$' # Is variable variadic (long... numbers)
84 }); 84 });
85 85
86 # Used to represent string constants 86 # Used to represent string constants
87 struct( domConstant => { 87 struct( domConstant => {
88 name => '$', # DOM Constant identifier 88 name => '$', # DOM Constant identifier
(...skipping 11 matching lines...) Expand all
100 struct( Token => { 100 struct( Token => {
101 type => '$', # type of token 101 type => '$', # type of token
102 value => '$' # value of token 102 value => '$' # value of token
103 }); 103 });
104 104
105 struct( Typedef => { 105 struct( Typedef => {
106 extendedAttributes => '$', # Extended attributes 106 extendedAttributes => '$', # Extended attributes
107 type => '$', # Type of data 107 type => '$', # Type of data
108 }); 108 });
109 109
110 struct( UnionTypeWithSuffix => {
111 unionType => '$', # UnionType
112 suffix => '$', # suffix
113 });
114
115 struct( UnionType => {
116 unionMemberTypes => '@', # UnionMemberType[]
117 });
118
119 struct( UnionMemberType => {
120 unionTypeWithSuffix => '$', # UnionTypeWithSuffix
121 singleType => '$', # NonAnyType | "any" "[" "]" TypeSuffix
122 });
123
110 # Maps 'typedef name' -> Typedef 124 # Maps 'typedef name' -> Typedef
111 my %typedefs = (); 125 my %typedefs = ();
112 126
113 sub new { 127 sub new {
114 my $class = shift; 128 my $class = shift;
115 129
116 my $emptyToken = Token->new(); 130 my $emptyToken = Token->new();
117 $emptyToken->type(EmptyToken); 131 $emptyToken->type(EmptyToken);
118 $emptyToken->value("empty"); 132 $emptyToken->value("empty");
119 133
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 return $self->getToken()->value(); 1758 return $self->getToken()->value();
1745 } 1759 }
1746 $self->assertUnexpectedToken($next->value(), __LINE__); 1760 $self->assertUnexpectedToken($next->value(), __LINE__);
1747 } 1761 }
1748 1762
1749 sub parseType 1763 sub parseType
1750 { 1764 {
1751 my $self = shift; 1765 my $self = shift;
1752 my $next = $self->nextToken(); 1766 my $next = $self->nextToken();
1753 if ($next->value() eq "(") { 1767 if ($next->value() eq "(") {
1754 $self->parseUnionType(); 1768 my $unionTypeWithSuffix = UnionTypeWithSuffix->new();
1755 $self->parseTypeSuffix(); 1769 $unionTypeWithSuffix->unionType($self->parseUnionType());
1756 return; 1770 $unionTypeWithSuffix->suffix($self->parseTypeSuffix());
1771 return $unionTypeWithSuffix;
1757 } 1772 }
1758 if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) { 1773 if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) {
1759 return $self->parseSingleType(); 1774 return $self->parseSingleType();
1760 } 1775 }
1761 $self->assertUnexpectedToken($next->value(), __LINE__); 1776 $self->assertUnexpectedToken($next->value(), __LINE__);
1762 } 1777 }
1763 1778
1764 sub parseSingleType 1779 sub parseSingleType
1765 { 1780 {
1766 my $self = shift; 1781 my $self = shift;
1767 my $next = $self->nextToken(); 1782 my $next = $self->nextToken();
1768 if ($next->value() eq "any") { 1783 if ($next->value() eq "any") {
1769 $self->assertTokenValue($self->getToken(), "any", __LINE__); 1784 $self->assertTokenValue($self->getToken(), "any", __LINE__);
1770 return "any" . $self->parseTypeSuffixStartingWithArray(); 1785 return "any" . $self->parseTypeSuffixStartingWithArray();
1771 } 1786 }
1772 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1 /) { 1787 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1 /) {
1773 return $self->parseNonAnyType(); 1788 return $self->parseNonAnyType();
1774 } 1789 }
1775 $self->assertUnexpectedToken($next->value(), __LINE__); 1790 $self->assertUnexpectedToken($next->value(), __LINE__);
1776 } 1791 }
1777 1792
1778 sub parseUnionType 1793 sub parseUnionType
1779 { 1794 {
1780 my $self = shift; 1795 my $self = shift;
1781 my $next = $self->nextToken(); 1796 my $next = $self->nextToken();
1782 if ($next->value() eq "(") { 1797 if ($next->value() eq "(") {
1798 my $unionType = UnionType->new();
1783 $self->assertTokenValue($self->getToken(), "(", __LINE__); 1799 $self->assertTokenValue($self->getToken(), "(", __LINE__);
1784 $self->parseUnionMemberType(); 1800 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType();
1785 $self->assertTokenValue($self->getToken(), "or", __LINE__); 1801 $self->assertTokenValue($self->getToken(), "or", __LINE__);
1786 $self->parseUnionMemberType(); 1802 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType();
1787 $self->parseUnionMemberTypes(); 1803 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberTypes();
1788 $self->assertTokenValue($self->getToken(), ")", __LINE__); 1804 $self->assertTokenValue($self->getToken(), ")", __LINE__);
1789 return; 1805 return $unionType;
1790 } 1806 }
1791 $self->assertUnexpectedToken($next->value(), __LINE__); 1807 $self->assertUnexpectedToken($next->value(), __LINE__);
1792 } 1808 }
1793 1809
1794 sub parseUnionMemberType 1810 sub parseUnionMemberType
1795 { 1811 {
1796 my $self = shift; 1812 my $self = shift;
1797 my $next = $self->nextToken(); 1813 my $next = $self->nextToken();
1798 if ($next->value() eq "(") { 1814 if ($next->value() eq "(") {
1799 $self->parseUnionType(); 1815 my $unionMemberType = UnionMemberType->new();
1800 $self->parseTypeSuffix(); 1816 my $unionTypeWithSuffix = UnionTypeWithSuffix->new();
1801 return; 1817 $unionTypeWithSuffix->unionType($self->parseUnionType());
1818 $unionTypeWithSuffix->suffix($self->parseTypeSuffix());
1819
1820 $unionMemberType->unionTypeWithSuffix($unionTypeWithSuffix);
1821 return $unionMemberType;
1802 } 1822 }
1803 if ($next->value() eq "any") { 1823 if ($next->value() eq "any") {
1804 $self->assertTokenValue($self->getToken(), "any", __LINE__); 1824 my $type = $self->assertTokenValue($self->getToken(), "any", __LINE__);
1805 $self->assertTokenValue($self->getToken(), "[", __LINE__); 1825 $type .= $self->assertTokenValue($self->getToken(), "[", __LINE__);
1806 $self->assertTokenValue($self->getToken(), "]", __LINE__); 1826 $type .= $self->assertTokenValue($self->getToken(), "]", __LINE__);
1807 $self->parseTypeSuffix(); 1827 $type .= $self->parseTypeSuffix();
1808 return; 1828 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
1809 } 1829 }
1810 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1 /) { 1830 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1 /) {
1811 $self->parseNonAnyType(); 1831 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
1812 return;
1813 } 1832 }
1814 $self->assertUnexpectedToken($next->value(), __LINE__); 1833 $self->assertUnexpectedToken($next->value(), __LINE__);
1815 } 1834 }
1816 1835
1817 sub parseUnionMemberTypes 1836 sub parseUnionMemberTypes
1818 { 1837 {
1819 my $self = shift; 1838 my $self = shift;
1820 my $next = $self->nextToken(); 1839 my $next = $self->nextToken();
1821 if ($next->value() eq "or") { 1840 if ($next->value() eq "or") {
1841 my @types = ();
1822 $self->assertTokenValue($self->getToken(), "or", __LINE__); 1842 $self->assertTokenValue($self->getToken(), "or", __LINE__);
1823 $self->parseUnionMemberType(); 1843 push @types, $self->parseUnionMemberType();
1824 $self->parseUnionMemberTypes(); 1844 push @types, $self->parseUnionMemberTypes();
1845 return @types;
1825 } 1846 }
1847 return ();
haraken 2013/05/15 12:09:43 Nit: You can write: my @types = (); if (...)
1826 } 1848 }
1827 1849
1828 sub parseNonAnyType 1850 sub parseNonAnyType
1829 { 1851 {
1830 my $self = shift; 1852 my $self = shift;
1831 my $next = $self->nextToken(); 1853 my $next = $self->nextToken();
1832 if ($next->value() =~ /$nextNonAnyType_1/) { 1854 if ($next->value() =~ /$nextNonAnyType_1/) {
1833 return $self->parsePrimitiveType() . $self->parseTypeSuffix(); 1855 return $self->parsePrimitiveType() . $self->parseTypeSuffix();
1834 } 1856 }
1835 if ($next->value() eq "ByteString") { 1857 if ($next->value() eq "ByteString") {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 $customConstructor->{overloadedIndex} = $index++; 2237 $customConstructor->{overloadedIndex} = $index++;
2216 push(@{$interface->customConstructors}, $customConstructor); 2238 push(@{$interface->customConstructors}, $customConstructor);
2217 } 2239 }
2218 delete $extendedAttributeList->{"CustomConstructors"}; 2240 delete $extendedAttributeList->{"CustomConstructors"};
2219 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; 2241 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING";
2220 } 2242 }
2221 $interface->extendedAttributes($extendedAttributeList); 2243 $interface->extendedAttributes($extendedAttributeList);
2222 } 2244 }
2223 2245
2224 1; 2246 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698