Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [33mcommit cfce024
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 12:21:38 -0300
- [scannermain] Create a new option parser
- Create a new option parser when parsing pkg-config output
- diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
- index bf2af39..d2bd876 100644
- --- a/giscanner/scannermain.py
- +++ b/giscanner/scannermain.py
- @@ -183,7 +183,7 @@ def process_options(output, allowed_flags):
- yield option
- break
- -def process_packages(parser, options, packages):
- +def process_packages(options, packages):
- args = ['pkg-config', '--cflags']
- args.extend(packages)
- output = subprocess.Popen(args,
- @@ -196,6 +196,7 @@ def process_packages(parser, options, packages):
- # so we explicitly filter to only the ones we need.
- options_whitelist = ['-I', '-D', '-U', '-l', '-L']
- filtered_output = list(process_options(output, options_whitelist))
- + parser = _get_option_parser()
- pkg_options, unused = parser.parse_args(filtered_output)
- options.cpp_includes.extend(pkg_options.cpp_includes)
- options.cpp_defines.extend(pkg_options.cpp_defines)
- @@ -283,7 +284,7 @@ def scanner_main(args):
- packages = set(options.packages)
- packages.update(transformer.get_pkgconfig_packages())
- - exit_code = process_packages(parser, options, packages)
- + exit_code = process_packages(options, packages)
- if exit_code:
- return exit_code
- [33mcommit ba943d6
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 12:09:52 -0300
- [message] Add an output parameter
- diff --git a/giscanner/message.py b/giscanner/message.py
- index 4355514..10a32a6 100644
- --- a/giscanner/message.py
- +++ b/giscanner/message.py
- @@ -32,8 +32,11 @@ from . import ast
- class MessageLogger(object):
- _instance = None
- - def __init__(self, namespace):
- + def __init__(self, namespace, output=None):
- + if output is None:
- + output = sys.stderr
- self._cwd = os.getcwd() + os.sep
- + self._output = output
- self._namespace = namespace
- self._enable_warnings = False
- self._warned = False
- @@ -76,7 +79,7 @@ If the warning is related to a ast.Node type, see log_node_warning()."""
- position_strings.append(position)
- for position in position_strings[:-1]:
- - print >>sys.stderr, "%s:" % (position, )
- + self._output.write("%s:\n" % (position, ))
- last_position = position_strings[-1]
- if log_type == WARNING:
- @@ -86,12 +89,12 @@ If the warning is related to a ast.Node type, see log_node_warning()."""
- elif log_type == FATAL:
- error_type = "Fatal"
- if prefix:
- - print >>sys.stderr, \
- -'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
- - prefix, text)
- + self._output.write(
- +'''%s: %s: %s: %s: %s\n''' % (last_position, error_type, self._namespace.name,
- + prefix, text))
- else:
- - print >>sys.stderr, \
- -'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
- + self._output.write(
- +'''%s: %s: %s: %s\n''' % (last_position, error_type, self._namespace.name, text))
- if log_type == FATAL:
- [33mcommit 4a98aec
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 11:44:47 -0300
- [scanner] Remove old logging functions
- And migrate over to using the message logger
- diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
- index ea1299e..bf2af39 100644
- --- a/giscanner/scannermain.py
- +++ b/giscanner/scannermain.py
- @@ -265,8 +265,9 @@ def scanner_main(args):
- options.namespace_version,
- identifier_prefixes=identifier_prefixes,
- symbol_prefixes=symbol_prefixes)
- - message.MessageLogger.get(namespace=namespace,
- - enable_warnings=options.warn_all)
- + logger = message.MessageLogger.get(namespace=namespace)
- + if options.warn_all:
- + logger.enable_warnings(True)
- transformer = Transformer(namespace,
- accept_unprefixed=options.accept_unprefixed)
- transformer.set_include_paths(options.include_paths)
- @@ -328,7 +329,7 @@ def scanner_main(args):
- final = IntrospectablePass(transformer)
- final.validate()
- - if options.warn_fatal and transformer.did_warn():
- + if options.warn_fatal and logger.did_warn():
- message.fatal("warnings configured as fatal")
- return 1
- diff --git a/giscanner/transformer.py b/giscanner/transformer.py
- index 8dd0129..9f76a7d 100644
- --- a/giscanner/transformer.py
- +++ b/giscanner/transformer.py
- @@ -53,14 +53,11 @@ class Transformer(object):
- UCASE_CONSTANT_RE = re.compile(r'[_A-Z0-9]+')
- def __init__(self, namespace, accept_unprefixed=False):
- - self._cwd = os.getcwd() + os.sep
- self._cachestore = CacheStore()
- self._accept_unprefixed = accept_unprefixed
- self._namespace = namespace
- self._pkg_config_packages = set()
- self._typedefs_ns = {}
- - self._enable_warnings = False
- - self._warned = False
- self._includes = {}
- self._include_names = set()
- self._includepaths = []
- @@ -68,12 +65,6 @@ class Transformer(object):
- def get_includes(self):
- return self._include_names
- - def enable_warnings(self, enable):
- - self._enable_warnings = enable
- -
- - def did_warn(self):
- - return self._warned
- -
- def get_pkgconfig_packages(self):
- return self._pkg_config_packages
- @@ -153,83 +144,6 @@ None."""
- # Private
- - def log_warning(self, text, file_positions=None, prefix=None,
- - fatal=False):
- - """Log a warning, using optional file positioning information.
- -If the warning is related to a ast.Node type, see log_node_warning()."""
- - if not fatal and not self._enable_warnings:
- - return
- -
- - self._warned = True
- -
- - if file_positions is None or len(file_positions) == 0:
- - target_file_positions = [('<unknown>', -1, -1)]
- - else:
- - target_file_positions = file_positions
- -
- - position_strings = []
- - for (filename, line, column) in target_file_positions:
- - if filename.startswith(self._cwd):
- - filename = filename[len(self._cwd):]
- - if column != -1:
- - position = '%s:%d:%d' % (filename, line, column)
- - elif line != -1:
- - position = '%s:%d' % (filename, line, )
- - else:
- - position = '%s:' % (filename, )
- - position_strings.append(position)
- -
- - for position in position_strings[:-1]:
- - print >>sys.stderr, "%s:" % (position, )
- - last_position = position_strings[-1]
- - error_type = 'error' if fatal else 'warning'
- - if prefix:
- - print >>sys.stderr, \
- -'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
- - prefix, text)
- - else:
- - print >>sys.stderr, \
- -'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
- - if fatal:
- - sys.exit(1)
- -
- - def log_symbol_warning(self, symbol, text, **kwargs):
- - """Log a warning in the context of the given symbol."""
- - if symbol.source_filename:
- - file_positions = [(symbol.source_filename, symbol.line, -1)]
- - else:
- - file_positions = None
- - prefix = "symbol=%r" % (symbol.ident, )
- - self.log_warning(text, file_positions, prefix=prefix, **kwargs)
- -
- - def log_node_warning(self, node, text, context=None, fatal=False):
- - """Log a warning, using information about file positions from
- -the given node. The optional context argument, if given, should be
- -another ast.Node type which will also be displayed. If no file position
- -information is available from the node, the position data from the
- -context will be used."""
- - if hasattr(node, 'file_positions'):
- - if (len(node.file_positions) == 0 and
- - (context is not None) and len(context.file_positions) > 0):
- - file_positions = context.file_positions
- - else:
- - file_positions = node.file_positions
- - else:
- - file_positions = None
- - if not context:
- - text = "context=%r %s" % (node, text)
- -
- - if context:
- - if isinstance(context, ast.Function):
- - name = context.symbol
- - else:
- - name = context.name
- - text = "%s: %s" % (name, text)
- - elif len(file_positions) == 0 and hasattr(node, 'name'):
- - text = "(%s)%s: %s" % (node.__class__.__name__, node.name, text)
- -
- - self.log_warning(text, file_positions, fatal=fatal)
- -
- def _find_include(self, include):
- searchdirs = self._includepaths[:]
- for path in _xdg_data_dirs:
- [33mcommit 3bd4087
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 11:44:27 -0300
- [scanner] Move over remaining callsites to message
- Move the remaining callsites over to the new message
- module
- diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
- index d93a464..d88f2e3 100644
- --- a/giscanner/gdumpparser.py
- +++ b/giscanner/gdumpparser.py
- @@ -209,8 +209,8 @@ blob containing data gleaned from GObject's primitive introspection."""
- rettype = func.retval.type
- if not (rettype.is_equiv(ast.TYPE_GTYPE)
- or rettype.target_giname == 'Gtk.Type'):
- - self._transformer.log_warning("function returns '%r', not a GType"
- - % (func.retval.type, ))
- + message.warn("function returns '%r', not a GType" % (
- + func.retval.type, ))
- return False
- self._get_type_functions.append(func.symbol)
- diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
- index 7843411..6653c09 100644
- --- a/giscanner/introspectablepass.py
- +++ b/giscanner/introspectablepass.py
- @@ -19,6 +19,7 @@
- from . import ast
- from . import glibast
- +from . import message
- class IntrospectablePass(object):
- @@ -38,7 +39,7 @@ class IntrospectablePass(object):
- if isinstance(node, glibast.GLibInterface):
- for vfunc in node.virtual_methods:
- if not vfunc.invoker:
- - self._transformer.log_node_warning(vfunc,
- + message.warn_node(vfunc,
- """Virtual function %r has no known invoker""" % (vfunc.name, ),
- context=node)
- @@ -51,7 +52,7 @@ class IntrospectablePass(object):
- context = "argument %s: " % (param.argname, )
- else:
- context = "return value: "
- - self._transformer.log_node_warning(parent, prefix + context + text, *args)
- + message.warn_node(parent, prefix + context + text, *args)
- def _introspectable_param_analysis(self, parent, node):
- is_return = isinstance(node, ast.Return)
- diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
- index 867a6c7..5a5a21e 100644
- --- a/giscanner/maintransformer.py
- +++ b/giscanner/maintransformer.py
- @@ -110,9 +110,10 @@ class MainTransformer(object):
- origin_name = 'parameter %s' % (origin.argname, )
- else:
- origin_name = 'return value'
- - self._transformer.log_node_warning(parent,
- + message.log_node(
- + message.FATAL, parent,
- "can't find parameter %s referenced by %s of %r"
- - % (param_name, origin_name, parent.name), fatal=True)
- + % (param_name, origin_name, parent.name))
- return param.argname
- @@ -125,18 +126,21 @@ class MainTransformer(object):
- rename_to = rename_to.value
- target = self._namespace.get_by_symbol(rename_to)
- if not target:
- - self._transformer.log_node_warning(node,
- -"Can't find symbol %r referenced by Rename annotation" % (rename_to, ))
- + message.warn_node(node,
- + "Can't find symbol %r referenced by Rename annotation" % (
- + rename_to, ))
- elif target.shadowed_by:
- - self._transformer.log_node_warning(node,
- -"Function %r already shadowed by %r, can't overwrite with %r" % (target.symbol,
- - target.shadowed_by,
- - rename_to))
- + message.warn_node(node,
- + "Function %r already shadowed by %r, can't overwrite with %r" % (
- + target.symbol,
- + target.shadowed_by,
- + rename_to))
- elif target.shadows:
- - self._transformer.log_node_warning(node,
- -"Function %r already shadows %r, can't multiply shadow with %r" % (target.symbol,
- - target.shadows,
- - rename_to))
- + message.warn_node(node,
- + "Function %r already shadows %r, can't multiply shadow with %r" % (
- + target.symbol,
- + target.shadows,
- + rename_to))
- else:
- target.shadows = node.symbol
- node.shadowed_by = target.symbol
- @@ -225,8 +229,8 @@ class MainTransformer(object):
- return ast.List(base.name, *rest)
- if isinstance(base, ast.Map) and len(rest) == 2:
- return ast.Map(*rest)
- - self._transformer.log_warning(
- -"Too many parameters in type specification %r" % (type_str, ))
- + message.warn(
- + "Too many parameters in type specification %r" % (type_str, ))
- return base
- def top_combiner(base, *rest):
- if orig_node is not None:
- @@ -235,8 +239,8 @@ class MainTransformer(object):
- result, rest = grab_one(type_str, resolver, top_combiner, combiner)
- if rest:
- - self._transformer.log_warning(
- -"Trailing components in type specification %r" % (type_str, ))
- + message.warn("Trailing components in type specification %r" % (
- + type_str, ))
- return result
- def _apply_annotations_array(self, parent, node, options):
- @@ -295,7 +299,7 @@ class MainTransformer(object):
- elif isinstance(node.type, ast.Array):
- node.type.element_type = self._resolve(element_type[0])
- else:
- - self._transformer.log_node_warning(parent,
- + message.warn_node(parent,
- "Unknown container %r for element-type annotation" % (node.type, ))
- def _get_transfer_default_param(self, parent, node):
- @@ -404,8 +408,8 @@ class MainTransformer(object):
- elif subtype == 'callee-allocates':
- caller_allocates = False
- else:
- - self._transformer.log_warning(
- -"out allocation for %s is invalid (%r)" % (node, subtype), fatal=True)
- + message.fatal("out allocation for %s is invalid (%r)" % (
- + node, subtype))
- elif OPT_IN in options:
- annotated_direction = ast.PARAM_DIRECTION_IN
- @@ -481,8 +485,9 @@ class MainTransformer(object):
- if scope not in [ast.PARAM_SCOPE_CALL,
- ast.PARAM_SCOPE_ASYNC,
- ast.PARAM_SCOPE_NOTIFIED]:
- - self._transformer.log_warning(parent,
- -"Invalid scope %r for parameter %r" % (scope, param.name))
- + message.warn(
- + parent,
- + "Invalid scope %r for parameter %r" % (scope, param.name))
- else:
- param.scope = scope
- param.transfer = ast.PARAM_TRANSFER_NONE
- @@ -544,9 +549,9 @@ class MainTransformer(object):
- if param.argname == tag:
- break
- else:
- - self._transformer.log_warning(
- -"Annotation for '%s' refers to unknown argument '%s'"
- -% (parent.name, tag))
- + message.warn(
- + "Annotation for '%s' refers to unknown argument '%s'"
- + % (parent.name, tag))
- def _apply_annotations_field(self, parent, block, field):
- if not block:
- @@ -620,7 +625,7 @@ class MainTransformer(object):
- self._apply_annotations_callable(vfunc, [parent], block)
- break
- if not matched:
- - self._transformer.log_symbol_warning(node.symbol,
- + message.warn_symbol(node.symbol,
- "Virtual slot %r not found for %r annotation" % (invoker_name, TAG_VFUNC))
- def _resolve_and_filter_type_list(self, typelist):
- @@ -716,8 +721,8 @@ the ones that failed to resolve removed."""
- if enum is not None:
- enum.error_quark = node.symbol
- else:
- - self._transformer.log_node_warning(node,
- -"""%s: Couldn't find corresponding enumeration""" % (node.symbol, ))
- + message.warn_node(node,
- + """%s: Couldn't find corresponding enumeration""" % (node.symbol, ))
- def _split_uscored_by_type(self, uscored):
- """'uscored' should be an un-prefixed uscore string. This
- @@ -809,7 +814,7 @@ method or constructor of some type."""
- split = self._split_uscored_by_type(subsymbol)
- if split is None:
- # TODO - need a e.g. (method) annotation
- - self._transformer.log_node_warning(func,
- + message.warn_node(func,
- "Can't find matching type for constructor; symbol=%r" % (func.symbol, ))
- return False
- (origin_node, funcname) = split
- @@ -823,15 +828,21 @@ method or constructor of some type."""
- else:
- parent = None
- if parent is None:
- - self._transformer.log_node_warning(func,
- -"Return value is not superclass for constructor; symbol=%r constructed=%r return=%r"
- -% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
- + message.warn_node(func,
- + "Return value is not superclass for constructor; "
- + "symbol=%r constructed=%r return=%r" % (
- + func.symbol,
- + str(origin_node.create_type()),
- + str(func.retval.type)))
- return False
- else:
- if origin_node != target:
- - self._transformer.log_node_warning(func,
- -"Constructor return type mismatch symbol=%r constructed=%r return=%r"
- -% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
- + message.warn_node(func,
- + "Constructor return type mismatch symbol=%r "
- + "constructed=%r return=%r" % (
- + func.symbol,
- + str(origin_node.create_type()),
- + str(func.retval.type)))
- return False
- self._namespace.float(func)
- func.name = funcname
- @@ -845,7 +856,7 @@ method or constructor of some type."""
- def _pair_class_virtuals(self, node):
- """Look for virtual methods from the class structure."""
- if not node.glib_type_struct:
- - self._transformer.log_node_warning(node,
- + message.warn_node(node,
- "Failed to find class structure for %r" % (node.name, ))
- return
- diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
- index eae10f7..ea1299e 100644
- --- a/giscanner/scannermain.py
- +++ b/giscanner/scannermain.py
- @@ -33,10 +33,10 @@ from giscanner.annotationparser import AnnotationParser
- from giscanner.ast import Include, Namespace
- from giscanner.dumper import compile_introspection_binary
- from giscanner.gdumpparser import GDumpParser, IntrospectionBinary
- -from giscanner.maintransformer import MainTransformer
- from giscanner.introspectablepass import IntrospectablePass
- from giscanner.girparser import GIRParser
- from giscanner.girwriter import GIRWriter
- +from giscanner.maintransformer import MainTransformer
- from giscanner.shlibs import resolve_shlibs
- from giscanner.sourcescanner import SourceScanner
- from giscanner.transformer import Transformer
- @@ -329,7 +329,7 @@ def scanner_main(args):
- final.validate()
- if options.warn_fatal and transformer.did_warn():
- - transformer.log_warning("warnings configured as fatal", fatal=True)
- + message.fatal("warnings configured as fatal")
- return 1
- # Write out AST
- diff --git a/giscanner/transformer.py b/giscanner/transformer.py
- index aa02fb3..8dd0129 100644
- --- a/giscanner/transformer.py
- +++ b/giscanner/transformer.py
- @@ -89,8 +89,8 @@ class Transformer(object):
- positions = set()
- positions.update(original.file_positions)
- positions.update(node.file_positions)
- - self.log_warning("Namespace conflict for '%s'" % (node.name, ),
- - positions, fatal=True)
- + message.fatal("Namespace conflict for '%s'" % (node.name, ),
- + positions)
- else:
- self._namespace.append(node)
- [33mcommit 5aed20a
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 11:07:01 -0300
- [scanner] Simplify strip_identifer/strip_symbol
- The strip_* functions are problematic since they
- have a fatal switch which determines if the message should
- kill the scanner. Change the api to make it easier to extend
- with other logging categories and move over the callsites to
- use the new message module
- diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
- index 7f1d229..d93a464 100644
- --- a/giscanner/gdumpparser.py
- +++ b/giscanner/gdumpparser.py
- @@ -27,6 +27,8 @@ from xml.etree.cElementTree import parse
- from . import ast
- from . import glibast
- +from . import message
- +from .transformer import TransformerException
- # GParamFlags
- G_PARAM_READABLE = 1 << 0
- @@ -254,7 +256,10 @@ blob containing data gleaned from GObject's primitive introspection."""
- klass = (glibast.GLibFlags if node.tag == 'flags' else glibast.GLibEnum)
- type_name = node.attrib['name']
- - enum_name = self._transformer.strip_identifier_or_warn(type_name, fatal=True)
- + try:
- + enum_name = self._transformer.strip_identifier(type_name)
- + except TransformerException, e:
- + message.fatal(e)
- node = klass(enum_name, type_name, members, node.attrib['get-type'])
- self._namespace.append(node, replace=True)
- @@ -275,11 +280,12 @@ blob containing data gleaned from GObject's primitive introspection."""
- return
- is_abstract = bool(xmlnode.attrib.get('abstract', False))
- (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- - node = glibast.GLibObject(
- - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- - None,
- - type_name,
- - get_type, c_symbol_prefix, is_abstract)
- + try:
- + object_name = self._transformer.strip_identifier(type_name)
- + except TransformerException, e:
- + message.fatal(e)
- + node = glibast.GLibObject(object_name, None, type_name,
- + get_type, c_symbol_prefix, is_abstract)
- self._parse_parents(xmlnode, node)
- self._introspect_properties(node, xmlnode)
- self._introspect_signals(node, xmlnode)
- @@ -291,10 +297,12 @@ blob containing data gleaned from GObject's primitive introspection."""
- def _introspect_interface(self, xmlnode):
- type_name = xmlnode.attrib['name']
- (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- - node = glibast.GLibInterface(
- - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- - None,
- - type_name, get_type, c_symbol_prefix)
- + try:
- + interface_name = self._transformer.strip_identifier(type_name)
- + except TransformerException, e:
- + message.fatal(e)
- + node = glibast.GLibInterface(interface_name, None, type_name,
- + get_type, c_symbol_prefix)
- self._introspect_properties(node, xmlnode)
- self._introspect_signals(node, xmlnode)
- for child in xmlnode.findall('prerequisite'):
- @@ -379,11 +387,13 @@ blob containing data gleaned from GObject's primitive introspection."""
- type_name = xmlnode.attrib['name']
- is_abstract = bool(xmlnode.attrib.get('abstract', False))
- (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- - node = glibast.GLibObject(
- - self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- - None,
- - type_name,
- - get_type, c_symbol_prefix, is_abstract)
- + try:
- + fundamental_name = self._transformer.strip_identifier(type_name)
- + except TransformerException, e:
- + message.fatal(e)
- +
- + node = glibast.GLibObject(fundamental_name, None, type_name,
- + get_type, c_symbol_prefix, is_abstract)
- self._parse_parents(xmlnode, node)
- node.fundamental = True
- self._introspect_implemented_interfaces(node, xmlnode)
- @@ -404,7 +414,10 @@ blob containing data gleaned from GObject's primitive introspection."""
- field.writable = False
- def _pair_boxed_type(self, boxed):
- - name = self._transformer.strip_identifier_or_warn(boxed.type_name, fatal=True)
- + try:
- + name = self._transformer.strip_identifier(boxed.type_name)
- + except TransformerException, e:
- + message.fatal(e)
- pair_node = self._namespace.get(name)
- if not pair_node:
- boxed_item = glibast.GLibBoxedOther(name, boxed.type_name,
- diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
- index b529ee8..867a6c7 100644
- --- a/giscanner/maintransformer.py
- +++ b/giscanner/maintransformer.py
- @@ -21,6 +21,7 @@ import re
- from . import ast
- from . import glibast
- +from . import message
- from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS,
- TAG_ATTRIBUTES, TAG_RENAME_TO, TAG_TYPE, TAG_TRANSFER,
- TAG_UNREF_FUNC, TAG_REF_FUNC, TAG_SET_VALUE_FUNC,
- @@ -32,6 +33,7 @@ from .annotationparser import (OPT_ALLOW_NONE,
- OPT_FOREIGN, OPT_ARRAY_FIXED_SIZE,
- OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED)
- from .annotationparser import AnnotationParser
- +from .transformer import TransformerException
- from .utils import to_underscores, to_underscores_noprefix
- class MainTransformer(object):
- @@ -688,7 +690,12 @@ the ones that failed to resolve removed."""
- uscore_enums[uscored] = enum
- - no_uscore_prefixed = self._transformer.strip_identifier_or_warn(type_name)
- + try:
- + no_uscore_prefixed = self._transformer.strip_identifier(type_name)
- + except TransformerException, e:
- + message.warn(e)
- + no_uscore_prefixed = None
- +
- if no_uscore_prefixed not in uscore_enums:
- uscore_enums[no_uscore_prefixed] = enum
- diff --git a/giscanner/transformer.py b/giscanner/transformer.py
- index 690cbab..aa02fb3 100644
- --- a/giscanner/transformer.py
- +++ b/giscanner/transformer.py
- @@ -24,6 +24,7 @@ import re
- from . import ast
- from . import glibast
- +from . import message
- from .cachestore import CacheStore
- from .config import DATADIR, GIR_DIR, GIR_SUFFIX
- from .girparser import GIRParser
- @@ -36,6 +37,10 @@ from .sourcescanner import (
- CSYMBOL_TYPE_MEMBER, CSYMBOL_TYPE_ELLIPSIS, CSYMBOL_TYPE_CONST,
- TYPE_QUALIFIER_CONST)
- +class TransformerException(Exception):
- + pass
- +
- +
- class TypeResolutionException(Exception):
- pass
- @@ -320,26 +325,26 @@ raise ValueError."""
- matches = self._split_c_string_for_namespace_matches(symbol, is_identifier=False)
- return matches[-1]
- - def strip_identifier_or_warn(self, ident, fatal=False):
- + def strip_identifier(self, ident):
- hidden = ident.startswith('_')
- if hidden:
- ident = ident[1:]
- try:
- matches = self.split_ctype_namespaces(ident)
- except ValueError, e:
- - self.log_warning(str(e), fatal=fatal)
- - return None
- + raise TransformerException(str(e))
- for ns, name in matches:
- if ns is self._namespace:
- if hidden:
- return '_' + name
- return name
- (ns, name) = matches[-1]
- - self.log_warning("Skipping foreign identifier %r from namespace %s" % (ident, ns.name, ),
- - fatal=fatal)
- + raise TransformerException(
- + "Skipping foreign identifier %r from namespace %s" % (
- + ident, ns.name, ))
- return None
- - def _strip_symbol_or_warn(self, symbol, is_constant=False, fatal=False):
- + def _strip_symbol(self, symbol, is_constant=False):
- ident = symbol.ident
- if is_constant:
- # Temporarily lowercase
- @@ -350,13 +355,10 @@ raise ValueError."""
- try:
- (ns, name) = self.split_csymbol(ident)
- except ValueError, e:
- - self.log_symbol_warning(symbol, "Unknown namespace", fatal=fatal)
- - return None
- + raise TransformerException("Unknown namespace")
- if ns != self._namespace:
- - self.log_symbol_warning(symbol,
- -"Skipping foreign symbol from namespace %s" % (ns.name, ),
- - fatal=fatal)
- - return None
- + raise TransformerException(
- + "Skipping foreign symbol from namespace %s" % (ns.name, ))
- if is_constant:
- name = name.upper()
- if hidden:
- @@ -424,15 +426,19 @@ raise ValueError."""
- # Ok, the enum members don't have a consistent prefix
- # among them, so let's just remove the global namespace
- # prefix.
- - name = self._strip_symbol_or_warn(child, is_constant=True)
- - if name is None:
- + try:
- + name = self._strip_symbol(child, is_constant=True)
- + except TransformerException, e:
- + message.warn_symbol(child, e)
- return None
- members.append(ast.Member(name.lower(),
- - child.const_int,
- - child.ident))
- + child.const_int,
- + child.ident))
- - enum_name = self.strip_identifier_or_warn(symbol.ident)
- - if not enum_name:
- + try:
- + enum_name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- if symbol.base_type.is_bitfield:
- klass = ast.Bitfield
- @@ -445,8 +451,10 @@ raise ValueError."""
- def _create_function(self, symbol):
- parameters = list(self._create_parameters(symbol.base_type))
- return_ = self._create_return(symbol.base_type.base_type)
- - name = self._strip_symbol_or_warn(symbol)
- - if not name:
- + try:
- + name = self._strip_symbol(symbol)
- + except TransformerException, e:
- + message.warn_symbol(symbol, e)
- return None
- func = ast.Function(name, return_, parameters, False, symbol.ident)
- func.add_symbol_reference(symbol)
- @@ -526,8 +534,10 @@ raise ValueError."""
- CTYPE_POINTER,
- CTYPE_BASIC_TYPE,
- CTYPE_VOID):
- - name = self.strip_identifier_or_warn(symbol.ident)
- - if not name:
- + try:
- + name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- if symbol.base_type.name:
- target = self.create_type_from_ctype_string(symbol.base_type.name)
- @@ -651,8 +661,10 @@ raise ValueError."""
- # ignore non-uppercase defines
- if not self.UCASE_CONSTANT_RE.match(symbol.ident):
- return None
- - name = self._strip_symbol_or_warn(symbol, is_constant=True)
- - if not name:
- + try:
- + name = self._strip_symbol(symbol, is_constant=True)
- + except TransformerException, e:
- + message.warn_symbol(symbol, e)
- return None
- if symbol.const_string is not None:
- typeval = ast.TYPE_STRING
- @@ -671,8 +683,10 @@ raise ValueError."""
- return const
- def _create_typedef_struct(self, symbol, disguised=False):
- - name = self.strip_identifier_or_warn(symbol.ident)
- - if not name:
- + try:
- + name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- struct = ast.Record(name, symbol.ident, disguised)
- self._parse_fields(symbol, struct)
- @@ -681,8 +695,10 @@ raise ValueError."""
- return None
- def _create_typedef_union(self, symbol):
- - name = self.strip_identifier_or_warn(symbol.ident)
- - if not name:
- + try:
- + name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- union = ast.Union(name, symbol.ident)
- self._parse_fields(symbol, union)
- @@ -727,8 +743,10 @@ raise ValueError."""
- if anonymous:
- name = symbol.ident
- else:
- - name = self.strip_identifier_or_warn(symbol.ident)
- - if not name:
- + try:
- + name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- compound = klass(name, symbol.ident)
- @@ -755,12 +773,16 @@ raise ValueError."""
- if member:
- name = symbol.ident
- elif symbol.ident.find('_') > 0:
- - name = self._strip_symbol_or_warn(symbol)
- - if not name:
- + try:
- + name = self._strip_symbol(symbol)
- + except TransformerException, e:
- + message.warn_symbol(symbol, e)
- return None
- else:
- - name = self.strip_identifier_or_warn(symbol.ident)
- - if not name:
- + try:
- + name = self.strip_identifier(symbol.ident)
- + except TransformerException, e:
- + message.warn(e)
- return None
- callback = ast.Callback(name, retval, parameters, False)
- callback.add_symbol_reference(symbol)
- [33mcommit 8420651
- Author: Johan Dahlin <johan@gnome.org>
- Date: 2010-09-02 11:04:58 -0300
- [scanner] add a message module
- This module will be used to report warnings, which
- doesn't explicitly depend on the transformer instance.
- diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am
- index c01599f..a2044cf 100644
- --- a/giscanner/Makefile.am
- +++ b/giscanner/Makefile.am
- @@ -47,6 +47,7 @@ pkgpyexec_PYTHON = \
- libtoolimporter.py \
- odict.py \
- maintransformer.py \
- + message.py \
- shlibs.py \
- scannermain.py \
- sourcescanner.py \
- diff --git a/giscanner/message.py b/giscanner/message.py
- new file mode 100644
- index 0000000..4355514
- --- /dev/null
- +++ b/giscanner/message.py
- @@ -0,0 +1,155 @@
- +#!/usr/bin/env python
- +# -*- Mode: Python -*-
- +# GObject-Introspection - a framework for introspecting GObject libraries
- +# Copyright (C) 2010 Red Hat, Inc.
- +# Copyright (C) 2010 Johan Dahlin
- +#
- +# This program is free software; you can redistribute it and/or
- +# modify it under the terms of the GNU General Public License
- +# as published by the Free Software Foundation; either version 2
- +# of the License, or (at your option) any later version.
- +#
- +# This program is distributed in the hope that it will be useful,
- +# but WITHOUT ANY WARRANTY; without even the implied warranty of
- +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +# GNU General Public License for more details.
- +#
- +# You should have received a copy of the GNU General Public License
- +# along with this program; if not, write to the Free Software
- +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- +# 02110-1301, USA.
- +#
- +
- +import os
- +import sys
- +
- +from . import ast
- +
- +(WARNING,
- + ERROR,
- + FATAL) = range(3)
- +
- +class MessageLogger(object):
- + _instance = None
- +
- + def __init__(self, namespace):
- + self._cwd = os.getcwd() + os.sep
- + self._namespace = namespace
- + self._enable_warnings = False
- + self._warned = False
- +
- + @classmethod
- + def get(cls, *args, **kwargs):
- + if cls._instance is None:
- + cls._instance = cls(*args, **kwargs)
- + return cls._instance
- +
- + def enable_warnings(self, enable):
- + self._enable_warnings = enable
- +
- + def did_warn(self):
- + return self._warned
- +
- + def log(self, log_type, text, file_positions=None, prefix=None):
- + """Log a warning, using optional file positioning information.
- +If the warning is related to a ast.Node type, see log_node_warning()."""
- + if not self._enable_warnings:
- + return
- +
- + self._warned = True
- +
- + if file_positions is None or len(file_positions) == 0:
- + target_file_positions = [('<unknown>', -1, -1)]
- + else:
- + target_file_positions = file_positions
- +
- + position_strings = []
- + for (filename, line, column) in target_file_positions:
- + if filename.startswith(self._cwd):
- + filename = filename[len(self._cwd):]
- + if column != -1:
- + position = '%s:%d:%d' % (filename, line, column)
- + elif line != -1:
- + position = '%s:%d' % (filename, line, )
- + else:
- + position = '%s:' % (filename, )
- + position_strings.append(position)
- +
- + for position in position_strings[:-1]:
- + print >>sys.stderr, "%s:" % (position, )
- + last_position = position_strings[-1]
- +
- + if log_type == WARNING:
- + error_type = "Warning"
- + elif log_type == ERROR:
- + error_type = "Error"
- + elif log_type == FATAL:
- + error_type = "Fatal"
- + if prefix:
- + print >>sys.stderr, \
- +'''%s: %s: %s: %s: %s''' % (last_position, error_type, self._namespace.name,
- + prefix, text)
- + else:
- + print >>sys.stderr, \
- +'''%s: %s: %s: %s''' % (last_position, error_type, self._namespace.name, text)
- +
- +
- + if log_type == FATAL:
- + raise SystemExit
- +
- + def log_node(self, log_type, node, text, context=None):
- + """Log a warning, using information about file positions from
- +the given node. The optional context argument, if given, should be
- +another ast.Node type which will also be displayed. If no file position
- +information is available from the node, the position data from the
- +context will be used."""
- + if hasattr(node, 'file_positions'):
- + if (len(node.file_positions) == 0 and
- + (context is not None) and len(context.file_positions) > 0):
- + file_positions = context.file_positions
- + else:
- + file_positions = node.file_positions
- + else:
- + file_positions = None
- + if not context:
- + text = "context=%r %s" % (node, text)
- +
- + if context:
- + if isinstance(context, ast.Function):
- + name = context.symbol
- + else:
- + name = context.name
- + text = "%s: %s" % (name, text)
- + elif len(file_positions) == 0 and hasattr(node, 'name'):
- + text = "(%s)%s: %s" % (node.__class__.__name__, node.name, text)
- +
- + self.log(log_type, text, file_positions)
- +
- + def log_symbol(self, log_type, symbol, text, **kwargs):
- + """Log a warning in the context of the given symbol."""
- + if symbol.source_filename:
- + file_positions = [(symbol.source_filename, symbol.line, -1)]
- + else:
- + file_positions = None
- + prefix = "symbol=%r" % (symbol.ident, )
- + self.log(log_type, text, file_positions, prefix=prefix, **kwargs)
- +
- +
- +def log_node(log_type, node, text, context=None):
- + ml = MessageLogger.get()
- + ml.log_node(log_type, node, text, context=context)
- +
- +def warn(text, file_positions=None, prefix=None):
- + ml = MessageLogger.get()
- + ml.log(WARNING, text, file_positions, prefix)
- +
- +def warn_node(node, text, context=None):
- + log_node(WARNING, node, text, context=context)
- +
- +def warn_symbol(symbol, text):
- + ml = MessageLogger.get()
- + ml.log_symbol(WARNING, symbol, text)
- +
- +def fatal(text, file_positions=None, prefix=None):
- + ml = MessageLogger.get()
- + ml.log(FATAL, text, file_positions, prefix)
- diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
- index cc01032..eae10f7 100644
- --- a/giscanner/scannermain.py
- +++ b/giscanner/scannermain.py
- @@ -28,6 +28,7 @@ import subprocess
- import sys
- import tempfile
- +from giscanner import message
- from giscanner.annotationparser import AnnotationParser
- from giscanner.ast import Include, Namespace
- from giscanner.dumper import compile_introspection_binary
- @@ -264,10 +265,10 @@ def scanner_main(args):
- options.namespace_version,
- identifier_prefixes=identifier_prefixes,
- symbol_prefixes=symbol_prefixes)
- + message.MessageLogger.get(namespace=namespace,
- + enable_warnings=options.warn_all)
- transformer = Transformer(namespace,
- accept_unprefixed=options.accept_unprefixed)
- - if options.warn_all:
- - transformer.enable_warnings(True)
- transformer.set_include_paths(options.include_paths)
- shown_include_warning = False
- for include in options.includes:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement