Class RMASNode
- java.lang.Object
-
- com.reportmill.flash.RMASNode
-
public final class RMASNode extends java.lang.Object
RMASNode is the class used by the parser to construct a tree representation of an ActionScript file based on the parser grammar.Encoding a tree of nodes to the binary Flash file format is performed in four stages:
1. First the nodes in the tree are re-ordered. This is used to move function definitions to the start of the block they are defined in - matching the behaviour performed by the Flash authoring application and making regression testing of the code generated against the code generated by Flash much easier.
2. then the node tree is searched for string literals, identifier and function names to construct a table of strings that is added to the start of the script, References to strings can then be made by specifying an index into the table rathe than pushing the string onto the Flash Player's stack - greatly reducing the size of the code.
3. The node tree is translated into an array of action objects. This intermediate step is required to calculate the relative branches and jumps performed when implementing if..else statements and construct such as for and while loops.
4. The array of actions generated by the translation step is then encoded to the binary data format support by Flash.
-
-
Field Summary
Fields Modifier and Type Field Description static int
Add
static int
And
static int
ASR
static int
Assign
static int
AssignAdd
static int
AssignASR
static int
AssignBitAnd
static int
AssignBitOr
static int
AssignBitXOr
static int
AssignDiv
static int
AssignLSL
static int
AssignLSR
static int
AssignMod
static int
AssignMul
static int
AssignSub
static int
Attribute
static int
BitAnd
static int
BitNot
static int
BitOr
static int
BitXOr
static int
Break
static int
Button
static java.util.HashMap
buttonEvents
static java.util.HashMap
clipEvents
static int
Continue
static int
DefineArray
static int
DefineAttribute
static int
DefineFunction
static int
DefineMethod
static int
DefineObject
static int
DefineVariable
static int
Div
static int
Do
static int
Equal
static int
For
static int
ForIn
static int
Frame
static int
Function
static int
GreaterThan
static int
GreaterThanEqual
static int
Identifier
static int
If
static int
LessThan
static int
LessThanEqual
static int
List
static int
Literal
static int
LSL
static int
LSR
static int
Method
static int
Minus
static int
Mod
static int
MovieClip
static int
Mul
static int
NewObject
static int
NoOp
static int
Not
static int
NotEqual
static int
On
static int
OnClipEvent
static int
Or
static int
Plus
static int
PostDec
static int
PostInc
static int
PreDec
static int
PreInc
static int
Return
static int
Select
static int
Sub
static int
Subscript
static int
Value
static int
While
static int
With
-
Constructor Summary
Constructors Constructor Description RMASNode(int nodeType)
Constructs an RMASNode with the specified type.RMASNode(int nodeType, int value)
Constructs an RMASNode with the specified type and integer value.RMASNode(int nodeType, RMASNode node)
Constructs an RMASNode with the specified type and adds the child node.RMASNode(int nodeType, RMASNode node1, RMASNode node2)
Constructs an RMASNode with the specified type and adds the child nodes.RMASNode(int nodeType, java.lang.String value)
Constructs an RMASNode with the specified type and string value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(RMASNode aNode)
Adds a node to the array of children.int
count()
Return the number of child nodes contained by this node.void
displayTree(java.lang.String prefix)
displayTree is used to display the structure of the node tree, with the root starting at the current node.byte[]
encode(int version)
The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player.RMASNode
get(int index)
Returns the node at the specified index from the array of child nodes.int
getIntValue()
Get the integer value assigned to a node.int
getNumber()
Get the number assigned to a node.RMASNode
getParent()
Gets the parent node of this one.java.lang.String
getStringValue()
Get the string value assigned to a node.int
getType()
Gets the type of the node.int
indexOf(RMASNode aNode)
Returns the index position of a node in the array of child nodes.void
insert(int index, RMASNode aNode)
Inserts a node at position i in the array of children.void
remove(int index)
Removes the node at position i in the array of children.void
set(int i, RMASNode aNode)
Replaces the node at position i in the array of children.void
setIntValue(int value)
Set the integer value assigned to a node.void
setNumber(int value)
Set the number assigned to a node.void
setStringValue(java.lang.String value)
Set the string value assigned to a node.void
setType(int type)
Sets the type of the node.java.lang.String
toString()
Returns a string containing the type of node, any associated value and the number of children.void
validate()
validate is used to provide additional error checking not covered in the parser grammar.
-
-
-
Field Detail
-
Frame
public static final int Frame
- See Also:
- Constant Field Values
-
Button
public static final int Button
- See Also:
- Constant Field Values
-
MovieClip
public static final int MovieClip
- See Also:
- Constant Field Values
-
List
public static final int List
- See Also:
- Constant Field Values
-
NoOp
public static final int NoOp
- See Also:
- Constant Field Values
-
If
public static final int If
- See Also:
- Constant Field Values
-
For
public static final int For
- See Also:
- Constant Field Values
-
ForIn
public static final int ForIn
- See Also:
- Constant Field Values
-
While
public static final int While
- See Also:
- Constant Field Values
-
Do
public static final int Do
- See Also:
- Constant Field Values
-
With
public static final int With
- See Also:
- Constant Field Values
-
OnClipEvent
public static final int OnClipEvent
- See Also:
- Constant Field Values
-
On
public static final int On
- See Also:
- Constant Field Values
-
Break
public static final int Break
- See Also:
- Constant Field Values
-
Return
public static final int Return
- See Also:
- Constant Field Values
-
Continue
public static final int Continue
- See Also:
- Constant Field Values
-
Value
public static final int Value
- See Also:
- Constant Field Values
-
Literal
public static final int Literal
- See Also:
- Constant Field Values
-
Identifier
public static final int Identifier
- See Also:
- Constant Field Values
-
Attribute
public static final int Attribute
- See Also:
- Constant Field Values
-
Method
public static final int Method
- See Also:
- Constant Field Values
-
Function
public static final int Function
- See Also:
- Constant Field Values
-
NewObject
public static final int NewObject
- See Also:
- Constant Field Values
-
Subscript
public static final int Subscript
- See Also:
- Constant Field Values
-
DefineFunction
public static final int DefineFunction
- See Also:
- Constant Field Values
-
DefineArray
public static final int DefineArray
- See Also:
- Constant Field Values
-
DefineObject
public static final int DefineObject
- See Also:
- Constant Field Values
-
DefineMethod
public static final int DefineMethod
- See Also:
- Constant Field Values
-
DefineAttribute
public static final int DefineAttribute
- See Also:
- Constant Field Values
-
DefineVariable
public static final int DefineVariable
- See Also:
- Constant Field Values
-
Add
public static final int Add
- See Also:
- Constant Field Values
-
Sub
public static final int Sub
- See Also:
- Constant Field Values
-
Mul
public static final int Mul
- See Also:
- Constant Field Values
-
Div
public static final int Div
- See Also:
- Constant Field Values
-
Mod
public static final int Mod
- See Also:
- Constant Field Values
-
LSL
public static final int LSL
- See Also:
- Constant Field Values
-
ASR
public static final int ASR
- See Also:
- Constant Field Values
-
LSR
public static final int LSR
- See Also:
- Constant Field Values
-
BitAnd
public static final int BitAnd
- See Also:
- Constant Field Values
-
BitOr
public static final int BitOr
- See Also:
- Constant Field Values
-
BitXOr
public static final int BitXOr
- See Also:
- Constant Field Values
-
And
public static final int And
- See Also:
- Constant Field Values
-
Or
public static final int Or
- See Also:
- Constant Field Values
-
Equal
public static final int Equal
- See Also:
- Constant Field Values
-
NotEqual
public static final int NotEqual
- See Also:
- Constant Field Values
-
GreaterThan
public static final int GreaterThan
- See Also:
- Constant Field Values
-
LessThan
public static final int LessThan
- See Also:
- Constant Field Values
-
GreaterThanEqual
public static final int GreaterThanEqual
- See Also:
- Constant Field Values
-
LessThanEqual
public static final int LessThanEqual
- See Also:
- Constant Field Values
-
Select
public static final int Select
- See Also:
- Constant Field Values
-
Not
public static final int Not
- See Also:
- Constant Field Values
-
BitNot
public static final int BitNot
- See Also:
- Constant Field Values
-
Plus
public static final int Plus
- See Also:
- Constant Field Values
-
Minus
public static final int Minus
- See Also:
- Constant Field Values
-
PreInc
public static final int PreInc
- See Also:
- Constant Field Values
-
PreDec
public static final int PreDec
- See Also:
- Constant Field Values
-
PostInc
public static final int PostInc
- See Also:
- Constant Field Values
-
PostDec
public static final int PostDec
- See Also:
- Constant Field Values
-
Assign
public static final int Assign
- See Also:
- Constant Field Values
-
AssignAdd
public static final int AssignAdd
- See Also:
- Constant Field Values
-
AssignSub
public static final int AssignSub
- See Also:
- Constant Field Values
-
AssignMul
public static final int AssignMul
- See Also:
- Constant Field Values
-
AssignDiv
public static final int AssignDiv
- See Also:
- Constant Field Values
-
AssignMod
public static final int AssignMod
- See Also:
- Constant Field Values
-
AssignLSL
public static final int AssignLSL
- See Also:
- Constant Field Values
-
AssignASR
public static final int AssignASR
- See Also:
- Constant Field Values
-
AssignLSR
public static final int AssignLSR
- See Also:
- Constant Field Values
-
AssignBitAnd
public static final int AssignBitAnd
- See Also:
- Constant Field Values
-
AssignBitOr
public static final int AssignBitOr
- See Also:
- Constant Field Values
-
AssignBitXOr
public static final int AssignBitXOr
- See Also:
- Constant Field Values
-
buttonEvents
public static java.util.HashMap buttonEvents
-
clipEvents
public static java.util.HashMap clipEvents
-
-
Constructor Detail
-
RMASNode
public RMASNode(int nodeType)
Constructs an RMASNode with the specified type.- Parameters:
nodeType
- the type of node being constructed.
-
RMASNode
public RMASNode(int nodeType, int value)
Constructs an RMASNode with the specified type and integer value. This constructor is primarily used to create nodes representing integer literals.- Parameters:
nodeType
- the type of node being constructed.value
- the integer value assigned to the node.
-
RMASNode
public RMASNode(int nodeType, java.lang.String value)
Constructs an RMASNode with the specified type and string value. This constructor is primarily used to create string literals and identifiers.- Parameters:
nodeType
- the type of node being constructed.value
- the string assigned to the node.
-
RMASNode
public RMASNode(int nodeType, RMASNode node)
Constructs an RMASNode with the specified type and adds the child node.- Parameters:
nodeType
- the type of node being constructed.node
- a child node which will be added to the new node.
-
RMASNode
public RMASNode(int nodeType, RMASNode node1, RMASNode node2)
Constructs an RMASNode with the specified type and adds the child nodes.- Parameters:
nodeType
- the type of node being constructed.node1
- a child node which will be added to the new node.node2
- a child node which will be added to the new node.
-
-
Method Detail
-
getType
public int getType()
Gets the type of the node.- Returns:
- the type assigned to the node.
-
setType
public void setType(int type)
Sets the type of the node.- Parameters:
type
- the type assigned to the node.
-
getIntValue
public int getIntValue()
Get the integer value assigned to a node.- Returns:
- the integer value assigned to a node.
-
setIntValue
public void setIntValue(int value)
Set the integer value assigned to a node.- Parameters:
value
- a value that will be assigned to the node.
-
getStringValue
public java.lang.String getStringValue()
Get the string value assigned to a node.- Returns:
- the string value assigned to a node.
-
setNumber
public void setNumber(int value)
Set the number assigned to a node.- Parameters:
value
- a unique number that will be assigned to the node.
-
getNumber
public int getNumber()
Get the number assigned to a node.- Returns:
- the number assigned to a node.
-
setStringValue
public void setStringValue(java.lang.String value)
Set the string value assigned to a node.- Parameters:
value
- a string that will be assigned to the node.
-
get
public RMASNode get(int index)
Returns the node at the specified index from the array of child nodes. If the index is outside the range of the array then an ArrayIndexOutOfBounds exception is thrown.- Parameters:
index
- the index of the child node to return.- Returns:
- the ith node in the array of children.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
set
public void set(int i, RMASNode aNode)
Replaces the node at position i in the array of children. If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.- Parameters:
i
- the index of the child node to replace.aNode
- the node to replace the ith node.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
add
public void add(RMASNode aNode)
Adds a node to the array of children. If the node is null then it is ignored.- Parameters:
aNode
- the node to be added.
-
insert
public void insert(int index, RMASNode aNode)
Inserts a node at position i in the array of children. The size of the array is increased by one and the nodes from the insertion point onwards are moved to the right.If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.
- Parameters:
index
- the index of the child node to replace.aNode
- the node to replace the ith node.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
remove
public void remove(int index)
Removes the node at position i in the array of children. The size of the array is decreased by one and the nodes from the insertion point onwards are moved to the left.If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.
- Parameters:
index
- the index of the child node to remove.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
indexOf
public int indexOf(RMASNode aNode)
Returns the index position of a node in the array of child nodes. If the node is not one of the current nodes children then -1 is returned.- Parameters:
aNode
- the node to search the array of children for.- Returns:
- the index of the node in the array of children, -1 if the node is not a child of this node.
-
getParent
public RMASNode getParent()
Gets the parent node of this one. If no parent is define then null is returned.- Returns:
- the parent node of this one.
-
count
public int count()
Return the number of child nodes contained by this node.- Returns:
- the number of child nodes.
-
toString
public java.lang.String toString()
Returns a string containing the type of node, any associated value and the number of children.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string representation of the node.
-
displayTree
public void displayTree(java.lang.String prefix)
displayTree is used to display the structure of the node tree, with the root starting at the current node. The prefix argument is used to ident the text displayed. The level of indent is increased by appending the string " " before calling the displayTree method on each child node. This illustrates the tree structure with nodes at the same level in the tree displayed with the same level of indent.- Parameters:
prefix
- the string prepended to the text representation for this node.
-
encode
public byte[] encode(int version)
The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player. The actions are then encoded to generate the binary data that can be added to an encoded Flash file.The version of Flash for which the actions are generated is specified to ensure compatibility with future release of Flash.
IMPORTANT: The programming model changed with Flash version 5 to support stack-based actions. Earlier versions of Flash are not support. An IllegalArgumentexception will be thrown if the version is earlier than 5.
- Parameters:
version
- the version of Flash that control the actions that are generated.version
- the version of Flash that the script should be encoded for.- Returns:
- an array of bytes containing encoded action objects.
- Throws:
IllegalArgumentexception
- is the version is less than 5.
-
validate
public void validate() throws ParseException
validate is used to provide additional error checking not covered in the parser grammar.- Throws:
ParseException
-
-