[cfe-dev] Remove explicit template specializations

Vassil Vassilev vasil.georgiev.vasilev at cern.ch
Wed Mar 2 10:35:11 PST 2011


On 02.3.2011 г. 21:08, Douglas Gregor wrote:
> On Mar 2, 2011, at 10:03 AM, Vassil Vassilev wrote:
>
>> Hi,
>> Yes, but in my case I know that nothing depends on the specific specialization (I inject one artificially, analyze the output, get what I need and I want to remove it).
> Injecting a specialization can cause a cascade of instantiations, some of which can refer back to that specialization. For example, you could end up instantiating a static data member of some other class template specialization that refers to a member of the specialization you injected.
>
I agree, but as I said nothing depends on the injected templated class 
and its explicit specialization in my case.
>> If I try to remove it like with DeclContext I end up with assert. It is not possible to remove it simply from the Scope (like I do with the when I create implicit function for the failed sema lookups (Sema::ImplicitlyDefineFunction()))
> The Clang AST does not offer removal of nodes because it is extremely complicated to undo the effects of the addition of a node.
>
Yes I agree that dependency analysis upon c++ semantic tree is far away 
from trivial. However, there is one thing that I don't get isn't there 
clang::DeclContext::removeDecl(clang::Decl), which is public interface 
that removes decls from given DeclContext? I think you use it for shadow 
declarations in one place... (I am writing by hard but: 
Shadow->getDeclContext()->removeDecl(Shadow))

I am curious do you plan to implement removing arbitrary nodes from the 
AST at some point? One can argue that if someone wants to delete a node 
it should be possible, but it's his responsibility to preserve semantics.
Or it'd be great if a node is removed and the AST to transform itself 
into semantically valid new AST.
> 	- Doug
>
>> Cheers,
>> Vassil
>>
>> On 02.3.2011 г. 19:50, Douglas Gregor wrote:
>>> On Mar 2, 2011, at 9:39 AM, Vassil Vassilev wrote:
>>>
>>>> Hi all,
>>>>    I am wondering if there is a way to remove existing explicit class
>>>> template specialization declaration? I cannot remove it like
>>>> Decl->getDeclContext()->removeDecl(Decl)..
>>>>    I know that in ClassTemplateDecl there is addSpecialization() and no
>>>> removeSpecialization(). Is it complex to implement removeSpecialization()?
>>> It is *extremely* complex to remove a specialization, since you would have to walk the entire AST to determine if anything in the AST references the specialization.
>>>
>>> 	- Doug
>>>




More information about the cfe-dev mailing list