Exemplo n.º 1
0
        void EmitDefault(CodeTypeDeclaration ctd)
        {
            // Override the HasDefault property

            CodeMemberProperty p = new CodeMemberProperty();

            p.Name       = "HasDefault";
            p.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            p.Type       = new CodeTypeReference(typeof(bool));
            p.HasGet     = true;
            p.HasSet     = false;
            p.GetStatements.Add(new CodeMethodReturnStatement(CDH.True));

            ctd.Members.Add(p);

            // Override the Default property

            p            = new CodeMemberProperty();
            p.Name       = "Default";
            p.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            p.Type       = CDH.Result;
            p.HasGet     = true;
            p.HasSet     = false;
            CodeExpression e = CDH.ThisDot(fields[comp_default_idx].Name);

            p.GetStatements.Add(new CodeMethodReturnStatement(e));

            ctd.Members.Add(p);
        }
Exemplo n.º 2
0
        public void EmitGetFingerprint(CodeTypeDeclaration ctd)
        {
            byte[] hash = Hash;

            CodeArrayCreateExpression mkdata = new CodeArrayCreateExpression(CDH.Byte, hash.Length);

            for (int i = 0; i < hash.Length; i++)
            {
                // well, this for loop sucks
                mkdata.Initializers.Add(new CodePrimitiveExpression(hash[i]));
            }

            CodeMemberMethod m = new CodeMemberMethod();

            m.Name       = "GetFingerprint";
            m.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            m.ReturnType = CDH.Fingerprint;
            m.Parameters.Add(CDH.Param(CDH.IContext, "unused1"));
            m.Parameters.Add(CDH.Param(CDH.Fingerprint, "unused2"));

            CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression();

            invoke.Method = new CodeMethodReferenceExpression(Generic, "Constant");
            invoke.Parameters.Add(mkdata);

            m.Statements.Add(new CodeMethodReturnStatement(invoke));

            ctd.Members.Add(m);
        }
Exemplo n.º 3
0
        void EmitTargetArg(CodeMemberMethod list, CodeVariableReferenceExpression sink,
                           CodeMemberMethod fetch, CodeVariableReferenceExpression source,
                           CodeMemberMethod clear, CodeTypeDeclaration cur_type)
        {
            // Field definition expression

            CodeMemberField fieldmem = new CodeMemberField(CDH.String, target_arg_name);

            fieldmem.Attributes = MemberAttributes.Family;
            cur_type.Members.Add(fieldmem);

            CodeFieldReferenceExpression fieldref = CDH.ThisDot(target_arg_name);

            // ListArguments

            CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression();

            invoke.Method = new CodeMethodReferenceExpression(sink, "WantTargetName");
            invoke.Parameters.Add(new CodePrimitiveExpression(target_arg_reqd));
            list.Statements.Add(invoke);

            // FetchArgValues

            invoke        = new CodeMethodInvokeExpression();
            invoke.Method = new CodeMethodReferenceExpression(source, "GetTargetName");

            CodeAssignStatement assg = new CodeAssignStatement(fieldref, invoke);

            fetch.Statements.Add(assg);

            // ClearArgValues

            assg = new CodeAssignStatement(fieldref, CDH.Null);
            clear.Statements.Add(assg);
        }
Exemplo n.º 4
0
        public void EmitApply(CodeMemberMethod apply,
                              CodeVariableReferenceExpression pb,
                              CodeVariableReferenceExpression tb,
                              CodeArgumentReferenceExpression log)
        {
            apply.Statements.Add(new CodeCommentStatement("Create target " + name));

            // Set the TargetBuilder var and rule or template.

            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();

            cmie.Method = new CodeMethodReferenceExpression(pb, "DefineTarget");
            cmie.Parameters.Add(new CodePrimitiveExpression(name));
            cmie.Parameters.Add(log);

            apply.Statements.Add(new CodeAssignStatement(tb, cmie));
            apply.Statements.Add(CDH.IfNullReturnTrue(tb));

            Converter = delegate(string targ) {
                return(prov.NS.MakeTargetNameExpr(targ, CDH.This,
                                                  new CodeFieldReferenceExpression(pb, "Basis")));
            };

            EmitInfo(apply, tb);
        }
Exemplo n.º 5
0
        public override void EmitApply(CodeMemberMethod apply, CodeArgumentReferenceExpression proj,
                                       CodeArgumentReferenceExpression declloc,
                                       CodeArgumentReferenceExpression log,
                                       CodeVariableReferenceExpression pb,
                                       CodeVariableReferenceExpression tb)
        {
            apply.Statements.Add(new CodeCommentStatement("Create provider for param " +
                                                          basisparam));

            CodeMethodInvokeExpression mie = new CodeMethodInvokeExpression();

            mie.Method = new CodeMethodReferenceExpression(proj, "EnsureProvider");
            mie.Parameters.Add(new CodeFieldReferenceExpression(CDH.This, basisparam));
            mie.Parameters.Add(declloc);

            apply.Statements.Add(new CodeAssignStatement(pb, mie));

            // Tell the PB about our Structure arguments so it can
            // use them to instantiate the objects we reference.
            // FIXME: catch if the provider references a rule or template
            // that requires a structure we don't have.

            //if (Structure != null) {
            mie        = new CodeMethodInvokeExpression();
            mie.Method = new CodeMethodReferenceExpression(pb, "AddContextStructure");
            mie.Parameters.Add(CDH.This);
            apply.Statements.Add(mie);

            foreach (string param in Structure.Parameters)
            {
                if (Structure[param] != StructureParameterKind.Structure)
                {
                    continue;
                }

                mie        = new CodeMethodInvokeExpression();
                mie.Method = new CodeMethodReferenceExpression(pb, "AddContextStructure");
                mie.Parameters.Add(new CodeFieldReferenceExpression(CDH.This, param));
                apply.Statements.Add(mie);
            }
            //}

            foreach (BGTargetBuilder iter in targs)
            {
                iter.EmitApply(apply, pb, tb, log);
            }

            foreach (string key in lits.Keys)
            {
                CodeExpression val = CDH.ResultExpression(lits[key]);

                CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();
                cmie.Method = new CodeMethodReferenceExpression(pb, "DefineConstantTarget");
                cmie.Parameters.Add(new CodePrimitiveExpression(key));
                cmie.Parameters.Add(val);
                cmie.Parameters.Add(log);

                apply.Statements.Add(CDH.IfTrueReturnTrue(cmie));
            }
        }
Exemplo n.º 6
0
        void EmitBuildFunc(CodeTypeDeclaration cur_type)
        {
            // FIXME: allow retclass to be 'bool', 'string', etc and do the
            // appropriate conversions.

            CodeParameterDeclarationExpression p = CDH.Param(CDH.IContext, bf_context_arg);

            CodeMemberMethod meth = new CodeMemberMethod();

            meth.Name       = "Build";
            meth.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            meth.ReturnType = CDH.Result;
            meth.Parameters.Add(p);

            if (bf_manual)
            {
                EmitBuildManual(meth);
            }
            else
            {
                EmitBuildWrapped(cur_type, meth);
            }

            cur_type.Members.Add(meth);

            // We know this. In Resolve() we check that OverrideResultType is
            // not set if we have a build func (which would lead to
            // emitting the 'general result type' code twice)

            EmitGeneralResult(cur_type, bf_ret_class);
        }
Exemplo n.º 7
0
        protected override void Emit(CodeTypeDeclaration ctd)
        {
            EmitEmptyCtor (ctd);

            // Parameter fields

            foreach (string name in sparams.Keys)
            EmitParameter (ctd, name);

            // ApplyDefaults

            EmitApplyDefaults (ctd);

            // Apply prologue

            CodeParameterDeclarationExpression p1 =
            new CodeParameterDeclarationExpression (ProjBuilder, "proj");
            CodeParameterDeclarationExpression p2 =
            new CodeParameterDeclarationExpression (CDH.String, "declloc");
            CodeParameterDeclarationExpression p3 =
            new CodeParameterDeclarationExpression (CDH.ILog, "log");

            CodeMemberMethod apply = new CodeMemberMethod ();
            apply.Name = "Apply";
            apply.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            apply.ReturnType = CDH.Bool;
            apply.Parameters.Add (p1);
            apply.Parameters.Add (p2);
            apply.Parameters.Add (p3);

            CDH.EmitBaseChainBool (apply);

            // Elements

            if (elts.Count > 0) {
            apply.Statements.Add (CDH.Variable (ProvBuilder, "pb"));
            apply.Statements.Add (CDH.Variable (TargBuilder, "tb"));

            CodeArgumentReferenceExpression proj = CDH.ARef ("proj");
            CodeArgumentReferenceExpression declloc = CDH.ARef ("declloc");
            CodeArgumentReferenceExpression log = CDH.ARef ("log");
            CodeVariableReferenceExpression pb = CDH.VRef ("pb");
            CodeVariableReferenceExpression tb = CDH.VRef ("tb");

            foreach (StructureElement se in elts)
            se.EmitApply (apply, proj, declloc, log, pb, tb);
            }

            // Apply epilogue

            apply.Statements.Add (new CodeMethodReturnStatement (CDH.False));
            ctd.Members.Add (apply);
        }
Exemplo n.º 8
0
        void EmitApplyDefaults(CodeTypeDeclaration ctd)
        {
            CodeMemberMethod meth = new CodeMemberMethod ();
            meth.Name = "ApplyDefaults";
            meth.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            meth.ReturnType = CDH.Bool;
            meth.Parameters.Add (CDH.Param (BMBase, "bmb"));
            meth.Parameters.Add (CDH.Param (CDH.ILog, "log"));

            CodeArgumentReferenceExpression bmb = CDH.ARef ("bmb");
            CodeArgumentReferenceExpression log = CDH.ARef ("log");

            // Set the parameters

            foreach (string param in sparams.Keys) {
            StructureParameterKind kind = sparams[param];
            string val = defaults[param];

            CodeAssignStatement assg = new CodeAssignStatement ();
            assg.Left = CDH.ThisDot (param);

            switch (kind) {
            case StructureParameterKind.Basis:
            if (val[val.Length - 1] != '/')
            // Canonicalize basis names.
            val += '/';
            goto case StructureParameterKind.Target;
            case StructureParameterKind.Target:
            assg.Right = new CodePrimitiveExpression (val);
            break;
            case StructureParameterKind.Structure:
            CodeMethodInvokeExpression mie = new CodeMethodInvokeExpression ();
            mie.Method = new CodeMethodReferenceExpression (bmb, "GetNamespaceTemplate");
            mie.Parameters.Add (new CodePrimitiveExpression (val));
            mie.Parameters.Add (log);
            UserType stype = structtypes[param];
            assg.Right = new CodeCastExpression (stype.AsCodeDom, mie);
            break;
            }

            meth.Statements.Add (assg);

            if (kind == StructureParameterKind.Structure)
            meth.Statements.Add (CDH.IfNullReturnTrue (assg.Left));
            }

            // All done.

            meth.Statements.Add (new CodeMethodReturnStatement (CDH.False));

            ctd.Members.Add (meth);
        }
Exemplo n.º 9
0
        protected override void Emit(CodeTypeDeclaration ctd)
        {
            EmitAttribute(ctd);

            // Constructor

            CodeConstructor ctor = EmitEmptyCtor(ctd);

            ctor.Parameters.Add(CDH.Param(NS.ParamsType, "stmpl"));
            ctor.BaseConstructorArgs.Add(CDH.ARef("stmpl"));

            // Matcher attr

            CodeAttributeDeclaration kattr =
                new CodeAttributeDeclaration("Mono.Build.Bundling.MatcherAttribute");

            kattr.Arguments.Add(new CodeAttributeArgument(KindExpression));
            ctd.CustomAttributes.Add(kattr);

            // GetRegex override

            CodeMemberMethod method = new CodeMemberMethod();

            method.Name = "GetRegex";
            //method.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            method.ReturnType = CDH.String;
            method.LinePragma = Location;

            CodeExpression val = new CodePrimitiveExpression(Regex);
            CodeStatement  ret = new CodeMethodReturnStatement(val);

            ret.LinePragma = Location;
            method.Statements.Add(ret);
            ctd.Members.Add(method);

            // GetMatchType override

            method      = new CodeMemberMethod();
            method.Name = "GetMatchType";
            //method.Attributes = MemberAttributes.Family | MemberAttributes.Override;
            method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            method.ReturnType = CDH.Type;
            method.LinePragma = Location;

            val            = new CodeTypeOfExpression(MatchType.AsCodeDom);
            ret            = new CodeMethodReturnStatement(val);
            ret.LinePragma = Location;
            method.Statements.Add(ret);
            ctd.Members.Add(method);
        }
Exemplo n.º 10
0
        protected CodeConstructor EmitTemplate(CodeTypeDeclaration ctd)
        {
            EmitAttribute(ctd);

            // A(n optional) field pointing to our bound structure

            if (UsesStructure)
            {
                CodeMemberField f = new CodeMemberField();
                f.Name       = "stmpl";
                f.Attributes = MemberAttributes.Private;
                f.Type       = NS.ParamsType.AsCodeDom;
                ctd.Members.Add(f);
            }

            // The template apply method.

            CodeMemberMethod meth = new CodeMemberMethod();

            meth.Name       = "ApplyTemplate";
            meth.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            meth.ReturnType = null;
            meth.Parameters.Add(CDH.Param(typeof(TargetBuilder), "tb"));

            CDH.EmitBaseChainVoid(meth);

            CodeVariableReferenceExpression tb = CDH.VRef("tb");

            if (UsesStructure)
            {
                info.Converter = delegate(string val) {
                    return(NS.MakeTargetNameExpr(val, CDH.ThisDot("stmpl"), null));
                };
            }

            info.EmitInfo(meth, tb);
            ctd.Members.Add(meth);

            // Constructor

            return(EmitConstructor(ctd));
        }
Exemplo n.º 11
0
        CodeConstructor EmitConstructor(CodeTypeDeclaration ctd)
        {
            // The ctor that inits the field and chains to the parent if necc.

            CodeConstructor ctor = EmitEmptyCtor(ctd);
            CodeArgumentReferenceExpression stmpl = CDH.ARef("stmpl");

            ctor.Parameters.Add(CDH.Param(NS.ParamsType, "stmpl"));

            if (UsesStructure)
            {
                CodeAssignStatement assg = new CodeAssignStatement();
                assg.Left  = CDH.ThisDot("stmpl");
                assg.Right = stmpl;
                ctor.Statements.Add(assg);
            }

            ctor.BaseConstructorArgs.Add(ContextualStructRef(basestruct, stmpl));
            return(ctor);
        }
Exemplo n.º 12
0
            public void Emit(CodeTypeDeclaration ctd, CodeMemberMethod copy, CodeExpression copyarray,
                             CodeMemberMethod clone, CodeExpression other)
            {
                // The field itself

                CodeMemberField f = new CodeMemberField();

                f.Name       = Name;
                f.Attributes = MemberAttributes.Public;
                f.LinePragma = Line;
                f.Type       = Type.AsCodeDom;
                f.CustomAttributes.Add(FieldAttr);
                ctd.Members.Add(f);

                // Copy statement in CopyItems

                CodeIndexerExpression index = new CodeIndexerExpression();

                index.TargetObject = copyarray;
                index.Indices.Add(ResultBuilder.BasePlusN(Idx));

                CodeFieldReferenceExpression fld  = CDH.ThisDot(Name);
                CodeMethodInvokeExpression   conv =
                    new CodeMethodInvokeExpression(CDH.This, "FieldAsResult",
                                                   new CodeExpression[] { fld });
                CodeAssignStatement assg =
                    new CodeAssignStatement(index, conv);

                copy.Statements.Add(assg);

                // Add statement to clone result in CloneItems

                CodeFieldReferenceExpression lhs =
                    new CodeFieldReferenceExpression(other, Name);

                conv = new CodeMethodInvokeExpression(CDH.This, "CloneField",
                                                      new CodeExpression[] { fld });
                assg = new CodeAssignStatement(lhs, new CodeCastExpression(f.Type, conv));
                clone.Statements.Add(assg);
            }
Exemplo n.º 13
0
        public CodeObjectCreateExpression ValueExpression(SingleValue <string> val)
        {
            CodeObjectCreateExpression oce = new CodeObjectCreateExpression();

            oce.CreateType = new CodeTypeReference(typeof(SingleValue <string>));

            if (val.IsResult)
            {
                oce.Parameters.Add(CDH.ResultExpression((Result)val));
            }
            else
            {
                if (conv == null)
                {
                    throw new InvalidOperationException();
                }

                oce.Parameters.Add(conv((string)val));
            }

            return(oce);
        }
Exemplo n.º 14
0
        void EmitBuildWrapped(CodeTypeDeclaration cur_type, CodeMemberMethod meth)
        {
            CodeMethodInvokeExpression inv =
                new CodeMethodInvokeExpression(CDH.This, "CreateResultObject",
                                               new CodeExpression[0] {
            });
            CodeCastExpression cast =
                new CodeCastExpression(bf_ret_class.AsCodeDom, inv);
            CodeVariableDeclarationStatement vd =
                new CodeVariableDeclarationStatement(bf_ret_class.AsCodeDom, bf_ret_arg, cast);

            meth.Statements.Add(vd);

            CodeVariableReferenceExpression r1 = CDH.VRef(bf_ret_arg);
            CodeVariableReferenceExpression r2 = CDH.VRef(bf_context_arg);

            inv = new CodeMethodInvokeExpression(CDH.This, "BuildImpl",
                                                 new CodeExpression[2] {
                r1, r2
            });

            meth.Statements.Add(CDH.IfTrueReturnNull(inv));
            meth.Statements.Add(new CodeMethodReturnStatement(r1));

            // BuildImpl

            CodeParameterDeclarationExpression p1 = CDH.Param(bf_ret_class.AsCodeDom, bf_ret_arg);
            CodeParameterDeclarationExpression p2 = CDH.Param(CDH.IContext, bf_context_arg);

            meth            = new CodeMemberMethod();
            meth.Name       = "BuildImpl";
            meth.Attributes = MemberAttributes.Private;
            meth.ReturnType = CDH.Bool;
            meth.Parameters.Add(p1);
            meth.Parameters.Add(p2);
            meth.Statements.Add(bf_code.AsStatement);
            cur_type.Members.Add(meth);
        }
Exemplo n.º 15
0
            protected override void Emit(CodeTypeDeclaration type)
            {
                type.CustomAttributes.Add(new CodeAttributeDeclaration("System.Serializable"));

                // Initialized constructor

                CodeFieldReferenceExpression left = CDH.ThisDot("Value");

                CodeConstructor ctor = EmitEmptyCtor(type);

                ctor.Parameters.Add(CDH.Param(etype, "init"));
                ctor.Statements.Add(new CodeAssignStatement(left, CDH.VRef("init")));

                // Default constructor.

                ctor = EmitEmptyCtor(type);

                CodeTypeReferenceExpression tre =
                    new CodeTypeReferenceExpression(etype.AsCodeDom);
                CodeFieldReferenceExpression right =
                    new CodeFieldReferenceExpression(tre, DefaultName);

                ctor.Statements.Add(new CodeAssignStatement(left, right));
            }
Exemplo n.º 16
0
        void EmitArguments(CodeTypeDeclaration cur_type)
        {
            CodeMemberMethod list, fetch, clear;
            CodeVariableReferenceExpression sink, source;

            // ListArguments prologue

            list            = new CodeMemberMethod();
            list.Name       = "ListArguments";
            list.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            list.ReturnType = null;
            list.Parameters.Add(CDH.Param(ArgInfoSink, "sink"));

            CDH.EmitBaseChainVoid(list);

            sink = CDH.VRef("sink");

            // FetchArgValues prologue

            fetch            = new CodeMemberMethod();
            fetch.Name       = "FetchArgValues";
            fetch.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            fetch.ReturnType = null;
            fetch.Parameters.Add(CDH.Param(ArgValueSource, "source"));

            CDH.EmitBaseChainVoid(fetch);

            source = new CodeVariableReferenceExpression("source");

            // ClearArgValues prologue

            clear            = new CodeMemberMethod();
            clear.Name       = "ClearArgValues";
            clear.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            clear.ReturnType = null;

            CDH.EmitBaseChainVoid(clear);

            // Per-arg statements

            if (target_arg_name != null)
            {
                EmitTargetArg(list, sink, fetch, source, clear, cur_type);
            }

            if (arguments.Count > 0)
            {
                list.Statements.Add(BaseNumArgs);
                fetch.Statements.Add(BaseNumArgs);
            }

            for (int i = 0; i < arguments.Count; i++)
            {
                arguments[i].EmitStatements(list, sink, fetch, source, clear);
                arguments[i].EmitField(cur_type);
            }

            // No epilogues.

            cur_type.Members.Add(list);
            cur_type.Members.Add(fetch);
            cur_type.Members.Add(clear);

            // NumArguments property override

            CodeMemberProperty p = new CodeMemberProperty();

            p.Name       = "NumArguments";
            p.HasGet     = true;
            p.HasSet     = false;
            p.Type       = new CodeTypeReference(typeof(int));
            p.Attributes = MemberAttributes.Public | MemberAttributes.Override;

            CodeBinaryOperatorExpression add = new CodeBinaryOperatorExpression();

            add.Left     = new CodePropertyReferenceExpression(CDH.Base, "NumArguments");
            add.Operator = CodeBinaryOperatorType.Add;
            add.Right    = new CodePrimitiveExpression(arguments.Count);

            p.GetStatements.Add(new CodeMethodReturnStatement(add));

            cur_type.Members.Add(p);
        }
Exemplo n.º 17
0
            public void EmitStatements(CodeMemberMethod list, CodeVariableReferenceExpression sink,
                                       CodeMemberMethod fetch, CodeVariableReferenceExpression source,
                                       CodeMemberMethod clear)
            {
                CodeExpression idexpr = RuleBuilder.BasePlusN(Idx);

                // List

                CodeMethodInvokeExpression invoke = CDH.AddBareInvoke(list, sink, "AddArg");

                invoke.Parameters.Add(idexpr);
                invoke.Parameters.Add(new CodePrimitiveExpression(Name));
                invoke.Parameters.Add(new CodeTypeOfExpression(arg_class.AsCodeDom));
                invoke.Parameters.Add(Flags);

                // Fetch

                invoke        = new CodeMethodInvokeExpression();
                invoke.Method = new CodeMethodReferenceExpression(source, "GetArgValue");
                invoke.Parameters.Add(idexpr);

                CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression();

                mref.TargetObject = TRERule;

                if (conv == RuleArgConversion.None)
                {
                    switch (Count)
                    {
                    case ArgCount.OneOrMore:
                        goto case ArgCount.ZeroOrMore;

                    case ArgCount.ZeroOrMore:
                        mref.MethodName = "AsArray";
                        mref.TypeArguments.Add(Type.AsCodeDom);
                        break;

                    case ArgCount.Optional:
                        mref.MethodName = "AsOptional";
                        mref.TypeArguments.Add(Type.AsCodeDom);
                        break;

                    case ArgCount.Standard:
                        mref.MethodName = "AsSingle";
                        mref.TypeArguments.Add(Type.AsCodeDom);
                        break;
                    }
                }
                else
                {
                    mref.TypeArguments.Add(Type.AsCodeDom);
                    mref.TypeArguments.Add(arg_class.AsCodeDom);

                    switch (Count)
                    {
                    case ArgCount.OneOrMore:
                        goto case ArgCount.ZeroOrMore;

                    case ArgCount.ZeroOrMore:
                        mref.MethodName = "AsArrayConv";
                        break;

                    case ArgCount.Optional:
                        if (conv == RuleArgConversion.ToValueType)
                        {
                            mref.MethodName = "AsOptionalValue";
                        }
                        else
                        {
                            mref.MethodName = "AsOptionalRef";
                        }
                        break;

                    case ArgCount.Standard:
                        mref.MethodName = "AsSingleConv";
                        break;
                    }
                }

                CodeMethodInvokeExpression inv2 = new CodeMethodInvokeExpression();

                inv2.Method = mref;
                inv2.Parameters.Add(invoke);

                CodeAssignStatement assg = new CodeAssignStatement(CDH.ThisDot(Name), inv2);

                fetch.Statements.Add(assg);

                // ClearArgValues. Can't clear standard value types -- eg, 'bool member;'.
                // Those we trust will get set again when FetchArgValues is called next time.

                if (conv != RuleArgConversion.ToValueType || Count != ArgCount.Standard)
                {
                    assg = new CodeAssignStatement(CDH.ThisDot(Name), CDH.Null);
                    clear.Statements.Add(assg);
                }
            }
Exemplo n.º 18
0
        void EmitAsComposite(CodeTypeDeclaration ctd)
        {
            if (fields.Count == 0)
            {
                return;
            }

            if (comp_default_idx >= 0)
            {
                EmitDefault(ctd);
            }

            // Prologues - TotalItems field

            CodeMemberProperty ti = new CodeMemberProperty();

            ti.Name       = "TotalItems";
            ti.HasGet     = true;
            ti.HasSet     = false;
            ti.Type       = new CodeTypeReference(typeof(int));
            ti.Attributes = MemberAttributes.Family | MemberAttributes.Override;

            CodeBinaryOperatorExpression add = new CodeBinaryOperatorExpression();

            add.Left     = new CodePropertyReferenceExpression(CDH.Base, "TotalItems");
            add.Operator = CodeBinaryOperatorType.Add;
            add.Right    = new CodePrimitiveExpression(fields.Count);

            CodeStatement ret = new CodeMethodReturnStatement(add);

            ti.GetStatements.Add(ret);

            ctd.Members.Add(ti);

            // Prologues - CopyItems

            CodeParameterDeclarationExpression p = CDH.Param(new CodeTypeReference(CDH.Result, 1), "r");

            CodeMemberMethod copy = new CodeMemberMethod();

            copy.Name       = "CopyItems";
            copy.ReturnType = null;
            copy.Parameters.Add(p);
            copy.Attributes = MemberAttributes.Family | MemberAttributes.Override;

            CDH.EmitBaseChainVoid(copy);

            CodeExpression copyarray = new CodeArgumentReferenceExpression(p.Name);

            copy.Statements.Add(BaseTotalItems);

            // Prologues - CloneTo method

            p = CDH.Param(CDH.Result, "r");

            CodeMemberMethod clone = new CodeMemberMethod();

            clone.Name       = "CloneTo";
            clone.ReturnType = null;
            clone.Parameters.Add(p);
            clone.Attributes = MemberAttributes.Family | MemberAttributes.Override;

            CDH.EmitBaseChainVoid(clone);

            CodeExpression cp = CDH.ARef(p.Name);

            CodeVariableDeclarationStatement vds = new CodeVariableDeclarationStatement();

            vds.Name           = "other";
            vds.Type           = new CodeTypeReference(ctd.Name);
            vds.InitExpression = new CodeCastExpression(vds.Type, cp);

            clone.Statements.Add(vds);
            CodeExpression other = CDH.VRef(vds.Name);

            // Now per-field statements

            foreach (FieldInfo fi in fields)
            {
                fi.Emit(ctd, copy, copyarray, clone, other);
            }

            // no epilogues.

            ctd.Members.Add(copy);
            ctd.Members.Add(clone);
        }