/// <summary> /// Creates cast_to_type method via given AS method /// </summary> /// <param name="type"></param> /// <param name="AS"></param> /// <returns></returns> private AbcMethod Impl(IType type, AbcMethod AS, AbcMultiname name) { var instance = AS.Instance; var typeName = _generator.TypeBuilder.BuildMemberType(type); return(instance.DefineMethod( Sig.@static(name, typeName, AvmTypeCode.Object, "value"), code => { const int value = 1; code.GetLocal(value); code.IfNullReturnNull(1); code.Getlex(instance); code.GetLocal(value); code.Call(AS); code.SetLocal(value); code.GetLocal(value); var notNull = code.IfNotNull(false); code.ThrowInvalidCastException(type); notNull.BranchTarget = code.Label(); code.GetLocal(value); code.ReturnValue(); })); }
public static AbcInstance FindInstance(IAssembly assembly, AbcMultiname name) { if (name == null) { throw new ArgumentNullException("name"); } //TODO: decide whether to return Object for any (*) type if (name.IsRuntime || name.IsAny) { return(null); } // TODO: fix importing of global types like void // if (name.IsGlobalType) // { // var fullName = GlobalTypes.GetCorlibTypeName(name.NameString); // return FindInstance(assembly, fullName); // } if (name.NamespaceSet != null) { return(name.NamespaceSet .Select(ns => ns.NameString.MakeFullName(name.NameString)) .Select(fullName => FindInstance(assembly, fullName)) .FirstOrDefault(instance => instance != null)); } return(FindInstance(assembly, name.FullName)); }
public AbcInstance BuildBitmapAsset(AbcMultiname name, Image image, bool jpeg) { var instance = BuildAssetInstance(name, GetBitmapAssetSuperName()); _generator.SwfCompiler.Assets.DefineBitmapAsset(image, instance, jpeg); return(instance); }
public void RegisterRemoteClass(string alias, AbcMultiname name) { if (name == null) { throw new ArgumentNullException("name"); } _remoteClasses.Add(new KeyValuePair <string, AbcMultiname>(alias, name)); }
void Add(AbcMultiname name, string type) { if (name == null) { return; } Add(name.ToSwcId(), type); }
private VarPtr CreateVarPtr(AbcMultiname type, string name) { var ptr = new VarPtr { Slot = CreateSlot(type, name) }; ptr.Ptr = CreateSlotPtr(ptr.Slot); return(ptr); }
private void CallCore(AbcCode code, IMethod method, AbcMultiname prop, CallFlags flags) { prop = _abc.ImportConst(prop); //determines whether method belongs to base type bool super = IsSuperCall(method, flags); CallCore(code, method, prop, super); }
internal static string ToSwcId(this AbcMultiname mn) { string ns = mn.NamespaceString; string name = mn.NameString; if (string.IsNullOrEmpty(ns)) { return(name); } return(ns + ":" + name); }
private static void WriteTraitName(TextWriter writer, AbcMultiname mn) { string ns = mn.NamespaceString; writer.Write("["); writer.Write(mn.Namespace.Kind); writer.Write(" = "); writer.Write(ns); writer.Write("] "); writer.Write(mn.NameString); }
private static void WriteTypeName(TextWriter writer, AbcMultiname mn) { if (mn == null || mn.Index == 0) { writer.Write("*"); } else { WriteQName(writer, mn); } }
private static void WriteQName(TextWriter writer, AbcMultiname mn) { string ns = mn.NamespaceString; if (!string.IsNullOrEmpty(ns)) { writer.Write(ns); writer.Write("."); } writer.Write(mn.NameString); }
private AbcInstance BuildAssetInstance(AbcTrait trait, AbcMultiname superName) { var name = GetAssetInstanceName(trait); //TODO: Check existance of instance var instance = BuildAssetInstance(name, superName); instance.Embed = trait.Embed; trait.AssetInstance = instance; return(instance); }
public static string ToXml(this AbcMultiname multiname) { if (multiname is AbcMultinameVoid) { return(""); } if (multiname is AbcMultinameAny) { return("*"); } return(multiname.ToString()); }
public ExternalCall(IMethod method, AbcMultiname name) { if (method == null) { throw new ArgumentNullException("method"); } if (name == null) { throw new ArgumentNullException("name"); } Method = method; Name = name; }
void AddSigRef(AbcMultiname name) { if (name == null) { return; } if (name.IsAny) { return; } //if (name.IsGlobalType) return; //var type = _app.FindInstance(name.FullName); //if (type != null && type.IsNative) return; Add(name, SwcCatalog.DepTypes.Signature); }
public InlineCall(IMethod method, AbcMultiname targetType, AbcMultiname name, AbcCode inlineCode) { if (method == null) { throw new ArgumentNullException("method"); } if (inlineCode == null) { throw new ArgumentNullException("inlineCode"); } Method = method; TargetType = targetType; Name = name; InlineCode = inlineCode; }
private void Call(AbcCode code, IMethod method, AbcMultiname prop, CallFlags flags) { if (prop == null) { throw new ArgumentNullException("prop"); } CallCore(code, method, prop, flags); if (MustCoerceReturnType(method)) { var type = method.Type; EnsureType(type); code.Coerce(type, true); } }
//TODO: avoid usage of out parameters private void DefineSuperType(IType type, out AbcMultiname superName, out AbcInstance superType) { superName = null; superType = null; if (type.IsInterface) { return; } if (type.IsEnum) { superType = DefineEnumSuperType(type); superName = superType.Name; return; } if (type.Is(SystemTypeCode.Exception)) { // TODO: use Native.Error // superType = typeof(Error); superName = Abc.BuiltinTypes.Error; return; } var baseType = type.BaseType; if (baseType != null) { //NOTE: This fix explicit usage of Avm.Object as base class. //In fact .NET developer will never use this class, or no need to use this class. if (baseType.IsAvmObject()) { baseType = SystemTypes.Object; } superName = DefineTypeName(baseType); superType = baseType.AbcInstance(); return; } if (type.Is(SystemTypeCode.Object)) { superName = Abc.BuiltinTypes.Object; } }
private AbcTrait CreateSlot(AbcMultiname type, string name) { var traitName = DefineSlotName(name); AbcTrait t; if (AbcGenConfig.UseActivationTraits) { t = _body.Traits.AddSlot(type, traitName); t.SlotId = _body.Traits.Count; } else { t = _activation.CreateSlot(traitName, type); t.SlotId = _activation.Traits.Count; } return(t); }
private AbcInstance BuildAssetInstance(AbcMultiname name, AbcMultiname superName) { var superType = FindAssetSuperType(superName); if (superType == null) { throw Errors.Type.UnableToFind.CreateException(superName.FullName); } //TODO: Check existance of instance var instance = new AbcInstance(true) { Name = name, BaseTypeName = superName, Flags = (AbcClassFlags.Sealed | AbcClassFlags.ProtectedNamespace), ProtectedNamespace = Abc.DefineProtectedNamespace(name.NameString), Initializer = Abc.DefineMethod( Sig.@void(), code => { code.PushThisScope(); code.ConstructSuper(); code.ReturnVoid(); }), BaseInstance = superType, Class = { Initializer = Abc.DefineMethod( Sig.global(null), code => { if (true) { code.PushThisScope(); } code.ReturnVoid(); }) } }; Abc.AddInstance(instance); return(instance); }
private AbcInstance FindAssetSuperType(AbcMultiname superName) { var type = _generator.FindTypeDefOrRef(superName.FullName); if (type == null) { throw new InvalidOperationException(); } var instance = type.AbcInstance(); if (instance == null) { throw new InvalidOperationException(); } instance = Abc.ImportInstance(instance); return(instance); }
public AbcMethod GetProperty(AbcMultiname prop) { if (prop == null) { throw new ArgumentNullException("prop"); } var m = _abc.DefineMethod( Sig.@global(AvmTypeCode.Object), code => { code.Getlex(prop); code.ReturnValue(); }); #if DEBUG m.Name = _abc.DefineString("get_" + prop.NameString); #endif return(m); }
public AbcMethod SetProperty(AbcMultiname prop) { if (prop == null) { throw new ArgumentNullException("prop"); } var m = _abc.DefineMethod( Sig.@void(AvmTypeCode.Object, "value"), code => { code.FindProperty(prop); code.GetLocal(1); //value code.SetProperty(prop); code.ReturnVoid(); }); #if DEBUG m.Name = _abc.DefineString("set_" + prop.NameString); #endif return(m); }
public InstructionCode GetCoercionInstructionCode(AbcMultiname type) { if (ReferenceEquals(type, Int32)) { return(InstructionCode.Coerce_i); } if (ReferenceEquals(type, UInt32)) { return(InstructionCode.Coerce_u); } if (ReferenceEquals(type, String)) { return(InstructionCode.Coerce_s); } if (ReferenceEquals(type, Boolean)) { return(InstructionCode.Coerce_b); } if (ReferenceEquals(type, Object)) { return(InstructionCode.Coerce_o); } return(InstructionCode.Coerce); }
private void CallCore(AbcCode code, IMethod method, AbcMultiname prop, bool super) { var abcMethod = method.AbcMethod(); if (abcMethod != null) { if (abcMethod.IsGetter) { code.Add(super ? InstructionCode.Getsuper : InstructionCode.Getproperty, prop); return; } if (abcMethod.IsSetter) { code.Add(super ? InstructionCode.Setsuper : InstructionCode.Setproperty, prop); return; } } int n = method.Parameters.Count; if (method.AsStaticCall()) { ++n; } bool isVoid = method.IsVoid(); if (CanUseCallStatic) { if (method.IsStaticCall() && method.IsManaged() && abcMethod != null && _abc.IsDefined(abcMethod)) { code.Add(InstructionCode.Callstatic, abcMethod, n); if (isVoid) { code.Pop(); } return; } } if (super) { if (isVoid) { code.Add(InstructionCode.Callsupervoid, prop, n); return; } code.Add(InstructionCode.Callsuper, prop, n); return; } if (isVoid) { code.Add(InstructionCode.Callpropvoid, prop, n); return; } code.Add(InstructionCode.Callproperty, prop, n); }
public static XElement AddName(this XElement node, AbcMultiname multiname) { node.Add(new XAttribute("name", multiname.ToXml())); return(node); }
public AbcInstance FindInstanceRef(AbcMultiname name) { return(AssemblyIndex.FindInstance(AppAssembly, name)); }
public static IType FindType(IAssembly assembly, AbcMultiname name) { return(name.GetFullNames().Select(fullName => FindType(assembly, fullName)).FirstOrDefault(type => type != null)); }
public AbcInstance PropertyPtr(AbcMultiname name) { return(name.Namespace.IsGlobalPackage ? GlobalPropertyPtr.Instance : PropPtr.Instance); }
void AddInheritanceRef(AbcMultiname name) { Add(name, SwcCatalog.DepTypes.Inheritance); }