void OrderByInheritance(AbcInstance instance) { if (instance == null) { return; } if (instance.Ordered) { return; } foreach (var other in Instances) { if (other == instance) { continue; } if (other.Ordered) { continue; } if (instance.IsInheritedFrom(other.Name)) { OrderByInheritance(other); } } instance.Ordered = true; _order.Add(instance); }
private AbcMultiname ImportType(AbcMultiname name, out AbcInstance type) { type = null; if (name == null) { return(null); } if (IsImportTypeExternally) { return(ImportConst(name)); } if (name.IsRuntime) { return(ImportConst(name)); } type = ImportInstance(name); if (type != null) { name = type.Name; } return(ImportConst(name)); }
public AbcInstance DefineEmptyInstance(object name, bool emptyCtor) { var instance = new AbcInstance(true) { Name = DefineName(name), BaseTypeName = BuiltinTypes.Object, Flags = AbcClassFlags.Final | AbcClassFlags.Sealed }; if (emptyCtor) { instance.Initializer = DefineMethod( Sig.@void(), code => { code.ConstructSuper(); code.ReturnVoid(); }); } instance.Class.Initializer = DefineEmptyMethod(); AddInstance(instance); return(instance); }
public void DefineScripts(IEnumerable <AbcInstance> instances) { var arr = new AbcInstance[1]; foreach (var instance in instances) { arr[0] = instance; DefineScript(arr); } }
private void ImportAbcFiles(AbcInstance instance) { if (instance.ImportAbcFiles.Count > 0) { foreach (var abc in instance.ImportAbcFiles) { Import(abc); } } }
public static IEnumerable <AbcInstance> BaseInstances(this AbcInstance instance) { var b = instance.BaseInstance; while (b != null) { yield return(b); b = b.BaseInstance; } }
void EnsureInterfaces(AbcInstance instance) { var ifaces = instance.Interfaces; int n = ifaces.Count; for (int i = 0; i < n; ++i) { var mn = ifaces[i]; ifaces[i] = ImportConst(mn); } }
/// <summary> /// Adds new instance to the ABC file. /// </summary> /// <param name="instance"><see cref="AbcInstance"/> to add</param> public void AddInstance(AbcInstance instance) { if (instance == null) { throw new ArgumentNullException("instance"); } if (instance.Class == null) { throw new ArgumentException("instance has no class"); } Instances.Add(instance); Classes.Add(instance.Class); }
public static bool FilterClass(AbcInstance instance) { if (ClassFilter == null) { return(false); } string key = instance.FullName; if (ClassFilter.Contains(key)) { return(true); } return(false); }
private AbcConst <string> ImportType(AbcConst <string> name, out AbcInstance type) { type = null; if (name == null) { return(null); } if (IsImportTypeExternally) { return(ImportConst(name)); } type = ImportInstance(name); return(ImportConst(name)); }
static void CheckInheritance(AbcInstance instance) { if (instance.IsInterface) { if (instance.Name.Kind != AbcConstKind.QName) { Debugger.Break(); } } if (instance.BaseTypeName != null && !instance.BaseTypeName.IsAny && instance.BaseTypeName.Kind != AbcConstKind.QName) { Debugger.Break(); } foreach (var mn in instance.Interfaces) { CheckQName(mn); } }
public void ImportResourceBundle(string locale, string name, ResourceBundleContext context) { if (context == null) { context = new ResourceBundleContext(); } context.Locale = locale; ResourceBundles.CopyFlexLocale(locale); string key = locale + "$" + name; if (ContainsResourceBundle(key)) { return; } var rb = ResourceBundles.Get(locale, name); //NOTE: null in case of Dynamic Resource Modules!!! if (rb == null) { return; } var superType = ResourceBundleSuper; var instance = new AbcInstance(true) { ResourceBundleName = name, Locale = locale }; _rbcache[key] = instance; //NOTE: naming is strongly determined in Flex Resource Manager. string fullname = locale + '$' + name + "_properties"; instance.Name = DefineName(QName.Global(fullname)); instance.Flags = AbcClassFlags.Sealed | AbcClassFlags.ProtectedNamespace; instance.ProtectedNamespace = DefineProtectedNamespace(fullname); instance.BaseInstance = superType; instance.BaseTypeName = superType.Name; AddInstance(instance); instance.Initializer = DefineMethod( Sig.@void(), code => { code.PushThisScope(); code.LoadThis(); code.PushString(locale); code.PushString(name); code.ConstructSuper(2); code.ReturnVoid(); }); instance.Class.Initializer = DefineEmptyMethod(); var mn = DefineQName(instance.ProtectedNamespace, "getContent"); instance.DefineMethod( Sig.@override(mn, AvmTypeCode.Object), code => { int n = 0; var lines = rb.Content; for (int i = 0; i < lines.Length; ++i) { string line = lines[i]; context.Line = i + 1; context.ResourceBundle = rb; if (PushKeyValue(line, code, context)) { ++n; } } code.Add(InstructionCode.Newobject, n); code.ReturnValue(); } ); DefineScript(instance); }
public AbcClass(AbcInstance instance) : this() { Instance = instance; }
/// <summary> /// Imports given instance /// </summary> /// <param name="instance"></param> /// <returns></returns> public AbcInstance ImportInstance(AbcInstance instance) { AbcMethod importMethod = null; return(ImportInstance(instance, ref importMethod)); }
public bool HasInterface(AbcInstance iface) { return(Interfaces.Any(mn => ReferenceEquals(mn, iface.Name))); }
private void ImportAssets(AbcInstance instance) { ImportAssets(instance.GetAllTraits()); }
/// <summary> /// Determines whether the given <see cref="AbcInstance"/> is defined in this ABC file. /// </summary> /// <param name="instance"><see cref="AbcInstance"/> to check</param> /// <returns></returns> public bool IsDefined(AbcInstance instance) { return(instance.IsNative || AllFrames.Any(abc => instance.Abc == abc)); }
public AbcInstance ImportInstance(AbcInstance instance, ref AbcMethod importMethod) { if (instance == null) { return(null); } if (instance.IsNative) { return(instance); } if (instance.UseExternalLinking) { if (instance.IsLinkedExternally) { return(instance); } if (AllowExternalLinking) { instance.IsLinkedExternally = true; if (instance.InSwc) { var abc = instance.Abc; if (!abc._importing) { Debug.Assert(abc != this); Import(abc); } } else { ImportAssets(instance); } return(instance); } } if (IsDefined(instance)) { return(instance); } if (instance.ImportedInstance != null) { return(instance.ImportedInstance); } if (instance.InSwc) { var abc = instance.Abc; if (!abc._importing) { Debug.Assert(abc != this); Import(abc); } } if (instance.ImportedInstance != null) { return(instance.ImportedInstance); } if (!IsImportTypeExternally) { var superType = instance.BaseInstance; if (superType != null) { ImportInstance(superType); } } if (instance.ImportedInstance != null) { return(instance.ImportedInstance); } ImportAbcFiles(instance); if (instance.ImportedInstance != null) { return(instance.ImportedInstance); } var result = ImportInstanceCore(instance, ref importMethod); //ImportAbcFiles(instance); return(result); }
public AbcNamespace DefinePrivateNamespace(AbcInstance instance) { string ns = InternalTypeExtensions.GetNamespaceForMembers(instance); return(DefinePrivateNamespace(ns)); }
private AbcInstance ImportInstanceCore(AbcInstance source, ref AbcMethod importMethod) { var instance = new AbcInstance { Name = ImportConst(source.Name), IsMixin = source.IsMixin, IsStyleMixin = source.IsStyleMixin, ImportedFrom = source }; source.ImportedInstance = instance; var klass = new AbcClass(instance); AddInstance(instance); AbcInstance superType; instance.BaseTypeName = ImportType(source.BaseTypeName, out superType); instance.BaseInstance = superType; instance.Flags = source.Flags; instance.ProtectedNamespace = ImportConst(source.ProtectedNamespace); instance.Type = source.Type; if (instance.Type != null) { SetData(instance.Type, instance); } foreach (var iname in source.Interfaces) { AbcInstance ifaceInstance; var mn = ImportType(iname, out ifaceInstance); if (mn == null) { throw new InvalidOperationException(); } //NOTE: Flex Compiler Bug!!! //I found that within SWC files interface names must be always declared as multinames (with namespace set) //This is true for flex 3. if (IsSwcScript) { mn = ToMultiname(mn); } instance.Interfaces.Add(mn); if (ifaceInstance != null) { ifaceInstance.Implementations.Add(instance); instance.Implements.Add(ifaceInstance); } } instance.Initializer = ImportMethod(source.Initializer); klass.Initializer = ImportMethod(source.Class.Initializer); if (importMethod == source.Initializer) { importMethod = instance.Initializer; } if (importMethod == source.Class.Initializer) { importMethod = klass.Initializer; } ImportTraits(source, instance, ref importMethod); ImportTraits(source.Class, klass, ref importMethod); return(instance); }
public void Add(AbcInstance instance) { string key = instance.FullName; _cache.Add(key, instance); }