SWFProcessing.SWFModeller.ABC.AbcCode.Op C# (CSharp) Method

Op() private method

Technically, from an OO perspective, this isn't the most logical place for this method. It's a factory method for opcodes used when building up new methods, bytecode by bytecode. It's here because this is the place that makes calling it require the least typing, which is good when you're creating lists of loads of these things.
private Op ( Opcode mnemonic ) : Opcode
mnemonic SWFProcessing.SWFModeller.ABC.Code.Opcode The opcode mnemonic
return SWFProcessing.SWFModeller.ABC.Code.Opcode
        internal Opcode Op(Opcode.Mnemonics mnemonic, params object[] args)
        {
            Opcode op = new Opcode(this) { Mnemonic = mnemonic, Args = args.Length == 0 ? null : args };

            if (mnemonic != Opcode.Mnemonics.LookupSwitch)
            {
                if (!Opcode.VerifyArgTypes(mnemonic, args))
                {
                    throw new SWFModellerException(
                            SWFModellerError.Internal,
                            "Invalid arg values or types in opcode " + mnemonic.ToString());
                }
            }

            /* ISSUE 7: There must be some way to verify lookupswitch to some degree.
             * Update: There is. The case count must be correct and the offsets must be references
             * to preceeding Label opcodes. */

            return op;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Factory method for a new timeline class.
        /// </summary>
        /// <param name="abc">The abc code to create the class within.</param>
        /// <param name="packageName">Name of the fla. You can make this up, since you probably don't have
        /// a fla.</param>
        /// <param name="className">Name of the class.</param>
        /// <returns>A bew timeline class.</returns>
        private static AS3ClassDef GenerateTimelineClass(AbcCode abc, string qClassName, SWFContext ctx)
        {
            int splitPos = qClassName.LastIndexOf('.');

            if (splitPos < 0)
            {
                throw new SWFModellerException(SWFModellerError.CodeMerge,
                                               "A generated timeline class must have a package name.",
                                               ctx.Sentinel("TimelineDefaultPackage"));
            }

            string packageName = qClassName.Substring(0, splitPos);
            string className   = qClassName.Substring(splitPos + 1);

            /* Class name: */
            Namespace flaNS = abc.CreateNamespace(Namespace.NamespaceKind.Package, packageName);
            Multiname classMultinameName = abc.CreateMultiname(Multiname.MultinameKind.QName, className, flaNS, null);

            /* Superclass: */
            Namespace nsFlashDisplay = abc.CreateNamespace(Namespace.NamespaceKind.Package, "flash.display");
            Multiname mnMovieClip    = abc.CreateMultiname(Multiname.MultinameKind.QName, "MovieClip", nsFlashDisplay, null);

            AS3ClassDef newClass = abc.CreateClass();

            newClass.Name      = classMultinameName;
            newClass.Supername = mnMovieClip;

            Namespace protectedNS = abc.CreateNamespace(Namespace.NamespaceKind.Protected, packageName + ":" + className);

            newClass.ProtectedNS = protectedNS;

            newClass.Cinit = abc.CreateMethod(className + "Constructor.abc", 1, 1, 9, 10,

                                              /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                               * I have no real ideal about how I'd work them out for myself, which would obviously be
                                               * more ideal. */

                                              /* AFAICT, this is always generated by the IDE because the abc file format
                                               * doesn't allow for classes with no static initialiser. It doesn't seem
                                               * to actually do anything. */

                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.PushScope),
                                              abc.Op(Opcode.Mnemonics.ReturnVoid));

            newClass.Iinit = abc.CreateMethod(className + "ClassInit.abc", 1, 1, 10, 11,

                                              /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                               * I have no real ideal about how I'd work them out for myself, which would obviously be
                                               * more ideal. */

                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.PushScope),
                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.ConstructSuper, 0U),

                                              abc.Op(Opcode.Mnemonics.ReturnVoid));

            return(newClass);
        }
All Usage Examples Of SWFProcessing.SWFModeller.ABC.AbcCode::Op