CreateNamespace() private method

private CreateNamespace ( Namespace kind, string name, string prefix = null ) : Namespace
kind Namespace
name string
prefix string
return Namespace
Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Factory method for a new timeline script.
        /// </summary>
        /// <param name="abc">The abc object to create the script into.</param>
        /// <param name="timelineClass">A generated timeline class. See GenerateTimelineClass</param>
        /// <returns>The new method</returns>
        private static Method GenerateTimelineScript(AbcCode abc, AS3ClassDef timelineClass)
        {
            Multiname mnMovieClip    = timelineClass.Supername;
            Namespace nsFlashDisplay = mnMovieClip.NS;

            Namespace nsEmptyPackage = abc.CreateNamespace(Namespace.NamespaceKind.Package, string.Empty);
            Namespace nsFlashEvents  = abc.CreateNamespace(Namespace.NamespaceKind.Package, "flash.events");

            Multiname mnObject                 = abc.CreateMultiname(Multiname.MultinameKind.QName, "Object", nsEmptyPackage, null);
            Multiname mnEventDispatcher        = abc.CreateMultiname(Multiname.MultinameKind.QName, "EventDispatcher", nsFlashEvents, null);
            Multiname mnDisplayObject          = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObject", nsFlashDisplay, null);
            Multiname mnInteractiveObject      = abc.CreateMultiname(Multiname.MultinameKind.QName, "InteractiveObject", nsFlashDisplay, null);
            Multiname mnDisplayObjectContainer = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObjectContainer", nsFlashDisplay, null);
            Multiname mnSprite                 = abc.CreateMultiname(Multiname.MultinameKind.QName, "Sprite", nsFlashDisplay, null);

            return(abc.CreateMethod("Timeline.abc", 2, 1, 1, 9,

                                    /* 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.GetScopeObject, (byte)0),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnEventDispatcher),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnInteractiveObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObjectContainer),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnSprite),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                    abc.Op(Opcode.Mnemonics.NewClass, timelineClass),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.InitProperty, timelineClass.Name),
                                    abc.Op(Opcode.Mnemonics.ReturnVoid)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Factory method for a new timeline script.
        /// </summary>
        /// <param name="abc">The abc object to create the script into.</param>
        /// <param name="timelineClass">A generated timeline class. See GenerateTimelineClass</param>
        /// <returns>The new method</returns>
        private static Method GenerateTimelineScript(AbcCode abc, AS3ClassDef timelineClass)
        {
            Multiname mnMovieClip = timelineClass.Supername;
            Namespace nsFlashDisplay = mnMovieClip.NS;

            Namespace nsEmptyPackage = abc.CreateNamespace(Namespace.NamespaceKind.Package, string.Empty);
            Namespace nsFlashEvents = abc.CreateNamespace(Namespace.NamespaceKind.Package, "flash.events");

            Multiname mnObject = abc.CreateMultiname(Multiname.MultinameKind.QName, "Object", nsEmptyPackage, null);
            Multiname mnEventDispatcher = abc.CreateMultiname(Multiname.MultinameKind.QName, "EventDispatcher", nsFlashEvents, null);
            Multiname mnDisplayObject = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObject", nsFlashDisplay, null);
            Multiname mnInteractiveObject = abc.CreateMultiname(Multiname.MultinameKind.QName, "InteractiveObject", nsFlashDisplay, null);
            Multiname mnDisplayObjectContainer = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObjectContainer", nsFlashDisplay, null);
            Multiname mnSprite = abc.CreateMultiname(Multiname.MultinameKind.QName, "Sprite", nsFlashDisplay, null);

            return abc.CreateMethod("Timeline.abc", 2, 1, 1, 9,

                /* 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.GetScopeObject, (byte)0),
                abc.Op(Opcode.Mnemonics.GetLex, mnObject),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnEventDispatcher),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObject),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnInteractiveObject),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObjectContainer),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnSprite),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                abc.Op(Opcode.Mnemonics.PushScope),
                abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                abc.Op(Opcode.Mnemonics.NewClass, timelineClass),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.PopScope),
                abc.Op(Opcode.Mnemonics.InitProperty, timelineClass.Name),
                abc.Op(Opcode.Mnemonics.ReturnVoid));
        }
Exemplo n.º 4
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;
        }