예제 #1
0
            public new FlatValue GetFlatValue()
            {
                FlatTableBuilder ftb = new FlatTableBuilder();
                ftb.Add("Name", FlatValue.String(Class.GetFullyQualifiedName()));
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();
                    foreach (FlatValue fv in Members)
                    {
                        fab.Add(fv);
                    }
                    ftb.Add("Members", fab.GetFlatValue());
                }

                // base type
                if (this.Class.BaseType != null && this.Class.BaseType.SpecialType!= SpecialType.System_Object)
                {
                    ftb.Add("Base", FlatValue.String(this.Class.BaseType.GetFullyQualifiedName()));
                }

                ReadOnlyArray<NamedTypeSymbol> interfaces = this.Class.Interfaces;
                if (interfaces != null && interfaces.Count > 0)
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();
                    foreach (NamedTypeSymbol iface in interfaces)
                    {
                        fab.Add(FlatValue.String(iface.GetFullyQualifiedName()));
                    }
                    ftb.Add("Interfaces", fab.GetFlatValue());
                }

                return ftb.GetFlatValue();
            }
예제 #2
0
파일: Chunk.cs 프로젝트: Noob536/ls2csc
            public new FlatValue GetFlatValue()
            {
                FlatTableBuilder ftb = new FlatTableBuilder();
                ftb.Add("Name", FlatValue.String(Class.GetFullyQualifiedName()));
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();
                    foreach (FlatValue fv in Members)
                    {
                        fab.Add(fv);
                    }
                    ftb.Add("Members", fab.GetFlatValue());
                }

                return ftb.GetFlatValue();
            }
예제 #3
0
        public void FlattenStringSwitch(SwitchStatementSyntax node, string prefix, string endSwitchLabel, string defaultCaseLabel, List<FlatStatement> instructions)
        {
            FlatTableBuilder ftb = new FlatTableBuilder();
            bool bHasDefault = false;
            // build table of cases
            foreach (SwitchSectionSyntax sss in node.Sections)
            {
                foreach (SwitchLabelSyntax sls in sss.Labels)
                {
                    if (sls.CaseOrDefaultKeyword.Kind == SyntaxKind.CaseKeyword)
                    {
                        if (!(sls.Value is LiteralExpressionSyntax))
                        {
                            throw new NotImplementedException("non-literal string case");
                        }

                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)sls.Value;
                        FlatOperand fop = ResolveExpression(les, FlatObjectType.System_String);

                        string labelName = prefix + "case[" + fop.ImmediateValue.ValueText+"]";
                        ftb.Add(fop.ImmediateValue.Object.ToString(), FlatValue.Label(labelName)); // these will be post-processed to instruction numbers
                    }
                    else if (sls.CaseOrDefaultKeyword.Kind == SyntaxKind.DefaultKeyword)
                    {
                        bHasDefault = true;
                    }
                }
            }

            int nValue = FunctionValues.Count;
            FlatValue fv_table = ftb.GetFlatValue();
            FunctionValues.Add(fv_table);
            FlatOperand fop_functionvalue = FlatOperand.FunctionValueRef(nValue, fv_table);

            FlatOperand fop_comparison = ResolveExpression(node.Expression, null, instructions);
            instructions.Add(FlatStatement.SWITCH(fop_functionvalue,fop_comparison));
            if (bHasDefault)
            {
                instructions.Add(FlatStatement.JMP(FlatOperand.LabelRef(defaultCaseLabel)));
            }
            else
            {
                instructions.Add(FlatStatement.JMP(FlatOperand.LabelRef(endSwitchLabel)));
            }

            //string switchTableBuilderLabel = this.MakeUniqueLabelName("switchTableBuilder");

            int nSection = 1;

            foreach (SwitchSectionSyntax sss in node.Sections)
            {
                string sectionBeginLabel = prefix + "section" + nSection + "begin";
                string sectionEndLabel = prefix + "section" + nSection + "end";

                instructions.Add(FlatStatement.LABEL(FlatOperand.LabelRef(sectionBeginLabel)));

                foreach (SwitchLabelSyntax sls in sss.Labels)
                {
                    if (sls.CaseOrDefaultKeyword.Kind == SyntaxKind.DefaultKeyword)
                    {
                        instructions.Add(FlatStatement.LABEL(FlatOperand.LabelRef(defaultCaseLabel)));
                    }
                    else
                    {
                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)sls.Value;
                        FlatOperand fop = ResolveExpression(les, FlatObjectType.System_String);

                        string labelName = prefix + "case[" + fop.ImmediateValue.ValueText+"]";
                        instructions.Add(FlatStatement.LABEL(FlatOperand.LabelRef(labelName)));
                    }
                }

                foreach (StatementSyntax ss in sss.Statements)
                {
                    FlattenStatement(ss, instructions);
                }

                FlatStatement fs = FlatStatement.THROW(FlatOperand.LiteralString("Illegal case fall-through, please use a break, return, goto case, etc"));
                fs.Comment = "this should be UNUSED and stripped during post-processing";
                instructions.Add(fs);
                /*
                        // Summary:
                        //     Gets a SyntaxList of SwitchLabelSyntax's the represents the possible labels
                        //     that control can transfer to within the section.
                        public SyntaxList<SwitchLabelSyntax> Labels { get; }
                        //
                        // Summary:
                        //     Gets a SyntaxList of StatementSyntax's the represents the statements to be
                        //     executed when control transfer to a label the belongs to the section.
                        public SyntaxList<StatementSyntax> Statements { get; }
                /**/
                instructions.Add(FlatStatement.LABEL(FlatOperand.LabelRef(sectionEndLabel)));

                nSection++;
            }
        }