Bug 1738926 Part 1: Check if sublayers need to be rebuilt. r=mstange
[gecko.git] / accessible / mac / SelectorMapGen.py
blob68074c8490b9f784cb31a5504390cbb96e82bc9e
1 #!/usr/bin/env python
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from __future__ import absolute_import
9 import re
12 def write_map(fd, name, text):
13 matches = re.findall(r"^//\s(AX\w+)\n-\s?\(.*?\)([\w:]+)", text, re.MULTILINE)
14 entries = [' @"%s" : @"%s"' % (a, s) for [a, s] in matches]
16 fd.write("NSDictionary* %s() {\n" % name)
17 fd.write(" // Create an autoreleased NSDictionary object once, and leak it.\n")
18 fd.write(" static NSDictionary* s%s = [@{\n" % name)
19 fd.write(",\n".join(entries))
20 fd.write("\n } retain];\n\n")
21 fd.write(" return s%s;\n" % name)
22 fd.write("}\n\n")
25 def gen_mm(fd, protocol_file):
26 protocol = open(protocol_file).read()
27 fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
28 fd.write("#import <Foundation/Foundation.h>\n\n")
29 fd.write("namespace mozilla {\nnamespace a11y {\nnamespace mac {\n\n")
31 sections = re.findall(
32 r"#pragma mark - (\w+)\n(.*?)(?=(?:#pragma mark|@end))", protocol, re.DOTALL
34 for name, text in sections:
35 write_map(fd, name, text)
37 fd.write("}\n}\n}\n")
40 def gen_h(fd, protocol_file):
41 protocol = open(protocol_file).read()
42 sections = re.findall(
43 r"#pragma mark - (\w+)\n(.*?)(?=(?:#pragma mark|@end))", protocol, re.DOTALL
46 fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
47 fd.write("#ifndef _MacSelectorMap_H_\n")
48 fd.write("#define _MacSelectorMap_H_\n")
49 fd.write("\n@class NSDictionary;\n")
50 fd.write("\nnamespace mozilla {\nnamespace a11y {\nnamespace mac {\n\n")
51 for name, _ in sections:
52 fd.write("NSDictionary* %s();\n\n" % name)
53 fd.write("}\n}\n}\n")
54 fd.write("\n#endif\n")
57 # For debugging
58 if __name__ == "__main__":
59 import sys
61 gen_mm(sys.stdout, "accessible/mac/MOXAccessibleProtocol.h")
63 gen_h(sys.stdout, "accessible/mac/MOXAccessibleProtocol.h")