flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - add -sort option to SWFDump to make it easier to compare two SWFs. Otherwise the order in the SWF of some dependencies can appear to vary depending on when the various threads discovered those dependencie
Date Fri, 02 Sep 2016 15:16:23 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 30616f658 -> 313f27b96


add -sort option to SWFDump to make it easier to compare two SWFs.  Otherwise the order in
the SWF of some dependencies can appear to vary depending on when the various threads discovered
those dependencies


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/313f27b9
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/313f27b9
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/313f27b9

Branch: refs/heads/develop
Commit: 313f27b962e49aa45fc801ee99e794667d030ca6
Parents: 30616f6
Author: Alex Harui <aharui@apache.org>
Authored: Fri Sep 2 08:16:09 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Sep 2 08:16:09 2016 -0700

----------------------------------------------------------------------
 .../apache/flex/abc/print/ABCDumpVisitor.java   | 55 ++++++++++++++---
 .../units/requests/ABCBytesRequestResult.java   |  2 +-
 .../java/org/apache/flex/swf/io/SWFDump.java    | 62 ++++++++++++++++++--
 3 files changed, 106 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/313f27b9/compiler/src/main/java/org/apache/flex/abc/print/ABCDumpVisitor.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/abc/print/ABCDumpVisitor.java b/compiler/src/main/java/org/apache/flex/abc/print/ABCDumpVisitor.java
index cecf4fc..c58148f 100644
--- a/compiler/src/main/java/org/apache/flex/abc/print/ABCDumpVisitor.java
+++ b/compiler/src/main/java/org/apache/flex/abc/print/ABCDumpVisitor.java
@@ -45,8 +45,10 @@ import java.io.FileInputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -92,13 +94,15 @@ public class ABCDumpVisitor extends PoolingABCVisitor
      *
      * @param p The PrintWriter to write the textual represention of the ABC to
      */
-    public ABCDumpVisitor (PrintWriter p)
+    public ABCDumpVisitor (PrintWriter p, boolean sortOption)
     {
         super();
         printer = new IndentingPrinter(p, 0, 2);
         dumpedMethods = new HashSet<MethodInfo>();
+        this.sortOption = sortOption;
     }
 
+    private boolean sortOption;
     private IndentingPrinter printer;
     private Set<MethodInfo> dumpedMethods;
 
@@ -275,10 +279,33 @@ public class ABCDumpVisitor extends PoolingABCVisitor
     {
         int nScripts = getScriptInfos().size();
         ScriptInfo si;
-        for (int i = 0; i < nScripts; ++i)
+        if (sortOption)
         {
-            si = getScriptInfos().get(i);
-            traverseScript(i, si);
+            HashMap<String, ScriptInfo> scripts = new HashMap<String, ScriptInfo>();
+            for (int i = 0; i < nScripts; ++i)
+            {
+                si = getScriptInfos().get(i);
+                Iterator<Trait> traits = si.getTraits().iterator();
+                Name name = traits.hasNext() ? traits.next().getName() : null;
+                String scriptName = name != null ? name.getSingleQualifier().getName() +
"." + name.getBaseName() : "";
+                scripts.put(scriptName, si);
+            }
+            ArrayList<String> nameList = new ArrayList<String>();
+            nameList.addAll(scripts.keySet());
+            Collections.sort(nameList);
+            for (int i = 0; i < nScripts; ++i)
+            {
+                si = scripts.get(nameList.get(i));
+                traverseScript(i, si);
+            }            
+        }
+        else
+        {
+            for (int i = 0; i < nScripts; ++i)
+            {
+                si = getScriptInfos().get(i);
+                traverseScript(i, si);
+            }
         }
     }
 
@@ -655,7 +682,10 @@ public class ABCDumpVisitor extends PoolingABCVisitor
                 if (i < entries.size() - 1)
                     sb.append(", ");
             }
-            printer.println("[" + mid.getName() + "(" + sb.toString() + ")]" + " // metadata_id="
+ mid);
+            if (sortOption && mid.getName().contains("_definition_help"))
+                printer.println("[" + mid.getName() + "(xxxx)]");
+            else
+                printer.println("[" + mid.getName() + "(" + sb.toString() + ")]");
         }
     }
 
@@ -807,7 +837,8 @@ public class ABCDumpVisitor extends PoolingABCVisitor
                 for (IBasicBlock s : succs)
                     succNames.add(blockNames.get(s));
 
-                printer.println("succs=[" + joinOn(",", succNames) + "]");
+                if (!sortOption)
+                    printer.println("succs=[" + joinOn(",", succNames) + "]");
                 /*
                 // TODO: implement this with FrameModelEncoder
                 if(mb.blocks[i].state != null) {
@@ -833,6 +864,16 @@ public class ABCDumpVisitor extends PoolingABCVisitor
                         switch (inst.getOpcode())
                         {
                             case OP_debugfile:
+                                if (sortOption)
+                                {
+                                    String fileName = (String) inst.getOperand(0);
+                                    fileName = fileName.substring(fileName.indexOf(";"));
+                                    fileName = fileName.replace("\\", "/");
+                                    constantStr = "\"" + stringToEscapedString(fileName)
+ "\"";
+                                }
+                                else
+                                    constantStr = "\"" + stringToEscapedString((String) inst.getOperand(0))
+ "\"";
+                                break;
                             case OP_pushstring:
                                 constantStr = "\"" + stringToEscapedString((String) inst.getOperand(0))
+ "\"";
                                 break;
@@ -1057,7 +1098,7 @@ public class ABCDumpVisitor extends PoolingABCVisitor
             if (f.exists())
             {
                 ABCParser parser = new ABCParser(new BufferedInputStream(new FileInputStream(f)));
-                PoolingABCVisitor printer = new ABCDumpVisitor(new PrintWriter(System.out));
+                PoolingABCVisitor printer = new ABCDumpVisitor(new PrintWriter(System.out),
false);
                 parser.parseABC(printer);
             }
         }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/313f27b9/compiler/src/main/java/org/apache/flex/compiler/internal/units/requests/ABCBytesRequestResult.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/units/requests/ABCBytesRequestResult.java
b/compiler/src/main/java/org/apache/flex/compiler/internal/units/requests/ABCBytesRequestResult.java
index ae5469f..452d1e9 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/units/requests/ABCBytesRequestResult.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/units/requests/ABCBytesRequestResult.java
@@ -137,7 +137,7 @@ public class ABCBytesRequestResult implements IABCBytesRequestResult
         catch (IOException e)
         {
         }
-        parser.parseABC(new ABCDumpVisitor(out));
+        parser.parseABC(new ABCDumpVisitor(out, false));
         
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/313f27b9/compiler/src/main/java/org/apache/flex/swf/io/SWFDump.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/swf/io/SWFDump.java b/compiler/src/main/java/org/apache/flex/swf/io/SWFDump.java
index 6d6c22b..78bee7c 100644
--- a/compiler/src/main/java/org/apache/flex/swf/io/SWFDump.java
+++ b/compiler/src/main/java/org/apache/flex/swf/io/SWFDump.java
@@ -32,8 +32,11 @@ import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.DateFormat;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 import org.apache.commons.io.IOUtils;
@@ -120,9 +123,39 @@ public final class SWFDump
                 if (swf.getFrameCount() > 0)
                     currentFrame = swf.getFrameAt(0);
 
+                HashMap<String, ITag> abcTags = new HashMap<String, ITag>();
                 for (ITag tag : tags)
                 {
-                    dumpTag(tag);
+                    if (sortOption)
+                    {
+                        if (tag.getTagType() == TagType.DoABC)
+                        {
+                            DoABCTag abcTag = (DoABCTag)tag;
+                            abcTags.put(abcTag.getName(), tag);
+                        }
+                        else if (tag.getTagType() == TagType.ShowFrame)
+                        {
+                            if (abcTags.size() > 0)
+                            {
+                                ArrayList<String> nameList = new ArrayList<String>();
+                                nameList.addAll(abcTags.keySet());
+                                Collections.sort(nameList);
+                                for (String name : nameList)
+                                {
+                                    ITag abcTag = abcTags.get(name);
+                                    dumpTag(abcTag);
+                                }
+                            }
+                            dumpTag(tag);
+                            abcTags = new HashMap<String, ITag>();
+                        }
+                        else
+                            dumpTag(tag);
+                    }
+                    else
+                    {
+                        dumpTag(tag);
+                    }
                     if (tag.getTagType() == TagType.ShowFrame)
                     {
                         currentFrameIndex++;
@@ -458,7 +491,10 @@ public final class SWFDump
                     "\"" + " >");
         indent++;
         indent();
-        out.println("<!-- framecount=" + h.getFrameCount() + " length=" + h.getLength()
+ " -->");
+        if (sortOption)
+            out.println("<!-- framecount=" + h.getFrameCount() + " length might be different
because of debugfile paths -->");
+        else
+            out.println("<!-- framecount=" + h.getFrameCount() + " length=" + h.getLength()
+ " -->");
     }
 
     public void dumpProductInfo(ProductInfoTag productInfo)
@@ -479,7 +515,12 @@ public final class SWFDump
         end();
         indent();
         openCDATA();
-        out.println(tag.getMetadata());
+        String metaData = tag.getMetadata();
+        if (sortOption)
+        {
+            metaData = metaData.replaceAll("build=\".*\"", "");
+        }
+        out.println(metaData);
         closeCDATA();
         close(tag);
     }
@@ -2242,7 +2283,7 @@ public final class SWFDump
             open(tag);
             end();
             ABCParser parser = new ABCParser(tag.getABCData());
-            PoolingABCVisitor printer = new ABCDumpVisitor(out);
+            PoolingABCVisitor printer = new ABCDumpVisitor(out, sortOption);
             parser.parseABC(printer);
             close(tag);
         }
@@ -2332,6 +2373,7 @@ public final class SWFDump
     static boolean decompileOption = true;
     static boolean defuncOption = true;
     static boolean saveOption = false;
+    static boolean sortOption = false;
     static boolean tabbedGlyphsOption = true;
     static boolean uncompressOption = false;
 
@@ -2372,6 +2414,15 @@ public final class SWFDump
                 saveOption = true;
                 outfile = args[index++];
             }
+            else if (args[index].equals("-sort"))
+            {
+                // Try to sort output by alpha-order of identifiers
+                // so compare of two dumps compare better.
+                // There is some randomness in the order of output
+                // of some scripts
+                ++index;
+                sortOption = true;
+            }
             else if (args[index].equals("-uncompress"))
             {
                 ++index;
@@ -2572,7 +2623,8 @@ public final class SWFDump
             throws IOException
     {
         out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-        out.println("<!-- Parsing swf " + url + " -->");
+        if (!sortOption)
+            out.println("<!-- Parsing swf " + url + " -->");
         SWFDump swfDump = new SWFDump(out);
 
         // TODO: Disable options


Mime
View raw message