[cfe-dev] overwrite rewritten text
Jonas Toth via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 10 11:50:53 PST 2018
I guess this sounds like the wanted functionality is not possible right
now. You probably need to patch Rewriter.
Best, Jonas
Am 10.12.18 um 19:46 schrieb Kihong Heo:
> According to “Rewriter.cpp”, changes are not directly applied to the rewrite buffer but stored in “Delta”, and there is no interface to remove elements in Delta.
>
> I think the segmentation fault was because the newly added text is longer than the original buffer.
>
> Thanks,
> Kihong
>
>> On Dec 10, 2018, at 1:12 PM, Jonas Toth <development at jonas-toth.eu> wrote:
>>
>> I never tried and not aware of a method of doing this, but looking at
>> `clang/lib/Rewrite/Rewriter.cpp` the locations are recalculated on the
>> buffer the operations work on which might invalidate the `Loc` you are
>> working with?
>>
>> You said the operations segfault, do they fail with an assertion or
>> normal segfault?
>>
>> Am 10.12.18 um 19:04 schrieb Kihong Heo:
>>> My intention is to transform the input source code. But this transformation is not pre-defined but dynamic. I first apply some transformation (here, adding some statement); check its correctness with an off-the-shelf checker; it is wrong then I want to roll back. Is there any systematic way to do that?
>>>
>>> Thanks,
>>> Kihong
>>>
>>>> On Dec 10, 2018, at 12:56 PM, Jonas Toth <development at jonas-toth.eu> wrote:
>>>>
>>>> I am a bit puzzled of what you want to achieve.
>>>>
>>>> AFAIK the change must be applied to the file and then the AST must be
>>>> recreated to get the new Source Locations, but if you `InsertText`
>>>> something and then `RemoveText` at the same location and same length
>>>> what do you intent to do?
>>>> For me this sounds like just replace a piece of original code with new
>>>> code. Otherwise that would be a no-op, not?
>>>>
>>>> Best Jonas
>>>>
>>>> Am 10.12.18 um 18:53 schrieb Kihong Heo:
>>>>> Hi,
>>>>>
>>>>> Thanks for your suggestion.
>>>>> But the result is the same.
>>>>> I noticed that It works as if the new string was not inserted.
>>>>> For example, “Loc” points to the location after the inserted string, and “Loc.getWithOffset(-1)” points to the location before the string.
>>>>> Is there any solution to sync up the mismatch?
>>>>>
>>>>> Thanks,
>>>>> Kihong
>>>>>
>>>>>> On Dec 10, 2018, at 11:38 AM, Jonas Toth <development at jonas-toth.eu> wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> did you consider creating a Replacement instead of a Insert-Remove
>>>>>> combination?
>>>>>>
>>>>>> Best, Jonas
>>>>>>
>>>>>> Am 10.12.18 um 06:04 schrieb Kihong Heo via cfe-dev:
>>>>>>> Hi All,
>>>>>>>
>>>>>>> How can I overwrite or remove some code parts which were already rewritten?
>>>>>>>
>>>>>>> Here is my code:
>>>>>>>
>>>>>>> string S = …
>>>>>>> Rewriter.InsertText(Loc, S);
>>>>>>> Rewriter.RemoveText(Loc, S.length()); <=== Here, Segmentation fault.
>>>>>>>
>>>>>>>
>>>>>>> Thanks for your help!
>>>>>>>
>>>>>>> Best,
>>>>>>> Kihong
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> cfe-dev mailing list
>>>>>>> cfe-dev at lists.llvm.org
>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list