| 1 |
''' |
| 2 |
MIT License |
| 3 |
|
| 4 |
Copyright 2020 Sophie Winter |
| 5 |
|
| 6 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 7 |
|
| 8 |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 9 |
|
| 10 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 11 |
''' |
| 12 |
|
| 13 |
import logging |
| 14 |
from datetime import datetime |
| 15 |
import os |
| 16 |
from os import path |
| 17 |
import re |
| 18 |
import mmap |
| 19 |
from collections import OrderedDict |
| 20 |
import tempfile |
| 21 |
import subprocess |
| 22 |
|
| 23 |
import parse |
| 24 |
from ast import * |
| 25 |
from version import COMBO_FACTOR, Version |
| 26 |
|
| 27 |
logger = logging.getLogger(__name__) |
| 28 |
|
| 29 |
INDENT = ' ' # used for generating code |
| 30 |
PROJECT_NAME = 'gtk-layer-shell' |
| 31 |
|
| 32 |
LGPL3_HEADER = ''' |
| 33 |
This program is free software; you can redistribute it and/or |
| 34 |
modify it under the terms of the GNU Lesser General Public |
| 35 |
License as published by the Free Software Foundation; either |
| 36 |
version 3 of the License, or (at your option) any later version. |
| 37 |
|
| 38 |
This program is distributed in the hope that it will be useful, |
| 39 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 41 |
Lesser General Public License for more details. |
| 42 |
|
| 43 |
You should have received a copy of the GNU Lesser General Public License |
| 44 |
along with this program; if not, write to the Free Software Foundation, |
| 45 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 46 |
''' |
| 47 |
|
| 48 |
CODE_EXTENSIONS = set(['.h', '.hpp', '.c', '.cpp', '.cc']) |
| 49 |
|
| 50 |
def typdef_to_struct_name(typedef): |
| 51 |
return '_' + typedef |
| 52 |
|
| 53 |
def get_all_source_files(search_dir): |
| 54 |
result = [] |
| 55 |
for item in os.listdir(search_dir): |
| 56 |
p = path.join(search_dir, item) |
| 57 |
if path.isdir(p): |
| 58 |
result += get_all_source_files(p) |
| 59 |
elif path.splitext(p)[1] in CODE_EXTENSIONS: |
| 60 |
result.append(p) |
| 61 |
return result |
| 62 |
|
| 63 |
def remove_headers_from_dir(header_dir): |
| 64 |
logger.info('Clearing header files out of ' + header_dir) |
| 65 |
for item in os.listdir(header_dir): |
| 66 |
p = path.join(header_dir, item) |
| 67 |
if item != 'common.h' and path.splitext(p)[1] == '.h': |
| 68 |
os.remove(p) |
| 69 |
|
| 70 |
def struct_regex_string(struct_name): |
| 71 |
return r'struct\s+' + struct_name + r'\s*\{' |
| 72 |
|
| 73 |
def extract_body(file_content, struct_name): |
| 74 |
halves = re.split(struct_regex_string(struct_name), file_content) |
| 75 |
if len(halves) < 2: |
| 76 |
raise RuntimeError(struct_name + ' not declared in ' + code_path + ' (even though it was detected)') |
| 77 |
if len(halves) > 2: |
| 78 |
raise RuntimeError(struct_name + ' declared multiple times in ' + code_path) |
| 79 |
body = '' |
| 80 |
brace_level = 1 |
| 81 |
for c in halves[1]: |
| 82 |
if c == '{': |
| 83 |
brace_level += 1 |
| 84 |
elif c == '}': |
| 85 |
brace_level -= 1 |
| 86 |
if brace_level <= 0: |
| 87 |
break |
| 88 |
body += c |
| 89 |
return body |
| 90 |
|
| 91 |
def camel_case_to_words(name): |
| 92 |
result = [] |
| 93 |
word = '' |
| 94 |
for l in name: |
| 95 |
if l.isupper() and word: |
| 96 |
result.append(word) |
| 97 |
word = '' |
| 98 |
word += l.lower() |
| 99 |
if word: |
| 100 |
result.append(word) |
| 101 |
return result |
| 102 |
|
| 103 |
def c_function(return_type, name, arg_list, body): |
| 104 |
result = '' |
| 105 |
result += return_type.str_left(False) |
| 106 |
result += ' ' + name + '(' |
| 107 |
arg_strs = [c_type.str_left(False) + ' ' + name + c_type.str_right(False) for c_type, name in arg_list] |
| 108 |
result += ', '.join(arg_strs) |
| 109 |
result += ')' + return_type.str_right(False) + ' {\n' |
| 110 |
for line in body.strip().splitlines(): |
| 111 |
result += INDENT + line + '\n' |
| 112 |
result += '}\n' |
| 113 |
return result |
| 114 |
|
| 115 |
def write_tmp_file(text): |
| 116 |
f = tempfile.NamedTemporaryFile(mode='w', delete=True) |
| 117 |
f.write(text) |
| 118 |
f.flush() |
| 119 |
return f |
| 120 |
|
| 121 |
def diff_between(old, new): |
| 122 |
old_f = write_tmp_file(old) |
| 123 |
new_f = write_tmp_file(new) |
| 124 |
result = subprocess.run(['diff', old_f.name, new_f.name], capture_output=True, text=True) |
| 125 |
code = '' |
| 126 |
for line in result.stdout.splitlines(): |
| 127 |
if line.startswith('<'): |
| 128 |
code += '// -' + line[1:] + '\n' |
| 129 |
elif line.startswith('>'): |
| 130 |
code += '// +' + line[1:] + '\n' |
| 131 |
return code |
| 132 |
|
| 133 |
class ResolveContext: |
| 134 |
def __init__(self, project, struct, version): |
| 135 |
self.project = project |
| 136 |
self.struct = struct |
| 137 |
self.version = version |
| 138 |
|
| 139 |
class StructVersion: |
| 140 |
def __init__(self, code_path, project, struct, version): |
| 141 |
with open(code_path, 'r') as f: |
| 142 |
source_code = f.read() |
| 143 |
self.code_path = code_path |
| 144 |
self.first_version = version |
| 145 |
self.last_version = version |
| 146 |
self.struct_name = struct.struct_name |
| 147 |
self.copyright_lines = set(re.findall(r'[Cc]opyright .*(?=\n)', source_code)) |
| 148 |
self.body = extract_body(source_code, self.struct_name) |
| 149 |
self.ast = parse.parse_ast(self.body) |
| 150 |
self.ast.resolve(ResolveContext(project, struct, version)) |
| 151 |
|
| 152 |
def get_code_path(self): |
| 153 |
return self.code_path |
| 154 |
|
| 155 |
def get_property_list(self): |
| 156 |
return self.ast.get_property_list('') |
| 157 |
|
| 158 |
def version_range_str(self): |
| 159 |
if self.first_version == self.last_version: |
| 160 |
return str(self.first_version) |
| 161 |
else: |
| 162 |
return str(self.first_version) + ' - ' + str(self.last_version) |
| 163 |
|
| 164 |
def emit_definition(self, generated): |
| 165 |
result = '' |
| 166 |
result += '// Valid for GTK ' + self.version_range_str() + '\n' |
| 167 |
result += 'struct ' + str(self) + '\n{' |
| 168 |
if generated: |
| 169 |
result += ( |
| 170 |
'\n' + INDENT + |
| 171 |
('\n' + INDENT).join(str(self.ast).splitlines()) + |
| 172 |
'\n') |
| 173 |
else: |
| 174 |
result += self.body |
| 175 |
result += '};\n' |
| 176 |
return result |
| 177 |
|
| 178 |
def is_valid_for(self, version): |
| 179 |
return version >= self.first_version and version <= self.last_version |
| 180 |
|
| 181 |
def versioned_struct_name(self): |
| 182 |
return self.struct_name + '_' + self.first_version.c_id() |
| 183 |
|
| 184 |
def __str__(self): |
| 185 |
return self.versioned_struct_name() |
| 186 |
|
| 187 |
def __eq__(self, other): |
| 188 |
assert isinstance(other, StructVersion) |
| 189 |
return self.ast == other.ast |
| 190 |
|
| 191 |
class Property: |
| 192 |
def __init__(self, struct, c_type, name, version_ids): |
| 193 |
assert isinstance(struct, Struct) |
| 194 |
assert isinstance(c_type, CType) |
| 195 |
assert isinstance(name, str) |
| 196 |
assert isinstance(version_ids, list) |
| 197 |
for i in version_ids: |
| 198 |
assert isinstance(i, bool) # If this property is supported for each version ID |
| 199 |
self.struct = struct |
| 200 |
self.c_type = c_type |
| 201 |
self.name = name |
| 202 |
self.version_ids = version_ids |
| 203 |
|
| 204 |
def all_versions_supported(self): |
| 205 |
for i in self.version_ids: |
| 206 |
if not i: |
| 207 |
return False |
| 208 |
return True |
| 209 |
|
| 210 |
def get_id_name(self): |
| 211 |
return self.name.replace('.', '_') |
| 212 |
|
| 213 |
def get_fn_name(self, action, suffix): |
| 214 |
result = '' |
| 215 |
result += '_'.join(camel_case_to_words(self.struct.typedef)) |
| 216 |
result += '_priv_' |
| 217 |
if action: |
| 218 |
result += action + '_' |
| 219 |
result += self.get_id_name() |
| 220 |
if suffix: |
| 221 |
result += '_' + suffix |
| 222 |
return result |
| 223 |
|
| 224 |
def emit_version_id_switch(self, on_supported, on_unsupported): |
| 225 |
result = '' |
| 226 |
result += 'switch (' + self.struct.get_version_id_fn_name() + '()) {\n' |
| 227 |
for i, supported in enumerate(self.version_ids): |
| 228 |
result += INDENT + 'case ' + str(i) + ': ' |
| 229 |
type_name = 'struct ' + self.struct.versions[i].versioned_struct_name() |
| 230 |
if supported: |
| 231 |
result += on_supported(type_name) |
| 232 |
else: |
| 233 |
result += on_unsupported(type_name) |
| 234 |
result += '\n' |
| 235 |
result += INDENT + 'default: g_error("Invalid version ID"); g_abort();\n' |
| 236 |
result += '}' |
| 237 |
return result |
| 238 |
|
| 239 |
def emit_ptr_getter(self): |
| 240 |
ret_type = PtrType(self.c_type) |
| 241 |
suffix = 'ptr' if self.all_versions_supported() else 'ptr_or_null' |
| 242 |
fn_name = self.get_fn_name('get', suffix) |
| 243 |
arg_list = [(self.struct.get_ptr_type(), 'self')] |
| 244 |
body = self.emit_version_id_switch( |
| 245 |
lambda type_name: 'return (' + str(ret_type) + ')&((' + type_name + '*)self)->' + self.name + ';', |
| 246 |
lambda type_name: 'return NULL;') |
| 247 |
return c_function(ret_type, fn_name, arg_list, body) |
| 248 |
|
| 249 |
def emit_is_supported(self): |
| 250 |
ret_type = StdType('gboolean') |
| 251 |
fn_name = self.get_fn_name('get', 'supported') |
| 252 |
body = self.emit_version_id_switch( |
| 253 |
lambda type_name: 'return TRUE;', |
| 254 |
lambda type_name: 'return FALSE;') |
| 255 |
return c_function(ret_type, fn_name, [], body) |
| 256 |
|
| 257 |
def emit_not_supported_error(self, type_name): |
| 258 |
msg = '"' + self.struct.typedef + '::' + self.name + ' not supported on this GTK"' |
| 259 |
return 'g_error(' + msg + '); g_abort();' |
| 260 |
|
| 261 |
def emit_getter(self): |
| 262 |
ret_type = self.c_type |
| 263 |
suffix = '' if self.all_versions_supported() else 'or_abort' |
| 264 |
fn_name = self.get_fn_name('get', suffix) |
| 265 |
arg_list = [(self.struct.get_ptr_type(), 'self')] |
| 266 |
body = self.emit_version_id_switch( |
| 267 |
lambda type_name: 'return ((' + type_name + '*)self)->' + self.name + ';', |
| 268 |
self.emit_not_supported_error) |
| 269 |
return c_function(ret_type, fn_name, arg_list, body) |
| 270 |
|
| 271 |
def emit_setter(self): |
| 272 |
ret_type = StdType('void') |
| 273 |
suffix = '' if self.all_versions_supported() else 'or_abort' |
| 274 |
fn_name = self.get_fn_name('set', suffix) |
| 275 |
arg_list = [(self.struct.get_ptr_type(), 'self'), (self.c_type, self.get_id_name())] |
| 276 |
body = self.emit_version_id_switch( |
| 277 |
lambda type_name: '((' + type_name + '*)self)->' + self.name + ' = ' + self.get_id_name() + '; break;', |
| 278 |
self.emit_not_supported_error) |
| 279 |
return c_function(ret_type, fn_name, arg_list, body) |
| 280 |
|
| 281 |
def emit_functions(self): |
| 282 |
result = '' |
| 283 |
result += '// ' + self.struct.typedef + '::' + self.name + '\n\n' |
| 284 |
if not self.all_versions_supported(): |
| 285 |
result += self.emit_is_supported() |
| 286 |
result += '\n' |
| 287 |
if isinstance(self.c_type, CustomType) or isinstance(self.c_type, ArrayType): |
| 288 |
result += self.emit_ptr_getter() |
| 289 |
else: |
| 290 |
result += self.emit_getter() |
| 291 |
result += '\n' |
| 292 |
result += self.emit_setter() |
| 293 |
return result |
| 294 |
|
| 295 |
class Struct: |
| 296 |
def __init__(self, typedef): |
| 297 |
self.typedef = typedef |
| 298 |
self.struct_name = typdef_to_struct_name(typedef) |
| 299 |
self.versions = [] |
| 300 |
self.supported_versions = [] |
| 301 |
self.copyright_lines = set() |
| 302 |
self.search_regex = re.compile(bytes(struct_regex_string(self.struct_name), 'utf-8')) |
| 303 |
|
| 304 |
def lookup_version(self, version): |
| 305 |
for i in self.versions: |
| 306 |
if i.is_valid_for(version): |
| 307 |
return i |
| 308 |
|
| 309 |
def get_code_path(self): |
| 310 |
if self.versions: |
| 311 |
return self.versions[-1].get_code_path() |
| 312 |
else: |
| 313 |
return None |
| 314 |
|
| 315 |
def get_ptr_type(self): |
| 316 |
return PtrType(CustomType(self.typedef)) |
| 317 |
|
| 318 |
def get_version_id_fn_name(self): |
| 319 |
return '_'.join(camel_case_to_words(self.typedef)) + '_priv_get_version_id' |
| 320 |
|
| 321 |
def header_name(self): |
| 322 |
return '_'.join(camel_case_to_words(self.typedef)) + '_priv.h' |
| 323 |
|
| 324 |
def macro_name(self): |
| 325 |
return self.header_name().replace('.', '_').upper() |
| 326 |
|
| 327 |
def add_version(self, new): |
| 328 |
self.versions.append(new) |
| 329 |
self.supported_versions.append(new.first_version) |
| 330 |
self.copyright_lines = self.copyright_lines.union(new.copyright_lines) |
| 331 |
|
| 332 |
# Returns if any changes were made |
| 333 |
def simplify(self): |
| 334 |
new_versions = [] |
| 335 |
dropped_versions = 0 |
| 336 |
for v in self.versions: |
| 337 |
if new_versions and new_versions[-1] == v: |
| 338 |
dropped_versions += 1 |
| 339 |
new_versions[-1].last_version = v.last_version |
| 340 |
else: |
| 341 |
new_versions.append(v) |
| 342 |
if dropped_versions > 0: |
| 343 |
logger.info('Found ' + str(dropped_versions) + ' unnecessary versions of ' + self.typedef); |
| 344 |
self.versions = new_versions |
| 345 |
return dropped_versions > 0 |
| 346 |
|
| 347 |
def setup_properties(self): |
| 348 |
prop_dict = OrderedDict() |
| 349 |
for i, v in enumerate(self.versions): |
| 350 |
for c_type, name in v.get_property_list(): |
| 351 |
if name in prop_dict and not (prop_dict[name][0] == c_type): |
| 352 |
logger.warning( |
| 353 |
'Property ' + name + |
| 354 |
' changes type from ' + str(prop_dict[name][0]) + |
| 355 |
' to ' + str(c_type) + |
| 356 |
', ignoring old type') |
| 357 |
del prop_dict[name] |
| 358 |
if name in prop_dict: |
| 359 |
assert prop_dict[name][0] == c_type |
| 360 |
prop_dict[name][1].add(i) |
| 361 |
else: |
| 362 |
prop_dict[name] = (c_type, set([i])) |
| 363 |
self.properties = [] |
| 364 |
for name, (c_type, supported_ids) in prop_dict.items(): |
| 365 |
versions_ids = [bool(i in supported_ids) for i in range(len(self.versions))] |
| 366 |
self.properties.append(Property(self, c_type, name, versions_ids)) |
| 367 |
|
| 368 |
def emit_get_version_id_fn(self): |
| 369 |
return_type = StdType('int') |
| 370 |
fn_name = self.get_version_id_fn_name() |
| 371 |
body = '' |
| 372 |
body += 'static int version_id = -1;\n' |
| 373 |
body += '\n' |
| 374 |
body += 'if (version_id == -1) {\n' |
| 375 |
body += INDENT + 'gtk_priv_assert_gtk_version_valid();' |
| 376 |
body += '\n' |
| 377 |
body += INDENT + 'int combo = gtk_get_minor_version() * 1000 + gtk_get_micro_version();\n' |
| 378 |
body += '\n' |
| 379 |
body += INDENT + 'switch (combo) {\n' |
| 380 |
for v in self.supported_versions: |
| 381 |
if v.is_released(): |
| 382 |
body += INDENT * 2 + 'case ' + str(v.get_combo()) + ':\n' |
| 383 |
body += INDENT * 3 + 'break;\n' |
| 384 |
body += '\n' |
| 385 |
body += INDENT * 2 + 'default:\n' |
| 386 |
body += INDENT * 3 + 'gtk_priv_warn_gtk_version_may_be_unsupported();\n' |
| 387 |
body += INDENT + '}\n' |
| 388 |
body += '\n' |
| 389 |
body += INDENT |
| 390 |
for i in range(len(self.versions) - 1, -1, -1): |
| 391 |
if i > 0: |
| 392 |
body += 'if (combo >= ' + str(self.versions[i].first_version.get_combo()) + ') ' |
| 393 |
body += '{\n' |
| 394 |
body += INDENT * 2 + 'version_id = ' + str(i) + ';\n' |
| 395 |
body += INDENT + '}' |
| 396 |
if i > 0: |
| 397 |
body += ' else ' |
| 398 |
body += '\n' |
| 399 |
body += '}\n' |
| 400 |
body += '\n' |
| 401 |
body += 'return version_id;\n' |
| 402 |
return c_function(return_type, fn_name, [], body) |
| 403 |
|
| 404 |
def emit_header(self, generated): |
| 405 |
result = '' |
| 406 |
result += '/* AUTOGENERATED, DO NOT EDIT DIRECTLY\n' |
| 407 |
result += ' * See gtk-priv/README.md for more information\n' |
| 408 |
result += ' *\n' |
| 409 |
result += ' * This file is part of ' + PROJECT_NAME + '\n' |
| 410 |
result += ' *\n' |
| 411 |
me = path.relpath(__file__, path.dirname(path.dirname(path.dirname(__file__)))) |
| 412 |
my_copyright_line = 'Copyright © ' + str(datetime.now().year) + ' ' + me |
| 413 |
for line in list(self.copyright_lines) + [my_copyright_line]: |
| 414 |
result += ' * ' + line + '\n' |
| 415 |
result += ' *' |
| 416 |
result += '\n * '.join(LGPL3_HEADER.splitlines()) |
| 417 |
result += '\n */\n' |
| 418 |
result += '\n' |
| 419 |
result += '#ifndef ' + self.macro_name() + '\n' |
| 420 |
result += '#define ' + self.macro_name() + '\n' |
| 421 |
result += '\n' |
| 422 |
result += '#include "common.h"\n' |
| 423 |
result += '\n' |
| 424 |
result += 'typedef struct ' + self.struct_name + ' ' + self.typedef + ';\n' |
| 425 |
result += '\n' |
| 426 |
prev_definition = None |
| 427 |
for i, struct in enumerate(self.versions): |
| 428 |
result += '// Version ID ' + str(i) + '\n' |
| 429 |
definition = struct.emit_definition(generated) |
| 430 |
if prev_definition: |
| 431 |
result += '// Diff from previous version:\n' |
| 432 |
result += '\n'.join(diff_between(prev_definition, definition).splitlines()[4:]) + '\n' |
| 433 |
prev_definition = definition |
| 434 |
result += definition |
| 435 |
result += '\n' |
| 436 |
result += '// For internal use only\n' |
| 437 |
result += self.emit_get_version_id_fn() |
| 438 |
result += '\n' |
| 439 |
for p in self.properties: |
| 440 |
result += p.emit_functions() |
| 441 |
result += '\n' |
| 442 |
result += '#endif // ' + self.macro_name() + '\n' |
| 443 |
return result |
| 444 |
|
| 445 |
def file_contains_byte_regex(source_file, regex): |
| 446 |
try: |
| 447 |
with open(source_file) as f: |
| 448 |
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as s: |
| 449 |
return bool(regex.search(s)) |
| 450 |
except (ValueError, FileNotFoundError): |
| 451 |
return False |
| 452 |
|
| 453 |
class Project: |
| 454 |
def __init__(self, repo_dir, typedef_names): |
| 455 |
self.repo_dir = repo_dir |
| 456 |
structs = [Struct(typedef) for typedef in typedef_names] |
| 457 |
self.typedefs = {struct.typedef: struct for struct in structs} |
| 458 |
self.struct_names = {struct.struct_name: struct for struct in structs} |
| 459 |
|
| 460 |
def lookup_struct_name(self, struct_name): |
| 461 |
return self.struct_names.get(struct_name) |
| 462 |
|
| 463 |
def lookup_typedef(self, typedef): |
| 464 |
return self.typedefs.get(typedef) |
| 465 |
|
| 466 |
def update(self, version): |
| 467 |
source_files = None |
| 468 |
for typedef, struct in self.typedefs.items(): |
| 469 |
code_path = struct.get_code_path() |
| 470 |
search_regex = struct.search_regex |
| 471 |
if not code_path or not file_contains_byte_regex(code_path, search_regex): |
| 472 |
if source_files is None: |
| 473 |
source_files = get_all_source_files(self.repo_dir) |
| 474 |
files = set() |
| 475 |
for source_file in source_files: |
| 476 |
if file_contains_byte_regex(source_file, search_regex): |
| 477 |
files.add(source_file) |
| 478 |
if not files: |
| 479 |
raise RuntimeError('Could not find ' + typedef + ' in ' + str(version)) |
| 480 |
if len(files) > 1: |
| 481 |
raise RuntimeError(typedef + ' implemented multiple places: ' + str(files)) |
| 482 |
code_path = list(files)[0] |
| 483 |
struct_version = StructVersion(code_path, self, struct, version) |
| 484 |
struct.add_version(struct_version) |
| 485 |
|
| 486 |
def simplify(self): |
| 487 |
i = 1; |
| 488 |
while True: |
| 489 |
logger.info('Detecting identical versions, round ' + str(i)) |
| 490 |
i += 1 |
| 491 |
made_change = False |
| 492 |
for _, struct in self.typedefs.items(): |
| 493 |
if struct.simplify(): |
| 494 |
made_change = True |
| 495 |
if not made_change: |
| 496 |
break |
| 497 |
for _, struct in self.typedefs.items(): |
| 498 |
struct.setup_properties() |
| 499 |
|
| 500 |
def write(self, output_dir): |
| 501 |
remove_headers_from_dir(output_dir) |
| 502 |
for typedef, struct in self.typedefs.items(): |
| 503 |
output_path = path.join(output_dir, struct.header_name()) |
| 504 |
logger.info('Writing ' + str(len(struct.versions)) + ' versions of ' + typedef + ' to ' + output_path) |
| 505 |
with open(output_path, "w") as f: |
| 506 |
f.write(struct.emit_header(True)) |