MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / generate_header

Function generate_header

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

Source from the content-addressed store, hash-verified

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

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