Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Adding consts and vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Richardson committed Apr 10, 2012
1 parent 1164668 commit 2d23417
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/com/codeazur/as3swf/data/abc/bytecode/ABCMethodInfo.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package com.codeazur.as3swf.data.abc.bytecode
public var label:String;
public var flags:uint;
public var optionalTotal:int;
// TODO (Simon) Implement is static
public var isStatic:Boolean;

public function ABCMethodInfo(abcData:ABCData) {
super(abcData);
Expand Down Expand Up @@ -67,8 +69,6 @@ package com.codeazur.as3swf.data.abc.bytecode
methodName = getMethodName(label);
methodNamespace = getMethodNamespace(label);

trace(">>", label, methodName);

flags = data.readUI8();

if(hasOptional) {
Expand Down
97 changes: 93 additions & 4 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectClass.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package com.codeazur.as3swf.data.abc.reflect
import com.codeazur.as3swf.data.abc.bytecode.ABCInstanceInfo;
import com.codeazur.as3swf.data.abc.bytecode.ABCMethodInfo;
import com.codeazur.as3swf.data.abc.bytecode.multiname.ABCQualifiedName;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitConstInfo;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitInfo;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitInfoKind;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitSlotInfo;
/**
* @author Simon Richardson - simon@ustwo.co.uk
*/
public class ABCReflectClass extends ABCReflectInstance {

private var _instance:ABCInstanceInfo;
private var _constants:Vector.<ABCReflectConstant>;
private var _variables:Vector.<ABCReflectVariable>;
private var _methods:Vector.<ABCReflectMethod>;
private var _getters:Vector.<ABCReflectGetter>;
private var _setters:Vector.<ABCReflectSetter>;
Expand Down Expand Up @@ -38,6 +43,56 @@ package com.codeazur.as3swf.data.abc.reflect
setters:Vector.<ABCMethodInfo>):ABCReflectClass {
return new ABCReflectClass(instance, methods, getters, setters);
}

public function getConstants(visbility:ABCReflectMemberVisibility=null):Vector.<ABCReflectConstant> {
visbility = visbility || ABCReflectMemberVisibility.ALL;

const instances:Vector.<ABCReflectConstant> = new Vector.<ABCReflectConstant>();

if(!_constants) {
populateConstants();
}

const total:uint = _constants.length;
for(var i:uint=0; i<total; i++) {
const constant:ABCReflectConstant = _constants[i];
if(constant.multiname && constant.multiname is ABCQualifiedName) {
const qname:ABCQualifiedName = ABCQualifiedName(constant.multiname);
if(qname.ns) {
const constVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(constVisbility, visbility)) {
instances.push(constant);
}
}
}
}
return instances;
}

public function getVariables(visbility:ABCReflectMemberVisibility=null):Vector.<ABCReflectVariable> {
visbility = visbility || ABCReflectMemberVisibility.ALL;

const instances:Vector.<ABCReflectVariable> = new Vector.<ABCReflectVariable>();

if(!_variables) {
populateVariables();
}

const total:uint = _variables.length;
for(var i:uint=0; i<total; i++) {
const variable:ABCReflectVariable = _variables[i];
if(variable.multiname && variable.multiname is ABCQualifiedName) {
const qname:ABCQualifiedName = ABCQualifiedName(variable.multiname);
if(qname.ns) {
const constVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(constVisbility, visbility)) {
instances.push(variable);
}
}
}
}
return instances;
}

public function getMethods(visbility:ABCReflectMemberVisibility=null):Vector.<ABCReflectMethod> {
visbility = visbility || ABCReflectMemberVisibility.ALL;
Expand Down Expand Up @@ -79,8 +134,8 @@ package com.codeazur.as3swf.data.abc.reflect
if(getter.multiname && getter.multiname is ABCQualifiedName) {
const qname:ABCQualifiedName = ABCQualifiedName(getter.multiname);
if(qname.ns) {
const methodVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(methodVisbility, visbility)) {
const getterVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(getterVisbility, visbility)) {
instances.push(getter);
}
}
Expand All @@ -104,8 +159,8 @@ package com.codeazur.as3swf.data.abc.reflect
if(setter.multiname && setter.multiname is ABCQualifiedName) {
const qname:ABCQualifiedName = ABCQualifiedName(setter.multiname);
if(qname.ns) {
const methodVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(methodVisbility, visbility)) {
const setterVisbility:ABCReflectMemberVisibility = ABCReflectMemberVisibility.getType(qname.ns.kind);
if(ABCReflectMemberVisibility.isType(setterVisbility, visbility)) {
instances.push(setter);
}
}
Expand All @@ -114,6 +169,40 @@ package com.codeazur.as3swf.data.abc.reflect
return instances;
}

private function populateConstants():void {
_constants = new Vector.<ABCReflectConstant>();

const total:uint = _instanceTraits.length;
for(var i:uint=0; i<total; i++) {
const traitInfo:ABCTraitInfo = _instanceTraits[i];
if(ABCTraitInfoKind.isType(traitInfo.kind, ABCTraitInfoKind.CONST)) {
const constInfo:ABCTraitConstInfo = ABCTraitConstInfo(traitInfo);
if(constInfo.multiname) {
_constants.push(ABCReflectConstant.create(constInfo));
} else {
throw new Error("Invalid const name (multiname: " + constInfo.multiname + ")");
}
}
}
}

private function populateVariables():void {
_variables = new Vector.<ABCReflectVariable>();

const total:uint = _instanceTraits.length;
for(var i:uint=0; i<total; i++) {
const traitInfo:ABCTraitInfo = _instanceTraits[i];
if(ABCTraitInfoKind.isType(traitInfo.kind, ABCTraitInfoKind.SLOT)) {
const slotInfo:ABCTraitSlotInfo = ABCTraitSlotInfo(traitInfo);
if(slotInfo.multiname) {
_variables.push(ABCReflectVariable.create(slotInfo));
} else {
throw new Error("Invalid variable name (multiname: " + slotInfo.multiname + ")");
}
}
}
}

private function populateMethods():void {
_methods = new Vector.<ABCReflectMethod>();

Expand Down
41 changes: 41 additions & 0 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectConstant.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.codeazur.as3swf.data.abc.reflect
{
import com.codeazur.as3swf.data.abc.ABC;
import com.codeazur.as3swf.data.abc.bytecode.IABCMultiname;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitConstInfo;
import com.codeazur.utils.StringUtils;
/**
* @author Simon Richardson - simon@ustwo.co.uk
*/
public class ABCReflectConstant implements IABCReflectObject {

private var _constInfo:ABCTraitConstInfo;

public function ABCReflectConstant(constInfo:ABCTraitConstInfo) {
_constInfo = constInfo;
}

public static function create(constInfo:ABCTraitConstInfo):ABCReflectConstant {
return new ABCReflectConstant(constInfo);
}

public function get multiname():IABCMultiname { return _constInfo.multiname; }

public function get isFinal():Boolean { return _constInfo.isFinal; }
public function get isStatic():Boolean { return _constInfo.isStatic; }
public function get typeMultiname():IABCMultiname { return _constInfo.typeMultiname; }
public function get hasDefaultValue():Boolean { return _constInfo.hasDefaultValue; }
public function get defaultValue():* { return _constInfo.defaultValue; }

public function get name():String { return "ABCReflectConstant"; }

public function toString(indent:uint=0):String {
var str:String = ABC.toStringCommon(name, indent);

str += "\n" + StringUtils.repeat(indent + 2) + "Multiname:";
str += "\n" + StringUtils.repeat(indent + 4) + multiname.fullPath;

return str;
}
}
}
5 changes: 5 additions & 0 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectGetter.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package com.codeazur.as3swf.data.abc.reflect
public static function create(methodInfo:ABCMethodInfo):ABCReflectGetter {
return new ABCReflectGetter(methodInfo);
}

public function get returnType():IABCMultiname { return _methodInfo.returnType; }

public function get opcodes():Vector.<ABCOpcode> { return _opcodes; }
public function get numOpcodes():int { return _opcodes.length; }
Expand All @@ -38,6 +40,9 @@ package com.codeazur.as3swf.data.abc.reflect
str += "\n" + StringUtils.repeat(indent + 2) + "Multiname:";
str += "\n" + StringUtils.repeat(indent + 4) + multiname.fullPath;

str += "\n" + StringUtils.repeat(indent + 2) + "ReturnType:";
str += "\n" + returnType.toString(indent + 4);

str += "\n" + StringUtils.repeat(indent + 2) + "numOpcodes: " + numOpcodes;

return str;
Expand Down
10 changes: 6 additions & 4 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectMethod.as
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ package com.codeazur.as3swf.data.abc.reflect

public function get name():String { return "ABCReflectMethod"; }

public function get isStatic():Boolean { return _methodInfo.isStatic; }

public function get hasOptional():Boolean { return _methodInfo.hasOptional; }
public function get hasParamNames():Boolean { return _methodInfo.hasParamNames; }
public function get needRest():Boolean { return _methodInfo.hasRest; }
public function get needArguments():Boolean { return _methodInfo.hasArguments; }
public function get hasRest():Boolean { return _methodInfo.hasRest; }
public function get hasArguments():Boolean { return _methodInfo.hasArguments; }

public function toString(indent:uint=0):String {
var str:String = ABC.toStringCommon(name, indent);
Expand All @@ -73,8 +75,8 @@ package com.codeazur.as3swf.data.abc.reflect

str += "\n" + StringUtils.repeat(indent + 2) + "hasParamNames: " + hasParamNames;
str += "\n" + StringUtils.repeat(indent + 2) + "hasOptional: " + hasOptional;
str += "\n" + StringUtils.repeat(indent + 2) + "needRest: " + needRest;
str += "\n" + StringUtils.repeat(indent + 2) + "needArguments: " + needArguments;
str += "\n" + StringUtils.repeat(indent + 2) + "needRest: " + hasRest;
str += "\n" + StringUtils.repeat(indent + 2) + "needArguments: " + hasArguments;

return str;
}
Expand Down
15 changes: 9 additions & 6 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectSetter.as
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ package com.codeazur.as3swf.data.abc.reflect
}

private function populateParameters():void {
const methodParam:ABCParameter = _methodInfo.parameters[0];
_parameter = ABCReflectParameter.create(methodParam);
if(_methodInfo.parameters.length > 0) {
const methodParam:ABCParameter = _methodInfo.parameters[0];
_parameter = ABCReflectParameter.create(methodParam);
}
}

public function get parameter():ABCReflectParameter {
Expand All @@ -50,21 +52,22 @@ package com.codeazur.as3swf.data.abc.reflect

public function get hasOptional():Boolean { return _methodInfo.hasOptional; }
public function get hasParamNames():Boolean { return _methodInfo.hasParamNames; }
public function get needRest():Boolean { return _methodInfo.hasRest; }
public function get needArguments():Boolean { return _methodInfo.hasArguments; }

public function toString(indent:uint=0):String {
var str:String = ABC.toStringCommon(name, indent);

str += "\n" + StringUtils.repeat(indent + 2) + "Multiname:";
str += "\n" + StringUtils.repeat(indent + 4) + multiname.fullPath;

if(parameter) {
str += "\n" + StringUtils.repeat(indent + 2) + "Parameter:";
str += "\n" + parameter.toString(indent + 4);
}

str += "\n" + StringUtils.repeat(indent + 2) + "numOpcodes: " + numOpcodes;

str += "\n" + StringUtils.repeat(indent + 2) + "hasParamNames: " + hasParamNames;
str += "\n" + StringUtils.repeat(indent + 2) + "hasOptional: " + hasOptional;
str += "\n" + StringUtils.repeat(indent + 2) + "needRest: " + needRest;
str += "\n" + StringUtils.repeat(indent + 2) + "needArguments: " + needArguments;

return str;
}
Expand Down
41 changes: 41 additions & 0 deletions src/com/codeazur/as3swf/data/abc/reflect/ABCReflectVariable.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.codeazur.as3swf.data.abc.reflect
{
import com.codeazur.as3swf.data.abc.ABC;
import com.codeazur.as3swf.data.abc.bytecode.IABCMultiname;
import com.codeazur.as3swf.data.abc.bytecode.traits.ABCTraitSlotInfo;
import com.codeazur.utils.StringUtils;
/**
* @author Simon Richardson - simon@ustwo.co.uk
*/
public class ABCReflectVariable implements IABCReflectObject {

private var _slotInfo:ABCTraitSlotInfo;

public function ABCReflectVariable(slotInfo:ABCTraitSlotInfo) {
_slotInfo = slotInfo;
}

public static function create(slotInfo:ABCTraitSlotInfo):ABCReflectVariable {
return new ABCReflectVariable(slotInfo);
}

public function get multiname():IABCMultiname { return _slotInfo.multiname; }

public function get isFinal():Boolean { return _slotInfo.isFinal; }
public function get isStatic():Boolean { return _slotInfo.isStatic; }
public function get typeMultiname():IABCMultiname { return _slotInfo.typeMultiname; }
public function get hasDefaultValue():Boolean { return _slotInfo.hasDefaultValue; }
public function get defaultValue():* { return _slotInfo.defaultValue; }

public function get name():String { return "ABCReflectVariable"; }

public function toString(indent:uint=0):String {
var str:String = ABC.toStringCommon(name, indent);

str += "\n" + StringUtils.repeat(indent + 2) + "Multiname:";
str += "\n" + StringUtils.repeat(indent + 4) + multiname.fullPath;

return str;
}
}
}

0 comments on commit 2d23417

Please sign in to comment.