Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.73 KB | None | 0 0
  1. commit cfce024
  2. Author: Johan Dahlin <johan@gnome.org>
  3. Date: 2010-09-02 12:21:38 -0300
  4.  
  5. [scannermain] Create a new option parser
  6.  
  7. Create a new option parser when parsing pkg-config output
  8.  
  9.  
  10. diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
  11. index bf2af39..d2bd876 100644
  12. --- a/giscanner/scannermain.py
  13. +++ b/giscanner/scannermain.py
  14. @@ -183,7 +183,7 @@ def process_options(output, allowed_flags):
  15. yield option
  16. break
  17.  
  18. -def process_packages(parser, options, packages):
  19. +def process_packages(options, packages):
  20. args = ['pkg-config', '--cflags']
  21. args.extend(packages)
  22. output = subprocess.Popen(args,
  23. @@ -196,6 +196,7 @@ def process_packages(parser, options, packages):
  24. # so we explicitly filter to only the ones we need.
  25. options_whitelist = ['-I', '-D', '-U', '-l', '-L']
  26. filtered_output = list(process_options(output, options_whitelist))
  27. + parser = _get_option_parser()
  28. pkg_options, unused = parser.parse_args(filtered_output)
  29. options.cpp_includes.extend(pkg_options.cpp_includes)
  30. options.cpp_defines.extend(pkg_options.cpp_defines)
  31. @@ -283,7 +284,7 @@ def scanner_main(args):
  32.  
  33. packages = set(options.packages)
  34. packages.update(transformer.get_pkgconfig_packages())
  35. - exit_code = process_packages(parser, options, packages)
  36. + exit_code = process_packages(options, packages)
  37. if exit_code:
  38. return exit_code
  39.  
  40. commit ba943d6
  41. Author: Johan Dahlin <johan@gnome.org>
  42. Date: 2010-09-02 12:09:52 -0300
  43.  
  44. [message] Add an output parameter
  45.  
  46.  
  47. diff --git a/giscanner/message.py b/giscanner/message.py
  48. index 4355514..10a32a6 100644
  49. --- a/giscanner/message.py
  50. +++ b/giscanner/message.py
  51. @@ -32,8 +32,11 @@ from . import ast
  52. class MessageLogger(object):
  53. _instance = None
  54.  
  55. - def __init__(self, namespace):
  56. + def __init__(self, namespace, output=None):
  57. + if output is None:
  58. + output = sys.stderr
  59. self._cwd = os.getcwd() + os.sep
  60. + self._output = output
  61. self._namespace = namespace
  62. self._enable_warnings = False
  63. self._warned = False
  64. @@ -76,7 +79,7 @@ If the warning is related to a ast.Node type, see log_node_warning()."""
  65. position_strings.append(position)
  66.  
  67. for position in position_strings[:-1]:
  68. - print >>sys.stderr, "%s:" % (position, )
  69. + self._output.write("%s:\n" % (position, ))
  70. last_position = position_strings[-1]
  71.  
  72. if log_type == WARNING:
  73. @@ -86,12 +89,12 @@ If the warning is related to a ast.Node type, see log_node_warning()."""
  74. elif log_type == FATAL:
  75. error_type = "Fatal"
  76. if prefix:
  77. - print >>sys.stderr, \
  78. -'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
  79. - prefix, text)
  80. + self._output.write(
  81. +'''%s: %s: %s: %s: %s\n''' % (last_position, error_type, self._namespace.name,
  82. + prefix, text))
  83. else:
  84. - print >>sys.stderr, \
  85. -'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
  86. + self._output.write(
  87. +'''%s: %s: %s: %s\n''' % (last_position, error_type, self._namespace.name, text))
  88.  
  89.  
  90. if log_type == FATAL:
  91. commit 4a98aec
  92. Author: Johan Dahlin <johan@gnome.org>
  93. Date: 2010-09-02 11:44:47 -0300
  94.  
  95. [scanner] Remove old logging functions
  96.  
  97. And migrate over to using the message logger
  98.  
  99.  
  100. diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
  101. index ea1299e..bf2af39 100644
  102. --- a/giscanner/scannermain.py
  103. +++ b/giscanner/scannermain.py
  104. @@ -265,8 +265,9 @@ def scanner_main(args):
  105. options.namespace_version,
  106. identifier_prefixes=identifier_prefixes,
  107. symbol_prefixes=symbol_prefixes)
  108. - message.MessageLogger.get(namespace=namespace,
  109. - enable_warnings=options.warn_all)
  110. + logger = message.MessageLogger.get(namespace=namespace)
  111. + if options.warn_all:
  112. + logger.enable_warnings(True)
  113. transformer = Transformer(namespace,
  114. accept_unprefixed=options.accept_unprefixed)
  115. transformer.set_include_paths(options.include_paths)
  116. @@ -328,7 +329,7 @@ def scanner_main(args):
  117. final = IntrospectablePass(transformer)
  118. final.validate()
  119.  
  120. - if options.warn_fatal and transformer.did_warn():
  121. + if options.warn_fatal and logger.did_warn():
  122. message.fatal("warnings configured as fatal")
  123. return 1
  124.  
  125. diff --git a/giscanner/transformer.py b/giscanner/transformer.py
  126. index 8dd0129..9f76a7d 100644
  127. --- a/giscanner/transformer.py
  128. +++ b/giscanner/transformer.py
  129. @@ -53,14 +53,11 @@ class Transformer(object):
  130. UCASE_CONSTANT_RE = re.compile(r'[_A-Z0-9]+')
  131.  
  132. def __init__(self, namespace, accept_unprefixed=False):
  133. - self._cwd = os.getcwd() + os.sep
  134. self._cachestore = CacheStore()
  135. self._accept_unprefixed = accept_unprefixed
  136. self._namespace = namespace
  137. self._pkg_config_packages = set()
  138. self._typedefs_ns = {}
  139. - self._enable_warnings = False
  140. - self._warned = False
  141. self._includes = {}
  142. self._include_names = set()
  143. self._includepaths = []
  144. @@ -68,12 +65,6 @@ class Transformer(object):
  145. def get_includes(self):
  146. return self._include_names
  147.  
  148. - def enable_warnings(self, enable):
  149. - self._enable_warnings = enable
  150. -
  151. - def did_warn(self):
  152. - return self._warned
  153. -
  154. def get_pkgconfig_packages(self):
  155. return self._pkg_config_packages
  156.  
  157. @@ -153,83 +144,6 @@ None."""
  158.  
  159. # Private
  160.  
  161. - def log_warning(self, text, file_positions=None, prefix=None,
  162. - fatal=False):
  163. - """Log a warning, using optional file positioning information.
  164. -If the warning is related to a ast.Node type, see log_node_warning()."""
  165. - if not fatal and not self._enable_warnings:
  166. - return
  167. -
  168. - self._warned = True
  169. -
  170. - if file_positions is None or len(file_positions) == 0:
  171. - target_file_positions = [('<unknown>', -1, -1)]
  172. - else:
  173. - target_file_positions = file_positions
  174. -
  175. - position_strings = []
  176. - for (filename, line, column) in target_file_positions:
  177. - if filename.startswith(self._cwd):
  178. - filename = filename[len(self._cwd):]
  179. - if column != -1:
  180. - position = '%s:%d:%d' % (filename, line, column)
  181. - elif line != -1:
  182. - position = '%s:%d' % (filename, line, )
  183. - else:
  184. - position = '%s:' % (filename, )
  185. - position_strings.append(position)
  186. -
  187. - for position in position_strings[:-1]:
  188. - print >>sys.stderr, "%s:" % (position, )
  189. - last_position = position_strings[-1]
  190. - error_type = 'error' if fatal else 'warning'
  191. - if prefix:
  192. - print >>sys.stderr, \
  193. -'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
  194. - prefix, text)
  195. - else:
  196. - print >>sys.stderr, \
  197. -'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
  198. - if fatal:
  199. - sys.exit(1)
  200. -
  201. - def log_symbol_warning(self, symbol, text, **kwargs):
  202. - """Log a warning in the context of the given symbol."""
  203. - if symbol.source_filename:
  204. - file_positions = [(symbol.source_filename, symbol.line, -1)]
  205. - else:
  206. - file_positions = None
  207. - prefix = "symbol=%r" % (symbol.ident, )
  208. - self.log_warning(text, file_positions, prefix=prefix, **kwargs)
  209. -
  210. - def log_node_warning(self, node, text, context=None, fatal=False):
  211. - """Log a warning, using information about file positions from
  212. -the given node. The optional context argument, if given, should be
  213. -another ast.Node type which will also be displayed. If no file position
  214. -information is available from the node, the position data from the
  215. -context will be used."""
  216. - if hasattr(node, 'file_positions'):
  217. - if (len(node.file_positions) == 0 and
  218. - (context is not None) and len(context.file_positions) > 0):
  219. - file_positions = context.file_positions
  220. - else:
  221. - file_positions = node.file_positions
  222. - else:
  223. - file_positions = None
  224. - if not context:
  225. - text = "context=%r %s" % (node, text)
  226. -
  227. - if context:
  228. - if isinstance(context, ast.Function):
  229. - name = context.symbol
  230. - else:
  231. - name = context.name
  232. - text = "%s: %s" % (name, text)
  233. - elif len(file_positions) == 0 and hasattr(node, 'name'):
  234. - text = "(%s)%s: %s" % (node.__class__.__name__, node.name, text)
  235. -
  236. - self.log_warning(text, file_positions, fatal=fatal)
  237. -
  238. def _find_include(self, include):
  239. searchdirs = self._includepaths[:]
  240. for path in _xdg_data_dirs:
  241. commit 3bd4087
  242. Author: Johan Dahlin <johan@gnome.org>
  243. Date: 2010-09-02 11:44:27 -0300
  244.  
  245. [scanner] Move over remaining callsites to message
  246.  
  247. Move the remaining callsites over to the new message
  248. module
  249.  
  250.  
  251. diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
  252. index d93a464..d88f2e3 100644
  253. --- a/giscanner/gdumpparser.py
  254. +++ b/giscanner/gdumpparser.py
  255. @@ -209,8 +209,8 @@ blob containing data gleaned from GObject's primitive introspection."""
  256. rettype = func.retval.type
  257. if not (rettype.is_equiv(ast.TYPE_GTYPE)
  258. or rettype.target_giname == 'Gtk.Type'):
  259. - self._transformer.log_warning("function returns '%r', not a GType"
  260. - % (func.retval.type, ))
  261. + message.warn("function returns '%r', not a GType" % (
  262. + func.retval.type, ))
  263. return False
  264.  
  265. self._get_type_functions.append(func.symbol)
  266. diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
  267. index 7843411..6653c09 100644
  268. --- a/giscanner/introspectablepass.py
  269. +++ b/giscanner/introspectablepass.py
  270. @@ -19,6 +19,7 @@
  271.  
  272. from . import ast
  273. from . import glibast
  274. +from . import message
  275.  
  276. class IntrospectablePass(object):
  277.  
  278. @@ -38,7 +39,7 @@ class IntrospectablePass(object):
  279. if isinstance(node, glibast.GLibInterface):
  280. for vfunc in node.virtual_methods:
  281. if not vfunc.invoker:
  282. - self._transformer.log_node_warning(vfunc,
  283. + message.warn_node(vfunc,
  284. """Virtual function %r has no known invoker""" % (vfunc.name, ),
  285. context=node)
  286.  
  287. @@ -51,7 +52,7 @@ class IntrospectablePass(object):
  288. context = "argument %s: " % (param.argname, )
  289. else:
  290. context = "return value: "
  291. - self._transformer.log_node_warning(parent, prefix + context + text, *args)
  292. + message.warn_node(parent, prefix + context + text, *args)
  293.  
  294. def _introspectable_param_analysis(self, parent, node):
  295. is_return = isinstance(node, ast.Return)
  296. diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
  297. index 867a6c7..5a5a21e 100644
  298. --- a/giscanner/maintransformer.py
  299. +++ b/giscanner/maintransformer.py
  300. @@ -110,9 +110,10 @@ class MainTransformer(object):
  301. origin_name = 'parameter %s' % (origin.argname, )
  302. else:
  303. origin_name = 'return value'
  304. - self._transformer.log_node_warning(parent,
  305. + message.log_node(
  306. + message.FATAL, parent,
  307. "can't find parameter %s referenced by %s of %r"
  308. - % (param_name, origin_name, parent.name), fatal=True)
  309. + % (param_name, origin_name, parent.name))
  310.  
  311. return param.argname
  312.  
  313. @@ -125,18 +126,21 @@ class MainTransformer(object):
  314. rename_to = rename_to.value
  315. target = self._namespace.get_by_symbol(rename_to)
  316. if not target:
  317. - self._transformer.log_node_warning(node,
  318. -"Can't find symbol %r referenced by Rename annotation" % (rename_to, ))
  319. + message.warn_node(node,
  320. + "Can't find symbol %r referenced by Rename annotation" % (
  321. + rename_to, ))
  322. elif target.shadowed_by:
  323. - self._transformer.log_node_warning(node,
  324. -"Function %r already shadowed by %r, can't overwrite with %r" % (target.symbol,
  325. - target.shadowed_by,
  326. - rename_to))
  327. + message.warn_node(node,
  328. + "Function %r already shadowed by %r, can't overwrite with %r" % (
  329. + target.symbol,
  330. + target.shadowed_by,
  331. + rename_to))
  332. elif target.shadows:
  333. - self._transformer.log_node_warning(node,
  334. -"Function %r already shadows %r, can't multiply shadow with %r" % (target.symbol,
  335. - target.shadows,
  336. - rename_to))
  337. + message.warn_node(node,
  338. + "Function %r already shadows %r, can't multiply shadow with %r" % (
  339. + target.symbol,
  340. + target.shadows,
  341. + rename_to))
  342. else:
  343. target.shadows = node.symbol
  344. node.shadowed_by = target.symbol
  345. @@ -225,8 +229,8 @@ class MainTransformer(object):
  346. return ast.List(base.name, *rest)
  347. if isinstance(base, ast.Map) and len(rest) == 2:
  348. return ast.Map(*rest)
  349. - self._transformer.log_warning(
  350. -"Too many parameters in type specification %r" % (type_str, ))
  351. + message.warn(
  352. + "Too many parameters in type specification %r" % (type_str, ))
  353. return base
  354. def top_combiner(base, *rest):
  355. if orig_node is not None:
  356. @@ -235,8 +239,8 @@ class MainTransformer(object):
  357.  
  358. result, rest = grab_one(type_str, resolver, top_combiner, combiner)
  359. if rest:
  360. - self._transformer.log_warning(
  361. -"Trailing components in type specification %r" % (type_str, ))
  362. + message.warn("Trailing components in type specification %r" % (
  363. + type_str, ))
  364. return result
  365.  
  366. def _apply_annotations_array(self, parent, node, options):
  367. @@ -295,7 +299,7 @@ class MainTransformer(object):
  368. elif isinstance(node.type, ast.Array):
  369. node.type.element_type = self._resolve(element_type[0])
  370. else:
  371. - self._transformer.log_node_warning(parent,
  372. + message.warn_node(parent,
  373. "Unknown container %r for element-type annotation" % (node.type, ))
  374.  
  375. def _get_transfer_default_param(self, parent, node):
  376. @@ -404,8 +408,8 @@ class MainTransformer(object):
  377. elif subtype == 'callee-allocates':
  378. caller_allocates = False
  379. else:
  380. - self._transformer.log_warning(
  381. -"out allocation for %s is invalid (%r)" % (node, subtype), fatal=True)
  382. + message.fatal("out allocation for %s is invalid (%r)" % (
  383. + node, subtype))
  384. elif OPT_IN in options:
  385. annotated_direction = ast.PARAM_DIRECTION_IN
  386.  
  387. @@ -481,8 +485,9 @@ class MainTransformer(object):
  388. if scope not in [ast.PARAM_SCOPE_CALL,
  389. ast.PARAM_SCOPE_ASYNC,
  390. ast.PARAM_SCOPE_NOTIFIED]:
  391. - self._transformer.log_warning(parent,
  392. -"Invalid scope %r for parameter %r" % (scope, param.name))
  393. + message.warn(
  394. + parent,
  395. + "Invalid scope %r for parameter %r" % (scope, param.name))
  396. else:
  397. param.scope = scope
  398. param.transfer = ast.PARAM_TRANSFER_NONE
  399. @@ -544,9 +549,9 @@ class MainTransformer(object):
  400. if param.argname == tag:
  401. break
  402. else:
  403. - self._transformer.log_warning(
  404. -"Annotation for '%s' refers to unknown argument '%s'"
  405. -% (parent.name, tag))
  406. + message.warn(
  407. + "Annotation for '%s' refers to unknown argument '%s'"
  408. + % (parent.name, tag))
  409.  
  410. def _apply_annotations_field(self, parent, block, field):
  411. if not block:
  412. @@ -620,7 +625,7 @@ class MainTransformer(object):
  413. self._apply_annotations_callable(vfunc, [parent], block)
  414. break
  415. if not matched:
  416. - self._transformer.log_symbol_warning(node.symbol,
  417. + message.warn_symbol(node.symbol,
  418. "Virtual slot %r not found for %r annotation" % (invoker_name, TAG_VFUNC))
  419.  
  420. def _resolve_and_filter_type_list(self, typelist):
  421. @@ -716,8 +721,8 @@ the ones that failed to resolve removed."""
  422. if enum is not None:
  423. enum.error_quark = node.symbol
  424. else:
  425. - self._transformer.log_node_warning(node,
  426. -"""%s: Couldn't find corresponding enumeration""" % (node.symbol, ))
  427. + message.warn_node(node,
  428. + """%s: Couldn't find corresponding enumeration""" % (node.symbol, ))
  429.  
  430. def _split_uscored_by_type(self, uscored):
  431. """'uscored' should be an un-prefixed uscore string. This
  432. @@ -809,7 +814,7 @@ method or constructor of some type."""
  433. split = self._split_uscored_by_type(subsymbol)
  434. if split is None:
  435. # TODO - need a e.g. (method) annotation
  436. - self._transformer.log_node_warning(func,
  437. + message.warn_node(func,
  438. "Can't find matching type for constructor; symbol=%r" % (func.symbol, ))
  439. return False
  440. (origin_node, funcname) = split
  441. @@ -823,15 +828,21 @@ method or constructor of some type."""
  442. else:
  443. parent = None
  444. if parent is None:
  445. - self._transformer.log_node_warning(func,
  446. -"Return value is not superclass for constructor; symbol=%r constructed=%r return=%r"
  447. -% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
  448. + message.warn_node(func,
  449. + "Return value is not superclass for constructor; "
  450. + "symbol=%r constructed=%r return=%r" % (
  451. + func.symbol,
  452. + str(origin_node.create_type()),
  453. + str(func.retval.type)))
  454. return False
  455. else:
  456. if origin_node != target:
  457. - self._transformer.log_node_warning(func,
  458. -"Constructor return type mismatch symbol=%r constructed=%r return=%r"
  459. -% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
  460. + message.warn_node(func,
  461. + "Constructor return type mismatch symbol=%r "
  462. + "constructed=%r return=%r" % (
  463. + func.symbol,
  464. + str(origin_node.create_type()),
  465. + str(func.retval.type)))
  466. return False
  467. self._namespace.float(func)
  468. func.name = funcname
  469. @@ -845,7 +856,7 @@ method or constructor of some type."""
  470. def _pair_class_virtuals(self, node):
  471. """Look for virtual methods from the class structure."""
  472. if not node.glib_type_struct:
  473. - self._transformer.log_node_warning(node,
  474. + message.warn_node(node,
  475. "Failed to find class structure for %r" % (node.name, ))
  476. return
  477.  
  478. diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
  479. index eae10f7..ea1299e 100644
  480. --- a/giscanner/scannermain.py
  481. +++ b/giscanner/scannermain.py
  482. @@ -33,10 +33,10 @@ from giscanner.annotationparser import AnnotationParser
  483. from giscanner.ast import Include, Namespace
  484. from giscanner.dumper import compile_introspection_binary
  485. from giscanner.gdumpparser import GDumpParser, IntrospectionBinary
  486. -from giscanner.maintransformer import MainTransformer
  487. from giscanner.introspectablepass import IntrospectablePass
  488. from giscanner.girparser import GIRParser
  489. from giscanner.girwriter import GIRWriter
  490. +from giscanner.maintransformer import MainTransformer
  491. from giscanner.shlibs import resolve_shlibs
  492. from giscanner.sourcescanner import SourceScanner
  493. from giscanner.transformer import Transformer
  494. @@ -329,7 +329,7 @@ def scanner_main(args):
  495. final.validate()
  496.  
  497. if options.warn_fatal and transformer.did_warn():
  498. - transformer.log_warning("warnings configured as fatal", fatal=True)
  499. + message.fatal("warnings configured as fatal")
  500. return 1
  501.  
  502. # Write out AST
  503. diff --git a/giscanner/transformer.py b/giscanner/transformer.py
  504. index aa02fb3..8dd0129 100644
  505. --- a/giscanner/transformer.py
  506. +++ b/giscanner/transformer.py
  507. @@ -89,8 +89,8 @@ class Transformer(object):
  508. positions = set()
  509. positions.update(original.file_positions)
  510. positions.update(node.file_positions)
  511. - self.log_warning("Namespace conflict for '%s'" % (node.name, ),
  512. - positions, fatal=True)
  513. + message.fatal("Namespace conflict for '%s'" % (node.name, ),
  514. + positions)
  515. else:
  516. self._namespace.append(node)
  517.  
  518. commit 5aed20a
  519. Author: Johan Dahlin <johan@gnome.org>
  520. Date: 2010-09-02 11:07:01 -0300
  521.  
  522. [scanner] Simplify strip_identifer/strip_symbol
  523.  
  524. The strip_* functions are problematic since they
  525. have a fatal switch which determines if the message should
  526. kill the scanner. Change the api to make it easier to extend
  527. with other logging categories and move over the callsites to
  528. use the new message module
  529.  
  530.  
  531. diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
  532. index 7f1d229..d93a464 100644
  533. --- a/giscanner/gdumpparser.py
  534. +++ b/giscanner/gdumpparser.py
  535. @@ -27,6 +27,8 @@ from xml.etree.cElementTree import parse
  536.  
  537. from . import ast
  538. from . import glibast
  539. +from . import message
  540. +from .transformer import TransformerException
  541.  
  542. # GParamFlags
  543. G_PARAM_READABLE = 1 << 0
  544. @@ -254,7 +256,10 @@ blob containing data gleaned from GObject's primitive introspection."""
  545.  
  546. klass = (glibast.GLibFlags if node.tag == 'flags' else glibast.GLibEnum)
  547. type_name = node.attrib['name']
  548. - enum_name = self._transformer.strip_identifier_or_warn(type_name, fatal=True)
  549. + try:
  550. + enum_name = self._transformer.strip_identifier(type_name)
  551. + except TransformerException, e:
  552. + message.fatal(e)
  553. node = klass(enum_name, type_name, members, node.attrib['get-type'])
  554. self._namespace.append(node, replace=True)
  555.  
  556. @@ -275,11 +280,12 @@ blob containing data gleaned from GObject's primitive introspection."""
  557. return
  558. is_abstract = bool(xmlnode.attrib.get('abstract', False))
  559. (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
  560. - node = glibast.GLibObject(
  561. - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
  562. - None,
  563. - type_name,
  564. - get_type, c_symbol_prefix, is_abstract)
  565. + try:
  566. + object_name = self._transformer.strip_identifier(type_name)
  567. + except TransformerException, e:
  568. + message.fatal(e)
  569. + node = glibast.GLibObject(object_name, None, type_name,
  570. + get_type, c_symbol_prefix, is_abstract)
  571. self._parse_parents(xmlnode, node)
  572. self._introspect_properties(node, xmlnode)
  573. self._introspect_signals(node, xmlnode)
  574. @@ -291,10 +297,12 @@ blob containing data gleaned from GObject's primitive introspection."""
  575. def _introspect_interface(self, xmlnode):
  576. type_name = xmlnode.attrib['name']
  577. (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
  578. - node = glibast.GLibInterface(
  579. - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
  580. - None,
  581. - type_name, get_type, c_symbol_prefix)
  582. + try:
  583. + interface_name = self._transformer.strip_identifier(type_name)
  584. + except TransformerException, e:
  585. + message.fatal(e)
  586. + node = glibast.GLibInterface(interface_name, None, type_name,
  587. + get_type, c_symbol_prefix)
  588. self._introspect_properties(node, xmlnode)
  589. self._introspect_signals(node, xmlnode)
  590. for child in xmlnode.findall('prerequisite'):
  591. @@ -379,11 +387,13 @@ blob containing data gleaned from GObject's primitive introspection."""
  592. type_name = xmlnode.attrib['name']
  593. is_abstract = bool(xmlnode.attrib.get('abstract', False))
  594. (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
  595. - node = glibast.GLibObject(
  596. - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
  597. - None,
  598. - type_name,
  599. - get_type, c_symbol_prefix, is_abstract)
  600. + try:
  601. + fundamental_name = self._transformer.strip_identifier(type_name)
  602. + except TransformerException, e:
  603. + message.fatal(e)
  604. +
  605. + node = glibast.GLibObject(fundamental_name, None, type_name,
  606. + get_type, c_symbol_prefix, is_abstract)
  607. self._parse_parents(xmlnode, node)
  608. node.fundamental = True
  609. self._introspect_implemented_interfaces(node, xmlnode)
  610. @@ -404,7 +414,10 @@ blob containing data gleaned from GObject's primitive introspection."""
  611. field.writable = False
  612.  
  613. def _pair_boxed_type(self, boxed):
  614. - name = self._transformer.strip_identifier_or_warn(boxed.type_name, fatal=True)
  615. + try:
  616. + name = self._transformer.strip_identifier(boxed.type_name)
  617. + except TransformerException, e:
  618. + message.fatal(e)
  619. pair_node = self._namespace.get(name)
  620. if not pair_node:
  621. boxed_item = glibast.GLibBoxedOther(name, boxed.type_name,
  622. diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
  623. index b529ee8..867a6c7 100644
  624. --- a/giscanner/maintransformer.py
  625. +++ b/giscanner/maintransformer.py
  626. @@ -21,6 +21,7 @@ import re
  627.  
  628. from . import ast
  629. from . import glibast
  630. +from . import message
  631. from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS,
  632. TAG_ATTRIBUTES, TAG_RENAME_TO, TAG_TYPE, TAG_TRANSFER,
  633. TAG_UNREF_FUNC, TAG_REF_FUNC, TAG_SET_VALUE_FUNC,
  634. @@ -32,6 +33,7 @@ from .annotationparser import (OPT_ALLOW_NONE,
  635. OPT_FOREIGN, OPT_ARRAY_FIXED_SIZE,
  636. OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED)
  637. from .annotationparser import AnnotationParser
  638. +from .transformer import TransformerException
  639. from .utils import to_underscores, to_underscores_noprefix
  640.  
  641. class MainTransformer(object):
  642. @@ -688,7 +690,12 @@ the ones that failed to resolve removed."""
  643.  
  644. uscore_enums[uscored] = enum
  645.  
  646. - no_uscore_prefixed = self._transformer.strip_identifier_or_warn(type_name)
  647. + try:
  648. + no_uscore_prefixed = self._transformer.strip_identifier(type_name)
  649. + except TransformerException, e:
  650. + message.warn(e)
  651. + no_uscore_prefixed = None
  652. +
  653. if no_uscore_prefixed not in uscore_enums:
  654. uscore_enums[no_uscore_prefixed] = enum
  655.  
  656. diff --git a/giscanner/transformer.py b/giscanner/transformer.py
  657. index 690cbab..aa02fb3 100644
  658. --- a/giscanner/transformer.py
  659. +++ b/giscanner/transformer.py
  660. @@ -24,6 +24,7 @@ import re
  661.  
  662. from . import ast
  663. from . import glibast
  664. +from . import message
  665. from .cachestore import CacheStore
  666. from .config import DATADIR, GIR_DIR, GIR_SUFFIX
  667. from .girparser import GIRParser
  668. @@ -36,6 +37,10 @@ from .sourcescanner import (
  669. CSYMBOL_TYPE_MEMBER, CSYMBOL_TYPE_ELLIPSIS, CSYMBOL_TYPE_CONST,
  670. TYPE_QUALIFIER_CONST)
  671.  
  672. +class TransformerException(Exception):
  673. + pass
  674. +
  675. +
  676. class TypeResolutionException(Exception):
  677. pass
  678.  
  679. @@ -320,26 +325,26 @@ raise ValueError."""
  680. matches = self._split_c_string_for_namespace_matches(symbol, is_identifier=False)
  681. return matches[-1]
  682.  
  683. - def strip_identifier_or_warn(self, ident, fatal=False):
  684. + def strip_identifier(self, ident):
  685. hidden = ident.startswith('_')
  686. if hidden:
  687. ident = ident[1:]
  688. try:
  689. matches = self.split_ctype_namespaces(ident)
  690. except ValueError, e:
  691. - self.log_warning(str(e), fatal=fatal)
  692. - return None
  693. + raise TransformerException(str(e))
  694. for ns, name in matches:
  695. if ns is self._namespace:
  696. if hidden:
  697. return '_' + name
  698. return name
  699. (ns, name) = matches[-1]
  700. - self.log_warning("Skipping foreign identifier %r from namespace %s" % (ident, ns.name, ),
  701. - fatal=fatal)
  702. + raise TransformerException(
  703. + "Skipping foreign identifier %r from namespace %s" % (
  704. + ident, ns.name, ))
  705. return None
  706.  
  707. - def _strip_symbol_or_warn(self, symbol, is_constant=False, fatal=False):
  708. + def _strip_symbol(self, symbol, is_constant=False):
  709. ident = symbol.ident
  710. if is_constant:
  711. # Temporarily lowercase
  712. @@ -350,13 +355,10 @@ raise ValueError."""
  713. try:
  714. (ns, name) = self.split_csymbol(ident)
  715. except ValueError, e:
  716. - self.log_symbol_warning(symbol, "Unknown namespace", fatal=fatal)
  717. - return None
  718. + raise TransformerException("Unknown namespace")
  719. if ns != self._namespace:
  720. - self.log_symbol_warning(symbol,
  721. -"Skipping foreign symbol from namespace %s" % (ns.name, ),
  722. - fatal=fatal)
  723. - return None
  724. + raise TransformerException(
  725. + "Skipping foreign symbol from namespace %s" % (ns.name, ))
  726. if is_constant:
  727. name = name.upper()
  728. if hidden:
  729. @@ -424,15 +426,19 @@ raise ValueError."""
  730. # Ok, the enum members don't have a consistent prefix
  731. # among them, so let's just remove the global namespace
  732. # prefix.
  733. - name = self._strip_symbol_or_warn(child, is_constant=True)
  734. - if name is None:
  735. + try:
  736. + name = self._strip_symbol(child, is_constant=True)
  737. + except TransformerException, e:
  738. + message.warn_symbol(child, e)
  739. return None
  740. members.append(ast.Member(name.lower(),
  741. - child.const_int,
  742. - child.ident))
  743. + child.const_int,
  744. + child.ident))
  745.  
  746. - enum_name = self.strip_identifier_or_warn(symbol.ident)
  747. - if not enum_name:
  748. + try:
  749. + enum_name = self.strip_identifier(symbol.ident)
  750. + except TransformerException, e:
  751. + message.warn(e)
  752. return None
  753. if symbol.base_type.is_bitfield:
  754. klass = ast.Bitfield
  755. @@ -445,8 +451,10 @@ raise ValueError."""
  756. def _create_function(self, symbol):
  757. parameters = list(self._create_parameters(symbol.base_type))
  758. return_ = self._create_return(symbol.base_type.base_type)
  759. - name = self._strip_symbol_or_warn(symbol)
  760. - if not name:
  761. + try:
  762. + name = self._strip_symbol(symbol)
  763. + except TransformerException, e:
  764. + message.warn_symbol(symbol, e)
  765. return None
  766. func = ast.Function(name, return_, parameters, False, symbol.ident)
  767. func.add_symbol_reference(symbol)
  768. @@ -526,8 +534,10 @@ raise ValueError."""
  769. CTYPE_POINTER,
  770. CTYPE_BASIC_TYPE,
  771. CTYPE_VOID):
  772. - name = self.strip_identifier_or_warn(symbol.ident)
  773. - if not name:
  774. + try:
  775. + name = self.strip_identifier(symbol.ident)
  776. + except TransformerException, e:
  777. + message.warn(e)
  778. return None
  779. if symbol.base_type.name:
  780. target = self.create_type_from_ctype_string(symbol.base_type.name)
  781. @@ -651,8 +661,10 @@ raise ValueError."""
  782. # ignore non-uppercase defines
  783. if not self.UCASE_CONSTANT_RE.match(symbol.ident):
  784. return None
  785. - name = self._strip_symbol_or_warn(symbol, is_constant=True)
  786. - if not name:
  787. + try:
  788. + name = self._strip_symbol(symbol, is_constant=True)
  789. + except TransformerException, e:
  790. + message.warn_symbol(symbol, e)
  791. return None
  792. if symbol.const_string is not None:
  793. typeval = ast.TYPE_STRING
  794. @@ -671,8 +683,10 @@ raise ValueError."""
  795. return const
  796.  
  797. def _create_typedef_struct(self, symbol, disguised=False):
  798. - name = self.strip_identifier_or_warn(symbol.ident)
  799. - if not name:
  800. + try:
  801. + name = self.strip_identifier(symbol.ident)
  802. + except TransformerException, e:
  803. + message.warn(e)
  804. return None
  805. struct = ast.Record(name, symbol.ident, disguised)
  806. self._parse_fields(symbol, struct)
  807. @@ -681,8 +695,10 @@ raise ValueError."""
  808. return None
  809.  
  810. def _create_typedef_union(self, symbol):
  811. - name = self.strip_identifier_or_warn(symbol.ident)
  812. - if not name:
  813. + try:
  814. + name = self.strip_identifier(symbol.ident)
  815. + except TransformerException, e:
  816. + message.warn(e)
  817. return None
  818. union = ast.Union(name, symbol.ident)
  819. self._parse_fields(symbol, union)
  820. @@ -727,8 +743,10 @@ raise ValueError."""
  821. if anonymous:
  822. name = symbol.ident
  823. else:
  824. - name = self.strip_identifier_or_warn(symbol.ident)
  825. - if not name:
  826. + try:
  827. + name = self.strip_identifier(symbol.ident)
  828. + except TransformerException, e:
  829. + message.warn(e)
  830. return None
  831. compound = klass(name, symbol.ident)
  832.  
  833. @@ -755,12 +773,16 @@ raise ValueError."""
  834. if member:
  835. name = symbol.ident
  836. elif symbol.ident.find('_') > 0:
  837. - name = self._strip_symbol_or_warn(symbol)
  838. - if not name:
  839. + try:
  840. + name = self._strip_symbol(symbol)
  841. + except TransformerException, e:
  842. + message.warn_symbol(symbol, e)
  843. return None
  844. else:
  845. - name = self.strip_identifier_or_warn(symbol.ident)
  846. - if not name:
  847. + try:
  848. + name = self.strip_identifier(symbol.ident)
  849. + except TransformerException, e:
  850. + message.warn(e)
  851. return None
  852. callback = ast.Callback(name, retval, parameters, False)
  853. callback.add_symbol_reference(symbol)
  854. commit 8420651
  855. Author: Johan Dahlin <johan@gnome.org>
  856. Date: 2010-09-02 11:04:58 -0300
  857.  
  858. [scanner] add a message module
  859.  
  860. This module will be used to report warnings, which
  861. doesn't explicitly depend on the transformer instance.
  862.  
  863.  
  864. diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am
  865. index c01599f..a2044cf 100644
  866. --- a/giscanner/Makefile.am
  867. +++ b/giscanner/Makefile.am
  868. @@ -47,6 +47,7 @@ pkgpyexec_PYTHON = \
  869. libtoolimporter.py \
  870. odict.py \
  871. maintransformer.py \
  872. + message.py \
  873. shlibs.py \
  874. scannermain.py \
  875. sourcescanner.py \
  876. diff --git a/giscanner/message.py b/giscanner/message.py
  877. new file mode 100644
  878. index 0000000..4355514
  879. --- /dev/null
  880. +++ b/giscanner/message.py
  881. @@ -0,0 +1,155 @@
  882. +#!/usr/bin/env python
  883. +# -*- Mode: Python -*-
  884. +# GObject-Introspection - a framework for introspecting GObject libraries
  885. +# Copyright (C) 2010 Red Hat, Inc.
  886. +# Copyright (C) 2010 Johan Dahlin
  887. +#
  888. +# This program is free software; you can redistribute it and/or
  889. +# modify it under the terms of the GNU General Public License
  890. +# as published by the Free Software Foundation; either version 2
  891. +# of the License, or (at your option) any later version.
  892. +#
  893. +# This program is distributed in the hope that it will be useful,
  894. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  895. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  896. +# GNU General Public License for more details.
  897. +#
  898. +# You should have received a copy of the GNU General Public License
  899. +# along with this program; if not, write to the Free Software
  900. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  901. +# 02110-1301, USA.
  902. +#
  903. +
  904. +import os
  905. +import sys
  906. +
  907. +from . import ast
  908. +
  909. +(WARNING,
  910. + ERROR,
  911. + FATAL) = range(3)
  912. +
  913. +class MessageLogger(object):
  914. + _instance = None
  915. +
  916. + def __init__(self, namespace):
  917. + self._cwd = os.getcwd() + os.sep
  918. + self._namespace = namespace
  919. + self._enable_warnings = False
  920. + self._warned = False
  921. +
  922. + @classmethod
  923. + def get(cls, *args, **kwargs):
  924. + if cls._instance is None:
  925. + cls._instance = cls(*args, **kwargs)
  926. + return cls._instance
  927. +
  928. + def enable_warnings(self, enable):
  929. + self._enable_warnings = enable
  930. +
  931. + def did_warn(self):
  932. + return self._warned
  933. +
  934. + def log(self, log_type, text, file_positions=None, prefix=None):
  935. + """Log a warning, using optional file positioning information.
  936. +If the warning is related to a ast.Node type, see log_node_warning()."""
  937. + if not self._enable_warnings:
  938. + return
  939. +
  940. + self._warned = True
  941. +
  942. + if file_positions is None or len(file_positions) == 0:
  943. + target_file_positions = [('<unknown>', -1, -1)]
  944. + else:
  945. + target_file_positions = file_positions
  946. +
  947. + position_strings = []
  948. + for (filename, line, column) in target_file_positions:
  949. + if filename.startswith(self._cwd):
  950. + filename = filename[len(self._cwd):]
  951. + if column != -1:
  952. + position = '%s:%d:%d' % (filename, line, column)
  953. + elif line != -1:
  954. + position = '%s:%d' % (filename, line, )
  955. + else:
  956. + position = '%s:' % (filename, )
  957. + position_strings.append(position)
  958. +
  959. + for position in position_strings[:-1]:
  960. + print >>sys.stderr, "%s:" % (position, )
  961. + last_position = position_strings[-1]
  962. +
  963. + if log_type == WARNING:
  964. + error_type = "Warning"
  965. + elif log_type == ERROR:
  966. + error_type = "Error"
  967. + elif log_type == FATAL:
  968. + error_type = "Fatal"
  969. + if prefix:
  970. + print >>sys.stderr, \
  971. +'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
  972. + prefix, text)
  973. + else:
  974. + print >>sys.stderr, \
  975. +'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
  976. +
  977. +
  978. + if log_type == FATAL:
  979. + raise SystemExit
  980. +
  981. + def log_node(self, log_type, node, text, context=None):
  982. + """Log a warning, using information about file positions from
  983. +the given node. The optional context argument, if given, should be
  984. +another ast.Node type which will also be displayed. If no file position
  985. +information is available from the node, the position data from the
  986. +context will be used."""
  987. + if hasattr(node, 'file_positions'):
  988. + if (len(node.file_positions) == 0 and
  989. + (context is not None) and len(context.file_positions) > 0):
  990. + file_positions = context.file_positions
  991. + else:
  992. + file_positions = node.file_positions
  993. + else:
  994. + file_positions = None
  995. + if not context:
  996. + text = "context=%r %s" % (node, text)
  997. +
  998. + if context:
  999. + if isinstance(context, ast.Function):
  1000. + name = context.symbol
  1001. + else:
  1002. + name = context.name
  1003. + text = "%s: %s" % (name, text)
  1004. + elif len(file_positions) == 0 and hasattr(node, 'name'):
  1005. + text = "(%s)%s: %s" % (node.__class__.__name__, node.name, text)
  1006. +
  1007. + self.log(log_type, text, file_positions)
  1008. +
  1009. + def log_symbol(self, log_type, symbol, text, **kwargs):
  1010. + """Log a warning in the context of the given symbol."""
  1011. + if symbol.source_filename:
  1012. + file_positions = [(symbol.source_filename, symbol.line, -1)]
  1013. + else:
  1014. + file_positions = None
  1015. + prefix = "symbol=%r" % (symbol.ident, )
  1016. + self.log(log_type, text, file_positions, prefix=prefix, **kwargs)
  1017. +
  1018. +
  1019. +def log_node(log_type, node, text, context=None):
  1020. + ml = MessageLogger.get()
  1021. + ml.log_node(log_type, node, text, context=context)
  1022. +
  1023. +def warn(text, file_positions=None, prefix=None):
  1024. + ml = MessageLogger.get()
  1025. + ml.log(WARNING, text, file_positions, prefix)
  1026. +
  1027. +def warn_node(node, text, context=None):
  1028. + log_node(WARNING, node, text, context=context)
  1029. +
  1030. +def warn_symbol(symbol, text):
  1031. + ml = MessageLogger.get()
  1032. + ml.log_symbol(WARNING, symbol, text)
  1033. +
  1034. +def fatal(text, file_positions=None, prefix=None):
  1035. + ml = MessageLogger.get()
  1036. + ml.log(FATAL, text, file_positions, prefix)
  1037. diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
  1038. index cc01032..eae10f7 100644
  1039. --- a/giscanner/scannermain.py
  1040. +++ b/giscanner/scannermain.py
  1041. @@ -28,6 +28,7 @@ import subprocess
  1042. import sys
  1043. import tempfile
  1044.  
  1045. +from giscanner import message
  1046. from giscanner.annotationparser import AnnotationParser
  1047. from giscanner.ast import Include, Namespace
  1048. from giscanner.dumper import compile_introspection_binary
  1049. @@ -264,10 +265,10 @@ def scanner_main(args):
  1050. options.namespace_version,
  1051. identifier_prefixes=identifier_prefixes,
  1052. symbol_prefixes=symbol_prefixes)
  1053. + message.MessageLogger.get(namespace=namespace,
  1054. + enable_warnings=options.warn_all)
  1055. transformer = Transformer(namespace,
  1056. accept_unprefixed=options.accept_unprefixed)
  1057. - if options.warn_all:
  1058. - transformer.enable_warnings(True)
  1059. transformer.set_include_paths(options.include_paths)
  1060. shown_include_warning = False
  1061. for include in options.includes:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement