Skip to content

Commit

Permalink
Auto merge of #7903 - Ms2ger:codegen-docs, r=Manishearth
Browse files Browse the repository at this point in the history
Add support for documenting CGAbstractMethods.



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7903)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Oct 7, 2015
2 parents 9a12c2c + 6b160c6 commit 745635a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -2064,10 +2064,12 @@ class CGAbstractMethod(CGThing):
If templateArgs is not None it should be a list of strings containing
template arguments, and the function will be templatized using those
arguments.
docs is None or documentation for the method in a string.
"""
def __init__(self, descriptor, name, returnType, args, inline=False,
alwaysInline=False, extern=False, pub=False, templateArgs=None,
unsafe=False):
unsafe=False, docs=None):
CGThing.__init__(self)
self.descriptor = descriptor
self.name = name
Expand All @@ -2078,6 +2080,7 @@ def __init__(self, descriptor, name, returnType, args, inline=False,
self.templateArgs = templateArgs
self.pub = pub
self.unsafe = unsafe
self.docs = docs

def _argstring(self):
return ', '.join([a.declare() for a in self.args])
Expand All @@ -2087,6 +2090,13 @@ def _template(self):
return ''
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):
decorators = []
if self.alwaysInline:
Expand Down Expand Up @@ -2118,8 +2128,9 @@ def define(self):
post=self.definition_epilogue()).define()

def definition_prologue(self):
return "%sfn %s%s(%s)%s {\n" % (self._decorators(), self.name, self._template(),
self._argstring(), self._returnType())
return "%s%sfn %s%s(%s)%s {\n" % (self._docs(), self._decorators(),
self.name, self._template(),
self._argstring(), self._returnType())

def definition_epilogue(self):
return "\n}\n"
Expand Down Expand Up @@ -4971,8 +4982,9 @@ def definition_body(self):

class CGRegisterProxyHandlersMethod(CGAbstractMethod):
def __init__(self, descriptors):
docs = "Create the global vtables used by the generated DOM bindings to implement JS proxies."
CGAbstractMethod.__init__(self, None, 'RegisterProxyHandlers', 'void', [],
unsafe=True, pub=True)
unsafe=True, pub=True, docs=docs)
self.descriptors = descriptors

def definition_body(self):
Expand Down

0 comments on commit 745635a

Please sign in to comment.