Return-Path: Delivered-To: apmail-jakarta-bcel-user-archive@www.apache.org Received: (qmail 13275 invoked from network); 19 Jan 2004 07:31:58 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Jan 2004 07:31:58 -0000 Received: (qmail 45296 invoked by uid 500); 19 Jan 2004 07:31:34 -0000 Delivered-To: apmail-jakarta-bcel-user-archive@jakarta.apache.org Received: (qmail 45274 invoked by uid 500); 19 Jan 2004 07:31:34 -0000 Mailing-List: contact bcel-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "BCEL Users List" Reply-To: "BCEL Users List" Delivered-To: mailing list bcel-user@jakarta.apache.org Received: (qmail 45241 invoked from network); 19 Jan 2004 07:31:33 -0000 Received: from unknown (HELO smtp.engin.umich.edu) (141.213.75.24) by daedalus.apache.org with SMTP; 19 Jan 2004 07:31:33 -0000 Received: from ultramega (bgp01132927bgs.ypeast01.mi.comcast.net [68.42.119.167]) (authenticated bits=0) by smtp.engin.umich.edu (8.12.9/8.12.9) with ESMTP id i0J7ViKm019859 for ; Mon, 19 Jan 2004 02:31:45 -0500 (EST) Message-ID: <003401c3de5e$4a6a04e0$8000a8c0@ultramega> From: "Rodney Mach" To: Subject: How to determine index of local variable if don't know name Date: Mon, 19 Jan 2004 02:31:44 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, I have a question regarding getting the index of a local variable when I don't know the name of the variable apriori. I am going through looking for certain pattern, in this case every time the "add" method is called on any ArrayList, what I want to do is after that line insert some code that modifies the referenced arraylist. The problem I am having is I don't know how to get the index to the arraylist being modified if I don't know the variable name apriori (if I know it then I look through the local variable table, find the index, and can call ALOAD with that index and everything works fine I did figure out that much). What is the best way to get the index? This is basically the code leading up to where I want to figure out the index of the local variable being modified when I see the "add" method on a "java.util.ArrayList": InstructionList il = methodGen.getInstructionList(); InstructionHandle[] ihs = il.getInstructionHandles(); for (int j = 1; j < ihs.length; j++) { Instruction ins = ihs[j].getInstruction(); if (ins instanceof INVOKEVIRTUAL) { //Now look to see if this virtual instruction modifies array INVOKEVIRTUAL invv = (INVOKEVIRTUAL) ins; if (invv.getClassName(cpg).equals("java.util.ArrayList") && invv.getMethodName(cpg).equals("add")) { *********************** //HERE: HOW DO I GET INDEX TO THE ARRAYLIST BEING MODIFIED IF I DON't KNOW VARIABLE NAME APRIORI? I want to get the index so I can modify the arraylist at this point int HOWDOIGETTHISINDEX = ???? ************************* InstructionList il2 = new InstructionList(); il2.append(factory.createNew("MyNewInstrument")); il2.append(InstructionConstants.DUP); il2.append(factory.createInvoke("MyNewInstrument","",Type.VOID,Type.NO _ARGS,Constants.INVOKESPECIAL)); LocalVariableGen lg = methodGen.addLocalVariable("instrument",new ObjectType("MyNewInstrument"),null,null); int index = lg.getIndex(); lg.setStart(il2.append(new ASTORE(index))); //Load the local variable we just created, from the index. il2.append(new ALOAD(index)); //Load the index to the array list that we want to modify. How to get index?? il2.append(new ALOAD(HOWDOIGETTHISINDEX)); il2.append(factory.createInvoke("MyNewInstrument","modify", new ObjectType("java.util.ArrayList") , new Type[] { new ObjectType("java.util.ArrayList") } ,Constants.INVOKEVIRTUAL)); //Etc etc } Any help/pointers would be appreciated. Thanks! -Rod --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: bcel-user-help@jakarta.apache.org