Review Request: specializeFrom for functions and template identifier free specializations

Olivier Jean de Gaalon olivier.jg at gmail.com
Wed Mar 21 09:01:16 UTC 2012



> On June 26, 2011, 11:29 a.m., David Nolden wrote:
> > languages/cpp/cppduchain/declarationbuilder.cpp, line 548
> > <http://git.reviewboard.kde.org/r/101690/diff/2/?file=24870#file24870line548>
> >
> >     I think every member of a template-class is itself based on TemplateDeclaration too, so this TODO is obsolete.
> 
> Olivier Jean de Gaalon wrote:
>     Yep, that's true.
>     -----------------
>     But before I can push this, I must ask for some assistance.
>     It seems that when you setSpecializedFrom on a function (or at least a non-template function of a template class), the duchain is unable to properly instantiate it, giving a borked context.
>     Its imported class context doesn't have any declarations, and it somehow ends up importing itself as a parent context (since it's instantiated this doesn't happen via addImportedParent context, which would catch it).
>     It will eventually end up in infinite recursion in cppduchain.cpp:getTemplateContext() and crash.
>     
>     Is there any chance you could take a look at that? I'm not sure at all what is the normal behavior of instantiation so it's hard for me to tell where it goes wrong.
>     
>     Reproduction:
>     -----------------
>     
>     template<class Type>
>     struct ConstantUnaryExpressionEvaluator {
>     
>       void evaluateSpecialTokens( int tokenKind, ConstantIntegralType* left ) {}
>     
>     };
>     
>     template<>
>     void ConstantUnaryExpressionEvaluator<double>::evaluateSpecialTokens( int tokenKind, ConstantIntegralType* left ) {
>     }
>     
>     template<>
>     void ConstantUnaryExpressionEvaluator<float>::evaluateSpecialTokens( int tokenKind, ConstantIntegralType* left ) {
>     }
>     ------------------
>     
>     If you hit the reparse button once or twice it'll give you the infinite recursion death.
> 
> David Nolden wrote:
>     I will try to check that.
> 
> Milian Wolff wrote:
>     david, any update?

Update on importing self as a parent context...
  It doesn't actually import itself, but it seems that way. The problem is in the DUContext::Import creation.
  At the time the import is created (to be added to the imports of the function declaration's expression context) the internalContext of a function is the parameter context. Later in the ContextBuilder, the internalContext is changed to be the expression context.
  For normal functions, when a DUContext::Import is created, the Import keeps a reference to the parameter context as intended.
  For specialized functions, when a DUContext::Import is created, the Import keeps a reference to the parameterContext's->owner(). Any later attempt to access the Import will return said owner's->internalContext(), which has actually been changed from the parameter context (which should be imported) to the expression context (self-import).
  It seems to work ok if I tell it to keep a direct reference to the context instead of to the owning declaration in the case of function specializations, but that doesn't seem like the correct fix...

Where should this be fixed?


- Olivier Jean de


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/101690/#review4166
-----------------------------------------------------------


On June 22, 2011, 5:49 a.m., Olivier Jean de Gaalon wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/101690/
> -----------------------------------------------------------
> 
> (Updated June 22, 2011, 5:49 a.m.)
> 
> 
> Review request for KDevelop and David Nolden.
> 
> 
> Description
> -------
> 
> Set specializedFrom for TemplateDeclarations in more cases then before.
> Make expressionvisitor check specializedFrom to find type of "this".
> 
> Also adds a test that should work (works in normal usage), but in the test environment for some reason the template declarations never have a templateContext().
> 
> 
> This addresses bug 183614.
>     http://bugs.kde.org/show_bug.cgi?id=183614
> 
> 
> Diffs
> -----
> 
>   languages/cpp/cppduchain/declarationbuilder.h 2242da2 
>   languages/cpp/cppduchain/declarationbuilder.cpp 0423842 
>   languages/cpp/cppduchain/expressionvisitor.cpp eef33e3 
>   languages/cpp/cppduchain/tests/test_expressionparser.h 385568f 
>   languages/cpp/cppduchain/tests/test_expressionparser.cpp 22e123a 
> 
> Diff: http://git.reviewboard.kde.org/r/101690/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Olivier Jean de Gaalon
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20120321/62b35c9e/attachment.html>


More information about the KDevelop-devel mailing list