Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # This module's classes provide an interface to mojo modules. Modules are | 5 # This module's classes provide an interface to mojo modules. Modules are |
| 6 # collections of interfaces and structs to be used by mojo ipc clients and | 6 # collections of interfaces and structs to be used by mojo ipc clients and |
| 7 # servers. | 7 # servers. |
| 8 # | 8 # |
| 9 # A simple interface would be created this way: | 9 # A simple interface would be created this way: |
| 10 # module = mojom.generate.module.Module('Foo') | 10 # module = mojom.generate.module.Module('Foo') |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 | 809 |
| 810 def HasCallbacks(interface): | 810 def HasCallbacks(interface): |
| 811 for method in interface.methods: | 811 for method in interface.methods: |
| 812 if method.response_parameters != None: | 812 if method.response_parameters != None: |
| 813 return True | 813 return True |
| 814 return False | 814 return False |
| 815 | 815 |
| 816 | 816 |
| 817 # Finds out whether an interface passes associated interfaces and associated | 817 # Finds out whether an interface passes associated interfaces and associated |
| 818 # interface requests. | 818 # interface requests. |
| 819 def PassesAssociatedKinds(interface): | 819 def PassesAssociatedKinds(interface): |
|
yzshen1
2017/04/19 21:11:34
This function should be able to call MethodPassesA
wangjimmy
2017/04/20 15:36:44
Done.
| |
| 820 def _ContainsAssociatedKinds(kind, visited_kinds): | 820 def _ContainsAssociatedKinds(kind, visited_kinds): |
| 821 if kind in visited_kinds: | 821 if kind in visited_kinds: |
| 822 # No need to examine the kind again. | 822 # No need to examine the kind again. |
| 823 return False | 823 return False |
| 824 visited_kinds.add(kind) | 824 visited_kinds.add(kind) |
| 825 if IsAssociatedKind(kind): | 825 if IsAssociatedKind(kind): |
| 826 return True | 826 return True |
| 827 if IsArrayKind(kind): | 827 if IsArrayKind(kind): |
| 828 return _ContainsAssociatedKinds(kind.kind, visited_kinds) | 828 return _ContainsAssociatedKinds(kind.kind, visited_kinds) |
| 829 if IsStructKind(kind) or IsUnionKind(kind): | 829 if IsStructKind(kind) or IsUnionKind(kind): |
| 830 for field in kind.fields: | 830 for field in kind.fields: |
| 831 if _ContainsAssociatedKinds(field.kind, visited_kinds): | 831 if _ContainsAssociatedKinds(field.kind, visited_kinds): |
| 832 return True | 832 return True |
| 833 if IsMapKind(kind): | 833 if IsMapKind(kind): |
| 834 # No need to examine the key kind, only primitive kinds and non-nullable | 834 # No need to examine the key kind, only primitive kinds and non-nullable |
| 835 # string are allowed to be key kinds. | 835 # string are allowed to be key kinds. |
| 836 return _ContainsAssociatedKinds(kind.value_kind, visited_kinds) | 836 return _ContainsAssociatedKinds(kind.value_kind, visited_kinds) |
| 837 return False | 837 return False |
| 838 | 838 |
| 839 visited_kinds = set() | 839 visited_kinds = set() |
| 840 for method in interface.methods: | 840 for method in interface.methods: |
| 841 for param in method.parameters: | 841 for param in method.parameters: |
| 842 if _ContainsAssociatedKinds(param.kind, visited_kinds): | 842 if _ContainsAssociatedKinds(param.kind, visited_kinds): |
| 843 return True | 843 return True |
| 844 if method.response_parameters != None: | 844 if method.response_parameters != None: |
| 845 for param in method.response_parameters: | 845 for param in method.response_parameters: |
| 846 if _ContainsAssociatedKinds(param.kind, visited_kinds): | 846 if _ContainsAssociatedKinds(param.kind, visited_kinds): |
| 847 return True | 847 return True |
| 848 return False | 848 return False |
| 849 | 849 |
|
yzshen1
2017/04/19 21:11:34
I understand some files don't respect this, but we
wangjimmy
2017/04/20 15:36:44
Done.
| |
| 850 # Finds out whether a method passes associated interfaces and associated | |
| 851 # interface requests. | |
| 852 def MethodPassesAssociatedKinds(method): | |
| 853 def _ContainsAssociatedKinds(kind, visited_kinds): | |
| 854 if kind in visited_kinds: | |
| 855 # No need to examine the kind again. | |
| 856 return False | |
| 857 visited_kinds.add(kind) | |
| 858 if IsAssociatedKind(kind): | |
| 859 return True | |
| 860 if IsArrayKind(kind): | |
| 861 return _ContainsAssociatedKinds(kind.kind, visited_kinds) | |
| 862 if IsStructKind(kind) or IsUnionKind(kind): | |
| 863 for field in kind.fields: | |
| 864 if _ContainsAssociatedKinds(field.kind, visited_kinds): | |
| 865 return True | |
| 866 if IsMapKind(kind): | |
| 867 # No need to examine the key kind, only primitive kinds and non-nullable | |
| 868 # string are allowed to be key kinds. | |
| 869 return _ContainsAssociatedKinds(kind.value_kind, visited_kinds) | |
| 870 return False | |
| 871 | |
| 872 visited_kinds = set() | |
| 873 for param in method.parameters: | |
| 874 if _ContainsAssociatedKinds(param.kind, visited_kinds): | |
| 875 return True | |
| 876 if method.response_parameters != None: | |
| 877 for param in method.response_parameters: | |
| 878 if _ContainsAssociatedKinds(param.kind, visited_kinds): | |
| 879 return True | |
| 880 return False | |
| 850 | 881 |
| 851 def HasSyncMethods(interface): | 882 def HasSyncMethods(interface): |
| 852 for method in interface.methods: | 883 for method in interface.methods: |
| 853 if method.sync: | 884 if method.sync: |
| 854 return True | 885 return True |
| 855 return False | 886 return False |
| 856 | 887 |
| 857 | 888 |
| 858 def ContainsHandlesOrInterfaces(kind): | 889 def ContainsHandlesOrInterfaces(kind): |
| 859 """Check if the kind contains any handles. | 890 """Check if the kind contains any handles. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 882 return True | 913 return True |
| 883 elif IsAnyInterfaceKind(kind): | 914 elif IsAnyInterfaceKind(kind): |
| 884 return True | 915 return True |
| 885 elif IsArrayKind(kind): | 916 elif IsArrayKind(kind): |
| 886 return Check(kind.kind) | 917 return Check(kind.kind) |
| 887 elif IsMapKind(kind): | 918 elif IsMapKind(kind): |
| 888 return Check(kind.key_kind) or Check(kind.value_kind) | 919 return Check(kind.key_kind) or Check(kind.value_kind) |
| 889 else: | 920 else: |
| 890 return False | 921 return False |
| 891 return Check(kind) | 922 return Check(kind) |
| OLD | NEW |