From 7dbbda9abea9882d2c98726f382a905fa8738706 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 12 Jan 2009 20:11:44 +0000 Subject: [PATCH] Bug 563794 - Redo annotation parsing & applying 2009-01-12 Johan Dahlin Bug 563794 - Redo annotation parsing & applying Thanks to Colin for helping out considerably in landing this. * giscanner/Makefile.am: * giscanner/ast.py: * giscanner/dumper.py: * giscanner/girparser.py: * giscanner/giscannermodule.c (pygi_source_scanner_get_comments), (calc_attrs_length), (pygi_collect_attributes), (init_giscanner): * giscanner/glibtransformer.py: * giscanner/scannerlexer.l: * giscanner/sourcescanner.c (gi_source_symbol_unref), (gi_source_scanner_new), (gi_source_scanner_free), (gi_source_scanner_get_comments): * giscanner/sourcescanner.h: * giscanner/sourcescanner.py: * giscanner/transformer.py: * giscanner/xmlwriter.py: * tests/scanner/annotation-1.0-expected.gir: * tests/scanner/annotation-1.0-expected.tgir: * tests/scanner/annotation.c: * tests/scanner/annotation.h: * tests/scanner/foo-1.0-expected.gir: * tests/scanner/foo-1.0-expected.tgir: * tests/scanner/foo.h: * tools/g-ir-scanner: This commit merges the annotation parser rewrite branch. It'll change the annotation parsing to be done completely in python code which will make it easier to do further annotation parsing easier. svn path=/trunk/; revision=1017 --- ChangeLog | 35 ++ giscanner/Makefile.am | 1 + giscanner/annotationparser.py | 505 +++++++++++++++++++++++++++++ giscanner/ast.py | 32 +- giscanner/dumper.py | 2 + giscanner/girparser.py | 11 +- giscanner/giscannermodule.c | 128 +------- giscanner/glibtransformer.py | 36 +- giscanner/scannerlexer.l | 172 +--------- giscanner/sourcescanner.c | 33 +- giscanner/sourcescanner.h | 19 +- giscanner/sourcescanner.py | 11 +- giscanner/transformer.py | 390 ++++------------------ giscanner/xmlwriter.py | 2 + tests/scanner/annotation-1.0-expected.gir | 7 + tests/scanner/annotation-1.0-expected.tgir | 7 + tests/scanner/annotation.c | 4 +- tests/scanner/annotation.h | 5 + tests/scanner/foo-1.0-expected.gir | 34 ++ tests/scanner/foo-1.0-expected.tgir | 30 ++ tests/scanner/foo.h | 5 + tools/g-ir-scanner | 7 + 22 files changed, 791 insertions(+), 685 deletions(-) create mode 100644 giscanner/annotationparser.py diff --git a/ChangeLog b/ChangeLog index ab812fd..a16f632 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2009-01-12 Johan Dahlin + + Bug 563794 - Redo annotation parsing & applying + + Thanks to Colin for helping out considerably in landing this. + + * giscanner/Makefile.am: + * giscanner/ast.py: + * giscanner/dumper.py: + * giscanner/girparser.py: + * giscanner/giscannermodule.c (pygi_source_scanner_get_comments), + (calc_attrs_length), (pygi_collect_attributes), (init_giscanner): + * giscanner/glibtransformer.py: + * giscanner/scannerlexer.l: + * giscanner/sourcescanner.c (gi_source_symbol_unref), + (gi_source_scanner_new), (gi_source_scanner_free), + (gi_source_scanner_get_comments): + * giscanner/sourcescanner.h: + * giscanner/sourcescanner.py: + * giscanner/transformer.py: + * giscanner/xmlwriter.py: + * tests/scanner/annotation-1.0-expected.gir: + * tests/scanner/annotation-1.0-expected.tgir: + * tests/scanner/annotation.c: + * tests/scanner/annotation.h: + * tests/scanner/foo-1.0-expected.gir: + * tests/scanner/foo-1.0-expected.tgir: + * tests/scanner/foo.h: + * tools/g-ir-scanner: + + This commit merges the annotation parser rewrite branch. + It'll change the annotation parsing to be done completely in python + code which will make it easier to do further annotation parsing + easier. + 2009-01-03 Andreas Rottmann Bug 563469 – Arrays not treated correctly in struct offset calculation diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am index 1d6942b..bc2977f 100644 --- a/giscanner/Makefile.am +++ b/giscanner/Makefile.am @@ -35,6 +35,7 @@ pkgpyexecdir = $(pyexecdir)/giscanner pkgpyexec_LTLIBRARIES = _giscanner.la pkgpyexec_PYTHON = \ __init__.py \ + annotationparser.py \ ast.py \ cachestore.py \ config.py \ diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py new file mode 100644 index 0000000..630508a --- /dev/null +++ b/giscanner/annotationparser.py @@ -0,0 +1,505 @@ +# -*- 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. +# + +# AnnotationParser - parses gtk-doc annotations + +# All gtk-doc comments needs to start with this: +_COMMENT_HEADER = '*\n * ' + +from .ast import (Array, Callback, Class, Enum, Field, Function, Interface, + List, Map, Parameter, Record, Return, Type, Union, Varargs, + default_array_types, + BASIC_GIR_TYPES, + PARAM_DIRECTION_INOUT, + PARAM_DIRECTION_IN, + PARAM_DIRECTION_OUT, + PARAM_TRANSFER_NONE, + PARAM_TRANSFER_CONTAINER, + PARAM_TRANSFER_FULL, + TYPE_ANY, TYPE_NONE) +from .glibast import GLibBoxed + + +class InvalidAnnotationError(Exception): + pass + + +class DocBlock(object): + + def __init__(self, name): + self.name = name + self.value = None + self.tags = {} + + def __repr__(self): + return '' % (self.name, ) + + def get(self, name): + if name == 'Returns': + value = self.tags.get(name) + if value is None: + return self.tags.get('Return value') + else: + return value + else: + return self.tags.get(name) + + +class DocTag(object): + + def __init__(self, name): + self.name = name + self.options = [] + + +class Option(object): + + def __init__(self, option): + self._array = [] + self._dict = {} + for p in option.split(' '): + if '=' in p: + name, value = p.split('=', 1) + else: + name = p + value = None + self._dict[name] = value + if value is None: + self._array.append(name) + else: + self._array.append((name, value)) + + def __repr__(self): + return '