summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-03-27 18:06:24 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2014-02-12 11:32:27 -0500
commite83d3f861fdc111e1bf2e372562978896db247e3 (patch)
tree1b1d1a133c49682a0d8eb70487b4aa1de3cd720d
parent9925045a0b7a67c3afcce16745c14eb2e07db3e8 (diff)
downloadgobject-introspection-e83d3f861fdc111e1bf2e372562978896db247e3.tar.gz
doctool: Add constants to the namespace
This is an initial test before we port over to docbook to see if we can build a new structure for how the pages should act.
-rw-r--r--Makefile-giscanner.am3
-rw-r--r--giscanner/doctemplates/C/constant.tmpl5
-rw-r--r--giscanner/doctemplates/Gjs/constant.tmpl5
-rw-r--r--giscanner/doctemplates/Python/constant.tmpl5
-rw-r--r--giscanner/doctemplates/namespace.tmpl8
-rw-r--r--giscanner/docwriter.py58
-rw-r--r--tests/scanner/Regress-1.0-C-expected/index.page128
-rw-r--r--tests/scanner/Regress-1.0-Gjs-expected/index.page128
-rw-r--r--tests/scanner/Regress-1.0-Python-expected/index.page128
9 files changed, 468 insertions, 0 deletions
diff --git a/Makefile-giscanner.am b/Makefile-giscanner.am
index e3a934ac..15efed22 100644
--- a/Makefile-giscanner.am
+++ b/Makefile-giscanner.am
@@ -63,6 +63,7 @@ nobase_dist_template_DATA = \
giscanner/doctemplates/class.tmpl \
giscanner/doctemplates/namespace.tmpl \
giscanner/doctemplates/C/class.tmpl \
+ giscanner/doctemplates/C/constant.tmpl \
giscanner/doctemplates/C/constructor.tmpl \
giscanner/doctemplates/C/default.tmpl \
giscanner/doctemplates/C/enum.tmpl \
@@ -74,6 +75,7 @@ nobase_dist_template_DATA = \
giscanner/doctemplates/C/signal.tmpl \
giscanner/doctemplates/C/vfunc.tmpl \
giscanner/doctemplates/Python/class.tmpl \
+ giscanner/doctemplates/Python/constant.tmpl \
giscanner/doctemplates/Python/constructor.tmpl \
giscanner/doctemplates/Python/default.tmpl \
giscanner/doctemplates/Python/enum.tmpl \
@@ -85,6 +87,7 @@ nobase_dist_template_DATA = \
giscanner/doctemplates/Python/signal.tmpl \
giscanner/doctemplates/Python/vfunc.tmpl \
giscanner/doctemplates/Gjs/class.tmpl \
+ giscanner/doctemplates/Gjs/constant.tmpl \
giscanner/doctemplates/Gjs/constructor.tmpl \
giscanner/doctemplates/Gjs/default.tmpl \
giscanner/doctemplates/Gjs/enum.tmpl \
diff --git a/giscanner/doctemplates/C/constant.tmpl b/giscanner/doctemplates/C/constant.tmpl
new file mode 100644
index 00000000..2401cee4
--- /dev/null
+++ b/giscanner/doctemplates/C/constant.tmpl
@@ -0,0 +1,5 @@
+<%page args="constant"/>
+<item>
+ <title><code>#define ${constant.ctype} ${formatter.format_value(constant.value)}</code></title>
+ ${formatter.format(constant, constant.doc)}
+</item>
diff --git a/giscanner/doctemplates/Gjs/constant.tmpl b/giscanner/doctemplates/Gjs/constant.tmpl
new file mode 100644
index 00000000..bada58c3
--- /dev/null
+++ b/giscanner/doctemplates/Gjs/constant.tmpl
@@ -0,0 +1,5 @@
+<%page args="constant"/>
+<item>
+ <title><code>${constant.parent.name}.${constant.name} = ${formatter.format_value(constant.value)};</code></title>
+ ${formatter.format(constant, constant.doc)}
+</item>
diff --git a/giscanner/doctemplates/Python/constant.tmpl b/giscanner/doctemplates/Python/constant.tmpl
new file mode 100644
index 00000000..96e55399
--- /dev/null
+++ b/giscanner/doctemplates/Python/constant.tmpl
@@ -0,0 +1,5 @@
+<%page args="constant"/>
+<item>
+ <title><code>${constant.parent.name}.${constant.name} = ${formatter.format_value(constant.value)}</code></title>
+ ${formatter.format(constant, constant.doc)}
+</item>
diff --git a/giscanner/doctemplates/namespace.tmpl b/giscanner/doctemplates/namespace.tmpl
index bb58bb16..2c27ee42 100644
--- a/giscanner/doctemplates/namespace.tmpl
+++ b/giscanner/doctemplates/namespace.tmpl
@@ -15,5 +15,13 @@
<title>Other</title>
</links>
</%block>
+<%block name="details">
+<terms>
+% for constant in formatter.collect('constant'):
+<%include file="${language}/constant.tmpl" args="constant=constant"/>
+% endfor
+</terms>
+</%block>
+
<%block name="since_version">
</%block>
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index e129dc0b..702a469e 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -21,6 +21,8 @@
# 02110-1301, USA.
#
+import itertools
+import json
import os
import re
import tempfile
@@ -178,6 +180,13 @@ class DocFormatter(object):
return True
+ def collect(self, type_name):
+ namespace = self._transformer.namespace
+ type_ = {'constant': ast.Constant}[type_name]
+ for item in namespace.itervalues():
+ if isinstance(item, type_):
+ yield item
+
def format(self, node, doc):
if doc is None:
return ''
@@ -309,6 +318,9 @@ class DocFormatter(object):
else:
return parameter.argname
+ def format_value(self, value):
+ raise NotImplementedError
+
def format_function_name(self, func):
raise NotImplementedError
@@ -377,6 +389,45 @@ class DocFormatterC(DocFormatter):
"NULL": "NULL",
}
+ def _c_escape_dictionary():
+ escapes = {
+ '\\': '\\\\',
+ '"': '\\"',
+ '\b': '\\b',
+ '\f': '\\f',
+ '\n': '\\n',
+ '\r': '\\r',
+ '\t': '\\t',
+ }
+ for i in itertools.chain(xrange(0, 0x20), xrange(0x80, 0x100)):
+ escapes[chr(i)] = '\\x%x' % (i, )
+ return escapes
+
+ def format_value(self, value, escapes=_c_escape_dictionary()):
+ def format_bytes(v):
+ return '"' + ''.join(escapes.get(c, c) for c in v) + '"'
+
+ def format_unicode(v):
+ # Assume UTF8 encoding
+ return format_bytes(v.encode('utf8'))
+
+ def format_integer(v):
+ return "%d" % (v, )
+
+ def format_float(v):
+ return "%g" % (v, )
+
+ if isinstance(value, str):
+ return format_bytes(value)
+ if isinstance(value, unicode):
+ return format_unicode(value)
+ elif isinstance(value, (int, long)):
+ return format_integer(value)
+ elif isinstance(value, float):
+ return format_float(value)
+ else:
+ raise NotImplementedError(type(value))
+
def format_type(self, type_):
if isinstance(type_, ast.Array):
return self.format_type(type_.element_type) + '*'
@@ -434,6 +485,9 @@ class DocFormatterPython(DocFormatterIntrospectableBase):
return False
+ def format_value(self, value):
+ return "%r" % (value, )
+
def format_parameter_name(self, node, parameter):
# Force "self" for the first parameter of a method
if self.is_method(node) and parameter is node.instance_parameter:
@@ -506,6 +560,9 @@ class DocFormatterGjs(DocFormatterIntrospectableBase):
return False
+ def format_value(self, value):
+ return json.dumps(value)
+
def format_fundamental_type(self, name):
fundamental_types = {
"utf8": "String",
@@ -637,6 +694,7 @@ class DocWriter(object):
template = self._lookup.get_template(template_name)
result = template.render(namespace=namespace,
+ language=self._language,
node=node,
page_id=page_id,
page_kind=page_kind,
diff --git a/tests/scanner/Regress-1.0-C-expected/index.page b/tests/scanner/Regress-1.0-C-expected/index.page
index a5426d89..7f67f718 100644
--- a/tests/scanner/Regress-1.0-C-expected/index.page
+++ b/tests/scanner/Regress-1.0-C-expected/index.page
@@ -17,7 +17,135 @@
+<terms>
+
+<item>
+ <title><code>#define REGRESS_ANNOTATION_CALCULATED_DEFINE "100"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_ANNOTATION_CALCULATED_LARGE "10000000000UL"</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_ANNOTATION_CALCULATED_LARGE_DIV "1000000UL"</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_BOOL_CONSTANT "true"</code></title>
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_DOUBLE_CONSTANT "44.220000"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_FOO_DEFINE_SHOULD_BE_EXPOSED "should be exposed"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_FOO_PIE_IS_TASTY "3.141590"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_FOO_SUCCESS_INT "4408"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_GI_SCANNER_ELSE "3"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_GI_SCANNER_IFDEF "3"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_GUINT64_CONSTANT "18446744073709551615"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_GUINT64_CONSTANTA "18446744073709551615"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_G_GINT64_CONSTANT "1000"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_INT_CONSTANT "4422"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_LONG_STRING_CONSTANT "TYPE,VALUE,ENCODING,CHARSET,LANGUAGE,DOM,INTL,POSTAL,PARCEL,HOME,WORK,PREF,VOICE,FAX,MSG,CELL,PAGER,BBS,MODEM,CAR,ISDN,VIDEO,AOL,APPLELINK,ATTMAIL,CIS,EWORLD,INTERNET,IBMMAIL,MCIMAIL,POWERSHARE,PRODIGY,TLX,X400,GIF,CGM,WMF,BMP,MET,PMB,DIB,PICT,TIFF,PDF,PS,JPEG,QTIME,MPEG,MPEG2,AVI,WAVE,AIFF,PCM,X509,PGP"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_MAXUINT64 "18446744073709551615"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_MININT64 "-9223372036854775808"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_Mixed_Case_Constant "4423"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_NEGATIVE_INT_CONSTANT "-42"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_STRING_CONSTANT "Some String"</code></title>
+
+</item>
+
+
+<item>
+ <title><code>#define REGRESS_UTF8_CONSTANT "const \xe2\x99\xa5 utf8"</code></title>
+
+</item>
+
+</terms>
+
<links type="topic" ui:expanded="true" groups="class" style="linklist">
<title>Classes</title>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/index.page b/tests/scanner/Regress-1.0-Gjs-expected/index.page
index a5426d89..41a1841c 100644
--- a/tests/scanner/Regress-1.0-Gjs-expected/index.page
+++ b/tests/scanner/Regress-1.0-Gjs-expected/index.page
@@ -17,7 +17,135 @@
+<terms>
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_DEFINE = "100";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_LARGE = "10000000000UL";</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_LARGE_DIV = "1000000UL";</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>Regress.BOOL_CONSTANT = "true";</code></title>
+</item>
+
+
+<item>
+ <title><code>Regress.DOUBLE_CONSTANT = "44.220000";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_DEFINE_SHOULD_BE_EXPOSED = "should be exposed";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_PIE_IS_TASTY = "3.141590";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_SUCCESS_INT = "4408";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GI_SCANNER_ELSE = "3";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GI_SCANNER_IFDEF = "3";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GUINT64_CONSTANT = "18446744073709551615";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GUINT64_CONSTANTA = "18446744073709551615";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.G_GINT64_CONSTANT = "1000";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.INT_CONSTANT = "4422";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.LONG_STRING_CONSTANT = "TYPE,VALUE,ENCODING,CHARSET,LANGUAGE,DOM,INTL,POSTAL,PARCEL,HOME,WORK,PREF,VOICE,FAX,MSG,CELL,PAGER,BBS,MODEM,CAR,ISDN,VIDEO,AOL,APPLELINK,ATTMAIL,CIS,EWORLD,INTERNET,IBMMAIL,MCIMAIL,POWERSHARE,PRODIGY,TLX,X400,GIF,CGM,WMF,BMP,MET,PMB,DIB,PICT,TIFF,PDF,PS,JPEG,QTIME,MPEG,MPEG2,AVI,WAVE,AIFF,PCM,X509,PGP";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.MAXUINT64 = "18446744073709551615";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.MININT64 = "-9223372036854775808";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.Mixed_Case_Constant = "4423";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.NEGATIVE_INT_CONSTANT = "-42";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.STRING_CONSTANT = "Some String";</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.UTF8_CONSTANT = "const \u2665 utf8";</code></title>
+
+</item>
+
+</terms>
+
<links type="topic" ui:expanded="true" groups="class" style="linklist">
<title>Classes</title>
diff --git a/tests/scanner/Regress-1.0-Python-expected/index.page b/tests/scanner/Regress-1.0-Python-expected/index.page
index a5426d89..f17051d4 100644
--- a/tests/scanner/Regress-1.0-Python-expected/index.page
+++ b/tests/scanner/Regress-1.0-Python-expected/index.page
@@ -17,7 +17,135 @@
+<terms>
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_DEFINE = '100'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_LARGE = '10000000000UL'</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>Regress.ANNOTATION_CALCULATED_LARGE_DIV = '1000000UL'</code></title>
+ <p>Constant to define a calculated large value</p>
+</item>
+
+
+<item>
+ <title><code>Regress.BOOL_CONSTANT = 'true'</code></title>
+</item>
+
+
+<item>
+ <title><code>Regress.DOUBLE_CONSTANT = '44.220000'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_DEFINE_SHOULD_BE_EXPOSED = 'should be exposed'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_PIE_IS_TASTY = '3.141590'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.FOO_SUCCESS_INT = '4408'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GI_SCANNER_ELSE = '3'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GI_SCANNER_IFDEF = '3'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GUINT64_CONSTANT = '18446744073709551615'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.GUINT64_CONSTANTA = '18446744073709551615'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.G_GINT64_CONSTANT = '1000'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.INT_CONSTANT = '4422'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.LONG_STRING_CONSTANT = 'TYPE,VALUE,ENCODING,CHARSET,LANGUAGE,DOM,INTL,POSTAL,PARCEL,HOME,WORK,PREF,VOICE,FAX,MSG,CELL,PAGER,BBS,MODEM,CAR,ISDN,VIDEO,AOL,APPLELINK,ATTMAIL,CIS,EWORLD,INTERNET,IBMMAIL,MCIMAIL,POWERSHARE,PRODIGY,TLX,X400,GIF,CGM,WMF,BMP,MET,PMB,DIB,PICT,TIFF,PDF,PS,JPEG,QTIME,MPEG,MPEG2,AVI,WAVE,AIFF,PCM,X509,PGP'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.MAXUINT64 = '18446744073709551615'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.MININT64 = '-9223372036854775808'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.Mixed_Case_Constant = '4423'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.NEGATIVE_INT_CONSTANT = '-42'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.STRING_CONSTANT = 'Some String'</code></title>
+
+</item>
+
+
+<item>
+ <title><code>Regress.UTF8_CONSTANT = u'const \u2665 utf8'</code></title>
+
+</item>
+
+</terms>
+
<links type="topic" ui:expanded="true" groups="class" style="linklist">
<title>Classes</title>