public override void EmitMetaSetup(DomBlock block, Offsets offsets)
        {
            var tmp = block.TempVar();
            PropertyDecorator element = Decorator.ElementDecorator;

            element.Definition.Name += "[]";

            offsets.OffsetStorage = "{0} + ({1} * {2}) /*required-storage:{2}*/".Expr(Decorator.OffsetStorage, tmp,
                                                                                      element.RequiredStorage);
            offsets.OffsetProperties = "{0} + ({1} * {2}) /*required-properties:{2}*/".Expr(Decorator.OffsetProperties,
                                                                                            tmp, element.RequiredProperties);

            if (element.RequiredObjects == 0)
            {
                offsets.OffsetObjects = "0 /*required-objects:{0}*/".Expr(element.RequiredObjects);
            }
            else
            {
                offsets.OffsetObjects = "{0} + ({1} * {2}) /*required-objects:{2}*/".Expr(Decorator.OffsetObjects + 1,
                                                                                          tmp, element.RequiredObjects);
            }

            block.Stmts.For(tmp, tmp + " < " + Decorator.PropertyType.ElementCount,
                            body => { Create(element).EmitMetaSetup(new DomBlock(body, tmp + "_"), offsets, tmp.Expr()); });
        }
        public override void EmitObjectSetup(DomBlock block, Offsets offsets)
        {
            PropertyDecorator element = Decorator.ElementDecorator;

            if (element is PropertyDecoratorStruct)
            {
                PropertyDecoratorStruct structDecorator = (PropertyDecoratorStruct)element;
                EmitInitObject(Decorator.ClrType, block, offsets,             /* size */
                               Decorator.PropertyType.ElementCount.Literal(), /* stride */
                               structDecorator.RequiredObjects.Literal());

                var tmp = block.TempVar();
                element.Definition.Name += "[]";

                offsets.OffsetStorage = "offsets.OffsetStorage + {0} + ({1} * {2})".Expr(Decorator.OffsetStorage, tmp,
                                                                                         element.RequiredStorage);
                offsets.OffsetObjects = "offsets.OffsetObjects + {0} + ({1} * {2})".Expr(Decorator.OffsetObjects + 1,
                                                                                         tmp, element.RequiredObjects);
                offsets.OffsetProperties =
                    "offsets.OffsetProperties + {0} + ({1} * {2})".Expr(Decorator.OffsetProperties, tmp,
                                                                        element.RequiredProperties);

                block.Stmts.For(tmp, tmp + " < " + Decorator.PropertyType.ElementCount,
                                body => { Create(element).EmitObjectSetup(new DomBlock(body, tmp + "_"), offsets); });
            }
            else
            {
                EmitInitObject(Decorator.ClrType, block, offsets, /* size */
                               Decorator.PropertyType.ElementCount.Literal(), /* stride */ element.RequiredStorage.Literal());
            }
        }
Example #3
0
        public virtual void EmitObjectSetup(DomBlock block, Offsets offsets)
        {
            Assert.True(Decorator.RequiredObjects == 0);
            block.Stmts.Comment("EMPTY");

            // add storage
            //block.Stmts.Expr("{0}.AddSerializer({1})", group, this.Decorator.RequiredStorage);
        }
Example #4
0
        public void EmitInitObject(string type, DomBlock block, Offsets offsets, params CodeExpression[] ctorArguments)
        {
            var tmp = block.Stmts.Var(type, block.TempVar());

            block.Stmts.Add(tmp.Assign(type.New(ctorArguments)));
            block.Stmts.Add(tmp.Call("Init", Decorator.Definition.Name.Literal(), "obj.Root".Expr(),
                                     "Ascension.Networking.NetworkObj_Meta.Offsets".New(offsets.OffsetProperties, offsets.OffsetStorage,
                                                                                        offsets.OffsetObjects)));
        }
Example #5
0
 public override void EmitMetaSetup(DomBlock block, Offsets offsets, CodeExpression indexExpression)
 {
     block.Add("this".Expr().Call("CopyProperties",
                                  offsets.OffsetProperties,
                                  offsets.OffsetObjects,
                                  Decorator.Object.NameMeta.Expr().Field("Instance"),
                                  Decorator.Definition.Name.Literal(),
                                  indexExpression ?? (-1).Literal()
                                  ));
 }
Example #6
0
        public virtual void EmitMetaSetup(DomBlock block, Offsets offsets, CodeExpression indexExpression)
        {
            var tmp = block.Stmts.Var(SerializerClassName, block.TempVar());

            block.Stmts.Assign(tmp, SerializerClassName.New());
            block.Stmts.Assign(tmp.Field("PropertyMeta"), "this".Expr());

            EmitAddSettings(tmp, block.Stmts, offsets);

            block.Stmts.Add("this".Expr()
                            .Call("AddProperty", offsets.OffsetProperties, offsets.OffsetObjects, tmp,
                                  indexExpression ?? (-1).Literal()));
        }
Example #7
0
        public virtual void EmitMetaSetup(DomBlock block)
        {
            Offsets offsets = new Offsets();

            offsets.OffsetStorage = "{0} /*required-storage:{1}*/".Expr(Decorator.OffsetStorage,
                                                                        Decorator.RequiredStorage);
            offsets.OffsetProperties = "{0} /*required-properties:{1}*/".Expr(Decorator.OffsetProperties,
                                                                              Decorator.RequiredProperties);
            offsets.OffsetObjects = "{0} /*required-objects:{1}*/".Expr(Decorator.OffsetObjects,
                                                                        Decorator.RequiredObjects);

            EmitMetaSetup(block, offsets);
        }
Example #8
0
        protected override void EmitFactory()
        {
            base.EmitFactory();

            MetaType.DeclareMethod(typeof(void), "Dispatch", method =>
            {
                method.DeclareParameter("Ascension.Networking.Event", "ev");
                method.DeclareParameter(typeof(object).FullName, "target");

                DomBlock block = new DomBlock(method.Statements);

                var tmp = block.TempVar();

                block.Stmts.Expr("{0} {1} = target as {0}", Decorator.ListenerInterface, tmp);
                block.Stmts.Expr("if ({0} != null) {{ {0}.OnEvent(({1})ev); }}", tmp, Decorator.Name);
            }).PrivateImplementationType = new CodeTypeReference(Decorator.FactoryInterface);
        }
Example #9
0
 public virtual void EmitMetaSetup(DomBlock block, Offsets offsets)
 {
     EmitMetaSetup(block, offsets, null);
 }
Example #10
0
 public override void EmitObjectSetup(DomBlock block, Offsets offsets)
 {
     EmitInitObject(Decorator.ClrType, block, offsets);
 }
        protected virtual void EmitMeta()
        {
            MetaType = Generator.DeclareClass(Decorator.NameMeta);
            //MetaType.TypeAttributes = TypeAttributes.NestedAssembly;
            //Needed to change the emitted code to be 'public' instead of 'internal'
            MetaType.Attributes     = MemberAttributes.Public;
            MetaType.TypeAttributes = TypeAttributes.Public;

            MetaType.BaseTypes.Add(Decorator.BaseClassMeta);
            MetaType.BaseTypes.Add(Decorator.FactoryInterface);

            //MetaType.DeclareField(Decorator.NameMeta, "Instance").Attributes = MemberAttributes.Static |
            //                                                                   MemberAttributes.Assembly;

            MetaType.DeclareField(Decorator.NameMeta, "Instance").Attributes = MemberAttributes.Static |
                                                                               MemberAttributes.Public;

            MetaType.DeclareConstructorStatic(ctor =>
            {
                ctor.Statements.Add("Instance".Expr().Assign(Decorator.NameMeta.New()));
                ctor.Statements.Add("Instance".Expr().Call("InitMeta"));

                EmitMetaStaticCtor(ctor);
            });

            // initialize object
            MetaType.DeclareMethod(typeof(void).FullName, "InitObject", method =>
            {
                //method.Attributes = MemberAttributes.Assembly | MemberAttributes.Override;

                method.Attributes = MemberAttributes.Public | MemberAttributes.Override;

                method.DeclareParameter("Ascension.Networking.NetworkObj", "obj");
                method.DeclareParameter("Ascension.Networking.NetworkObj_Meta.Offsets", "offsets");

                DomBlock block;
                block = new DomBlock(method.Statements);

                for (int i = 0; i < Decorator.Properties.Count; ++i)
                {
                    block.Stmts.Comment("");
                    block.Stmts.Comment("Property: " + Decorator.Properties[i].Definition.Name);
                    PropertyCodeEmitter.Create(Decorator.Properties[i]).EmitObjectSetup(block);
                }

                EmitObjectInit(method);
            });

            // initialize meta class
            MetaType.DeclareMethod(typeof(void).FullName, "InitMeta", method =>
            {
                //method.Attributes = MemberAttributes.Assembly | MemberAttributes.Override;

                method.Attributes = MemberAttributes.Public | MemberAttributes.Override;

                DomBlock block;

                block = new DomBlock(method.Statements);
                block.Stmts.Comment("Setup fields");
                block.Stmts.Expr("this.TypeId = new Ascension.Networking.TypeId({0})", Decorator.TypeId);
                block.Stmts.Expr("this.CountStorage = {0}", Decorator.CountStorage);
                block.Stmts.Expr("this.CountObjects = {0}", Decorator.CountObjects);
                block.Stmts.Expr("this.CountProperties = {0}", Decorator.CountProperties);
                block.Stmts.Expr("this.Properties = new Ascension.Networking.NetworkPropertyInfo[{0}]", Decorator.CountProperties);

                EmitMetaInit(method);

                for (int i = 0; i < Decorator.Properties.Count; ++i)
                {
                    block.Stmts.Comment("");
                    block.Stmts.Comment("Property: " + Decorator.Properties[i].Definition.Name);
                    PropertyCodeEmitter.Create(Decorator.Properties[i]).EmitMetaSetup(block);
                }

                block.Stmts.Expr("base.InitMeta()");
            });

            // emit factory interface
            EmitFactory();
        }