Changeset View
Changeset View
Standalone View
Standalone View
find-modules/sip_generator.py
Show All 33 Lines | |||||
34 | import gettext | 34 | import gettext | ||
35 | import inspect | 35 | import inspect | ||
36 | import logging | 36 | import logging | ||
37 | import os | 37 | import os | ||
38 | import re | 38 | import re | ||
39 | import sys | 39 | import sys | ||
40 | import traceback | 40 | import traceback | ||
41 | from clang import cindex | 41 | from clang import cindex | ||
42 | from clang.cindex import AccessSpecifier, CursorKind, SourceRange, StorageClass, TokenKind, TypeKind, TranslationUnit | 42 | from clang.cindex import AccessSpecifier, AvailabilityKind, CursorKind, SourceRange, StorageClass, TokenKind, TypeKind, TranslationUnit | ||
43 | 43 | | |||
44 | import rules_engine | 44 | import rules_engine | ||
45 | 45 | | |||
46 | 46 | | |||
47 | class HelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter): | 47 | class HelpFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter): | ||
48 | pass | 48 | pass | ||
49 | 49 | | |||
50 | 50 | | |||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | 177 | def _container_get(self, container, level, h_file, include_filename): | |||
205 | name = container.displayname | 205 | name = container.displayname | ||
206 | if container.access_specifier == AccessSpecifier.PRIVATE: | 206 | if container.access_specifier == AccessSpecifier.PRIVATE: | ||
207 | if self.dump_privates: | 207 | if self.dump_privates: | ||
208 | logger.debug("Ignoring private {}".format(SipGenerator.describe(container))) | 208 | logger.debug("Ignoring private {}".format(SipGenerator.describe(container))) | ||
209 | return "" | 209 | return "" | ||
210 | base_specifiers = [] | 210 | base_specifiers = [] | ||
211 | template_type_parameters = [] | 211 | template_type_parameters = [] | ||
212 | had_copy_constructor = False | 212 | had_copy_constructor = False | ||
213 | had_deleted_copy_constructor = False; | ||||
213 | had_const_member = False | 214 | had_const_member = False | ||
214 | for member in container.get_children(): | 215 | for member in container.get_children(): | ||
215 | # | 216 | # | ||
216 | # Only emit items in the translation unit. | 217 | # Only emit items in the translation unit. | ||
217 | # | 218 | # | ||
218 | if member.location.file.name != self.tu.spelling: | 219 | if member.location.file.name != self.tu.spelling: | ||
219 | continue | 220 | continue | ||
220 | decl = "" | 221 | decl = "" | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 286 | if member.kind != CursorKind.CONSTRUCTOR: | |||
286 | return False | 287 | return False | ||
287 | numParams = 0 | 288 | numParams = 0 | ||
288 | for parameter in member.get_children(): | 289 | for parameter in member.get_children(): | ||
289 | if (has_parameter_default(parameter)): | 290 | if (has_parameter_default(parameter)): | ||
290 | break | 291 | break | ||
291 | numParams += 1 | 292 | numParams += 1 | ||
292 | return numParams == 0 | 293 | return numParams == 0 | ||
293 | 294 | | |||
294 | had_copy_constructor = had_copy_constructor or is_copy_constructor(member) | 295 | if is_copy_constructor(member): | ||
296 | had_copy_constructor = True | ||||
297 | # We need to generate a fake private copy constructor for deleted constructors | ||||
298 | if member.availability == AvailabilityKind.NOT_AVAILABLE and member.access_specifier != AccessSpecifier.PRIVATE: | ||||
299 | had_deleted_copy_constructor = True | ||||
300 | continue | ||||
301 | | ||||
295 | # | 302 | # | ||
296 | # Discard almost anything which is private. | 303 | # Discard almost anything which is private. | ||
297 | # | 304 | # | ||
298 | if member.access_specifier == AccessSpecifier.PRIVATE: | 305 | if member.access_specifier == AccessSpecifier.PRIVATE: | ||
299 | if member.kind == CursorKind.CXX_ACCESS_SPEC_DECL: | 306 | if member.kind == CursorKind.CXX_ACCESS_SPEC_DECL: | ||
300 | # | 307 | # | ||
301 | # We need these because... | 308 | # We need these because... | ||
302 | # | 309 | # | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 365 | else: | |||
359 | body = pad + "// Discarded {} (by {})\n".format(SipGenerator.describe(container), "default forward declaration handling") | 366 | body = pad + "// Discarded {} (by {})\n".format(SipGenerator.describe(container), "default forward declaration handling") | ||
360 | 367 | | |||
361 | else: | 368 | else: | ||
362 | body = pad + "// Discarded {} (by {})\n".format(SipGenerator.describe(container), modifying_rule) | 369 | body = pad + "// Discarded {} (by {})\n".format(SipGenerator.describe(container), modifying_rule) | ||
363 | else: | 370 | else: | ||
364 | # | 371 | # | ||
365 | # Generate private copy constructor for non-copyable types. | 372 | # Generate private copy constructor for non-copyable types. | ||
366 | # | 373 | # | ||
367 | if had_const_member and not had_copy_constructor: | 374 | if (had_deleted_copy_constructor) or (had_const_member and not had_copy_constructor): | ||
368 | body += " private:\n {}(const {} &); // Generated\n".format(name, container.type.get_canonical().spelling) | 375 | body += " private:\n {}(const {} &); // Generated\n".format(name, container.type.get_canonical().spelling) | ||
369 | # | 376 | # | ||
370 | # Flesh out the SIP context for the rules engine. | 377 | # Flesh out the SIP context for the rules engine. | ||
371 | # | 378 | # | ||
372 | sip["base_specifiers"] = base_specifiers | 379 | sip["base_specifiers"] = base_specifiers | ||
373 | sip["body"] = body | 380 | sip["body"] = body | ||
374 | modifying_rule = self.rules.container_rules().apply(container, sip) | 381 | modifying_rule = self.rules.container_rules().apply(container, sip) | ||
375 | if sip["name"]: | 382 | if sip["name"]: | ||
▲ Show 20 Lines • Show All 437 Lines • Show Last 20 Lines |