OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
7 | 7 |
8 import emitter | 8 import emitter |
9 import idlnode | 9 import idlnode |
10 import logging | 10 import logging |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 self._interface.id is self._super_interface): | 1243 self._interface.id is self._super_interface): |
1244 self._EmitConstant(self._members_emitter, constant) | 1244 self._EmitConstant(self._members_emitter, constant) |
1245 | 1245 |
1246 def _EmitConstant(self, emitter, constant): | 1246 def _EmitConstant(self, emitter, constant): |
1247 emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', | 1247 emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', |
1248 NAME=constant.id, | 1248 NAME=constant.id, |
1249 TYPE=constant.type.id, | 1249 TYPE=constant.type.id, |
1250 VALUE=constant.value) | 1250 VALUE=constant.value) |
1251 | 1251 |
1252 def AddAttribute(self, getter, setter): | 1252 def AddAttribute(self, getter, setter): |
1253 if getter: | 1253 if getter and setter and getter.type.id == setter.type.id: |
1254 self._members_emitter.Emit('\n $TYPE get $NAME();\n', | 1254 self._members_emitter.Emit('\n $TYPE $NAME;\n', |
1255 NAME=getter.id, TYPE=getter.type.id) | 1255 NAME=getter.id, TYPE=getter.type.id); |
1256 if setter: | 1256 return |
1257 self._members_emitter.Emit('\n void set $NAME($TYPE value);\n', | 1257 if getter and not setter: |
1258 NAME=setter.id, TYPE=setter.type.id) | 1258 self._members_emitter.Emit('\n final $TYPE $NAME;\n', |
| 1259 NAME=getter.id, TYPE=getter.type.id); |
| 1260 return |
| 1261 raise Exception('Unexpected getter/setter combination %s %s' % |
| 1262 (getter, setter)) |
1259 | 1263 |
1260 def AddIndexer(self, element_type): | 1264 def AddIndexer(self, element_type): |
1261 # Interface inherits all operations from List<element_type>. | 1265 # Interface inherits all operations from List<element_type>. |
1262 pass | 1266 pass |
1263 | 1267 |
1264 def AddOperation(self, info): | 1268 def AddOperation(self, info): |
1265 """ | 1269 """ |
1266 Arguments: | 1270 Arguments: |
1267 operations - contains the overloads, one or more operations with the same | 1271 operations - contains the overloads, one or more operations with the same |
1268 name. | 1272 name. |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 # generate the constants as part of the class. This will need to go away | 1975 # generate the constants as part of the class. This will need to go away |
1972 # if we revert back to generating interfaces. | 1976 # if we revert back to generating interfaces. |
1973 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', | 1977 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', |
1974 NAME=constant.id, | 1978 NAME=constant.id, |
1975 TYPE=constant.type.id, | 1979 TYPE=constant.type.id, |
1976 VALUE=constant.value) | 1980 VALUE=constant.value) |
1977 | 1981 |
1978 pass | 1982 pass |
1979 | 1983 |
1980 def AddAttribute(self, getter, setter): | 1984 def AddAttribute(self, getter, setter): |
1981 use_fields = True | |
1982 output_type = getter and self._NarrowOutputType(getter.type.id) | 1985 output_type = getter and self._NarrowOutputType(getter.type.id) |
1983 input_type = setter and self._NarrowInputType(setter.type.id) | 1986 input_type = setter and self._NarrowInputType(setter.type.id) |
1984 if use_fields and getter and setter: | 1987 if getter and setter and input_type == output_type: |
1985 if input_type == output_type: | 1988 self._members_emitter.Emit( |
1986 self._members_emitter.Emit( | 1989 '\n $TYPE $NAME;\n', |
1987 '\n $TYPE $NAME;\n', | 1990 NAME=getter.id, TYPE=output_type) |
1988 NAME=getter.id, TYPE=output_type) | 1991 return |
1989 return | 1992 if getter and not setter: |
1990 if use_fields and getter and not setter: | 1993 self._members_emitter.Emit( |
1991 self._members_emitter.Emit( | 1994 '\n final $TYPE $NAME;\n', |
1992 '\n final $TYPE $NAME;\n', | 1995 NAME=getter.id, TYPE=output_type) |
1993 NAME=getter.id, TYPE=output_type) | 1996 return |
1994 return | |
1995 if getter: | 1997 if getter: |
1996 self._AddGetter(getter) | 1998 self._AddGetter(getter) |
1997 if setter: | 1999 if setter: |
1998 self._AddSetter(setter) | 2000 self._AddSetter(setter) |
1999 | 2001 |
2000 def _AddGetter(self, attr): | 2002 def _AddGetter(self, attr): |
2001 # TODO(sra): Remove native body when Issue 829 fixed. | 2003 # TODO(sra): Remove native body when Issue 829 fixed. |
2002 self._members_emitter.Emit( | 2004 self._members_emitter.Emit( |
2003 '\n $TYPE get $NAME() native "return this.$NAME;";\n', | 2005 '\n $TYPE get $NAME() native "return this.$NAME;";\n', |
2004 NAME=attr.id, TYPE=self._NarrowOutputType(attr.type.id)) | 2006 NAME=attr.id, TYPE=self._NarrowOutputType(attr.type.id)) |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 INDENT=indent, | 2314 INDENT=indent, |
2313 NATIVENAME=native_name, | 2315 NATIVENAME=native_name, |
2314 ARGS=argument_expressions) | 2316 ARGS=argument_expressions) |
2315 | 2317 |
2316 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 2318 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2317 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 2319 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2318 NATIVE_NAME=native_name, | 2320 NATIVE_NAME=native_name, |
2319 TYPE=info.type_name, | 2321 TYPE=info.type_name, |
2320 PARAMS=', '.join(arg_names), | 2322 PARAMS=', '.join(arg_names), |
2321 INTERFACE=self._interface.id) | 2323 INTERFACE=self._interface.id) |
OLD | NEW |