Re: Re: Re: Re: Re: Two MethodVisitor with the same instances of Labels

John Bergin <[email protected]> Thu, 20 Mar 2014 13:13:52 +0000
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
Hi again.

Yes - you will need to invoke reader.accept(....)
twice on your ClassVisitor which creates your
MethodVisitor instance. You will need to tell
your MethodVisitor which pass it is in. A hack
like this would work

YourClassVisitor extends ClassVisitor {
     byte pass;

     YourClassVisitor(byte pass....) {
         super(.....);
         this.pass = pass;
     }

     MethodVisitor visitMethod(....) {
         return new YourMethodVisitor(this.pass......);
     }
}

So that's one ClassVisitor and one MethodVisitor
(or you could use a separate MethodVisitor for
each pass - whatever is easiest for you). And
remember that your first pass doesn't need to
emit bytecode so no need to have a ClassWriter
for the first pass.

Hope this clarifies your query.

On 20/03/14 12:31, Grzegorz Głąb wrote:
> Dnia 2014-03-20, o godz. 12:09:49
> John Bergin <[email protected]> napisał(a):
>
>> Grzesiek - if you want to stick with the Core API
>> then for each pass labels will be visited in the
>> same order and you could use your own mapping
>> for label names that is consistent across each
>> pass. You could add the following to your
>> MethodVisitor.
>>
>> // LabelData is whatever you want to store about the labels.
>> static Map<Integer, LabelData> labels;
>>
>> Integer currentLabel;
>>
>> // This is visited before visitLabel.
>> visitTryCatchBlock(Label start, Label end, Label handler, String
>> type) { addLabel(start);
>>       // And do the same for the remaining Label parameters.
>> }
>>
>> visitLabel(Label label) {
>>       addLabel(label);
>>       currentLabel = getLabel(label);
>> }
>>
>> // Took this from somewhere in the ASM code base I
>> // think I might have taken it from the Textifier class.
>> void addLabel(Label label) {
>>       LabelData ld = labels.get(label);
>>       if( ld == null ) {
>>           labels.put(Integer.valueOf(labels.size()), new LabelData());
>>       }
>> }
>>
>> LabelData getLabel(Label label) {
>>       return labels.get( label );
>> }
>>
>> Hope this helps.
>>
>
> Hi,
>
> thank for answer, to clarify : I need two two separate
> reader.accept(**) calls, right?
>
> reader.accept(VisitorWithMethodCollector);
> reader.accept(VisitorBasingOfPreviousCollectedData);
>
> AFAIK it is not possible to do it in core API in chained ClassVisitor
> with one reader.accept() call, or maybe there is some trick to do it ?
>
> Regards,
>
> Grzesiek
>
>
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws