Skip to content

Commit

Permalink
Merge pull request #290 from Tiwalun/fix-c-typedef
Browse files Browse the repository at this point in the history
Fix missing type in C typedefs
  • Loading branch information
vitaut committed Jan 11, 2017
2 parents 870a5cd + 3d9ac13 commit cc8f830
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
12 changes: 11 additions & 1 deletion breathe/renderer/sphinxrenderer.py
Expand Up @@ -963,8 +963,18 @@ def visit_typedef(self, node):
elif declaration.startswith(using):
declaration = declaration[len(using):]
obj_type = "using"

def update_signature(signature, obj_type):
"""Update the signature node if necessary, e.g. add qualifiers."""
prefix = obj_type + ' '
annotation = self.node_factory.desc_annotation(prefix, prefix)
if signature[0].tagname != 'desc_annotation':
signature.insert(0, annotation)
else:
signature[0] = annotation

return self.render_declaration(node, declaration, objtype=obj_type,
update_signature=self.update_signature)
update_signature=update_signature)

def update_signature_with_initializer(self, signature, node):
initializer = node.initializer
Expand Down
2 changes: 2 additions & 0 deletions documentation/source/conf.py
Expand Up @@ -208,6 +208,7 @@
"qtslots":"../../examples/specific/qtslots/xml/",
"array":"../../examples/specific/array/xml/",
"c_enum":"../../examples/specific/c_enum/xml/",
"c_typedef":"../../examples/specific/c_typedef/xml/",
"multifile":"../../examples/specific/multifilexml/xml/",
}

Expand All @@ -226,6 +227,7 @@
"*/class.h" : "cpp",
"*/alias.h" : "c",
"*/c_enum.h" : "c",
"c_typedef.h" : "c",
}


Expand Down
7 changes: 7 additions & 0 deletions documentation/source/specific.rst
Expand Up @@ -122,7 +122,14 @@ C Enum
:project: c_enum
:no-link:


C Typedef
---------

.. doxygenfile:: c_typedef.h
:project: c_typedef
:no-link:

Multifile
---------

Expand Down
2 changes: 1 addition & 1 deletion examples/specific/Makefile
Expand Up @@ -22,7 +22,7 @@ projects = nutshell alias rst inline namespacefile c_file array c_enum inherita
members userdefined fixedwidthfont latexmath functionOverload \
image name union group struct struct_function qtslots lists \
headings links parameters template_class template_class_non_type \
template_function template_specialisation enum
template_function template_specialisation enum c_typedef

special = programlisting decl_impl multifilexml auto class typedef

Expand Down
11 changes: 11 additions & 0 deletions examples/specific/c_typedef.cfg
@@ -0,0 +1,11 @@
PROJECT_NAME = "Function Type Def Command"
OUTPUT_DIRECTORY = c_typedef
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
INPUT = c_typedef.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
GENERATE_HTML = NO
GENERATE_XML = YES
17 changes: 17 additions & 0 deletions examples/specific/c_typedef.h
@@ -0,0 +1,17 @@
/**
* Sample typedef for a function pointer
*/
typedef int (*cTypeDefTestFuncPtr)(void);

typedef void* (*cVoidFuncPtr)(float, int);

typedef void* cVoidPointer;

typedef float* cFloatPointer;

typedef float cFloatingPointNumber;

/**
* @brief Test for a simple C typedef
*/
typedef int cTestTypedef;
28 changes: 24 additions & 4 deletions tests/test_renderer.py
Expand Up @@ -7,6 +7,9 @@
from breathe.renderer.filter import OpenFilter
from docutils import frontend, nodes, parsers, utils
from sphinx.domains.cpp import CPPDomain
from sphinx.domains.c import CDomain

from nose.tools import eq_


sphinx.locale.init([], None)
Expand Down Expand Up @@ -60,6 +63,7 @@ class MockState:
def __init__(self):
env = sphinx.environment.BuildEnvironment(None, None, MockConfig())
CPPDomain(env)
CDomain(env)
env.temp_data['docname'] = 'mock-doc'
settings = frontend.OptionParser(
components=(parsers.rst.Parser,)).get_default_values()
Expand Down Expand Up @@ -95,8 +99,8 @@ def mask(self, node):


class MockContext:
def __init__(self, node_stack):
self.domain = None
def __init__(self, node_stack, domain=None):
self.domain = domain
self.node_stack = node_stack
self.directive_args = [
None, # name
Expand Down Expand Up @@ -207,7 +211,7 @@ def test_find_node():
'the number of nodes Text is 2')


def render(member_def):
def render(member_def, domain=None):
"""Render Doxygen *member_def* with *renderer_class*."""
renderer = SphinxRenderer(MockProjectInfo(),
None, # renderer_factory
Expand All @@ -217,7 +221,7 @@ def render(member_def):
MockTargetHandler(),
None, # compound_parser
OpenFilter())
renderer.context = MockContext([member_def])
renderer.context = MockContext([member_def], domain)
return renderer.render(member_def)


Expand All @@ -239,6 +243,22 @@ def test_render_typedef():
assert signature.astext() == 'typedef int foo'


def test_render_c_typedef():
member_def = TestMemberDef(kind='typedef', definition='typedef unsigned int bar')
signature = find_node(render(member_def, domain='c'), 'desc_signature')
eq_(signature.astext(), 'typedef unsigned int bar')


def test_render_c_function_typedef():
member_def = TestMemberDef(kind='typedef', definition='typedef void* (*voidFuncPtr)(float, int)')
signature = find_node(render(member_def, domain='c'), 'desc_signature')
assert signature.astext().startswith('typedef void*')
params = find_node(signature, 'desc_parameterlist')
assert len(params) == 2
eq_(params[0].astext(), "float")
eq_(params[1].astext(), "int")


def test_render_using_alias():
member_def = TestMemberDef(kind='typedef', definition='using foo = int')
signature = find_node(render(member_def), 'desc_signature')
Expand Down

0 comments on commit cc8f830

Please sign in to comment.