1 /*
2   take a stack, turn it into a tree.
3   e.g.:
4 
5   cmd        stack
6   push 'a'   'a'
7   push 'a'   'a' 'a'
8   getvar     'a'  a
9   push '1'   'a'  a   1
10   add        'a'  a+1
11   setvar     a = a+1
12 
13   when all that's left on the stack is a tree, you've got a statement.
14 
15   read everything into a list of statements, noting offsets and branches.
16   step through list, resolving branches into if/else/while/do:
17 
18   if branch backwards, it's a do (or while(true))
19 
20   if forwards, check instruction before branch target:
21 	 if a branch, this is either:
22            branch backwards- while
23            branch forwards- if/else
24 
25   inside loop, continue jumps to beginning, break jumps to end.
26 */
27 
28 #include "action.h"
29 #include "swftypes.h"
30 
31 struct _stack;
32 
33 struct _tree
34 {
35   struct _stack *left;
36   struct _stack *right;
37   Action action;
38 };
39 typedef struct _tree *Tree;
40 
41 struct _stack
42 {
43   struct _stack *next;
44   char type; /* (s)tring, (t)ree, (p)roperty, (b)ranch, (i)nt, (d)ouble, (r)register */
45   char seenit;
46   union
47   {
48     const char *string;
49     int inum;
50     double dnum;
51     int reg;
52     Tree tree;
53     Property prop;
54     int *iptr;
55     struct _stack **sptr;
56   } data;
57 
58   int offset;
59   int target; /* statement number which branches to this statement */
60 };
61 typedef struct _stack *Stack;
62 
63 char *decompile5Action(int n, SWF_ACTION *actions,int indent);
64 
65 void setNewLineString(const char* ch);
66