diff options
author | Johan Dahlin <jdahlin@async.com.br> | 2008-06-03 23:32:04 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-06-03 23:32:04 +0000 |
commit | e8b29ce05be743bb695959fc7f5fa6ccbc69fbe9 (patch) | |
tree | c88dd42ddb3d673fdc9cbb5d70d33bcdb7cc6beb /giscanner/utils.py | |
parent | 6b52e768cce135b576fd0ebee5e0531310ef42f4 (diff) | |
download | gobject-introspection-e8b29ce05be743bb695959fc7f5fa6ccbc69fbe9.tar.gz |
Improve enum member parsing and introspection
2008-06-03 Johan Dahlin <jdahlin@async.com.br>
* giscanner/Makefile.am:
* giscanner/ast.py:
* giscanner/girwriter.py:
* giscanner/glibast.py:
* giscanner/glibtransformer.py:
* giscanner/transformer.py:
* giscanner/utils.py:
* tests/parser/Foo-expected.gir:
Improve enum member parsing and introspection
svn path=/trunk/; revision=283
Diffstat (limited to 'giscanner/utils.py')
-rw-r--r-- | giscanner/utils.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/giscanner/utils.py b/giscanner/utils.py new file mode 100644 index 00000000..488baadd --- /dev/null +++ b/giscanner/utils.py @@ -0,0 +1,53 @@ +# -*- Mode: Python -*- +# GObject-Introspection - a framework for introspecting GObject libraries +# Copyright (C) 2008 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 re +import os + +# Copied from h2defs.py +_upperstr_pat1 = re.compile(r'([^A-Z])([A-Z])') +_upperstr_pat2 = re.compile(r'([A-Z][A-Z])([A-Z][0-9a-z])') +_upperstr_pat3 = re.compile(r'^([A-Z])([A-Z])') + +def to_underscores(name): + """Converts a typename to the equivalent underscores name. + This is used to form the type conversion macros and enum/flag + name variables""" + name = _upperstr_pat1.sub(r'\1_\2', name) + name = _upperstr_pat2.sub(r'\1_\2', name) + name = _upperstr_pat3.sub(r'\1_\2', name, count=1) + return name + +_libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n") + +def resolve_libtool(libname): + data = open(libname).read() + filename = _libtool_pat.search(data).groups()[0] + libname = os.path.join(os.path.dirname(libname), + '.libs', filename) + return libname + +def strip_common_prefix(first, second): + first_underscore = to_underscores(first) + for i, c in enumerate(first_underscore.upper()): + if c != second[i]: + break + return second[i:] + |