[cfe-dev] overwrite rewritten text
Kihong Heo via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 10 10:04:27 PST 2018
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