diff --git a/trunk/lib/jsyntaxpane-0.9.5.jar b/trunk/lib/jsyntaxpane-0.9.5.jar index 735b1947c..ca402af38 100644 Binary files a/trunk/lib/jsyntaxpane-0.9.5.jar and b/trunk/lib/jsyntaxpane-0.9.5.jar differ diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 62ddcb507..ec37161ac 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -72,7 +72,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.ecma.EcmaScript; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphSourceItem; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java index 45be3ab7b..ef2cf39a4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java @@ -29,7 +29,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.io.Serializable; import java.util.HashMap; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java index affb70867..27479f7e1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java @@ -24,7 +24,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.model.NewFunctionAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.helpers.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -46,7 +45,7 @@ public class NewFunctionIns extends InstructionDefinition { String paramStr = ""; if (mybody != null) { try { - bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(path + "/inner", false, isStatic, scriptIndex, classIndex, abc, null, constants, method_info, new Stack()/*scopeStack*/, false, true, false, fullyQualifiedNames, null) + Highlighting.hilighMethodBegin(body.method_info); + bodyStr = /*Highlighting.hilighMethodEnd() +*/ mybody.toString(path + "/inner", false, isStatic, scriptIndex, classIndex, abc, null, constants, method_info, new Stack()/*scopeStack*/, false, true, false, fullyQualifiedNames, null);// + Highlighting.hilighMethodBegin(body.method_info); } catch (Exception ex) { Logger.getLogger(NewFunctionIns.class.getName()).log(Level.SEVERE, "error during newfunction", ex); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CallSuperAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CallSuperAVM2Item.java index 4e96758ec..6aa902c3d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CallSuperAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/CallSuperAVM2Item.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructSuperAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructSuperAVM2Item.java index 376190f61..43fe52ea2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructSuperAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/ConstructSuperAVM2Item.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java index ed503c4d2..2bd72cc76 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSuperAVM2Item.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java index e980acf77..d24f3be82 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/NewFunctionAVM2Item.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.Graph; import java.util.HashMap; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java index b71084583..e015d5856 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 13a624de7..c739f1565 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -24,7 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index ab64eb9dc..4f691dd0c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -31,7 +31,7 @@ import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.NamespaceSet; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index 0f3825dd2..d1a59ec78 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -21,7 +21,7 @@ import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.ValueKind; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index 6fa1b164e..fd926a44f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -17,7 +17,7 @@ package com.jpexs.decompiler.flash.abc.types.traits; import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.io.Serializable; import java.util.ArrayList; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index b71398920..f27f48337 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -47,8 +47,8 @@ import com.jpexs.decompiler.flash.action.swf4.*; import com.jpexs.decompiler.flash.action.swf5.*; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.ecma.Null; -import com.jpexs.decompiler.flash.helpers.Highlighting; import com.jpexs.decompiler.flash.helpers.collections.MyEntry; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.GraphSourceItem; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 72d0a8723..e2a3654c9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -27,7 +27,7 @@ import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 305694be1..4b5f2ac7b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -26,7 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.gui.GraphFrame; import com.jpexs.decompiler.flash.gui.View; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.helpers.Helper; import java.io.ByteArrayInputStream; @@ -86,17 +86,15 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi if (isEditable()) { return; } - for (Highlighting h2 : disassembledHilights) { - if (h2.offset == offset) { - ignoreCarret = true; - try { - setCaretPosition(h2.startPos); - } catch (IllegalArgumentException iex) { - } - getCaret().setVisible(true); - ignoreCarret = false; - break; + Highlighting h2 = Highlighting.search(disassembledHilights, "offset", "" + offset); + if (h2 != null) { + ignoreCarret = true; + try { + setCaretPosition(h2.startPos); + } catch (IllegalArgumentException iex) { } + getCaret().setVisible(true); + ignoreCarret = false; } } @@ -232,14 +230,14 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi public long getSelectedOffset() { int pos = getCaretPosition(); - Highlighting lastH = new Highlighting(0, 0, 0); + Highlighting lastH = null; for (Highlighting h : disassembledHilights) { if (pos < h.startPos) { break; } lastH = h; } - return lastH.offset; + return lastH == null ? 0 : lastH.getPropertyLong("offset"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java index d70c9604a..04f55bcee 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/CachedDecompilation.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import java.io.Serializable; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 453266b31..75cee31c1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2010-2013 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 3 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, see . */ @@ -28,7 +28,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import static com.jpexs.decompiler.flash.gui.AppStrings.translate; import com.jpexs.decompiler.flash.gui.View; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.helpers.Cache; import java.util.ArrayList; @@ -77,19 +77,16 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL if (currentMethodHighlight == null) { return; } - for (Highlighting h2 : highlights) { - if ((h2.startPos >= currentMethodHighlight.startPos) && (h2.startPos + h2.len <= currentMethodHighlight.startPos + currentMethodHighlight.len)) { - if (h2.offset == offset) { - ignoreCarret = true; - try { - setCaretPosition(h2.startPos); - } catch (IllegalArgumentException ie) { - } - getCaret().setVisible(true); - ignoreCarret = false; - break; - } + Highlighting h2 = Highlighting.search(highlights, "offset", "" + offset, currentMethodHighlight.startPos, currentMethodHighlight.startPos + currentMethodHighlight.len); + if (h2 != null) { + ignoreCarret = true; + try { + setCaretPosition(h2.startPos); + } catch (IllegalArgumentException ie) { + //ignored } + getCaret().setVisible(true); + ignoreCarret = false; } } @@ -130,12 +127,10 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL this.isStatic = isStatic; } boolean success = false; - for (Highlighting h : highlights) { - if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.offset); - success = true; - //return true; - } + Highlighting h = Highlighting.search(highlights, pos); + if (h != null) { + abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.getPropertyLong("offset")); + success = true; } return success; } @@ -154,29 +149,28 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL public int getMultinameUnderCursor() { int pos = getCaretPosition(); - for (Highlighting h : highlights) { - if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { - List list = abc.bodies[abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex()].code.code; - AVM2Instruction lastIns = null; - long inspos = 0; - AVM2Instruction selIns = null; - for (AVM2Instruction ins : list) { - if (h.offset == ins.getOffset()) { - selIns = ins; - break; - } - if (ins.getOffset() > h.offset) { - inspos = h.offset - lastIns.offset; - selIns = lastIns; - break; - } - lastIns = ins; + Highlighting h = Highlighting.search(highlights, pos); + if (h != null) { + List list = abc.bodies[abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex()].code.code; + AVM2Instruction lastIns = null; + long inspos = 0; + AVM2Instruction selIns = null; + for (AVM2Instruction ins : list) { + if (h.getPropertyLong("offset") == ins.getOffset()) { + selIns = ins; + break; } - if (selIns != null) { - for (int i = 0; i < selIns.definition.operands.length; i++) { - if (selIns.definition.operands[i] == AVM2Code.DAT_MULTINAME_INDEX) { - return selIns.operands[i]; - } + if (ins.getOffset() > h.getPropertyLong("offset")) { + inspos = h.getPropertyLong("offset") - lastIns.offset; + selIns = lastIns; + break; + } + lastIns = ins; + } + if (selIns != null) { + for (int i = 0; i < selIns.definition.operands.length; i++) { + if (selIns.definition.operands[i] == AVM2Code.DAT_MULTINAME_INDEX) { + return selIns.operands[i]; } } } @@ -207,42 +201,35 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setIgnoreCarret(true); try { classIndex = -1; - for (Highlighting cm : classHighlights) { - if ((pos >= cm.startPos) && (pos < cm.startPos + cm.len)) { - classIndex = (int) cm.offset; - displayClass(classIndex, script.scriptIndex); - break; - } + Highlighting cm = Highlighting.search(classHighlights, pos); + if (cm != null) { + classIndex = (int) (long) cm.getPropertyLong("index"); + displayClass(classIndex, script.scriptIndex); } - - for (Highlighting tm : methodHighlights) { - if ((pos >= tm.startPos) && ((pos < tm.startPos + tm.len) || (tm.len == 0 && pos == tm.startPos))) { - String name = ""; - if (abc != null) { - if (classIndex > -1) { - name = abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants); - } + Highlighting tm = Highlighting.search(methodHighlights, pos); + if (tm != null) { + String name = ""; + if (abc != null) { + if (classIndex > -1) { + name = abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants); } - currentTrait = null; - for (Highlighting th : traitHighlights) { - if ((pos >= th.startPos) && (pos < th.startPos + th.len)) { - lastTraitIndex = (int) th.offset; - if ((abc != null) && (classIndex != -1)) { - currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); - isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); - if (currentTrait != null) { - name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList()); - } - } - } - } - - displayMethod(pos, (int) tm.offset, name, currentTrait, isStatic); - currentMethodHighlight = tm; - - - return; } + currentTrait = null; + Highlighting th = Highlighting.search(traitHighlights, pos); + if (th != null) { + lastTraitIndex = (int) (long) th.getPropertyLong("index"); + if ((abc != null) && (classIndex != -1)) { + currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); + isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); + if (currentTrait != null) { + name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList()); + } + } + } + + displayMethod(pos, (int) (long) tm.getPropertyLong("index"), name, currentTrait, isStatic); + currentMethodHighlight = tm; + return; } if (classIndex == -1) { @@ -250,34 +237,33 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL return; } currentTrait = null; - for (Highlighting th : traitHighlights) { - if ((pos >= th.startPos) && (pos < th.startPos + th.len)) { - lastTraitIndex = (int) th.offset; - currentTrait = abc.findTraitByTraitId(classIndex, (int) th.offset); - if (currentTrait != null) { - if (currentTrait instanceof TraitSlotConst) { - abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) currentTrait, abc, - abc.isStaticTraitId(classIndex, lastTraitIndex)); - abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD, currentTrait); - abcPanel.detailPanel.setEditMode(false); - return; - } + Highlighting th = Highlighting.search(traitHighlights, pos); + if (th != null) { + lastTraitIndex = (int) (long) th.getPropertyLong("index"); + currentTrait = abc.findTraitByTraitId(classIndex, (int) (long) th.getPropertyLong("index")); + if (currentTrait != null) { + if (currentTrait instanceof TraitSlotConst) { + abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) currentTrait, abc, + abc.isStaticTraitId(classIndex, lastTraitIndex)); + abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD, currentTrait); + abcPanel.detailPanel.setEditMode(false); + return; } - currentMethodHighlight = th; - String name = ""; - currentTrait = null; - if (abc != null) { - name = abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants); - currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); - isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); - if (currentTrait != null) { - name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList()); - } - } - - displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) th.offset), name, currentTrait, isStatic); - return; } + currentMethodHighlight = th; + String name = ""; + currentTrait = null; + if (abc != null) { + name = abc.instance_info[classIndex].getName(abc.constants).getNameWithNamespace(abc.constants); + currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex); + isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex); + if (currentTrait != null) { + name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList()); + } + } + + displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) (long) th.getPropertyLong("index")), name, currentTrait, isStatic); + return; } setNoTrait(); } finally { @@ -314,32 +300,27 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL return; } - for (Highlighting tc : classHighlights) { - if (tc.offset == classIndex) { - for (Highlighting th : traitHighlights) { - if ((th.startPos > tc.startPos) && (th.startPos + th.len < tc.startPos + tc.len)) { - if (th.offset == traitId) { - try { - ignoreCarret = true; - setCaretPosition(th.startPos + th.len - 1); - ignoreCarret = false; - } catch (IllegalArgumentException iae) { - } - final int pos = th.startPos; - new Timer().schedule(new TimerTask() { - @Override - public void run() { - try { - setCaretPosition(pos); - } catch (IllegalArgumentException iae) { - } - } - }, 100); - return; + Highlighting tc = Highlighting.search(classHighlights, "index", "" + classIndex); + if (tc != null) { + Highlighting th = Highlighting.search(traitHighlights, "index", "" + traitId, tc.startPos, tc.startPos + tc.len); + if (th != null) { + try { + ignoreCarret = true; + setCaretPosition(th.startPos + th.len - 1); + ignoreCarret = false; + } catch (IllegalArgumentException iae) { + } + final int pos = th.startPos; + new Timer().schedule(new TimerTask() { + @Override + public void run() { + try { + setCaretPosition(pos); + } catch (IllegalArgumentException iae) { } } - } - break; + }, 100); + return; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index a8af56045..85be6ecf5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -34,7 +34,7 @@ import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.TagTreeModel; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.graph.Graph; @@ -123,39 +123,39 @@ public class ActionPanel extends JPanel implements ActionListener { public String getStringUnderCursor() { int pos = decompiledEditor.getCaretPosition(); - for (Highlighting h : decompiledHilights) { - if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { - List list = lastCode; - Action lastIns = null; - int inspos = 0; - Action selIns = null; - for (Action ins : list) { - if (h.offset == ins.getOffset()) { - selIns = ins; - break; - } - if (ins.getOffset() > h.offset) { - inspos = (int) (h.offset - lastIns.getAddress()); - selIns = lastIns; - break; - } - lastIns = ins; + Highlighting h = Highlighting.search(decompiledHilights, pos); + if (h != null) { + List list = lastCode; + Action lastIns = null; + int inspos = 0; + Action selIns = null; + for (Action ins : list) { + if (h.getPropertyLong("offset") == ins.getOffset()) { + selIns = ins; + break; } - if (selIns != null) { - if (selIns instanceof ActionPush) { - ActionPush ap = (ActionPush) selIns; - Object var = ap.values.get(inspos - 1); - String identifier = null; - if (var instanceof String) { - identifier = (String) var; - } - if (var instanceof ConstantIndex) { - identifier = ap.constantPool.get(((ConstantIndex) var).index); - } - return identifier; + if (ins.getOffset() > h.getPropertyLong("offset")) { + inspos = (int) (h.getPropertyLong("offset") - lastIns.getAddress()); + selIns = lastIns; + break; + } + lastIns = ins; + } + if (selIns != null) { + if (selIns instanceof ActionPush) { + ActionPush ap = (ActionPush) selIns; + Object var = ap.values.get(inspos - 1); + String identifier = null; + if (var instanceof String) { + identifier = (String) var; } + if (var instanceof ConstantIndex) { + identifier = ap.constantPool.get(((ConstantIndex) var).index); + } + return identifier; } } + } return null; } @@ -255,7 +255,7 @@ public class ActionPanel extends JPanel implements ActionListener { } lastH = h; } - long offset = lastH.offset; + String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); editor.setText("; " + translate("work.gettinghilights") + "..."); disassembledHilights = Highlighting.getInstrHighlights(text); String stripped = Highlighting.stripHilights(text); @@ -265,12 +265,10 @@ public class ActionPanel extends JPanel implements ActionListener { editor.setContentType("text/flasm"); }*/ editor.setText(stripped); - for (Highlighting h : disassembledHilights) { - if (h.offset == offset) { - if (h.startPos <= editor.getText().length()) { - editor.setCaretPosition(h.startPos); - } - break; + Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); + if (h != null) { + if (h.startPos <= editor.getText().length()) { + editor.setCaretPosition(h.startPos); } } @@ -500,21 +498,21 @@ public class ActionPanel extends JPanel implements ActionListener { } editor.getCaret().setVisible(true); int pos = editor.getCaretPosition(); - Highlighting lastH = new Highlighting(0, 0, 0); + Highlighting lastH = null; for (Highlighting h : disassembledHilights) { if (pos < h.startPos) { break; } lastH = h; } - for (Highlighting h2 : decompiledHilights) { - if (h2.offset == lastH.offset) { - ignoreCarret = true; - decompiledEditor.setCaretPosition(h2.startPos); - decompiledEditor.getCaret().setVisible(true); - ignoreCarret = false; - break; - } + String ofs = lastH == null ? "0" : lastH.getPropertyString("offset"); + Highlighting h2 = Highlighting.search(decompiledHilights, "offset", ofs); + if (h2 != null) { + ignoreCarret = true; + decompiledEditor.setCaretPosition(h2.startPos); + decompiledEditor.getCaret().setVisible(true); + ignoreCarret = false; + } } }); @@ -529,20 +527,16 @@ public class ActionPanel extends JPanel implements ActionListener { } decompiledEditor.getCaret().setVisible(true); int pos = decompiledEditor.getCaretPosition(); - for (Highlighting h : decompiledHilights) { - if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { - for (Highlighting h2 : disassembledHilights) { - if (h2.offset == h.offset) { - ignoreCarret = true; - if (h2.startPos > 0 && h2.startPos < editor.getText().length()) { - editor.setCaretPosition(h2.startPos); - } - editor.getCaret().setVisible(true); - ignoreCarret = false; - break; - } + Highlighting h = Highlighting.search(decompiledHilights, pos); + if (h != null) { + Highlighting h2 = Highlighting.search(disassembledHilights, "offset", h.getPropertyString("offset")); + if (h2 != null) { + ignoreCarret = true; + if (h2.startPos > 0 && h2.startPos < editor.getText().length()) { + editor.setCaretPosition(h2.startPos); } - break; + editor.getCaret().setVisible(true); + ignoreCarret = false; } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/CachedScript.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/CachedScript.java index b13b7315f..42aa6c254 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/CachedScript.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/CachedScript.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.flash.gui.action; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import java.io.Serializable; import java.util.List; diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/Highlighting.java b/trunk/src/com/jpexs/decompiler/flash/helpers/Highlighting.java deleted file mode 100644 index 2709ecb48..000000000 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/Highlighting.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (C) 2010-2013 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 3 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, see . - */ -package com.jpexs.decompiler.flash.helpers; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Pattern; - -/** - * Provides methods for highlighting positions of instructions in the text. - * - * @author JPEXS - */ -public class Highlighting implements Serializable { - - /** - * Starting position - */ - public int startPos; - /** - * Length of highlighted text - */ - public int len; - /** - * Offset of instruction or trait - */ - public long offset; - /** - * Turn hignlighting on/off - */ - private static boolean doHighlight = true; - - /** - * Returns a string representation of the object - * - * @return a string representation of the object. - */ - @Override - public String toString() { - return "" + startPos + "-" + (startPos + len) + " ofs" + offset; - } - - /** - * Constructor - * - * @param startPos Starting position - * @param len Length of highlighted text - * @param offset Offset of instruction or trait - */ - public Highlighting(int startPos, int len, long offset) { - this.startPos = startPos; - this.len = len; - this.offset = offset; - } - private static final String OFSOPEN = "[OFS"; - private static final String OFSCLOSE = "]"; - private static final String OFSEND = "[/OFS]"; - private static final String TRAITOPEN = "[TRAIT"; - private static final String TRAITCLOSE = "]"; - private static final String TRAITEND = "[/TRAIT]"; - private static final String METHODOPEN = "[METHOD"; - private static final String METHODCLOSE = "]"; - private static final String METHODEND = "[/METHOD]"; - private static final String CLASSOPEN = "[CLASS"; - private static final String CLASSCLOSE = "]"; - private static final String CLASSEND = "[/CLASS]"; - - /** - * Highlights specified text as instruction by adding special tags - * - * @param text Text to highlight - * @param offset Offset of instruction - * @return Highlighted text - */ - public static String hilighOffset(String text, long offset) { - if (!doHighlight) { - return text; - } - return OFSOPEN + offset + OFSCLOSE + text + OFSEND; - } - - /** - * Highlights specified text as method by adding special tags - * - * @param text Text to highlight - * @param index Methodinfo index - * @return Highlighted text - */ - public static String hilighMethod(String text, long index) { - if (!doHighlight) { - return text; - } - return hilighMethodBegin(index) + text + hilighMethodEnd(); - } - - /** - * Beggining of hilight of method - * - * @param index - * @return Hilighted method begin - */ - public static String hilighMethodBegin(long index) { - if (!doHighlight) { - return ""; - } - return METHODOPEN + index + METHODCLOSE; - } - - /** - * Ending of hilight of method - * - * @return Hilighted method end - */ - public static String hilighMethodEnd() { - if (!doHighlight) { - return ""; - } - return METHODEND; - } - - /** - * Highlights specified text as trait by adding special tags - * - * @param text Text to highlight - * @param offset Offset of trait - * @return Highlighted text - */ - public static String hilighTrait(String text, long offset) { - if (!doHighlight) { - return text; - } - return TRAITOPEN + offset + TRAITCLOSE + text + TRAITEND; - } - - /** - * Highlights specified text as class by adding special tags - * - * @param text Text to highlight - * @param offset Offset of trait - * @return Highlighted text - */ - public static String hilighClass(String text, long offset) { - if (!doHighlight) { - return text; - } - return CLASSOPEN + offset + CLASSCLOSE + text + CLASSEND; - } - - /** - * Strips all highlights from the text - * - * @param text Text to strip highlights in - * @return Text with no highlights - */ - public static String stripHilights(String text) { - if (!doHighlight) { - return text; - } - text = stripInstrHilights(text); - text = stripTraitHilights(text); - text = stripMethodHilights(text); - text = stripClassHilights(text); - return text; - } - - /** - * Strips instruction highlights from the text - * - * @param text Text to strip instruction highlights in - * @return Text with no instruction highlights - */ - private static String stripInstrHilights(String text) { - return stripSpecificHilights(text, OFSOPEN, OFSCLOSE, OFSEND); - } - - /** - * Strips method highlights from the text - * - * @param text Text to strip method highlights in - * @return Text with no method highlights - */ - private static String stripMethodHilights(String text) { - return stripSpecificHilights(text, METHODOPEN, METHODCLOSE, METHODEND); - } - - /** - * Strips trait highlights from the text - * - * @param text Text to strip trait highlights in - * @return Text with no trait highlights - */ - private static String stripTraitHilights(String text) { - return stripSpecificHilights(text, TRAITOPEN, TRAITCLOSE, TRAITEND); - } - - /** - * Strips class highlights from the text - * - * @param text Text to strip trait highlights in - * @return Text with no class highlights - */ - private static String stripClassHilights(String text) { - return stripSpecificHilights(text, CLASSOPEN, CLASSCLOSE, CLASSEND); - } - - private static String stripSpecificHilights(String text, String txtOpen, String txtClose, String txtEnd) { - text = text.replaceAll(Pattern.quote(txtOpen) + "[0-9]+" + Pattern.quote(txtClose), ""); - text = text.replace(txtEnd, ""); - return text; - } - - private static List getSpecificHighlights(String texts, String txtOpen, String txtClose, String txtEnd) { - List ret = new ArrayList<>(); - StringBuilder text = new StringBuilder(texts); - int pos = 0; - while (true) { - int openpos = text.indexOf(txtOpen); - if (openpos == -1) { - break; - } - int closepos = text.indexOf(txtClose, openpos); - int enpos = text.indexOf(txtEnd, openpos); - int textlen = enpos - closepos - txtClose.length(); - - int nextopenpos = text.indexOf(txtOpen, openpos + 1); - if (nextopenpos != -1) { - if (nextopenpos < enpos) { - Logger.getLogger(Highlighting.class.getName()).log(Level.SEVERE, "Crossed highligh - str:{0}", text); - enpos = nextopenpos; - } - } - long offset = Long.parseLong(text.substring(openpos + txtOpen.length(), closepos)); - Highlighting hl = new Highlighting(pos + openpos, textlen, offset); - pos += openpos + textlen; - text = text.delete(0, enpos + txtEnd.length()); - ret.add(hl); - } - return ret; - } - - /** - * Gets all trait highlight objects from specified text - * - * @param text Text to get highlights from - * @return List of trait highlights - */ - public static List getTraitHighlights(String text) { - text = text.replace("\r\n", "\n"); - text = stripInstrHilights(text); - text = stripMethodHilights(text); - text = stripClassHilights(text); - return getSpecificHighlights(text, TRAITOPEN, TRAITCLOSE, TRAITEND); - } - - /** - * Gets all method highlight objects from specified text - * - * @param text Text to get highlights from - * @return List of method highlights - */ - public static List getMethodHighlights(String text) { - text = text.replace("\r\n", "\n"); - text = stripInstrHilights(text); - text = stripTraitHilights(text); - text = stripClassHilights(text); - return getSpecificHighlights(text, METHODOPEN, METHODCLOSE, METHODEND); - } - - /** - * Gets all instruction highlight objects from specified text - * - * @param text Text to get highlights from - * @return List of instruction highlights - */ - public static List getInstrHighlights(String text) { - text = text.replace("\r\n", "\n"); - text = stripTraitHilights(text); - text = stripMethodHilights(text); - text = stripClassHilights(text); - return getSpecificHighlights(text, OFSOPEN, OFSCLOSE, OFSEND); - } - - /** - * Gets all class highlight objects from specified text - * - * @param text Text to get highlights from - * @return List of class highlights - */ - public static List getClassHighlights(String text) { - text = text.replace("\r\n", "\n"); - text = stripTraitHilights(text); - text = stripMethodHilights(text); - text = stripInstrHilights(text); - return getSpecificHighlights(text, CLASSOPEN, CLASSCLOSE, CLASSEND); - } -} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java new file mode 100644 index 000000000..c2956f774 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2010-2013 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 3 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, see . + */ +package com.jpexs.decompiler.flash.helpers.hilight; + +import com.jpexs.helpers.Helper; +import java.io.IOException; +import java.io.Serializable; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Provides methods for highlighting positions of instructions in the text. + * + * @author JPEXS + */ +public class Highlighting implements Serializable { + + public String data; + /** + * Starting position + */ + public int startPos; + /** + * Length of highlighted text + */ + public int len; + private Map properties; + + public Long getPropertyLong(String key) { + String dataStr = getPropertyString(key); + if (dataStr == null) { + return null; + } + try { + return Long.parseLong(dataStr); + } catch (NumberFormatException nfe) { + return null; + } + } + + public String getPropertyString(String key) { + return properties.get(key); + } + + public static Highlighting search(List list, long pos) { + return search(list, pos, null, null, -1, -1); + } + + public static Highlighting search(List list, long pos, String type) { + return search(list, pos, "type", null, -1, -1); + } + + public static Highlighting search(List list, String property, String value) { + return search(list, -1, property, value, -1, -1); + } + + public static Highlighting search(List list, String property, String value, int from, int to) { + return search(list, -1, property, value, from, to); + } + + public static Highlighting search(List list, long pos, String property, String value, long from, long to) { + Highlighting ret = null; + for (Highlighting h : list) { + if (property != null) { + String v = h.getPropertyString(property); + if (v == null) { + if (value != null) { + continue; + } + } else { + if (!v.equals(value)) { + continue; + } + } + } + if (from > -1) { + if (h.startPos < from) { + continue; + } + } + if (to > -1) { + if (h.startPos > to) { + continue; + } + } + if (pos == -1 || (pos >= h.startPos && (pos < h.startPos + h.len))) { + if (ret == null || h.startPos > ret.startPos) { //get the closest one + ret = h; + } + } + if (pos == -1 && ret != null) { + return ret; + } + } + return ret; + } + + /** + * Returns a string representation of the object + * + * @return a string representation of the object. + */ + @Override + public String toString() { + return "" + startPos + "-" + (startPos + len) + " data:" + data; + } + + /** + * Constructor + * + * @param startPos Starting position + * @param len Length of highlighted text + * @param offset Offset of instruction or trait + */ + public Highlighting(int startPos, int len, String data) { + this.startPos = startPos; + this.len = len; + this.data = data; + parseData(); + } + + private void parseData() { + properties = new HashMap<>(); + String pairs[]; + if (data.contains(";")) { + pairs = data.split(";"); + } else { + pairs = new String[]{data}; + } + for (String p : pairs) { + String keyval[]; + if (p.contains("=")) { + keyval = p.split("="); + } else { + keyval = new String[]{p, p}; + } + properties.put(keyval[0], keyval[1]); + } + } + + public Highlighting(int startPos, int len, long offset) { + this(startPos, len, ""); + } + private static final String HLOPEN = ""; + private static final String HLCLOSE = ""; + + public static String hilight(String text, String data) { + return HLOPEN + Helper.escapeString(data) + HLEND + text + HLCLOSE; + } + + public static List getHilights(String text) { + return getHilights(text, null); + } + + public static List getHilights(String text, String typePrefix) { + text = text.replace("\r\n", "\n"); + List tokens = getHilightTokens(text); + Stack positions = new Stack<>(); + Stack datas = new Stack<>(); + int pos = 0; + List ret = new ArrayList<>(); + for (HilightToken token : tokens) { + switch (token.type) { + case HILIGHTSTART: + positions.push(pos); + datas.push(token.value); + break; + case HILIGHTEND: + int start = positions.pop(); + String data = datas.pop(); + Highlighting hl = new Highlighting(start, pos - start, data); + if (typePrefix == null || data.startsWith(typePrefix)) { + ret.add(hl); + } + break; + case TEXT: + pos += token.tokenLength; + break; + } + } + return ret; + } + + public static List getHilightTokens(String text) { + HilightLexer lexer = new HilightLexer(new StringReader(text)); + HilightToken tok; + List ret = new ArrayList<>(); + try { + while (true) { + tok = lexer.lex(); + if (tok.type == TokenType.EOF) { + break; + } + ret.add(tok); + } + } catch (ParseException | IOException ex) { + Logger.getLogger(Highlighting.class.getName()).log(Level.SEVERE, "Error during getting hilight tokens", ex); + } + return ret; + } + + /** + * Highlights specified text as instruction by adding special tags + * + * @param text Text to highlight + * @param offset Offset of instruction + * @return Highlighted text + */ + public static String hilighOffset(String text, long offset) { + return hilight(text, "type=instruction;offset=" + offset); + } + + /** + * Highlights specified text as method by adding special tags + * + * @param text Text to highlight + * @param index Methodinfo index + * @return Highlighted text + */ + public static String hilighMethod(String text, long index) { + return hilight(text, "type=method;index=" + index); + } + + /** + * Highlights specified text as trait by adding special tags + * + * @param text Text to highlight + * @param offset Offset of trait + * @return Highlighted text + */ + public static String hilighTrait(String text, long index) { + + return hilight(text, "type=trait;index=" + index); + } + + /** + * Highlights specified text as class by adding special tags + * + * @param text Text to highlight + * @param offset Offset of trait + * @return Highlighted text + */ + public static String hilighClass(String text, long index) { + + return hilight(text, "type=class;index=" + index); + } + + /** + * Strips all highlights from the text + * + * @param text Text to strip highlights in + * @return Text with no highlights + */ + public static String stripHilights(String text) { + text = text.replace("\r\n", "\n"); + List tokens = getHilightTokens(text); + StringBuilder ret = new StringBuilder(); + for (HilightToken token : tokens) { + if (token.type == TokenType.TEXT) { + ret.append(token.value); + } + } + return ret.toString(); + } + + /** + * Gets all trait highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of trait highlights + */ + public static List getTraitHighlights(String text) { + return getHilights(text, "type=trait;"); + } + + /** + * Gets all method highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of method highlights + */ + public static List getMethodHighlights(String text) { + return getHilights(text, "type=method;"); + } + + /** + * Gets all instruction highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of instruction highlights + */ + public static List getInstrHighlights(String text) { + return getHilights(text, "type=instruction;"); + } + + /** + * Gets all class highlight objects from specified text + * + * @param text Text to get highlights from + * @return List of class highlights + */ + public static List getClassHighlights(String text) { + return getHilights(text, "type=class;"); + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightLexer.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightLexer.java new file mode 100644 index 000000000..0e1b388b9 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightLexer.java @@ -0,0 +1,741 @@ +/* The following code was generated by JFlex 1.4.3 on 15.9.13 8:58 */ + +/* Flash assembler language lexer specification */ +package com.jpexs.decompiler.flash.helpers.hilight; + +import java.util.Stack; + +/** + * This class is a scanner generated by + * JFlex 1.4.3 on 15.9.13 8:58 from the + * specification file + * D:/Dropbox/Programovani/JavaSE/FFDec/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/hilight.flex + */ +public final class HilightLexer { + + /** + * This character denotes the end of file + */ + public static final int YYEOF = -1; + /** + * initial size of the lookahead buffer + */ + private static final int ZZ_BUFFERSIZE = 16384; + /** + * lexical states + */ + public static final int STRING = 2; + public static final int YYINITIAL = 0; + /** + * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l + * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l at the + * beginning of a line l is of the form l = 2*k, k a non negative integer + */ + private static final int ZZ_LEXSTATE[] = { + 0, 0, 1, 1 + }; + /** + * Translates characters to character classes + */ + private static final String ZZ_CMAP_PACKED = + "\12\0\1\3\2\0\1\2\24\0\1\12\4\0\1\21\7\0\1\13" + + "\12\0\1\11\1\0\1\4\1\0\1\14\35\0\1\1\5\0\1\15" + + "\1\10\1\6\1\7\1\5\7\0\1\17\3\0\1\20\1\0\1\16" + + "\uff8b\0"; + /** + * Translates characters to character classes + */ + private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); + /** + * Translates DFA states to action switch labels. + */ + private static final int[] ZZ_ACTION = zzUnpackAction(); + private static final String ZZ_ACTION_PACKED_0 = + "\2\0\2\1\1\2\1\0\2\3\3\0\1\4\1\5" + + "\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15" + + "\12\0\1\16\1\17"; + + private static int[] zzUnpackAction() { + int[] result = new int[33]; + int offset = 0; + offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAction(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do { + result[j++] = value; + } while (--count > 0); + } + return j; + } + /** + * Translates a state to a row index in the transition table + */ + private static final int[] ZZ_ROWMAP = zzUnpackRowMap(); + private static final String ZZ_ROWMAP_PACKED_0 = + "\0\0\0\22\0\44\0\66\0\110\0\132\0\154\0\44" + + "\0\176\0\220\0\242\0\44\0\44\0\44\0\44\0\44" + + "\0\44\0\44\0\44\0\44\0\44\0\264\0\306\0\330" + + "\0\352\0\374\0\u010e\0\u0120\0\u0132\0\u0144\0\u0156\0\44" + + "\0\44"; + + private static int[] zzUnpackRowMap() { + int[] result = new int[33]; + int offset = 0; + offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackRowMap(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int high = packed.charAt(i++) << 16; + result[j++] = high | packed.charAt(i++); + } + return j; + } + /** + * The transition table of the DFA + */ + private static final int[] ZZ_TRANS = zzUnpackTrans(); + private static final String ZZ_TRANS_PACKED_0 = + "\4\3\1\4\15\3\1\5\1\6\1\7\1\10\6\5" + + "\1\11\7\5\27\0\1\12\5\0\1\13\6\0\1\5" + + "\3\0\6\5\1\0\7\5\1\14\1\15\1\14\1\0" + + "\1\14\1\16\4\14\1\17\2\14\1\20\1\21\1\22" + + "\1\23\1\24\3\0\1\10\32\0\1\25\12\0\1\26" + + "\21\0\1\27\22\0\1\30\20\0\1\31\23\0\1\32" + + "\20\0\1\33\23\0\1\34\20\0\1\35\23\0\1\36" + + "\20\0\1\37\23\0\1\40\23\0\1\41\5\0"; + + private static int[] zzUnpackTrans() { + int[] result = new int[360]; + int offset = 0; + offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackTrans(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + value--; + do { + result[j++] = value; + } while (--count > 0); + } + return j; + } + /* error codes */ + private static final int ZZ_UNKNOWN_ERROR = 0; + private static final int ZZ_NO_MATCH = 1; + private static final int ZZ_PUSHBACK_2BIG = 2; + + /* error messages for the codes above */ + private static final String ZZ_ERROR_MSG[] = { + "Unkown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" + }; + /** + * ZZ_ATTRIBUTE[aState] contains the attributes of state + * aState + */ + private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); + private static final String ZZ_ATTRIBUTE_PACKED_0 = + "\2\0\1\11\2\1\1\0\1\1\1\11\3\0\12\11" + + "\12\0\2\11"; + + private static int[] zzUnpackAttribute() { + int[] result = new int[33]; + int offset = 0; + offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAttribute(String packed, int offset, int[] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do { + result[j++] = value; + } while (--count > 0); + } + return j; + } + /** + * the input device + */ + private java.io.Reader zzReader; + /** + * the current state of the DFA + */ + private int zzState; + /** + * the current lexical state + */ + private int zzLexicalState = YYINITIAL; + /** + * this buffer contains the current text to be matched and is the source of + * the yytext() string + */ + private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; + /** + * the textposition at the last accepting state + */ + private int zzMarkedPos; + /** + * the current text position in the buffer + */ + private int zzCurrentPos; + /** + * startRead marks the beginning of the yytext() string in the buffer + */ + private int zzStartRead; + /** + * endRead marks the last character in the buffer, that has been read from + * input + */ + private int zzEndRead; + /** + * number of newlines encountered up to the start of the matched text + */ + private int yyline; + /** + * the number of characters up to the start of the matched text + */ + private int yychar; + /** + * the number of characters from the last newline up to the start of the + * matched text + */ + private int yycolumn; + /** + * zzAtBOL == true <=> the scanner is currently at the beginning of a line + */ + private boolean zzAtBOL = true; + /** + * zzAtEOF == true <=> the scanner is at the EOF + */ + private boolean zzAtEOF; + /** + * denotes if the user-EOF-code has already been executed + */ + private boolean zzEOFDone; + + /* user code: */ + StringBuffer string = new StringBuffer(); + + /** + * Create an empty lexer, yyrset will be called later to reset and assign + * the reader + */ + public HilightLexer() { + } + + public int yychar() { + return yychar; + } + + public int yyline() { + return yyline + 1; + } + private boolean doHilightEnd = false; + private Stack pushedBack = new Stack<>(); + private int tokenLength = 0; + + public void pushforward(HilightToken symb) { + pushedBack.add(0, symb); + } + + public void pushback(HilightToken symb) { + pushedBack.push(symb); + } + + public HilightToken lex() throws java.io.IOException, ParseException { + HilightToken ret = null; + if (!pushedBack.isEmpty()) { + ret = pushedBack.pop(); + } else { + ret = yylex(); + } + return ret; + } + + /** + * Creates a new scanner There is also a java.io.InputStream version of this + * constructor. + * + * @param in the java.io.Reader to read input from. + */ + public HilightLexer(java.io.Reader in) { + this.zzReader = in; + } + + /** + * Creates a new scanner. There is also java.io.Reader version of this + * constructor. + * + * @param in the java.io.Inputstream to read input from. + */ + public HilightLexer(java.io.InputStream in) { + this(new java.io.InputStreamReader(in)); + } + + /** + * Unpacks the compressed character translation table. + * + * @param packed the packed character translation table + * @return the unpacked character translation table + */ + private static char[] zzUnpackCMap(String packed) { + char[] map = new char[0x10000]; + int i = 0; /* index in packed string */ + int j = 0; /* index in unpacked array */ + while (i < 62) { + int count = packed.charAt(i++); + char value = packed.charAt(i++); + do { + map[j++] = value; + } while (--count > 0); + } + return map; + } + + /** + * Refills the input buffer. + * + * @return false, iff there was new input. + * + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + + /* first: make room (if you can) */ + if (zzStartRead > 0) { + System.arraycopy(zzBuffer, zzStartRead, + zzBuffer, 0, + zzEndRead - zzStartRead); + + /* translate stored positions */ + zzEndRead -= zzStartRead; + zzCurrentPos -= zzStartRead; + zzMarkedPos -= zzStartRead; + zzStartRead = 0; + } + + /* is the buffer big enough? */ + if (zzCurrentPos >= zzBuffer.length) { + /* if not: blow it up */ + char newBuffer[] = new char[zzCurrentPos * 2]; + System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); + zzBuffer = newBuffer; + } + + /* finally: fill the buffer with new input */ + int numRead = zzReader.read(zzBuffer, zzEndRead, + zzBuffer.length - zzEndRead); + + if (numRead > 0) { + zzEndRead += numRead; + return false; + } + // unlikely but not impossible: read 0 characters, but not at end of stream + if (numRead == 0) { + int c = zzReader.read(); + if (c == -1) { + return true; + } else { + zzBuffer[zzEndRead++] = (char) c; + return false; + } + } + + // numRead < 0 + return true; + } + + /** + * Closes the input stream. + */ + public final void yyclose() throws java.io.IOException { + zzAtEOF = true; /* indicate end of file */ + zzEndRead = zzStartRead; /* invalidate buffer */ + + if (zzReader != null) { + zzReader.close(); + } + } + + /** + * Resets the scanner to read from a new input stream. Does not close the + * old reader. + * + * All internal variables are reset, the old input stream + * cannot be reused (internal buffer is discarded and lost). Lexical + * state is set to ZZ_INITIAL. + * + * @param reader the new input stream + */ + public final void yyreset(java.io.Reader reader) { + zzReader = reader; + zzAtBOL = true; + zzAtEOF = false; + zzEOFDone = false; + zzEndRead = zzStartRead = 0; + zzCurrentPos = zzMarkedPos = 0; + yyline = yychar = yycolumn = 0; + zzLexicalState = YYINITIAL; + } + + /** + * Returns the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + /** + * Enters a new lexical state + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + /** + * Returns the text matched by the current regular expression. + */ + public final String yytext() { + return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead); + } + + /** + * Returns the character at position pos from the matched text. + * + * It is equivalent to yytext().charAt(pos), but faster + * + * @param pos the position of the character to fetch. A value from 0 to + * yylength()-1. + * + * @return the character at position pos + */ + public final char yycharat(int pos) { + return zzBuffer[zzStartRead + pos]; + } + + /** + * Returns the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos - zzStartRead; + } + + /** + * Reports an error that occured while scanning. + * + * In a wellformed scanner (no or only correct usage of yypushback(int) and + * a match-all fallback rule) this method will only be called with things + * that "Can't Possibly Happen". If this method is called, something is + * seriously wrong (e.g. a JFlex bug producing a faulty scanner etc.). + * + * Usual syntax/scanner level error handling should be done in error + * fallback rules. + * + * @param errorCode the code of the errormessage to display + */ + private void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + + throw new Error(message); + } + + /** + * Pushes the specified amount of characters back into the input stream. + * + * They will be read again by then next call of the scanning method + * + * @param number the number of characters to be read again. This number must + * not be greater than yylength()! + */ + public void yypushback(int number) { + if (number > yylength()) { + zzScanError(ZZ_PUSHBACK_2BIG); + } + + zzMarkedPos -= number; + } + + /** + * Resumes scanning until the next regular expression is matched, the end of + * input is encountered or an I/O-Error occurs. + * + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs + */ + public HilightToken yylex() throws java.io.IOException, ParseException { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + char[] zzBufferL = zzBuffer; + char[] zzCMapL = ZZ_CMAP; + + int[] zzTransL = ZZ_TRANS; + int[] zzRowMapL = ZZ_ROWMAP; + int[] zzAttrL = ZZ_ATTRIBUTE; + + while (true) { + zzMarkedPosL = zzMarkedPos; + + yychar += zzMarkedPosL - zzStartRead; + + boolean zzR = false; + for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; + zzCurrentPosL++) { + switch (zzBufferL[zzCurrentPosL]) { + case '\u000B': + case '\u000C': + case '\u0085': + case '\u2028': + case '\u2029': + yyline++; + yycolumn = 0; + zzR = false; + break; + case '\r': + yyline++; + yycolumn = 0; + zzR = true; + break; + case '\n': + if (zzR) { + zzR = false; + } else { + yyline++; + yycolumn = 0; + } + break; + default: + zzR = false; + yycolumn++; + } + } + + if (zzR) { + // peek one character ahead if it is \n (if we have counted one line too much) + boolean zzPeek; + if (zzMarkedPosL < zzEndReadL) { + zzPeek = zzBufferL[zzMarkedPosL] == '\n'; + } else if (zzAtEOF) { + zzPeek = false; + } else { + boolean eof = zzRefill(); + zzEndReadL = zzEndRead; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + if (eof) { + zzPeek = false; + } else { + zzPeek = zzBufferL[zzMarkedPosL] == '\n'; + } + } + if (zzPeek) { + yyline--; + } + } + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + + zzForAction: + { + while (true) { + + if (zzCurrentPosL < zzEndReadL) { + zzInput = zzBufferL[zzCurrentPosL++]; + } else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } else { + zzInput = zzBufferL[zzCurrentPosL++]; + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + if (zzNext == -1) { + break zzForAction; + } + zzState = zzNext; + + int zzAttributes = zzAttrL[zzState]; + if ((zzAttributes & 1) == 1) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ((zzAttributes & 8) == 8) { + break zzForAction; + } + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 2: { + tokenLength++; + string.append(yytext()); + } + case 16: + break; + case 10: { + tokenLength += 2; + string.append('\n'); + } + case 17: + break; + case 4: { + throw new ParseException("Illegal escape sequence \"" + yytext() + "\"", yyline + 1); + } + case 18: + break; + case 8: { + tokenLength += 2; + string.append('\b'); + } + case 19: + break; + case 12: { + tokenLength += 2; + string.append('\''); + } + case 20: + break; + case 15: { + if (string.length() > 0) { + pushforward(new HilightToken(TokenType.TEXT, string.toString())); + } + string.setLength(0); + pushforward(new HilightToken(TokenType.HILIGHTEND, yytext())); + return lex(); + } + case 21: + break; + case 13: { + yybegin(YYINITIAL); + tokenLength++; + pushforward(new HilightToken(TokenType.HILIGHTSTART, string.toString(), tokenLength)); + string.setLength(0); + return lex(); + } + case 22: + break; + case 9: { + tokenLength += 2; + string.append('\t'); + } + case 23: + break; + case 14: { + if (string.length() > 0) { + pushforward(new HilightToken(TokenType.TEXT, string.toString())); + } + yybegin(STRING); + string.setLength(0); + tokenLength = yylength(); + } + case 24: + break; + case 5: { + tokenLength += 2; + string.append('\\'); + } + case 25: + break; + case 1: { + string.append(yytext()); + } + case 26: + break; + case 7: { + tokenLength += 2; + string.append('\"'); + } + case 27: + break; + case 11: { + tokenLength += 2; + string.append('\r'); + } + case 28: + break; + case 6: { + tokenLength += 2; + string.append('\f'); + } + case 29: + break; + case 3: { + throw new ParseException("Unterminated string at end of line", yyline + 1); + } + case 30: + break; + default: + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + { + if (string.length() > 0) { + pushforward(new HilightToken(TokenType.TEXT, string.toString())); + string.setLength(0); + } + pushforward(new HilightToken(TokenType.EOF)); + return lex(); + } + } else { + zzScanError(ZZ_NO_MATCH); + } + } + } + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightToken.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightToken.java new file mode 100644 index 000000000..75b2bb797 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/HilightToken.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2013 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 3 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, see . + */ +package com.jpexs.decompiler.flash.helpers.hilight; + +/** + * + * @author JPEXS + */ +public class HilightToken { + + public TokenType type; + public String value; + public int tokenLength; + + public HilightToken(TokenType type) { + this(type, ""); + } + + public HilightToken(TokenType type, String value) { + this.type = type; + this.value = value; + tokenLength = value.length(); + } + + public HilightToken(TokenType type, String value, int tokenLength) { + this.type = type; + this.value = value; + this.tokenLength = tokenLength; + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/ParseException.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/ParseException.java new file mode 100644 index 000000000..a4c1b7cea --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/ParseException.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 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 3 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, see . + */ +package com.jpexs.decompiler.flash.helpers.hilight; + +/** + * + * @author JPEXS + */ +public class ParseException extends Exception { + + public String message; + public int line; + + public ParseException(String message, int line) { + super("ParseException:" + message + " on line " + line); + this.message = message; + this.line = line; + + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/TokenType.java b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/TokenType.java new file mode 100644 index 000000000..c67cb65b4 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/TokenType.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2013 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 3 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, see . + */ +package com.jpexs.decompiler.flash.helpers.hilight; + +/** + * + * @author JPEXS + */ +public enum TokenType { + + HILIGHTSTART, + TEXT, + HILIGHTEND, + EOF +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/hilight.flex b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/hilight.flex new file mode 100644 index 000000000..f596c1874 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/hilight/hilight.flex @@ -0,0 +1,127 @@ +/* Flash assembler language lexer specification */ + +package com.jpexs.decompiler.flash.helpers.hilight; + +import java.util.Stack; +%% + +%public +%class HilightLexer +%final +%unicode +%char +%line +%column +%type HilightToken +%throws ParseException + +%{ + + StringBuffer string = new StringBuffer(); + + /** + * Create an empty lexer, yyrset will be called later to reset and assign + * the reader + */ + public HilightLexer() { + + } + + public int yychar() { + return yychar; + } + + public int yyline() { + return yyline+1; + } + + private boolean doHilightEnd=false; + + private Stack pushedBack=new Stack<>(); + + private int tokenLength=0; + + public void pushforward(HilightToken symb) { + pushedBack.add(0,symb); + } + + public void pushback(HilightToken symb) { + pushedBack.push(symb); + } + public HilightToken lex() throws java.io.IOException, ParseException{ + HilightToken ret=null; + if(!pushedBack.isEmpty()){ + ret = pushedBack.pop(); + }else{ + ret = yylex(); + } + return ret; + } + +%} + +StringCharacter = [^\r\n\"\\] +LineTerminator = \r|\n|\r\n + +%state STRING + +%% + + { + + /* string literal */ + "0) + pushforward(new HilightToken(TokenType.TEXT,string.toString())); + yybegin(STRING); + string.setLength(0); + tokenLength=yylength(); + } + "" { + if(string.length()>0) + pushforward(new HilightToken(TokenType.TEXT,string.toString())); + string.setLength(0); + pushforward(new HilightToken(TokenType.HILIGHTEND,yytext())); + return lex(); + } + .|\n { + string.append( yytext() ); + } + +} + + { + \"> { + yybegin(YYINITIAL); + tokenLength++; + pushforward(new HilightToken(TokenType.HILIGHTSTART,string.toString(),tokenLength)); + string.setLength(0); + return lex(); + } + + {StringCharacter}+ { tokenLength++; string.append( yytext() ); } + + /* escape sequences */ + "\\b" { tokenLength+=2; string.append( '\b' ); } + "\\t" { tokenLength+=2; string.append( '\t' ); } + "\\n" { tokenLength+=2; string.append( '\n' ); } + "\\f" { tokenLength+=2; string.append( '\f' ); } + "\\r" { tokenLength+=2; string.append( '\r' ); } + "\\\"" { tokenLength+=2; string.append( '\"' ); } + "\\'" { tokenLength+=2; string.append( '\'' ); } + "\\\\" { tokenLength+=2; string.append( '\\' ); } + + /* error cases */ + \\. { throw new ParseException("Illegal escape sequence \""+yytext()+"\"",yyline+1); } + {LineTerminator} { throw new ParseException("Unterminated string at end of line",yyline+1); } + +} + +<> { + if(string.length()>0){ + pushforward(new HilightToken(TokenType.TEXT,string.toString())); + string.setLength(0); + } + pushforward(new HilightToken(TokenType.EOF)); + return lex(); + } diff --git a/trunk/src/com/jpexs/decompiler/graph/Graph.java b/trunk/src/com/jpexs/decompiler/graph/Graph.java index bc6955c3f..d76c69681 100644 --- a/trunk/src/com/jpexs/decompiler/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/graph/Graph.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.ecma.EcmaScript; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.model.AndItem; import com.jpexs.decompiler.graph.model.BreakItem; import com.jpexs.decompiler.graph.model.ContinueItem; diff --git a/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 6002910c3..df20e31a2 100644 --- a/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/trunk/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.graph; -import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.graph.model.BinaryOp; import java.io.Serializable; import java.util.ArrayList;