cldoc在模板部分特化上崩溃

时间:2014-11-26 08:50:23

标签: c++ documentation cldoc

这个问题被标记为不清楚我在问什么。为清楚起见,我要求一个解决方法,让这个文档生成器对我的代码库正常工作。 (也许将工作分成批处理?这可能与cldocs有关吗?也许发出不同的命令行选项?也许我的调用是错误的或误导的?)

我已经针对项目提交了一个错误,您可以在此处找到有关我的环境的一些其他信息(包括位于此处的完整命令行:http://pastebin.com/JxWf9hRB)。

https://github.com/jessevdk/cldoc/issues/73

原始问题:

我正在调查使用cldocs进行自动化文档编制。但是,它在我的代码库上崩溃,出现以下错误:

Traceback (most recent call last):
  File "/usr/local/bin/cldoc", line 9, in <module>
    load_entry_point('cldoc==1.6', 'console_scripts', 'cldoc')()
  File "/usr/local/lib/python2.7/site-packages/cldoc/__init__.py", line 57, in run
    run_generate(rest)
  File "/usr/local/lib/python2.7/site-packages/cldoc/__init__.py", line 27, in run_generate
    cmdgenerate.run(args)
  File "/usr/local/lib/python2.7/site-packages/cldoc/cmdgenerate.py", line 151, in run
    run_generate(t, opts)
  File "/usr/local/lib/python2.7/site-packages/cldoc/cmdgenerate.py", line 33, in run_generate
    generator.generate(xmlout)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 55, in generate
    Generator.generate(self, outdir)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/generator.py", line 22, in generate
    self.generate_node(node)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 543, in generate_node
    self.generate_page(node)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 510, in generate_page
    elem = self.node_to_xml(node)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 496, in node_to_xml
    chelem = self.node_to_xml(child)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 485, in node_to_xml
    self.call_type_specific(node, elem, 'to_xml')
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 465, in call_type_specific
    getattr(self, nm)(node, elem)
  File "/usr/local/lib/python2.7/site-packages/cldoc/generators/xml.py", line 273, in method_to_xml
    if len(node.override) > 0:
  File "/usr/local/lib/python2.7/site-packages/cldoc/nodes/method.py", line 43, in override
    bases = list(self.parent.bases)
AttributeError: 'Namespace' object has no attribute 'bases'

编辑:

过了一会儿,我已经把它削减到了一个极小的例子。

template<typename T>
struct Foo {
  int baz(T const& t) const { }
};

template<typename T, int N>
class Bar { };

template<typename T, int N>
struct Foo<Bar<T, N>> {
  int baz(Bar<T, N> const& a) const;
};

template<typename T, int N>
int Foo<Bar<T, N>>::baz(Bar<T, N> const& a) const { }

虽然这有效:

template<typename T>
struct Foo {
  int baz(T const& t) const { }
};

template<typename T, int N>
class Bar { };

template<typename T, int N>
struct Foo<Bar<T, N>> {
  int baz(Bar<T, N> const& a) const { }
};

1 个答案:

答案 0 :(得分:1)

首先,cldoc在解析源时依赖于clang,它需要正确的C / C ++标志(例如-std=c++11)才能正常运行。

然后,即使使用适当的标志,它也会在某些看起来有效的结构上爆炸。特别是它试图用看似错误的上下文来处理模板类方法定义。特别是Foo<Bar<T, N>>::baz()定义的问题是,在处理期间,self.parent等于RootNamespace个对象(显然没有“基础”属性且应该' t),而不是Class或类似对象,bases用于跟踪特定方法的覆盖列表。

我已经为这个问题准备了一个解决方法,它只是在爆炸点“放松”self.parent属性的操作,并将其作为对该问题的评论发布。但肯定不是解决方案。也许正确的解决方案应首先确定是否必须以这种方式处理这种类外的方法定义,可能正确的方法是仅在方法声明处理覆盖列表。

这是补丁:

diff --git a/cldoc/nodes/method.py b/cldoc/nodes/method.py
index f910241..3e1208f 100644
--- a/cldoc/nodes/method.py
+++ b/cldoc/nodes/method.py
@@ -40,7 +40,7 @@ class Method(Function):
             return self._override

         # Lookup in bases, recursively
-        bases = list(self.parent.bases)
+        bases = list(getattr(self.parent, "bases", []))
         mname = self.name

         self._override = []