summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2010-09-16 00:37:49 -0300
committerJohan Dahlin <johan@gnome.org>2010-09-24 16:06:53 -0300
commit7cc31be7753b124b7f17febbbe0607765b426fa0 (patch)
tree1ad650110b5862701c653882fe2701cc937663b8 /giscanner
parent2aadc9201bf320820a02a789aaf9b1681fd453d5 (diff)
downloadgobject-introspection-7cc31be7753b124b7f17febbbe0607765b426fa0.tar.gz
Add an annotation tool
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/Makefile.am1
-rw-r--r--giscanner/annotationmain.py78
-rw-r--r--giscanner/annotationparser.py52
3 files changed, 131 insertions, 0 deletions
diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am
index 6fee40dd..2779b70c 100644
--- a/giscanner/Makefile.am
+++ b/giscanner/Makefile.am
@@ -33,6 +33,7 @@ pkgpyexecdir = $(pkglibdir)/giscanner
pkgpyexec_LTLIBRARIES = _giscanner.la
pkgpyexec_PYTHON = \
__init__.py \
+ annotationmain.py \
annotationparser.py \
ast.py \
cachestore.py \
diff --git a/giscanner/annotationmain.py b/giscanner/annotationmain.py
new file mode 100644
index 00000000..d6e2eef5
--- /dev/null
+++ b/giscanner/annotationmain.py
@@ -0,0 +1,78 @@
+# -*- Mode: Python -*-
+# GObject-Introspection - a framework for introspecting GObject libraries
+# 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 optparse
+
+from giscanner.annotationparser import AnnotationParser
+from giscanner.scannermain import (get_preprocessor_option_group,
+ create_source_scanner,
+ process_packages)
+
+def annotation_main(args):
+ parser = optparse.OptionParser('%prog [options] sources')
+
+ group = optparse.OptionGroup(parser, "Tool modes, one is required")
+ group.add_option("-e", "--extract",
+ action="store_true", dest="extract",
+ help="Extract annotations from the input files")
+ parser.add_option_group(group)
+
+ group = get_preprocessor_option_group(parser)
+ group.add_option("-L", "--library-path",
+ action="append", dest="library_paths", default=[],
+ help="directories to search for libraries")
+ group.add_option("", "--pkg",
+ action="append", dest="packages", default=[],
+ help="pkg-config packages to get cflags from")
+ parser.add_option_group(group)
+
+ options, args = parser.parse_args(args)
+
+ if not options.extract:
+ raise SystemExit("ERROR: Nothing to do")
+
+ if options.packages:
+ process_packages(options, options.packages)
+
+ ss = create_source_scanner(options, args)
+
+ if options.extract:
+ ap = AnnotationParser()
+ blocks = ap.parse(ss.get_comments())
+ for block in blocks.values():
+ print block.to_gtk_doc()
+ print
+ elif options.validate:
+ transformer = create_transformer(namespace, options)
+ transformer.parse(ss.get_symbols())
+
+ shlibs = create_binary(transformer, options, args)
+
+ ap = AnnotationParser()
+ blocks = ap.parse(ss.get_comments())
+
+ main = MainTransformer(transformer, blocks)
+ main.transform()
+
+ final = IntrospectablePass(transformer)
+ final.validate()
+
+
+ return 0
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index f2bc1d4b..282ea550 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -106,6 +106,9 @@ class DocBlock(object):
self.params = []
self.position = None
+ def __cmp__(self, other):
+ return cmp(self.name, other.name)
+
def __repr__(self):
return '<DocBlock %r %r>' % (self.name, self.options)
@@ -116,6 +119,29 @@ class DocBlock(object):
def get(self, name):
return self.tags.get(name)
+ def to_gtk_doc(self):
+ lines = [self.name + ':']
+ tags = []
+ for name, tag in self.tags.iteritems():
+ if name in self.params:
+ lines.append(tag.to_gtk_doc_param())
+ else:
+ tags.append(tag)
+
+ lines.append('')
+ for l in self.comment.split('\n'):
+ lines.append(l)
+ if tags:
+ lines.append('')
+ for tag in tags:
+ lines.append(tag.to_gtk_doc_tag())
+
+ comment = '/**\n'
+ for line in lines:
+ comment += ' * %s\n' % (line, )
+ comment += ' */\n'
+ return comment
+
def validate(self):
for tag in self.tags.values():
tag.validate()
@@ -169,6 +195,32 @@ class DocTag(object):
self.position = position
self.options.position = position
+ def _get_gtk_doc_value(self):
+ def serialize_one(option, value, fmt, fmt2):
+ if value:
+ if type(value) != str:
+ value = ' '.join((serialize_one(k, v, '%s=%s', '%s')
+ for k,v in value.all().iteritems()))
+ return fmt % (option, value)
+ else:
+ return fmt2 % (option, )
+ annotations = []
+ for option, value in self.options.iteritems():
+ annotations.append(
+ serialize_one(option, value, '(%s %s)', '(%s)'))
+ if annotations:
+ return ' '.join(annotations) + ': '
+ else:
+ return self.value
+
+ def to_gtk_doc_param(self):
+ return '@%s: %s%s' % (self.name, self._get_gtk_doc_value(), self.comment)
+
+ def to_gtk_doc_tag(self):
+ return '%s: %s%s' % (self.name.capitalize(),
+ self._get_gtk_doc_value(),
+ self.comment or '')
+
def validate(self):
for option in self.options:
value = self.options[option]