Add support for documenting CGAbstractMethods.

This commit is contained in:
Ms2ger 2015-10-07 12:21:59 +02:00
parent 409fbafe9c
commit 03b04e5363

View file

@ -2064,10 +2064,12 @@ class CGAbstractMethod(CGThing):
If templateArgs is not None it should be a list of strings containing If templateArgs is not None it should be a list of strings containing
template arguments, and the function will be templatized using those template arguments, and the function will be templatized using those
arguments. arguments.
docs is None or documentation for the method in a string.
""" """
def __init__(self, descriptor, name, returnType, args, inline=False, def __init__(self, descriptor, name, returnType, args, inline=False,
alwaysInline=False, extern=False, pub=False, templateArgs=None, alwaysInline=False, extern=False, pub=False, templateArgs=None,
unsafe=False): unsafe=False, docs=None):
CGThing.__init__(self) CGThing.__init__(self)
self.descriptor = descriptor self.descriptor = descriptor
self.name = name self.name = name
@ -2078,6 +2080,7 @@ class CGAbstractMethod(CGThing):
self.templateArgs = templateArgs self.templateArgs = templateArgs
self.pub = pub self.pub = pub
self.unsafe = unsafe self.unsafe = unsafe
self.docs = docs
def _argstring(self): def _argstring(self):
return ', '.join([a.declare() for a in self.args]) return ', '.join([a.declare() for a in self.args])
@ -2087,6 +2090,13 @@ class CGAbstractMethod(CGThing):
return '' return ''
return '<%s>\n' % ', '.join(self.templateArgs) return '<%s>\n' % ', '.join(self.templateArgs)
def _docs(self):
if self.docs is None:
return ''
lines = self.docs.splitlines()
return ''.join('/// %s\n' % line for line in lines)
def _decorators(self): def _decorators(self):
decorators = [] decorators = []
if self.alwaysInline: if self.alwaysInline:
@ -2118,7 +2128,8 @@ class CGAbstractMethod(CGThing):
post=self.definition_epilogue()).define() post=self.definition_epilogue()).define()
def definition_prologue(self): def definition_prologue(self):
return "%sfn %s%s(%s)%s {\n" % (self._decorators(), self.name, self._template(), return "%s%sfn %s%s(%s)%s {\n" % (self._docs(), self._decorators(),
self.name, self._template(),
self._argstring(), self._returnType()) self._argstring(), self._returnType())
def definition_epilogue(self): def definition_epilogue(self):