public void RecursivelyCreatesUsingStatementForEachTypeInUnionReference() { NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference(union: new UnionTypeReference(new TypeReference[] { new TypeReference(collection: new CollectionTypeReference( CollectionKind.Array, new TypeReference(collection: new CollectionTypeReference( CollectionKind.Array, new TypeReference(primitive: PrimitiveType.Json) )) )), new TypeReference(primitive: PrimitiveType.Date), }))); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;", "using Newtonsoft.Json.Linq;", "using System;" ); }
public void toStringMethodTest(Namespace[] elements) { var nsSet = new NamespaceSet(elements); var str = nsSet.ToString(); if (nsSet.count == 0) { Assert.Equal("[]", str); return; } Assert.Equal('[', str[0]); Assert.Equal(']', str[str.Length - 1]); var parts = str.Substring(1, str.Length - 2).Split(", "); Assert.Equal(nsSet.count, parts.Length); var namespaces = nsSet.getNamespaces(); for (int i = 0; i < namespaces.length; i++) { Assert.Contains(namespaces[i].isPublic ? "<public>" : namespaces[i].ToString(), parts); } }
public void CreatesUsingStatementForType() { EnumType type = new EnumType ( "myEnumFqn", "myModule", "myEnum", "myNamespace", new EnumMember[] { } ); Symbols.MapNamespace("myNamespace", "MyNamespace"); NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(type); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;", "using MyNamespace;" ); }
public void defaultValueShouldBeEmpty() { NamespaceSet nsSet = default; Assert.Equal(0, nsSet.count); Assert.Equal(0, nsSet.getNamespaces().length); }
INamespaceSet INamespaceSet.Union(IEnumerable <Namespace> items, bool canMutate) { if (items.All(ns => ((INamespaceSet)this).Comparer.Equals(this, ns))) { return(this); } return(NamespaceSet.Create(items).Add(this, false)); }
/// <summary> /// Gets an ID for a namespace set, ensuring that all other dependencies of the namespace set /// are themselves registered with IDs. /// </summary> /// <param name="set">The namespace set</param> /// <returns>The ID of the namespace set</returns> private int NamespaceSetID(NamespaceSet set) { foreach (Namespace ns in set) { /*(void)*/ this.NamespaceID(ns); } return(this.nsSetMarshal.GetIDFor(set)); }
/// <summary> /// Immutable multiname object. /// </summary> /// <param name="kind">The kind of multiname</param> /// <param name="name">The multiname name</param> /// <param name="ns">Optional namespace, dependant on kind. See AVM2 spec</param> /// <param name="set">Optional namespace set, dependant on kind. See AVM2 spec</param> internal Multiname(MultinameKind kind, string name, Namespace ns, NamespaceSet set) { this.Kind = kind; this.Name = name; this.NS = ns; this.Set = set; /* Sanity checking... */ switch (kind) { case MultinameKind.QName: case MultinameKind.QNameA: if (ns == null) { throw new SWFModellerException( SWFModellerError.Internal, "A " + kind.ToString() + " requires a namespace"); } break; case MultinameKind.RTQName: case MultinameKind.RTQNameA: break; case MultinameKind.RTQNameL: case MultinameKind.RTQNameLA: break; case MultinameKind.Multiname: case MultinameKind.MultinameA: if (set == null) { throw new SWFModellerException( SWFModellerError.Internal, "A " + kind.ToString() + " requires a namespace set"); } break; case MultinameKind.MultinameL: case MultinameKind.MultinameLA: if (set == null) { throw new SWFModellerException( SWFModellerError.Internal, "A " + kind.ToString() + " requires a namespace set"); } break; default: break; } }
INamespaceSet INamespaceSet.Union(IEnumerable <Namespace> items, out bool wasChanged, bool canMutate) { if (items.All(ns => ((INamespaceSet)this).Comparer.Equals(this, ns))) { wasChanged = false; return(this); } wasChanged = true; return(NamespaceSet.Create(items).Add(this, false)); }
public void constructorTest(Namespace[] elements) { NamespaceSet nsSet; HashSet <Namespace> hashSet = elements.ToHashSet(); nsSet = new NamespaceSet(elements); Assert.Equal(nsSet.count, nsSet.getNamespaces().length); Assert.Equal(hashSet.Count, nsSet.getNamespaces().length); Assert.Subset(hashSet, nsSet.getNamespaces().ToHashSet()); nsSet = new NamespaceSet(elements.AsSpan()); Assert.Equal(nsSet.count, nsSet.getNamespaces().length); Assert.Equal(hashSet.Count, nsSet.getNamespaces().length); Assert.Subset(hashSet, nsSet.getNamespaces().ToHashSet()); }
public void CreatesUsingStatementForJsonReference() { NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference(primitive: PrimitiveType.Json)); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;", "using Newtonsoft.Json.Linq;" ); }
public void constructorTest_withNullOrEmptySet() { NamespaceSet nsSet = new NamespaceSet(null); Assert.Equal(0, nsSet.count); Assert.Equal(0, nsSet.getNamespaces().length); nsSet = new NamespaceSet(new Namespace[0]); Assert.Equal(0, nsSet.count); Assert.Equal(0, nsSet.getNamespaces().length); nsSet = new NamespaceSet(ReadOnlySpan <Namespace> .Empty); Assert.Equal(0, nsSet.count); Assert.Equal(0, nsSet.getNamespaces().length); }
public void DoesNotCreateUsingStatementForCurrentNamespace() { Symbols.MapTypeToNamespace("myFqn", "MyCurrentNamespace"); NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference("myFqn")); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;" ); }
public void SortsUsingStatementsAlphaNumerically() { Symbols.MapTypeToNamespace("myFqn", "AAA"); NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference("myFqn")); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using AAA;", "using Amazon.JSII.Runtime.Deputy;" ); }
public void DoesNotCreateUsingStatementForSystemPrimitive() { NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference(primitive: PrimitiveType.Any)); namespaces.Add(new TypeReference(primitive: PrimitiveType.Boolean)); namespaces.Add(new TypeReference(primitive: PrimitiveType.Number)); namespaces.Add(new TypeReference(primitive: PrimitiveType.String)); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;" ); }
public void DoesNotCreateUsingStatementForArrayReference() { NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference(collection: new CollectionTypeReference( CollectionKind.Array, new TypeReference(primitive: PrimitiveType.String) ))); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;" ); }
public void CreatesUsingStatementForMapReference() { NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace")); namespaces.Add(new TypeReference(collection: new CollectionTypeReference( kind: CollectionKind.Map, elementType: new TypeReference(primitive: PrimitiveType.String) ))); SyntaxList <UsingDirectiveSyntax> usings = namespaces.GetUsings(); AssertUsings ( usings, "using Amazon.JSII.Runtime.Deputy;", "using System.Collections.Generic;" ); }
internal void Check() { switch (Kind) { case AbcConstKind.QName: case AbcConstKind.QNameA: Namespace.Check(); CheckConst(Name); break; case AbcConstKind.RTQNameL: case AbcConstKind.RTQNameLA: break; case AbcConstKind.RTQName: case AbcConstKind.RTQNameA: CheckConst(Name); break; case AbcConstKind.Multiname: case AbcConstKind.MultinameA: NamespaceSet.Check(); CheckConst(Name); break; case AbcConstKind.MultinameL: case AbcConstKind.MultinameLA: NamespaceSet.Check(); break; case AbcConstKind.TypeName: Type.Check(); TypeParameter.Check(); break; } }
public bool IsMatch(ASMultiname other) { if (Equals(other)) { return(true); } if (!Equals(Name, other.Name)) { return(false); } if (Kind == MultinameKind.QName && other.Kind == MultinameKind.Multiname) { return(other.NamespaceSet.GetNamespaces().Any(x => x.ns.Equals(Namespace))); } if (Kind == MultinameKind.Multiname && other.Kind == MultinameKind.QName) { return(NamespaceSet.GetNamespaces().Any(x => x.ns.Equals(other.Namespace))); } return(false); }
internal NamespaceSet CreateNamespaceSet(Namespace[] nsRefs) { NamespaceSet set = new NamespaceSet(nsRefs); this.nsSetConsts.Add(set); return set; }
internal void SetNamespaceSets(NamespaceSet[] sets) { this.nsSetConsts = new List<NamespaceSet>(); this.nsSetConsts.Add(NamespaceSet.EmptySet); this.nsSetConsts.AddRange(sets); }
/// <summary> /// Gets an ID for a namespace set, ensuring that all other dependencies of the namespace set /// are themselves registered with IDs. /// </summary> /// <param name="set">The namespace set</param> /// <returns>The ID of the namespace set</returns> private int NamespaceSetID(NamespaceSet set) { foreach (Namespace ns in set) { /*(void)*/this.NamespaceID(ns); } return this.nsSetMarshal.GetIDFor(set); }
/// <summary> /// Writes out the constants to the SWF file. This will also re-set the tables in the /// code object, so be sure you don't have anything in there that you need. /// </summary> /// <param name="writer">Where to write the constants to.</param> /// <param name="code">The code object with the tables in it, that we'll /// overwrite.</param> private void WriteConstantPool(ABCDataTypeWriter writer, AbcCode code) { /* Integer constants */ int[] ints = this.intMarshal.ToArray(); writer.WriteU30Packed((uint)(ints.Length == 1 ? 0 : ints.Length)); for (int i = 1; i < ints.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const int #" + i + ": " + ints[i]); #endif writer.WriteSI32(ints[i]); } code.IntConsts = ints; /* Unsigned integer constants */ uint[] uints = this.uintMarshal.ToArray(); writer.WriteU30Packed((uint)(uints.Length == 1 ? 0 : uints.Length)); for (int i = 1; i < uints.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const uint #" + i + ": " + uints[i]); #endif writer.WriteUI32(uints[i]); } code.UIntConsts = uints; /* Double constants */ ulong[] doubles = this.doubleMarshal.ToArray(); writer.WriteU30Packed((uint)(doubles.Length == 1 ? 0 : doubles.Length)); for (int i = 1; i < doubles.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const double (bits) #" + i + ": " + doubles[i]); #endif /* We hack this here instead of having a U64 type, because it's a hack around not * treating double properly. There's no such thing as U64 in SWF. */ ulong d = doubles[i]; uint low = (uint)(d & 0x00000000FFFFFFFF); d >>= 32; uint high = (uint)(d & 0x00000000FFFFFFFF); writer.WriteUI32(high); writer.WriteUI32(low); } code.DoubleConsts = doubles; /* String constants */ string[] strings = this.stringMarshal.ToArray(); writer.WriteU30Packed((uint)(strings.Length == 1 ? 0 : strings.Length)); for (int i = 1; i < strings.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const string #" + i + ": \"" + strings[i] + "\""); #endif writer.WriteString(strings[i]); } code.StringConsts = strings; /* Namespace constants */ Namespace[] namespaces = this.nsMarshal.ToArray(); writer.WriteU30Packed((uint)(namespaces.Length == 1 ? 0 : namespaces.Length)); for (int i = 1; i < namespaces.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const ns #" + i + ": " + namespaces[i]); #endif Namespace ns = namespaces[i]; writer.WriteUI8((uint)ns.Kind); writer.WriteU30Packed((uint)this.stringMarshal.GetExistingIDFor(ns.Name)); } code.SetNamespaces(namespaces); /* Namespace set constants */ NamespaceSet[] namespaceSets = this.nsSetMarshal.ToArray(); writer.WriteU30Packed((uint)(namespaceSets.Length == 1 ? 0 : namespaceSets.Length)); for (int i = 1; i < namespaceSets.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const ns set #" + i + ": " + namespaceSets[i]); #endif NamespaceSet nss = namespaceSets[i]; writer.WriteU30Packed((uint)nss.Count); foreach (Namespace ns in nss) { writer.WriteU30Packed((uint)this.nsMarshal.GetExistingIDFor(ns)); } } code.SetNamespaceSets(namespaceSets); /* Multiname constants */ Multiname[] multinames = this.multinameMarshal.ToArray(); writer.WriteU30Packed((uint)(multinames.Length == 1 ? 0 : multinames.Length)); for (int i = 1; i < multinames.Length; i++) /* Omit value at [0] */ { #if DEBUG this.writeLog.AppendLine("Const mn set #" + i + ": " + multinames[i]); #endif Multiname mn = multinames[i]; writer.WriteUI8((uint)mn.Kind); switch (mn.Kind) { case Multiname.MultinameKind.QName: case Multiname.MultinameKind.QNameA: uint nsIdx = (uint)this.nsMarshal.GetExistingIDFor(mn.NS); uint nameIdx = (uint)this.stringMarshal.GetExistingIDFor(mn.Name); writer.WriteU30Packed(nsIdx); writer.WriteU30Packed(nameIdx); break; case Multiname.MultinameKind.RTQName: case Multiname.MultinameKind.RTQNameA: writer.WriteU30Packed((uint)this.stringMarshal.GetExistingIDFor(mn.Name)); break; case Multiname.MultinameKind.RTQNameL: case Multiname.MultinameKind.RTQNameLA: /* No data */ break; case Multiname.MultinameKind.Multiname: case Multiname.MultinameKind.MultinameA: writer.WriteU30Packed((uint)this.stringMarshal.GetExistingIDFor(mn.Name)); writer.WriteU30Packed((uint)this.nsSetMarshal.GetExistingIDFor(mn.Set)); break; case Multiname.MultinameKind.MultinameL: case Multiname.MultinameKind.MultinameLA: writer.WriteU30Packed((uint)this.nsSetMarshal.GetExistingIDFor(mn.Set)); break; default: break; } } code.SetMultinames(multinames); }
private void _readConstantPools() { int intPoolSize = _readU30(); if (intPoolSize != 0) { intPoolSize--; } int[] intPool = new int[intPoolSize + 1]; for (int i = 1; i < intPool.Length; i++) { intPool[i] = (int)_readU32(); } m_abcFile.setIntPool(intPool); int uintPoolSize = _readU30(); if (uintPoolSize != 0) { uintPoolSize--; } uint[] uintPool = new uint[uintPoolSize + 1]; for (int i = 1; i < uintPool.Length; i++) { uintPool[i] = _readU32(); } m_abcFile.setUintPool(uintPool); int doublePoolSize = _readU30(); if (doublePoolSize != 0) { doublePoolSize--; } double[] doublePool = new double[doublePoolSize + 1]; doublePool[0] = Double.NaN; for (int i = 1; i < doublePool.Length; i++) { doublePool[i] = _readD64(); } m_abcFile.setDoublePool(doublePool); int stringPoolSize = _readU30(); if (stringPoolSize != 0) { stringPoolSize--; } string?[] stringPool = new string?[stringPoolSize + 1]; for (int i = 1; i < stringPool.Length; i++) { stringPool[i] = _readString(); } m_abcFile.setStringPool(stringPool); int nsPoolSize = _readU30(); if (nsPoolSize != 0) { nsPoolSize--; } Namespace[] nsPool = new Namespace[nsPoolSize + 1]; for (int i = 1; i < nsPool.Length; i++) { nsPool[i] = _readNamespace(); } m_abcFile.setNamespacePool(nsPool); int nsSetPoolSize = _readU30(); if (nsSetPoolSize != 0) { nsSetPoolSize--; } NamespaceSet[] nsSetPool = new NamespaceSet[nsSetPoolSize + 1]; for (int i = 1; i < nsSetPool.Length; i++) { int setCount = _readU30(); Namespace[] nsInSet = new Namespace[setCount]; for (int j = 0; j < nsInSet.Length; j++) { Namespace ns = m_abcFile.resolveNamespace(_readU30()); if (ns.isPublic) { // Set the public namespace to be first in a set to improve runtime lookup performance nsInSet[j] = nsInSet[0]; nsInSet[0] = ns; } else { nsInSet[j] = ns; } } nsSetPool[i] = new NamespaceSet(nsInSet); } m_abcFile.setNamespaceSetPool(nsSetPool); int multinamePoolSize = _readU30(); if (multinamePoolSize != 0) { multinamePoolSize--; } ABCMultiname[] multinamePool = new ABCMultiname[multinamePoolSize + 1]; multinamePool[0] = new ABCMultiname(ABCConstKind.QName, 0, 0); for (int i = 1; i < multinamePool.Length; i++) { multinamePool[i] = _readMultiname(); } m_abcFile.setMultinamePool(multinamePool); int genArgListPoolSize = m_genArgLists.length; ABCMultiname[][] genArgListPool = new ABCMultiname[genArgListPoolSize][]; for (int i = 0; i < genArgListPool.Length; i++) { int[] argIndices = m_genArgLists[i]; var arglist = new ABCMultiname[argIndices.Length]; for (int j = 0; j < argIndices.Length; j++) { arglist[j] = m_abcFile.resolveMultiname(argIndices[j]); } genArgListPool[i] = arglist; } m_abcFile.setGenericArgListPool(genArgListPool); }
internal Multiname CreateMultiname(Multiname.MultinameKind kind, string name, Namespace ns, NamespaceSet set) { Multiname mn = new Multiname(kind, name, ns, set); this.multinameConsts.Add(mn); return mn; }
/// <summary> /// Reads in all the constant values referenced from the bytecode. /// </summary> private void ReadConstantPool() { uint intCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant ints length " + intCount); } #endif this.code.SetIntCount(intCount); for (int i = 1; i < intCount; i++) { this.code.IntConsts[i] = this.abcdtr.ReadSI32(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("int #" + i + ": " + this.code.IntConsts[i]); } #endif } uint uintCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant uints length " + uintCount); } #endif this.code.SetUintCount(uintCount); for (int i = 1; i < uintCount; i++) { this.code.UIntConsts[i] = this.abcdtr.ReadUI32(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("uint #" + i + ": " + this.code.UIntConsts[i]); } #endif } uint double64Count = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant d64 length " + double64Count); } #endif this.code.SetDoubleCount(double64Count); for (int i = 1; i < double64Count; i++) { /* See the comment on AbcCode.DoubleConsts for the reason for all * of this strange ulong shenanigans. */ ulong ul = (ulong)this.abcdtr.ReadInt32(); ul |= ((ulong)this.abcdtr.ReadInt32()) << 32; this.code.DoubleConsts[i] = ul; #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("d64 #" + i + ": " + this.code.DoubleConsts[i]); } #endif } uint stringCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant string length " + stringCount); } #endif this.code.SetStringCount(stringCount); for (int i = 1; i < stringCount; i++) { this.code.StringConsts[i] = this.abcdtr.ReadString(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("str #" + i + ": " + this.code.StringConsts[i]); } #endif } uint nspaceCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant ns length " + nspaceCount); } #endif for (int i = 1; i < nspaceCount; i++) { Namespace.NamespaceKind kind = (Namespace.NamespaceKind) this.abcdtr.ReadUI8(); Namespace ns = null; if (kind == Namespace.NamespaceKind.Private) { uint sidx = this.abcdtr.ReadU30(); string name = string.Empty; if (sidx > 0) { name = this.code.StringConsts[sidx]; } ns = this.code.CreateNamespace(kind, name); } else { ns = this.code.CreateNamespace(kind, this.ReadString()); } #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("ns #" + i + ": " + ns); } #endif } uint nssetCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant ns set length " + nssetCount); } #endif for (int i = 1; i < nssetCount; i++) { uint count = this.abcdtr.ReadU30(); Namespace[] nsRefs = new Namespace[count]; for (int j = 0; j < count; j++) { nsRefs[j] = this.code.GetNamespace((int)this.abcdtr.ReadU30()); } NamespaceSet nss = this.code.CreateNamespaceSet(nsRefs); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("nss #" + i + ": " + nss); } #endif } uint multinameCount = this.abcdtr.ReadU30(); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("Constant mname length " + multinameCount); } #endif for (int i = 1; i < multinameCount; i++) { string name = null; Namespace ns = null; NamespaceSet set = null; Multiname.MultinameKind kind = (Multiname.MultinameKind) this.abcdtr.ReadUI8(); switch (kind) { case Multiname.MultinameKind.QName: case Multiname.MultinameKind.QNameA: int nsi = (int)this.abcdtr.ReadU30(); ns = this.code.GetNamespace(nsi); name = this.ReadString(); break; case Multiname.MultinameKind.RTQName: case Multiname.MultinameKind.RTQNameA: name = this.ReadString(); break; case Multiname.MultinameKind.RTQNameL: case Multiname.MultinameKind.RTQNameLA: /* No data */ break; case Multiname.MultinameKind.Multiname: case Multiname.MultinameKind.MultinameA: name = this.ReadString(); set = this.code.GetNamespaceSet((int)this.abcdtr.ReadU30()); break; case Multiname.MultinameKind.MultinameL: case Multiname.MultinameKind.MultinameLA: set = this.code.GetNamespaceSet((int)this.abcdtr.ReadU30()); break; default: throw new SWFModellerException( SWFModellerError.ABCParsing, "Bad multiname kind in ABC data."); } Multiname mn = this.code.CreateMultiname(kind, name, ns, set); #if DEBUG if (this.ReadLog != null) { this.ReadLog.AppendLine("mn #" + i + ": " + mn); } #endif } }
/// <summary> /// Renames the main timeline class. /// </summary> /// <param name="classQName">New name of the class.</param> internal void RenameMainTimelineClass(string classQName) { if (this.Class == null) { throw new SWFModellerException(SWFModellerError.Internal, "Can't rename non-existant timeline class."); } AS3ClassDef classDef = this.Class as AS3ClassDef; if (classDef == null) { throw new SWFModellerException(SWFModellerError.Internal, "MainTimeline class is an in-built class, which is impossible."); } int splitPos = classQName.LastIndexOf('.'); string className = classQName; string newPackageName = string.Empty; if (splitPos != -1) { newPackageName = classQName.Substring(0, splitPos); className = classQName.Substring(splitPos + 1); } /* Class name will be a QName, so won't have a NS set */ Multiname oldName = classDef.Name; Namespace oldNameNS = oldName.NS; Multiname newName = this.scripts[0].Code.CreateMultiname( oldName.Kind, className, this.scripts[0].Code.CreateNamespace(oldNameNS.Kind, newPackageName), null); Namespace oldProtectedNS = classDef.ProtectedNS; Namespace newProtectedNS = null; if (oldProtectedNS != null) { newProtectedNS = this.scripts[0].Code.CreateNamespace(oldProtectedNS.Kind, newPackageName + ":" + className); } this.ClassProc(delegate(AS3ClassDef c) { bool inRenamedClass = false; if (c.Name == oldName) { inRenamedClass = true; c.Name = newName; } if (c.Supername == oldName) { c.Supername = newName; } if (c.ProtectedNS == oldProtectedNS) { c.ProtectedNS = newProtectedNS; } c.TraitProc(delegate(ref Trait t, AbcCode abc) { Namespace traitNS = t.Name.NS; if (traitNS == null) { return; } if (!t.Name.IsEmptySet) { /* ISSUE 32: Delete this once confidence is felt. */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "Trait name has a set. I didn't think that was possible! Following code needs fixed!!!"); } switch (traitNS.Kind) { case Namespace.NamespaceKind.PackageInternal: case Namespace.NamespaceKind.Package: if (inRenamedClass && traitNS.Name == oldNameNS.Name) { t.Name = this.scripts[0].Code.CreateMultiname( t.Name.Kind, t.Name.Name, this.scripts[0].Code.CreateNamespace(traitNS.Kind, newPackageName), null); } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported namespace (" + traitNS.Kind + ") when remapping a class trait (" + c.Name.Name + "::" + t.Name + ")"); } }); }); this.MethodProc(delegate(Method m, AS3ClassDef c) { bool inRenamedClass = c.Name == newName; m.OpcodeFilter(delegate(ref Opcode op, AbcCode abc) { if (op.Args == null) { return; } for (int i = 0; i < op.Args.Length; i++) { object arg = op.Args[i]; if (arg is Multiname) { Multiname mn = (Multiname)arg; if (mn == oldName) { op.Args[i] = newName; } else if (inRenamedClass) { bool isMnModified = false; Namespace multinameNS = mn.NS; NamespaceSet multinameSet = mn.Set; if (multinameNS != null) { switch (multinameNS.Kind) { case Namespace.NamespaceKind.Package: case Namespace.NamespaceKind.PackageInternal: if (inRenamedClass && multinameNS.Name == oldNameNS.Name) { multinameNS = this.scripts[0].Code.CreateNamespace( multinameNS.Kind, newPackageName); isMnModified = true; } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported multiname's NS kind (" + multinameNS.Kind.ToString() + ") in op's Multiname arg during MethodProc"); } } if (multinameSet != null) { List <Namespace> newSet = new List <Namespace>(multinameSet.Count); bool isSetModified = false; foreach (Namespace ns in multinameSet) { switch (ns.Kind) { case Namespace.NamespaceKind.Protected: case Namespace.NamespaceKind.StaticProtected: if (ns.Name == oldProtectedNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newProtectedNS.Name)); isSetModified = true; continue; } break; case Namespace.NamespaceKind.Package: case Namespace.NamespaceKind.PackageInternal: case Namespace.NamespaceKind.Private: if (inRenamedClass && ns.Name == oldNameNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newPackageName)); isSetModified = true; continue; } break; case Namespace.NamespaceKind.Ns: if (ns.Name == oldNameNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newPackageName)); isSetModified = true; continue; } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported multiname NS set entry kind (" + ns.Kind.ToString() + ") in op's Multiname arg during MethodProc"); } newSet.Add(ns); } if (isSetModified) { isMnModified = true; multinameSet = new NamespaceSet(newSet.ToArray()); } } if (isMnModified) { op.Args[i] = this.scripts[0].Code.CreateMultiname( mn.Kind, mn.Name, multinameNS, multinameSet); } } } else if (arg is Namespace) { /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported op arg in MethodProc: Namespace"); } else if (arg is AS3Class) { /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported op arg in MethodProc: AS3Class"); } } }); }); }
/// <summary> /// Renames the main timeline class. /// </summary> /// <param name="classQName">New name of the class.</param> internal void RenameMainTimelineClass(string classQName) { if (this.Class == null) { throw new SWFModellerException(SWFModellerError.Internal, "Can't rename non-existant timeline class."); } AS3ClassDef classDef = this.Class as AS3ClassDef; if (classDef == null) { throw new SWFModellerException(SWFModellerError.Internal, "MainTimeline class is an in-built class, which is impossible."); } int splitPos = classQName.LastIndexOf('.'); string className = classQName; string newPackageName = string.Empty; if (splitPos != -1) { newPackageName = classQName.Substring(0, splitPos); className = classQName.Substring(splitPos + 1); } /* Class name will be a QName, so won't have a NS set */ Multiname oldName = classDef.Name; Namespace oldNameNS = oldName.NS; Multiname newName = this.scripts[0].Code.CreateMultiname( oldName.Kind, className, this.scripts[0].Code.CreateNamespace(oldNameNS.Kind, newPackageName), null); Namespace oldProtectedNS = classDef.ProtectedNS; Namespace newProtectedNS = null; if (oldProtectedNS != null) { newProtectedNS = this.scripts[0].Code.CreateNamespace(oldProtectedNS.Kind, newPackageName + ":" + className); } this.ClassProc(delegate(AS3ClassDef c) { bool inRenamedClass = false; if (c.Name == oldName) { inRenamedClass = true; c.Name = newName; } if (c.Supername == oldName) { c.Supername = newName; } if (c.ProtectedNS == oldProtectedNS) { c.ProtectedNS = newProtectedNS; } c.TraitProc(delegate(ref Trait t, AbcCode abc) { Namespace traitNS = t.Name.NS; if (traitNS == null) { return; } if (!t.Name.IsEmptySet) { /* ISSUE 32: Delete this once confidence is felt. */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "Trait name has a set. I didn't think that was possible! Following code needs fixed!!!"); } switch (traitNS.Kind) { case Namespace.NamespaceKind.PackageInternal: case Namespace.NamespaceKind.Package: if (inRenamedClass && traitNS.Name == oldNameNS.Name) { t.Name = this.scripts[0].Code.CreateMultiname( t.Name.Kind, t.Name.Name, this.scripts[0].Code.CreateNamespace(traitNS.Kind, newPackageName), null); } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported namespace (" + traitNS.Kind + ") when remapping a class trait (" + c.Name.Name + "::" + t.Name + ")"); } }); }); this.MethodProc(delegate(Method m, AS3ClassDef c) { bool inRenamedClass = c.Name == newName; m.OpcodeFilter(delegate(ref Opcode op, AbcCode abc) { if (op.Args == null) { return; } for (int i = 0; i < op.Args.Length; i++) { object arg = op.Args[i]; if (arg is Multiname) { Multiname mn = (Multiname)arg; if (mn == oldName) { op.Args[i] = newName; } else if (inRenamedClass) { bool isMnModified = false; Namespace multinameNS = mn.NS; NamespaceSet multinameSet = mn.Set; if (multinameNS != null) { switch (multinameNS.Kind) { case Namespace.NamespaceKind.Package: case Namespace.NamespaceKind.PackageInternal: if (inRenamedClass && multinameNS.Name == oldNameNS.Name) { multinameNS = this.scripts[0].Code.CreateNamespace( multinameNS.Kind, newPackageName); isMnModified = true; } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported multiname's NS kind (" + multinameNS.Kind.ToString() + ") in op's Multiname arg during MethodProc"); } } if (multinameSet != null) { List<Namespace> newSet = new List<Namespace>(multinameSet.Count); bool isSetModified = false; foreach (Namespace ns in multinameSet) { switch (ns.Kind) { case Namespace.NamespaceKind.Protected: case Namespace.NamespaceKind.StaticProtected: if (ns.Name == oldProtectedNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newProtectedNS.Name)); isSetModified = true; continue; } break; case Namespace.NamespaceKind.Package: case Namespace.NamespaceKind.PackageInternal: case Namespace.NamespaceKind.Private: if (inRenamedClass && ns.Name == oldNameNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newPackageName)); isSetModified = true; continue; } break; case Namespace.NamespaceKind.Ns: if (ns.Name == oldNameNS.Name) { newSet.Add(this.scripts[0].Code.CreateNamespace( ns.Kind, newPackageName)); isSetModified = true; continue; } break; default: /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported multiname NS set entry kind (" + ns.Kind.ToString() + ") in op's Multiname arg during MethodProc"); } newSet.Add(ns); } if (isSetModified) { isMnModified = true; multinameSet = new NamespaceSet(newSet.ToArray()); } } if (isMnModified) { op.Args[i] = this.scripts[0].Code.CreateMultiname( mn.Kind, mn.Name, multinameNS, multinameSet); } } } else if (arg is Namespace) { /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported op arg in MethodProc: Namespace"); } else if (arg is AS3Class) { /* ISSUE 73 */ throw new SWFModellerException( SWFModellerError.UnimplementedFeature, "As yet unsupported op arg in MethodProc: AS3Class"); } } }); }); }
/// <summary> /// Adds a set to the code. /// </summary> /// <param name="set">The set to add.</param> public void AddNamespaceSet(NamespaceSet set) { this.nsSetConsts.Add(set); }