mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-24 22:00:55 +00:00
AS3: Automatic Calculating Body parameters (Experimental)
This commit is contained in:
@@ -889,4 +889,10 @@ public class ABC {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void autoFillAllBodyParams(){
|
||||
for(int i=0;i<bodies.length;i++){
|
||||
bodies[i].autoFillStats(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2319,12 +2319,22 @@ public HashMap<Integer,String> getLocalRegNamesFromDebug(ABC abc){
|
||||
return true;
|
||||
}
|
||||
|
||||
public CodeStats getStats(ABC abc)
|
||||
public CodeStats getStats(ABC abc,MethodBody body)
|
||||
{
|
||||
CodeStats stats=new CodeStats(this);
|
||||
if(!walkCode(stats,0,0,0,abc)){
|
||||
return null;
|
||||
}
|
||||
for(ABCException ex:body.exceptions){
|
||||
try {
|
||||
int exStart=adr2pos(ex.start);
|
||||
if(!walkCode(stats, adr2pos(ex.target), stats.instructionStats[exStart].stackpos, stats.instructionStats[exStart].scopepos, abc)){
|
||||
return null;
|
||||
}
|
||||
} catch (ConvertException ex1) {
|
||||
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.jpexs.asdec.abc.gui;
|
||||
import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.abc.avm2.CodeStats;
|
||||
import com.jpexs.asdec.abc.types.MethodBody;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.text.NumberFormat;
|
||||
import javax.swing.JCheckBox;
|
||||
@@ -47,7 +48,7 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener{
|
||||
public JFormattedTextField maxScopeDepthField = new JFormattedTextField(NumberFormat.getNumberInstance());
|
||||
public MethodBody body;
|
||||
public JCheckBox autoFillCheckBox=new JCheckBox("Auto fill on code save (GLOBAL SETTING)");
|
||||
|
||||
public JLabel experimentalLabel=new JLabel("...EXPERIMENTAL");
|
||||
public MethodBodyParamsPanel() {
|
||||
setLayout(null);
|
||||
|
||||
@@ -71,10 +72,14 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener{
|
||||
add(maxScopeDepthLabel);
|
||||
add(maxScopeDepthField);
|
||||
|
||||
autoFillCheckBox.setBounds(50, 10+30+30+30+30, 250, 25);
|
||||
autoFillCheckBox.setBounds(30, 10+30+30+30+30, 230, 25);
|
||||
add(autoFillCheckBox);
|
||||
autoFillCheckBox.addChangeListener(this);
|
||||
|
||||
experimentalLabel.setForeground(Color.red);
|
||||
experimentalLabel.setBounds(250,10+30+30+30+30, 100, 25);
|
||||
add(experimentalLabel);
|
||||
|
||||
setPreferredSize(new Dimension(300,150));
|
||||
}
|
||||
|
||||
@@ -101,16 +106,10 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener{
|
||||
body.max_stack = Integer.parseInt(maxStackField.getText());
|
||||
body.max_regs = Integer.parseInt(localCountField.getText());
|
||||
body.max_scope_depth = Integer.parseInt(maxScopeDepthField.getText());
|
||||
}else{
|
||||
CodeStats stats=body.code.getStats(Main.abcMainFrame.abc);
|
||||
if(stats==null)
|
||||
}else{
|
||||
if(!body.autoFillStats(Main.abcMainFrame.abc))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Cannot get code stats for automatic body params.\r\nUncheck autofill to avoid this message.","Warning",JOptionPane.WARNING_MESSAGE);
|
||||
}else{
|
||||
System.out.println(stats.toString(Main.abcMainFrame.abc));
|
||||
/*body.max_stack=stats.maxstack;
|
||||
body.max_scope_depth=body.init_scope_depth+stats.maxscope;
|
||||
body.max_regs=stats.maxlocal;*/
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.jpexs.asdec.abc.types;
|
||||
import com.jpexs.asdec.Main;
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.avm2.AVM2Code;
|
||||
import com.jpexs.asdec.abc.avm2.CodeStats;
|
||||
import com.jpexs.asdec.abc.avm2.ConstantPool;
|
||||
import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.asdec.abc.types.traits.Traits;
|
||||
@@ -119,5 +120,19 @@ public class MethodBody implements Cloneable {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean autoFillStats(ABC abc)
|
||||
{
|
||||
CodeStats stats=code.getStats(abc,this);
|
||||
if(stats==null){
|
||||
return false;
|
||||
}
|
||||
max_stack=stats.maxstack;
|
||||
max_scope_depth=init_scope_depth+stats.maxscope;
|
||||
max_regs=stats.maxlocal;
|
||||
abc.method_info[method_info].setFlagSetsdxns(stats.has_set_dxns);
|
||||
abc.method_info[method_info].setFlagNeed_activation(stats.has_activation);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,48 @@ public class MethodInfo {
|
||||
public ValueKind optional[];
|
||||
public int paramNames[];
|
||||
|
||||
public void setFlagSetsdxns()
|
||||
{
|
||||
flags|=64;
|
||||
}
|
||||
|
||||
public void setFlagSetsdxns(boolean val)
|
||||
{
|
||||
if(val){
|
||||
setFlagSetsdxns();
|
||||
}else{
|
||||
unsetFlagSetsdxns();
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetFlagSetsdxns()
|
||||
{
|
||||
if(flagSetsdxns()){
|
||||
flags-=64;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagNeed_activation()
|
||||
{
|
||||
flags|=2;
|
||||
}
|
||||
|
||||
public void setFlagNeed_activation(boolean val)
|
||||
{
|
||||
if(val){
|
||||
setFlagNeed_activation();
|
||||
}else{
|
||||
unsetFlagNeed_activation();
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetFlagNeed_activation()
|
||||
{
|
||||
if(flagNeed_activation()){
|
||||
flags-=2;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagNeed_rest()
|
||||
{
|
||||
flags|=4;
|
||||
@@ -47,6 +89,15 @@ public class MethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagNeed_rest(boolean val)
|
||||
{
|
||||
if(val){
|
||||
setFlagNeed_rest();
|
||||
}else{
|
||||
unsetFlagNeed_rest();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_optional()
|
||||
{
|
||||
flags|=8;
|
||||
@@ -59,6 +110,15 @@ public class MethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_optional(boolean val)
|
||||
{
|
||||
if(val){
|
||||
setFlagHas_optional();
|
||||
}else{
|
||||
unsetFlagHas_optional();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_paramnames()
|
||||
{
|
||||
flags|=128;
|
||||
@@ -71,6 +131,15 @@ public class MethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_paramnames(boolean val)
|
||||
{
|
||||
if(val){
|
||||
setFlagHas_paramnames();
|
||||
}else{
|
||||
unsetFlagHas_paramnames();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean flagNeed_arguments() {
|
||||
return (flags & 1) == 1;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class DoABCTag extends Tag {
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
public byte[] getData(int version) {
|
||||
public byte[] getData(int version) {
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
OutputStream os = bos;
|
||||
|
||||
Reference in New Issue
Block a user