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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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
UnionType) |
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 UnionType) |
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 Loading... |
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( UnionType => { |
| 111 unionMemberTypes => '@', # (UnionType or string)[] |
| 112 }); |
| 113 |
110 # Maps 'typedef name' -> Typedef | 114 # Maps 'typedef name' -> Typedef |
111 my %typedefs = (); | 115 my %typedefs = (); |
112 | 116 |
113 sub new { | 117 sub new { |
114 my $class = shift; | 118 my $class = shift; |
115 | 119 |
116 my $emptyToken = Token->new(); | 120 my $emptyToken = Token->new(); |
117 $emptyToken->type(EmptyToken); | 121 $emptyToken->type(EmptyToken); |
118 $emptyToken->value("empty"); | 122 $emptyToken->value("empty"); |
119 | 123 |
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 return $self->getToken()->value(); | 1748 return $self->getToken()->value(); |
1745 } | 1749 } |
1746 $self->assertUnexpectedToken($next->value(), __LINE__); | 1750 $self->assertUnexpectedToken($next->value(), __LINE__); |
1747 } | 1751 } |
1748 | 1752 |
1749 sub parseType | 1753 sub parseType |
1750 { | 1754 { |
1751 my $self = shift; | 1755 my $self = shift; |
1752 my $next = $self->nextToken(); | 1756 my $next = $self->nextToken(); |
1753 if ($next->value() eq "(") { | 1757 if ($next->value() eq "(") { |
1754 $self->parseUnionType(); | 1758 my $unionType = $self->parseUnionType(); |
1755 $self->parseTypeSuffix(); | 1759 my $suffix = $self->parseTypeSuffix(); |
1756 return; | 1760 die "Suffix after UnionType is not supported." if $suffix ne ""; |
| 1761 return $unionType; |
1757 } | 1762 } |
1758 if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) { | 1763 if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) { |
1759 return $self->parseSingleType(); | 1764 return $self->parseSingleType(); |
1760 } | 1765 } |
1761 $self->assertUnexpectedToken($next->value(), __LINE__); | 1766 $self->assertUnexpectedToken($next->value(), __LINE__); |
1762 } | 1767 } |
1763 | 1768 |
1764 sub parseSingleType | 1769 sub parseSingleType |
1765 { | 1770 { |
1766 my $self = shift; | 1771 my $self = shift; |
1767 my $next = $self->nextToken(); | 1772 my $next = $self->nextToken(); |
1768 if ($next->value() eq "any") { | 1773 if ($next->value() eq "any") { |
1769 $self->assertTokenValue($self->getToken(), "any", __LINE__); | 1774 $self->assertTokenValue($self->getToken(), "any", __LINE__); |
1770 return "any" . $self->parseTypeSuffixStartingWithArray(); | 1775 return "any" . $self->parseTypeSuffixStartingWithArray(); |
1771 } | 1776 } |
1772 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1
/) { | 1777 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1
/) { |
1773 return $self->parseNonAnyType(); | 1778 return $self->parseNonAnyType(); |
1774 } | 1779 } |
1775 $self->assertUnexpectedToken($next->value(), __LINE__); | 1780 $self->assertUnexpectedToken($next->value(), __LINE__); |
1776 } | 1781 } |
1777 | 1782 |
1778 sub parseUnionType | 1783 sub parseUnionType |
1779 { | 1784 { |
1780 my $self = shift; | 1785 my $self = shift; |
1781 my $next = $self->nextToken(); | 1786 my $next = $self->nextToken(); |
1782 if ($next->value() eq "(") { | 1787 if ($next->value() eq "(") { |
| 1788 my $unionType = UnionType->new(); |
1783 $self->assertTokenValue($self->getToken(), "(", __LINE__); | 1789 $self->assertTokenValue($self->getToken(), "(", __LINE__); |
1784 $self->parseUnionMemberType(); | 1790 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType(); |
1785 $self->assertTokenValue($self->getToken(), "or", __LINE__); | 1791 $self->assertTokenValue($self->getToken(), "or", __LINE__); |
1786 $self->parseUnionMemberType(); | 1792 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberType(); |
1787 $self->parseUnionMemberTypes(); | 1793 push @{$unionType->unionMemberTypes}, $self->parseUnionMemberTypes(); |
1788 $self->assertTokenValue($self->getToken(), ")", __LINE__); | 1794 $self->assertTokenValue($self->getToken(), ")", __LINE__); |
1789 return; | 1795 return $unionType; |
1790 } | 1796 } |
1791 $self->assertUnexpectedToken($next->value(), __LINE__); | 1797 $self->assertUnexpectedToken($next->value(), __LINE__); |
1792 } | 1798 } |
1793 | 1799 |
| 1800 # Returns UnionType or string |
1794 sub parseUnionMemberType | 1801 sub parseUnionMemberType |
1795 { | 1802 { |
1796 my $self = shift; | 1803 my $self = shift; |
1797 my $next = $self->nextToken(); | 1804 my $next = $self->nextToken(); |
1798 if ($next->value() eq "(") { | 1805 if ($next->value() eq "(") { |
1799 $self->parseUnionType(); | 1806 my $unionType = $self->parseUnionType(); |
1800 $self->parseTypeSuffix(); | 1807 my $suffix = $self->parseTypeSuffix(); |
1801 return; | 1808 die "Suffix after UnionType is not supported." if $suffix ne ""; |
| 1809 return $unionType; |
1802 } | 1810 } |
1803 if ($next->value() eq "any") { | 1811 if ($next->value() eq "any") { |
1804 $self->assertTokenValue($self->getToken(), "any", __LINE__); | 1812 my $type = $self->assertTokenValue($self->getToken(), "any", __LINE__); |
1805 $self->assertTokenValue($self->getToken(), "[", __LINE__); | 1813 $type .= $self->assertTokenValue($self->getToken(), "[", __LINE__); |
1806 $self->assertTokenValue($self->getToken(), "]", __LINE__); | 1814 $type .= $self->assertTokenValue($self->getToken(), "]", __LINE__); |
1807 $self->parseTypeSuffix(); | 1815 $type .= $self->parseTypeSuffix(); |
1808 return; | 1816 return $type; |
1809 } | 1817 } |
1810 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1
/) { | 1818 if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1
/) { |
1811 $self->parseNonAnyType(); | 1819 return $self->parseNonAnyType(); |
1812 return; | |
1813 } | 1820 } |
1814 $self->assertUnexpectedToken($next->value(), __LINE__); | 1821 $self->assertUnexpectedToken($next->value(), __LINE__); |
1815 } | 1822 } |
1816 | 1823 |
1817 sub parseUnionMemberTypes | 1824 sub parseUnionMemberTypes |
1818 { | 1825 { |
1819 my $self = shift; | 1826 my $self = shift; |
| 1827 my @types = (); |
1820 my $next = $self->nextToken(); | 1828 my $next = $self->nextToken(); |
1821 if ($next->value() eq "or") { | 1829 if ($next->value() eq "or") { |
1822 $self->assertTokenValue($self->getToken(), "or", __LINE__); | 1830 $self->assertTokenValue($self->getToken(), "or", __LINE__); |
1823 $self->parseUnionMemberType(); | 1831 push @types, $self->parseUnionMemberType(); |
1824 $self->parseUnionMemberTypes(); | 1832 push @types, $self->parseUnionMemberTypes(); |
1825 } | 1833 } |
| 1834 return @types; |
1826 } | 1835 } |
1827 | 1836 |
1828 sub parseNonAnyType | 1837 sub parseNonAnyType |
1829 { | 1838 { |
1830 my $self = shift; | 1839 my $self = shift; |
1831 my $next = $self->nextToken(); | 1840 my $next = $self->nextToken(); |
1832 if ($next->value() =~ /$nextNonAnyType_1/) { | 1841 if ($next->value() =~ /$nextNonAnyType_1/) { |
1833 return $self->parsePrimitiveType() . $self->parseTypeSuffix(); | 1842 return $self->parsePrimitiveType() . $self->parseTypeSuffix(); |
1834 } | 1843 } |
1835 if ($next->value() eq "ByteString") { | 1844 if ($next->value() eq "ByteString") { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 $customConstructor->{overloadedIndex} = $index++; | 2224 $customConstructor->{overloadedIndex} = $index++; |
2216 push(@{$interface->customConstructors}, $customConstructor); | 2225 push(@{$interface->customConstructors}, $customConstructor); |
2217 } | 2226 } |
2218 delete $extendedAttributeList->{"CustomConstructors"}; | 2227 delete $extendedAttributeList->{"CustomConstructors"}; |
2219 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; | 2228 $extendedAttributeList->{"CustomConstructor"} = "VALUE_IS_MISSING"; |
2220 } | 2229 } |
2221 $interface->extendedAttributes($extendedAttributeList); | 2230 $interface->extendedAttributes($extendedAttributeList); |
2222 } | 2231 } |
2223 | 2232 |
2224 1; | 2233 1; |
OLD | NEW |