AS3 p-code Popup docs for other items than instructions

This commit is contained in:
Jindra Petřík
2016-08-28 23:39:47 +02:00
parent 8f29c8f8db
commit 1fcc9c6ba0
7 changed files with 306 additions and 86 deletions

View File

@@ -393,19 +393,23 @@ public abstract class Trait implements Cloneable, Serializable {
writer.hilightSpecial(abc.constants.multinameToString(name_index), HighlightSpecialType.TRAIT_NAME);
if ((kindFlags & ATTR_Final) > 0) {
writer.append(" flag ");
writer.newLine();
writer.append("flag ");
writer.hilightSpecial("FINAL", HighlightSpecialType.ATTR_FINAL);
}
if ((kindFlags & ATTR_Override) > 0) {
writer.append(" flag ");
writer.newLine();
writer.append("flag ");
writer.hilightSpecial("OVERRIDE", HighlightSpecialType.ATTR_OVERRIDE);
}
if ((kindFlags & ATTR_Metadata) > 0) {
writer.append(" flag ");
writer.newLine();
writer.append("flag ");
writer.hilightSpecial("METADATA", HighlightSpecialType.ATTR_METADATA);
}
if ((kindFlags & ATTR_0x8) > 0) {
writer.append(" flag ");
writer.newLine();
writer.append("flag ");
writer.hilightSpecial("0x8", HighlightSpecialType.ATTR_0x8);
}
if ((kindFlags & ATTR_Metadata) > 0) {

View File

@@ -235,9 +235,11 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
writer.newLine();
writer.appendNoHilight("slotid ");
writer.hilightSpecial(Integer.toString(slot_id), HighlightSpecialType.SLOT_ID);
writer.appendNoHilight(" type ");
writer.newLine();
writer.appendNoHilight("type ");
writer.hilightSpecial(abc.constants.multinameToString(type_index), HighlightSpecialType.TRAIT_TYPE_NAME);
writer.appendNoHilight(" value ");
writer.newLine();
writer.appendNoHilight("value ");
writer.hilightSpecial((new ValueKind(value_index, value_kind).toASMString(abc.constants)), HighlightSpecialType.TRAIT_VALUE);
writer.newLine();
return writer;

View File

@@ -0,0 +1,64 @@
package com.jpexs.decompiler.flash.docs;
import com.jpexs.decompiler.flash.ApplicationInfo;
import static com.jpexs.decompiler.flash.docs.As3PCodeOtherDocs.NEWLINE;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AbstractDocs {
protected static Cache<String, String> docsCache = Cache.getInstance(false, true, "abstractDocsCache");
protected static String htmlFooter() {
StringBuilder sb = new StringBuilder();
sb.append("</html>");
return sb.toString();
}
public static String getStyle() {
String cached = docsCache.get("__style");
if (cached != null) {
return cached;
}
String style = "";
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found");
} else {
style = new String(Helper.readStream(is), Utf8Helper.charset);
}
docsCache.put("__style", style);
return style;
}
protected static String meta(String name, String content) {
return "\t\t<meta name=\"" + name + "\" content=\"" + content + "\">" + NEWLINE;
}
protected static String metaProp(String name, String content) {
return "\t\t<meta property=\"" + name + "\" content=\"" + content + "\">" + NEWLINE;
}
protected static String meta(String name, Date content) {
return "\t\t<meta name=\"" + name + "\" content=\"" + getISO8601StringForDate(content) + "\">" + NEWLINE;
}
protected static String getISO8601StringForDate(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(date);
}
}

View File

@@ -28,15 +28,12 @@ import java.util.logging.Logger;
*
* @author JPEXS
*/
public class As3PCodeDocs {
public class As3PCodeDocs extends AbstractDocs {
private static ResourceBundle prop;
static ResourceBundle prop;
private static final Map<AVM2InstructionFlag, String> flagDescriptions = new HashMap<>();
private static Map<AVM2InstructionFlag, String> flagDescriptions = new HashMap<>();
private static Cache<String, String> docsCache = Cache.getInstance(false, true, "as3DocsCache");
private static Map<String, InstructionDefinition> nameToDef = new HashMap<>();
private final static Map<String, InstructionDefinition> nameToDef = new HashMap<>();
static final String NEWLINE = "\r\n";
@@ -82,56 +79,6 @@ public class As3PCodeDocs {
return getDocsForIns(nameToDef.get(insName), showDataSize, ui, withStyle);
}
private static String getProperty(String name) {
if (prop.containsKey(name)) {
return Helper.escapeHTML(prop.getString(name));
}
return null;
}
private static String htmlFooter() {
StringBuilder sb = new StringBuilder();
sb.append("</html>");
return sb.toString();
}
private static String meta(String name, String content) {
return "\t\t<meta name=\"" + name + "\" content=\"" + content + "\">" + NEWLINE;
}
private static String metaProp(String name, String content) {
return "\t\t<meta property=\"" + name + "\" content=\"" + content + "\">" + NEWLINE;
}
private static String meta(String name, Date content) {
return "\t\t<meta name=\"" + name + "\" content=\"" + getISO8601StringForDate(content) + "\">" + NEWLINE;
}
private static String htmlHeader(String js, String style) {
Date dateGenerated = new Date();
StringBuilder sb = new StringBuilder();
sb.append("<!DOCTYPE html>").append(NEWLINE).
append("<html>").append(NEWLINE).
append("\t<head>").append(NEWLINE);
if (style != null && !style.isEmpty()) {
sb.append("\t\t<style>").append(style).append("</style>").append(NEWLINE);
}
if (js != null && !js.isEmpty()) {
sb.append("\t\t<script>").append(js).append("</script>").append(NEWLINE);
}
sb.append("\t\t<meta charset=\"UTF-8\">").append(NEWLINE).
append(meta("generator", ApplicationInfo.applicationVerName)).
append(meta("description", getProperty("ui.list.pageDescription"))).
append(metaProp("og:title", getProperty("ui.list.pageTitle"))).
append(metaProp("og:type", "article")).
append(metaProp("og:description", getProperty("ui.list.pageDescription"))).
append(meta("date", dateGenerated)).
append("\t\t<title>").append(getProperty("ui.list.documentTitle")).append("</title>").append(NEWLINE).
append("\t</head>").append(NEWLINE);
return sb.toString();
}
public static String getDocsForIns(InstructionDefinition def, boolean showDataSize, boolean ui, boolean standalone) {
final String cacheKey = def.instructionName + "|" + (showDataSize ? 1 : 0) + "|" + (ui ? 1 : 0) + "|" + (standalone ? 1 : 0);
String v = docsCache.get(cacheKey);
@@ -267,23 +214,6 @@ public class As3PCodeDocs {
return r;
}
public static String getStyle() {
String cached = docsCache.get("__style");
if (cached != null) {
return cached;
}
String style = "";
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found");
} else {
style = new String(Helper.readStream(is), Utf8Helper.charset);
}
docsCache.put("__style", style);
return style;
}
public static String getJs() {
String cached = docsCache.get("__js");
if (cached != null) {
@@ -301,12 +231,6 @@ public class As3PCodeDocs {
return js;
}
private static String getISO8601StringForDate(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(date);
}
public static String getAllInstructionDocs() {
String jsData = "";
@@ -353,4 +277,35 @@ public class As3PCodeDocs {
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(getAllInstructionDocs());
}
protected static String htmlHeader(String js, String style) {
Date dateGenerated = new Date();
StringBuilder sb = new StringBuilder();
sb.append("<!DOCTYPE html>").append(NEWLINE).
append("<html>").append(NEWLINE).
append("\t<head>").append(NEWLINE);
if (style != null && !style.isEmpty()) {
sb.append("\t\t<style>").append(style).append("</style>").append(NEWLINE);
}
if (js != null && !js.isEmpty()) {
sb.append("\t\t<script>").append(js).append("</script>").append(NEWLINE);
}
sb.append("\t\t<meta charset=\"UTF-8\">").append(NEWLINE).
append(meta("generator", ApplicationInfo.applicationVerName)).
append(meta("description", getProperty("ui.list.pageDescription"))).
append(metaProp("og:title", getProperty("ui.list.pageTitle"))).
append(metaProp("og:type", "article")).
append(metaProp("og:description", getProperty("ui.list.pageDescription"))).
append(meta("date", dateGenerated)).
append("\t\t<title>").append(getProperty("ui.list.documentTitle")).append("</title>").append(NEWLINE).
append("\t</head>").append(NEWLINE);
return sb.toString();
}
protected static String getProperty(String name) {
if (prop.containsKey(name)) {
return Helper.escapeHTML(prop.getString(name));
}
return null;
}
}

View File

@@ -0,0 +1,102 @@
package com.jpexs.decompiler.flash.docs;
import com.jpexs.decompiler.flash.ApplicationInfo;
import static com.jpexs.decompiler.flash.docs.As3PCodeDocs.NEWLINE;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
public class As3PCodeOtherDocs extends AbstractDocs {
static ResourceBundle prop;
static final String NEWLINE = "\r\n";
static {
prop = ResourceBundle.getBundle("com.jpexs.decompiler.flash.locales.docs.pcode.AS3other");
}
public static String getDocsForPath(String path) {
return getDocsForPath(path, true);
}
private static String getDocsForPath(String path, boolean standalone) {
final String cacheKey = path + "|" + (standalone ? 1 : 0);
String v = docsCache.get(cacheKey);
if (v != null) {
return v;
}
String docStr = "";
String pathNoTrait = path;
if (path.startsWith("trait.method")) {
pathNoTrait = path.substring("trait.".length());
}
if (prop.containsKey(pathNoTrait)) {
docStr = prop.getString(pathNoTrait);
}
StringBuilder sb = new StringBuilder();
if (standalone) {
sb.append(htmlHeader("", getStyle()));
}
sb.append("<");
sb.append(standalone ? "body" : "div");
sb.append(" class=\"otherdoc\"");
sb.append(">");
sb.append(docStr);
sb.append("</");
sb.append(standalone ? "body" : "div"); //.instruction
sb.append(">").append(NEWLINE);
if (standalone) {
sb.append(htmlFooter());
}
String r = sb.toString();
docsCache.put(cacheKey, r);
return r;
}
protected static String htmlHeader(String js, String style) {
Date dateGenerated = new Date();
StringBuilder sb = new StringBuilder();
sb.append("<!DOCTYPE html>").append(NEWLINE).
append("<html>").append(NEWLINE).
append("\t<head>").append(NEWLINE);
if (style != null && !style.isEmpty()) {
sb.append("\t\t<style>").append(style).append("</style>").append(NEWLINE);
}
if (js != null && !js.isEmpty()) {
sb.append("\t\t<script>").append(js).append("</script>").append(NEWLINE);
}
sb.append("\t\t<meta charset=\"UTF-8\">").append(NEWLINE).
append(meta("generator", ApplicationInfo.applicationVerName)).
append(meta("description", getProperty("ui.list.pageDescription"))).
append(metaProp("og:title", getProperty("ui.list.pageTitle"))).
append(metaProp("og:type", "article")).
append(metaProp("og:description", getProperty("ui.list.pageDescription"))).
append(meta("date", dateGenerated)).
append("\t\t<title>").append(getProperty("ui.list.documentTitle")).append("</title>").append(NEWLINE).
append("\t</head>").append(NEWLINE);
return sb.toString();
}
protected static String getProperty(String name) {
if (prop.containsKey(name)) {
return Helper.escapeHTML(prop.getString(name));
}
return null;
}
}

View File

@@ -1,5 +1,6 @@
html, body {margin:0px; padding: 0px;}
.instruction {background-color: #f5f5b5; color:black;}
.otherdoc {background-color: #f5f5b5; color:black;}
li.instruction-item {list-style:none; padding:0px;border:1px solid black; border-bottom:none; border-collapse:collapse; }
ul.instruction-list {padding-left:0; display:table; border-bottom:1px solid black;}
strong.instruction-name {font-weight: bold; color: blue;}

View File

@@ -0,0 +1,92 @@
# Copyright (C) 2010-2016 JPEXS, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
ui.list.heading = AVM2 p-code
ui.list.pageTitle = AVM2 p-code
ui.list.documentTitle = AVM2 p-code
ui.list.pageDescription = List of p-code settings
name.QName = Qualified Name
name.QNameA = Qualified Name of Attribute
name.RTQName = Runtime Qualified Name
name.RTQNameA = Runtime Qualified Name of Attribute
name.RTQNameL = Runtime Qualified Name Late
name.RTQNameLA = Runtime Qualified Name Late of Attribute
name.Multiname = Multiple Namespace Name
name.MultinameA = Multiple Namespace Name of Attribute
name.MultinameL = Multiple Namespace Name Late
name.MultinameLA = Multiple Namespace Name Late of Attribute
name.TypeName = Type Name
namespacekind.Namespace = Namespace
namespacekind.PrivateNamespace = Private Namespace
namespacekind.PackageNamespace = Package Namespace
namespacekind.PackageInternalNs = Package Internal Namespace
namespacekind.ProtectedNamespace = Protected Namespace
namespacekind.ExplicitNamespace = Explicit Namespace
namespacekind.StaticProtectedNs = Static Protected Namespace
trait = Trait
#types:
trait.method = Trait of type method
trait.slot = Trait of type slot
trait.const = Trait of type const
trait.method = Trait of type method
trait.setter = Trait of type setter
trait.getter = Trait of type getter
trait.class = Trait of type class
trait.function = Trait of type function
trait.metadata = Metadata
trait.metadata.item = One metadata item
trait.metadata.end = End of metadata
trait.flag = Trait flag
trait.flag.METADATA = Trait has metadata attached
trait.flag.FINAL = Trais if final
trait.flag.OVERRIDE = Trait overrides parent
#method/getter/setter
trait.dispid = Dispatch id
#slot/const/class/function
trait.slotid = Slot id
method = Method
method.name = Name of the method
method.flag = Method flag
method.flag.NEED_ARGUMENTS = Create "arguments" object in register method_info.param_count+1
method.flag.NEED_ACTIVATION = This method uses newactivation instruction
method.flag.NEED_REST = Create rest arguments array in register method_info.param_count+1
method.flag.HAS_OPTIONAL = This method has optional arguments
method.flag.IGNORE_REST = ??
method.flag.EXPLICIT = ??
method.flag.SETSDXNS = This method uses dxns or dxnslate instructions
method.flag.HAS_PARAMNAMES = This method has parameter names in method_info
method.param = Type of parameter
method.paramname = Name of parameter
method.optional = Default value for optional parameter
method.returns = Return type of method
method.body = Body of method
method.body.maxstack = Maximum number of stack slots at any point of execution
method.body.localcount = Index of highest-numbered local register plus one
method.body.initscopedepth = Minimum scope depth (relative to maxscopedepth) that may be accessed
method.body.maxscopedepth = Maximum scope depth that may be accessed
method.body.try = Exception block
method.body.try.from = Starting position from which exception is enabled
method.body.try.to = Ending position after which the exception is disabled
method.body.try.target = Position to which control should jump if exception of this type is thrown
method.body.try.type = Type of catched exception
method.body.try.name = Name of the exception object
method.body.code = Code of the method body