mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-19 12:28:29 +00:00
AS3 - Editing method parameters
This commit is contained in:
Binary file not shown.
@@ -105,6 +105,38 @@ public class ConstantPool {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int forceGetStringId(String val){
|
||||
int id=getStringId(val);
|
||||
if(id==0){
|
||||
id=addString(val);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public int forceGetIntId(long val){
|
||||
int id=getIntId(val);
|
||||
if(id==0){
|
||||
id=addInt(val);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public int forceGetUIntId(long val){
|
||||
int id=getUIntId(val);
|
||||
if(id==0){
|
||||
id=addUInt(val);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public int forceGetDoubleId(double val){
|
||||
int id=getDoubleId(val);
|
||||
if(id==0){
|
||||
id=addDouble(val);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public void dump(OutputStream os) {
|
||||
PrintStream output = new PrintStream(os);
|
||||
String s = "";
|
||||
|
||||
@@ -59,6 +59,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
if (Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) {
|
||||
Main.abcMainFrame.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc);
|
||||
Main.abcMainFrame.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]);
|
||||
Main.abcMainFrame.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc);
|
||||
}
|
||||
for (Highlighting h : highlights) {
|
||||
if ((pos >= h.startPos) && (pos < h.startPos + h.len)) {
|
||||
|
||||
@@ -84,12 +84,14 @@ public class MethodBodyParamsPanel extends JPanel {
|
||||
maxScopeDepthField.setText("" + body.max_scope_depth);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
public boolean save() {
|
||||
if (body != null) {
|
||||
body.max_stack = Integer.parseInt(maxStackField.getText());
|
||||
body.max_regs = Integer.parseInt(localCountField.getText());
|
||||
body.init_scope_depth = Integer.parseInt(initScopeDepthField.getText());
|
||||
body.max_scope_depth = Integer.parseInt(maxScopeDepthField.getText());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
106
trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java
Normal file
106
trunk/src/com/jpexs/asdec/abc/gui/MethodInfoPanel.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2011 JPEXS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package com.jpexs.asdec.abc.gui;
|
||||
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.methodinfo_parser.MethodInfoParser;
|
||||
import com.jpexs.asdec.abc.methodinfo_parser.ParseException;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
import com.jpexs.asdec.helpers.Helper;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MethodInfoPanel extends JPanel {
|
||||
public LineMarkedEditorPane paramEditor;
|
||||
private MethodInfo methodInfo;
|
||||
private ABC abc;
|
||||
public MethodInfoPanel()
|
||||
{
|
||||
paramEditor=new LineMarkedEditorPane();
|
||||
setLayout(new BorderLayout());
|
||||
add(new JLabel("Parameters:"),BorderLayout.NORTH);
|
||||
add(new JScrollPane(paramEditor), BorderLayout.CENTER);
|
||||
paramEditor.setContentType("text/flasm3_methodinfo");
|
||||
}
|
||||
|
||||
public void load(int methodInfoIndex,ABC abc)
|
||||
{
|
||||
this.abc=abc;
|
||||
if(methodInfoIndex<=0)
|
||||
{
|
||||
paramEditor.setText("");
|
||||
}
|
||||
this.methodInfo=abc.method_info[methodInfoIndex];
|
||||
int p=0;
|
||||
String ret="";
|
||||
int optParPos=0;
|
||||
if(methodInfo.flagHas_optional())
|
||||
{
|
||||
optParPos=methodInfo.param_types.length-methodInfo.optional.length;
|
||||
}
|
||||
for(int ptype:methodInfo.param_types)
|
||||
{
|
||||
if(p>0){
|
||||
ret+=",\n";
|
||||
}
|
||||
if(methodInfo.flagHas_paramnames())
|
||||
{
|
||||
ret=ret+abc.constants.constant_string[methodInfo.paramNames[p]];
|
||||
}else{
|
||||
ret=ret+"param"+(p+1);
|
||||
}
|
||||
ret+=":";
|
||||
if(ptype==0){
|
||||
ret+="*";
|
||||
}else{
|
||||
ret+="m["+ptype+"]\""+Helper.escapeString(abc.constants.constant_multiname[ptype].toString(abc.constants))+"\"";
|
||||
}
|
||||
if(methodInfo.flagHas_optional())
|
||||
{
|
||||
if(p>=optParPos)
|
||||
{
|
||||
ret+="="+methodInfo.optional[p-optParPos].toString(abc.constants);
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if(methodInfo.flagNeed_rest()){
|
||||
ret+=",\n... rest";
|
||||
}
|
||||
paramEditor.setText(ret);
|
||||
}
|
||||
|
||||
public boolean save()
|
||||
{
|
||||
try {
|
||||
MethodInfoParser.parse(paramEditor.getText(), methodInfo, abc);
|
||||
} catch (ParseException ex) {
|
||||
JOptionPane.showMessageDialog(paramEditor, ex.text, "MethodInfo Error", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -29,23 +29,34 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
|
||||
|
||||
public MethodCodePanel methodCodePanel;
|
||||
public MethodBodyParamsPanel methodBodyParamsPanel;
|
||||
public MethodInfoPanel methodInfoPanel;
|
||||
|
||||
public MethodTraitDetailPanel() {
|
||||
methodCodePanel = new MethodCodePanel();
|
||||
methodBodyParamsPanel = new MethodBodyParamsPanel();
|
||||
methodInfoPanel=new MethodInfoPanel();
|
||||
addTab("MethodInfo",methodInfoPanel);
|
||||
addTab("MethodBody Code", methodCodePanel);
|
||||
addTab("MethodBody params", new JScrollPane(methodBodyParamsPanel));
|
||||
|
||||
addTab("MethodBody params", new JScrollPane(methodBodyParamsPanel));
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
if (methodCodePanel.sourceTextArea.save(Main.abcMainFrame.abc.constants)) {
|
||||
methodBodyParamsPanel.save();
|
||||
int lasttrait = Main.abcMainFrame.decompiledTextArea.lastTraitIndex;
|
||||
Main.abcMainFrame.decompiledTextArea.reloadClass();
|
||||
Main.abcMainFrame.decompiledTextArea.gotoTrait(lasttrait);
|
||||
return true;
|
||||
if(!methodInfoPanel.save())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if (!methodCodePanel.sourceTextArea.save(Main.abcMainFrame.abc.constants))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!methodBodyParamsPanel.save())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int lasttrait = Main.abcMainFrame.decompiledTextArea.lastTraitIndex;
|
||||
Main.abcMainFrame.decompiledTextArea.reloadClass();
|
||||
Main.abcMainFrame.decompiledTextArea.gotoTrait(lasttrait);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
1036
trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoLexer.java
Normal file
1036
trunk/src/com/jpexs/asdec/abc/methodinfo_parser/MethodInfoLexer.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2011 JPEXS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package com.jpexs.asdec.abc.methodinfo_parser;
|
||||
|
||||
import com.jpexs.asdec.abc.ABC;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
import com.jpexs.asdec.abc.types.ValueKind;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MethodInfoParser {
|
||||
|
||||
public static void parse(String text, MethodInfo update,ABC abc) throws ParseException {
|
||||
MethodInfoLexer lexer = new MethodInfoLexer(new ByteArrayInputStream(text.getBytes()));
|
||||
List<String> paramNames=new ArrayList<String>();
|
||||
List<Long> paramTypes=new ArrayList<Long>();
|
||||
List<ValueKind> optionalValues=new ArrayList<ValueKind>();
|
||||
boolean hasOptional=false;
|
||||
boolean needsRest=false;
|
||||
try {
|
||||
ParsedSymbol symb;
|
||||
symb = lexer.yylex();
|
||||
while (symb.type != ParsedSymbol.TYPE_EOF)
|
||||
{
|
||||
if(symb.type==ParsedSymbol.TYPE_DOTS)
|
||||
{
|
||||
needsRest=true;
|
||||
symb = lexer.yylex();
|
||||
if(symb.type!=ParsedSymbol.TYPE_IDENTIFIER)
|
||||
{
|
||||
throw new ParseException("Identifier expected", lexer.yyline());
|
||||
}
|
||||
symb = lexer.yylex();
|
||||
if(symb.type!=ParsedSymbol.TYPE_EOF)
|
||||
{
|
||||
throw new ParseException("End expected after rest params", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(symb.type!=ParsedSymbol.TYPE_IDENTIFIER)
|
||||
{
|
||||
throw new ParseException("Identifier expected", lexer.yyline());
|
||||
}
|
||||
paramNames.add((String)symb.value);
|
||||
symb = lexer.yylex();
|
||||
if(symb.type==ParsedSymbol.TYPE_COLON){
|
||||
ParsedSymbol symbType=lexer.yylex();
|
||||
if(symbType.type==ParsedSymbol.TYPE_STAR)
|
||||
{
|
||||
paramTypes.add(new Long(0));
|
||||
}else if(symbType.type==ParsedSymbol.TYPE_MULTINAME){
|
||||
paramTypes.add((Long)symbType.value);
|
||||
}else{
|
||||
throw new ParseException("Multiname or * expected", lexer.yyline());
|
||||
}
|
||||
ParsedSymbol symbEqual=lexer.yylex();
|
||||
if(symbEqual.type==ParsedSymbol.TYPE_ASSIGN)
|
||||
{
|
||||
hasOptional=true;
|
||||
ParsedSymbol symbValue;
|
||||
String nstype="";
|
||||
do{
|
||||
symbValue=lexer.yylex();
|
||||
if(symbValue.type>=8&&symbValue.type<=13){
|
||||
nstype=nstype+symbValue.type+":";
|
||||
}
|
||||
}while(symbValue.type>=8&&symbValue.type<=13);
|
||||
if((!nstype.equals(""))&&(symbValue.type!=ParsedSymbol.TYPE_NAMESPACE))
|
||||
{
|
||||
throw new ParseException("Namespace expected", lexer.yyline());
|
||||
}
|
||||
int id=0;
|
||||
switch(symbValue.type)
|
||||
{
|
||||
case ParsedSymbol.TYPE_INTEGER:
|
||||
optionalValues.add(new ValueKind(abc.constants.forceGetIntId((Long)symbValue.value),ValueKind.CONSTANT_Int));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_FLOAT:
|
||||
optionalValues.add(new ValueKind(abc.constants.forceGetDoubleId((Double)symbValue.value),ValueKind.CONSTANT_Double));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_STRING:
|
||||
optionalValues.add(new ValueKind(abc.constants.forceGetStringId((String)symbValue.value),ValueKind.CONSTANT_Utf8));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_TRUE:
|
||||
optionalValues.add(new ValueKind(0,ValueKind.CONSTANT_True));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_FALSE:
|
||||
optionalValues.add(new ValueKind(0,ValueKind.CONSTANT_False));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_NULL:
|
||||
optionalValues.add(new ValueKind(0,ValueKind.CONSTANT_Null));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_UNDEFINED:
|
||||
optionalValues.add(new ValueKind(0,ValueKind.CONSTANT_Undefined));
|
||||
break;
|
||||
case ParsedSymbol.TYPE_NAMESPACE:
|
||||
if(nstype.equals("9:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PackageNamespace));
|
||||
}else
|
||||
if(nstype.equals("9:10:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PackageInternalNs));
|
||||
}else
|
||||
if(nstype.equals("13:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_ProtectedNamespace));
|
||||
}else
|
||||
if(nstype.equals("12:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_ExplicitNamespace));
|
||||
}else
|
||||
if(nstype.equals("11:13:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_StaticProtectedNs));
|
||||
}else
|
||||
if(nstype.equals("8:")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_PrivateNs));
|
||||
}else if(nstype.equals("")){
|
||||
optionalValues.add(new ValueKind((int)(long)(Long)symbValue.value,ValueKind.CONSTANT_Namespace));
|
||||
}else{
|
||||
throw new ParseException("Invalid type of namespace", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
symb=lexer.yylex();
|
||||
if(symb.type==ParsedSymbol.TYPE_COMMA){
|
||||
|
||||
}else if(symb.type==ParsedSymbol.TYPE_EOF){
|
||||
break;
|
||||
}
|
||||
}else if(symbEqual.type==ParsedSymbol.TYPE_COMMA){
|
||||
if(hasOptional)
|
||||
{
|
||||
throw new ParseException("Parameter must have default value", lexer.yyline());
|
||||
}
|
||||
}else if(symbEqual.type==ParsedSymbol.TYPE_EOF){
|
||||
if(hasOptional)
|
||||
{
|
||||
throw new ParseException("Parameter must have default value", lexer.yyline());
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
}else if(symb.type==ParsedSymbol.TYPE_COMMA){
|
||||
|
||||
}else if(symb.type==ParsedSymbol.TYPE_EOF){
|
||||
break;
|
||||
}else{
|
||||
throw new ParseException("Unexpected symbol", lexer.yyline());
|
||||
}
|
||||
symb = lexer.yylex();
|
||||
}
|
||||
} catch (IOException iex) {
|
||||
}
|
||||
|
||||
if(needsRest&&(!optionalValues.isEmpty())){
|
||||
throw new ParseException("Rest parameter canot be combined with default values", lexer.yyline());
|
||||
}
|
||||
|
||||
update.param_types=new int[paramTypes.size()];
|
||||
for(int p=0;p<paramTypes.size();p++)
|
||||
{
|
||||
update.param_types[p]=(int)(long)paramTypes.get(p);
|
||||
}
|
||||
update.optional=(ValueKind[])optionalValues.toArray(new ValueKind[optionalValues.size()]);
|
||||
update.unsetFlagHas_optional();
|
||||
if(!optionalValues.isEmpty()){
|
||||
update.setFlagHas_optional();
|
||||
}
|
||||
update.unsetFlagNeed_rest();
|
||||
if(needsRest){
|
||||
update.setFlagNeed_rest();
|
||||
}
|
||||
|
||||
update.unsetFlagHas_paramnames();
|
||||
update.paramNames=new int[]{};
|
||||
boolean useParamNames=false;
|
||||
for(int p=0;p<paramNames.size();p++){
|
||||
if(!paramNames.get(p).equals("param"+(p+1)))
|
||||
{
|
||||
useParamNames=true;
|
||||
}
|
||||
}
|
||||
if(useParamNames){
|
||||
update.setFlagHas_paramnames();
|
||||
update.paramNames=new int[paramNames.size()];
|
||||
for(int p=0;p<paramNames.size();p++){
|
||||
update.paramNames[p]=abc.constants.forceGetStringId(paramNames.get(p));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 JPEXS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package com.jpexs.asdec.abc.methodinfo_parser;
|
||||
|
||||
import com.jpexs.asdec.action.parser.*;
|
||||
|
||||
|
||||
public class ParseException extends Exception {
|
||||
public long line;
|
||||
public String text;
|
||||
|
||||
public ParseException(String text, long line) {
|
||||
super("ParseException:" + text + " on line " + line);
|
||||
this.line = line;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 JPEXS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package com.jpexs.asdec.abc.methodinfo_parser;
|
||||
|
||||
|
||||
public class ParsedSymbol {
|
||||
public int type;
|
||||
public Object value;
|
||||
|
||||
public static final int TYPE_INTEGER = 1;
|
||||
public static final int TYPE_FLOAT = 2;
|
||||
public static final int TYPE_TRUE = 3;
|
||||
public static final int TYPE_FALSE = 4;
|
||||
public static final int TYPE_NULL = 5;
|
||||
public static final int TYPE_UNDEFINED = 6;
|
||||
public static final int TYPE_STRING = 7;
|
||||
|
||||
//8-12 namespace prefix
|
||||
public static final int TYPE_PRIVATE = 8;
|
||||
public static final int TYPE_PACKAGE = 9;
|
||||
public static final int TYPE_INTERNAL = 10;
|
||||
public static final int TYPE_STATIC = 11;
|
||||
public static final int TYPE_EXPLICIT = 12;
|
||||
public static final int TYPE_PROTECTED = 13;
|
||||
public static final int TYPE_NAMESPACE = 14;
|
||||
|
||||
public static final int TYPE_COLON = 15;
|
||||
public static final int TYPE_COMMA = 16;
|
||||
public static final int TYPE_DOTS = 17;
|
||||
|
||||
|
||||
|
||||
|
||||
public static final int TYPE_MULTINAME = 18;
|
||||
public static final int TYPE_IDENTIFIER = 19;
|
||||
|
||||
|
||||
public static final int TYPE_EOF = 20;
|
||||
public static final int TYPE_STAR = 21;
|
||||
public static final int TYPE_ASSIGN = 22;
|
||||
|
||||
public ParsedSymbol(int type, Object value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ParsedSymbol(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
160
trunk/src/com/jpexs/asdec/abc/methodinfo_parser/methodinfo.flex
Normal file
160
trunk/src/com/jpexs/asdec/abc/methodinfo_parser/methodinfo.flex
Normal file
@@ -0,0 +1,160 @@
|
||||
/* Method info lexer specification */
|
||||
|
||||
package com.jpexs.asdec.abc.methodinfo_parser;
|
||||
|
||||
%%
|
||||
|
||||
%public
|
||||
%class MethodInfoLexer
|
||||
%final
|
||||
%unicode
|
||||
%char
|
||||
%line
|
||||
%column
|
||||
%type ParsedSymbol
|
||||
%throws ParseException
|
||||
|
||||
%{
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
boolean isMultiname=false;
|
||||
long multinameId=0;
|
||||
|
||||
|
||||
/**
|
||||
* Create an empty lexer, yyrset will be called later to reset and assign
|
||||
* the reader
|
||||
*/
|
||||
public MethodInfoLexer() {
|
||||
|
||||
}
|
||||
|
||||
public int yychar() {
|
||||
return yychar;
|
||||
}
|
||||
|
||||
public int yyline() {
|
||||
return yyline+1;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
/* main character classes */
|
||||
LineTerminator = \r|\n|\r\n
|
||||
|
||||
WhiteSpace = [ \t\f]+
|
||||
|
||||
|
||||
|
||||
/* identifiers */
|
||||
|
||||
Identifier = [:jletter:][:jletterdigit:]*
|
||||
|
||||
/* integer literals */
|
||||
NumberLiteral = 0 | -?[1-9][0-9]*
|
||||
|
||||
PositiveNumberLiteral = 0 | [1-9][0-9]*
|
||||
|
||||
Multiname = m\[{PositiveNumberLiteral}\]
|
||||
|
||||
Namespace = ns\{PositiveNumberLiteral}\]
|
||||
|
||||
/* floating point literals */
|
||||
FloatLiteral = -?({FLit1}|{FLit2}|{FLit3}) {Exponent}?
|
||||
|
||||
FLit1 = [0-9]+ \. [0-9]*
|
||||
FLit2 = \. [0-9]+
|
||||
FLit3 = [0-9]+
|
||||
Exponent = [eE] [+-]? [0-9]+
|
||||
|
||||
OctDigit = [0-7]
|
||||
|
||||
/* string and character literals */
|
||||
StringCharacter = [^\r\n\"\\]
|
||||
|
||||
%state STRING
|
||||
|
||||
%%
|
||||
|
||||
<YYINITIAL> {
|
||||
/* whitespace */
|
||||
{WhiteSpace} { }
|
||||
{Multiname}\" {
|
||||
isMultiname=true;
|
||||
String s=yytext();
|
||||
multinameId=Long.parseLong(s.substring(2,s.length()-2));
|
||||
yybegin(STRING);
|
||||
string.setLength(0);
|
||||
}
|
||||
/* string literal */
|
||||
\" {
|
||||
isMultiname=false;
|
||||
yybegin(STRING);
|
||||
string.setLength(0);
|
||||
}
|
||||
|
||||
|
||||
/* numeric literals */
|
||||
|
||||
{NumberLiteral} { return new ParsedSymbol(ParsedSymbol.TYPE_INTEGER,new Long(Long.parseLong((yytext())))); }
|
||||
{FloatLiteral} { return new ParsedSymbol(ParsedSymbol.TYPE_FLOAT,new Double(Double.parseDouble((yytext())))); }
|
||||
|
||||
":" {return new ParsedSymbol(ParsedSymbol.TYPE_COLON);}
|
||||
"," {return new ParsedSymbol(ParsedSymbol.TYPE_COMMA);}
|
||||
"..." {return new ParsedSymbol(ParsedSymbol.TYPE_DOTS);}
|
||||
"*" {return new ParsedSymbol(ParsedSymbol.TYPE_STAR);}
|
||||
"=" {return new ParsedSymbol(ParsedSymbol.TYPE_ASSIGN);}
|
||||
|
||||
private {return new ParsedSymbol(ParsedSymbol.TYPE_PRIVATE);}
|
||||
protected {return new ParsedSymbol(ParsedSymbol.TYPE_PROTECTED);}
|
||||
package {return new ParsedSymbol(ParsedSymbol.TYPE_PACKAGE);}
|
||||
internal {return new ParsedSymbol(ParsedSymbol.TYPE_INTERNAL);}
|
||||
static {return new ParsedSymbol(ParsedSymbol.TYPE_STATIC);}
|
||||
explicit {return new ParsedSymbol(ParsedSymbol.TYPE_EXPLICIT);}
|
||||
{Namespace} {
|
||||
String s=yytext();
|
||||
long ns=Long.parseLong(s.substring(3,s.length()-2));
|
||||
return new ParsedSymbol(ParsedSymbol.TYPE_NAMESPACE,new Long(ns));
|
||||
}
|
||||
true {return new ParsedSymbol(ParsedSymbol.TYPE_TRUE);}
|
||||
false {return new ParsedSymbol(ParsedSymbol.TYPE_FALSE);}
|
||||
null {return new ParsedSymbol(ParsedSymbol.TYPE_NULL);}
|
||||
undefined {return new ParsedSymbol(ParsedSymbol.TYPE_UNDEFINED);}
|
||||
{Identifier} {
|
||||
return new ParsedSymbol(ParsedSymbol.TYPE_IDENTIFIER,yytext()); }
|
||||
}
|
||||
|
||||
<STRING> {
|
||||
\" {
|
||||
yybegin(YYINITIAL);
|
||||
// length also includes the trailing quote
|
||||
if(isMultiname){
|
||||
return new ParsedSymbol(ParsedSymbol.TYPE_MULTINAME,new Long(multinameId));
|
||||
}else{
|
||||
return new ParsedSymbol(ParsedSymbol.TYPE_STRING,string.toString());
|
||||
}
|
||||
}
|
||||
|
||||
{StringCharacter}+ { string.append( yytext() ); }
|
||||
|
||||
/* escape sequences */
|
||||
"\\b" { string.append( '\b' ); }
|
||||
"\\t" { string.append( '\t' ); }
|
||||
"\\n" { string.append( '\n' ); }
|
||||
"\\f" { string.append( '\f' ); }
|
||||
"\\r" { string.append( '\r' ); }
|
||||
"\\\"" { string.append( '\"' ); }
|
||||
"\\'" { string.append( '\'' ); }
|
||||
"\\\\" { string.append( '\\' ); }
|
||||
\\[0-3]?{OctDigit}?{OctDigit} { char val = (char) Integer.parseInt(yytext().substring(1),8);
|
||||
string.append( val ); }
|
||||
|
||||
/* error cases */
|
||||
\\. { throw new ParseException("Illegal escape sequence \""+yytext()+"\"",yyline+1); }
|
||||
{LineTerminator} { throw new ParseException("Unterminated string at end of line",yyline+1); }
|
||||
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
<<EOF>> { return new ParsedSymbol(ParsedSymbol.TYPE_EOF); }
|
||||
@@ -32,6 +32,42 @@ public class MethodInfo {
|
||||
public ValueKind optional[];
|
||||
public int paramNames[];
|
||||
|
||||
public void setFlagNeed_rest()
|
||||
{
|
||||
flags|=4;
|
||||
}
|
||||
|
||||
public void unsetFlagNeed_rest()
|
||||
{
|
||||
if(flagNeed_rest()){
|
||||
flags-=4;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_optional()
|
||||
{
|
||||
flags|=8;
|
||||
}
|
||||
|
||||
public void unsetFlagHas_optional()
|
||||
{
|
||||
if(flagHas_optional()){
|
||||
flags-=8;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlagHas_paramnames()
|
||||
{
|
||||
flags|=128;
|
||||
}
|
||||
|
||||
public void unsetFlagHas_paramnames()
|
||||
{
|
||||
if(flagHas_paramnames()){
|
||||
flags-=128;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean flagNeed_arguments() {
|
||||
return (flags & 1) == 1;
|
||||
}
|
||||
|
||||
@@ -82,34 +82,34 @@ public class ValueKind {
|
||||
ret = "\"" + constants.constant_string[value_index] + "\"";
|
||||
break;
|
||||
case CONSTANT_True:
|
||||
ret = "True";
|
||||
ret = "true";
|
||||
break;
|
||||
case CONSTANT_False:
|
||||
ret = "False";
|
||||
ret = "false";
|
||||
break;
|
||||
case CONSTANT_Null:
|
||||
ret = "Null";
|
||||
ret = "null";
|
||||
break;
|
||||
case CONSTANT_Undefined:
|
||||
ret = "Undefined";
|
||||
ret = "undefined";
|
||||
break;
|
||||
case CONSTANT_Namespace:
|
||||
ret = "" + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "ns[" +value_index+"]";
|
||||
break;
|
||||
case CONSTANT_PackageInternalNs:
|
||||
ret = "" + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "package internal ns[" +value_index+"]";
|
||||
break;
|
||||
case CONSTANT_ProtectedNamespace:
|
||||
ret = "protected " + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "protected ns[" +value_index+"]";
|
||||
break;
|
||||
case CONSTANT_ExplicitNamespace:
|
||||
ret = "explicit " + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "explicit ns[" +value_index+"]";
|
||||
break;
|
||||
case CONSTANT_StaticProtectedNs:
|
||||
ret = "static protected " + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "static protected ns[" +value_index+"]";
|
||||
break;
|
||||
case CONSTANT_PrivateNs:
|
||||
ret = "private " + constants.constant_namespace[value_index].getName(constants);
|
||||
ret = "private ns[" +value_index+"]";
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user