MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / generate_header

Function generate_header

javascript/private/gen_file.py:78–121  ·  view source on GitHub ↗
(file_name, out, js_map, just_declare, utf8)

Source from the content-addressed store, hash-verified

76
77
78def generate_header(file_name, out, js_map, just_declare, utf8):
79 define_guard = "WEBDRIVER_{}".format(os.path.basename(file_name.upper()).replace(".", "_"))
80 include_stddef = "" if utf8 else "\n#include <stddef.h> // For wchar_t."
81 out.write(
82 f"""{_copyright}
83
84/* AUTO GENERATED - DO NOT EDIT BY HAND */
85#ifndef {define_guard}
86#define {define_guard}
87{include_stddef}
88#include <string> // For std::(w)string.
89
90namespace webdriver {{
91namespace atoms {{
92
93"""
94 )
95
96 string_type = "std::string" if utf8 else "std::wstring"
97 char_type = "char" if utf8 else "wchar_t"
98
99 for name, file in js_map.items():
100 if just_declare:
101 out.write(f"extern const {char_type}* const {name.upper()}[];\n")
102 else:
103 contents = open(file).read()
104 write_atom_literal(out, name, contents, "hh", utf8)
105
106 out.write(
107 f"""
108static inline {string_type} asString(const {char_type}* const atom[]) {{
109 {string_type} source;
110 for (int i = 0; atom[i] != NULL; i++) {{
111 source += atom[i];
112 }}
113 return source;
114}}
115
116}} // namespace atoms
117}} // namespace webdriver
118
119#endif // {define_guard}
120"""
121 )
122
123
124def generate_cc_source(out, js_map, utf8):

Callers 1

mainFunction · 0.85

Calls 4

write_atom_literalFunction · 0.85
readMethod · 0.65
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected