当前位置: 首页>>代码示例>>C#>>正文


C# FlatOperand.AsRValue方法代码示例

本文整理汇总了C#中LS2IL.FlatOperand.AsRValue方法的典型用法代码示例。如果您正苦于以下问题:C# FlatOperand.AsRValue方法的具体用法?C# FlatOperand.AsRValue怎么用?C# FlatOperand.AsRValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LS2IL.FlatOperand的用法示例。


在下文中一共展示了FlatOperand.AsRValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Resolve

        public override FlatOperand Resolve(ExpressionSyntax expression, ArgumentListSyntax argumentList, TypeInfo result_type, SymbolInfo si, FlatOperand into_lvalue, Function function, List<FlatStatement> instructions)
        {
            FlatOperand fop_subject;
            if (expression is IdentifierNameSyntax)
            {
                // typeof this
                fop_subject = FlatOperand.ThisRef(FlatValue.FromType(result_type.ConvertedType));
            }
            else if (expression is MemberAccessExpressionSyntax)
            {
                MemberAccessExpressionSyntax meas = (MemberAccessExpressionSyntax)expression;

                fop_subject = function.ResolveExpression(meas.Expression, null, instructions);
            }
            else
            {
                throw new NotImplementedException("GetMetaTable on expression type " + expression.GetType().ToString());
            }

            if (into_lvalue == null)
            {
                FlatOperand fop_register = function.AllocateRegister("");
                into_lvalue = fop_register.GetLValue(function, instructions);
            }
            instructions.Add(FlatStatement.GETMETATABLE(into_lvalue, fop_subject));
            return into_lvalue.AsRValue(FlatValue.Table());
        }
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:27,代码来源:Intrinsics.cs

示例2: Resolve

        public override FlatOperand Resolve(InvocationExpressionSyntax node, TypeInfo result_type, SymbolInfo si, FlatOperand into_lvalue, Function function, List<FlatStatement> instructions)
        {
            if (!(node.Expression is MemberAccessExpressionSyntax))
            {
                throw new NotImplementedException("GETPROPERTY not on MemberAccessExpressionSyntax");
            }

            MemberAccessExpressionSyntax meas = (MemberAccessExpressionSyntax)node.Expression;

            FlatOperand fop_subject = function.ResolveExpression(meas.Expression, null, instructions);

            if (into_lvalue == null)
            {
                FlatOperand fop_register = function.AllocateRegister("");
                into_lvalue = fop_register.GetLValue(function, instructions);
            }
            instructions.Add(FlatStatement.STRINGVAL(into_lvalue, fop_subject));
            return into_lvalue.AsRValue(FlatValue.String(string.Empty));
        }
开发者ID:Noob536,项目名称:ls2csc,代码行数:19,代码来源:Intrinsics.cs

示例3: Resolve

        public FlatOperand Resolve(ArrayCreationExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            /*        // Summary:
            //     InitializerExpressionSyntax node representing the initializer of the array
            //     creation expression.
            public InitializerExpressionSyntax Initializer { get; }
            //
            // Summary:
            //     SyntaxToken representing the new keyword.
            public SyntaxToken NewKeyword { get; }
            //
            // Summary:
            //     ArrayTypeSyntax node representing the type of the array.
            public ArrayTypeSyntax Type { get; }
             */
            if (node.Initializer != null)
            {
                throw new NotImplementedException("new array with initializer");
            }

            /*
            // Summary:
            //     TypeSyntax node representing the type of the element of the array.
            public TypeSyntax ElementType { get; }
            //
            // Summary:
            //     SyntaxList of ArrayRankSpecifierSyntax nodes representing the list of rank
            //     specifiers for the array.
            public SyntaxList<ArrayRankSpecifierSyntax> RankSpecifiers { get; }
            /**/
            /*
            if (node.Type.RankSpecifiers.Count > 1)
            {
                throw new NotImplementedException("new array with multiple rank specifiers");
            }

            /*
            public int Rank { get; }
            public SeparatedSyntaxList<ExpressionSyntax> Sizes { get; }
             */

            // get total number of elements
            FlatOperand fop_total = null;

            foreach(ArrayRankSpecifierSyntax arss in node.Type.RankSpecifiers)
            {
                foreach(ExpressionSyntax es in arss.Sizes)
                {
                    if (fop_total != null)
                    {
                        FlatOperand fop_size = ResolveExpression(es, null, instructions);

                        FlatOperand fop_total_lvalue = AllocateRegister("");

                        FlatStatement.MUL(fop_total_lvalue, fop_total, fop_size);

                        fop_total = fop_total_lvalue.AsRValue(FlatValue.Int32(0));
                    }
                    else
                    {
                        fop_total = ResolveExpression(es, null, instructions);
                    }
                }
            }

            TypeInfo ti = Model.GetTypeInfo(node.Type.ElementType);
            FlatOperand fop_type = Resolve(ti.ConvertedType, null, instructions);

            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }
            instructions.Add(FlatStatement.NEWARRAY(into_lvalue, fop_total, fop_type));

            return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:77,代码来源:Function.cs

示例4: ResolveExpression

        public FlatOperand ResolveExpression(ExpressionSyntax node, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            TypeInfo result_type = Model.GetTypeInfo(node);
            // resultant type of the expression
            if (!result_type.ImplicitConversion.IsIdentity && !result_type.ImplicitConversion.IsImplicit)
            {
                throw new NotImplementedException("type conversion");
            }

            if (node is ParenthesizedExpressionSyntax)
            {
                ParenthesizedExpressionSyntax pes = (ParenthesizedExpressionSyntax)node;
                return ResolveExpression(pes.Expression, into_lvalue, instructions);
            }
            if (node is PostfixUnaryExpressionSyntax)
            {
                PostfixUnaryExpressionSyntax pues = (PostfixUnaryExpressionSyntax)node;

                //pues.Operand;
                FlatOperand left = ResolveLValue(pues.Operand, instructions);

                FlatOperand left_lvalue = left.GetLValue(this, instructions);

                switch (pues.Kind)
                {
                    case SyntaxKind.PostIncrementExpression:
                        instructions.Add(FlatStatement.ADD(left_lvalue, left, FlatOperand.Immediate(FlatValue.Int32(1))));
                        // TODO: this should be trying to return immediatevalue+1...?
                        return FlatOperand.Immediate(left_lvalue.ImmediateValue);
                    case SyntaxKind.PostDecrementExpression:
                        instructions.Add(FlatStatement.SUB(left_lvalue, left, FlatOperand.Immediate(FlatValue.Int32(1))));
                        // TODO: this should be trying to return immediatevalue-1...?
                        return FlatOperand.Immediate(left_lvalue.ImmediateValue);
                }

                throw new NotImplementedException("postfix unary " + pues.Kind.ToString());
            }
            if (node is BinaryExpressionSyntax)
            {
                BinaryExpressionSyntax bes = (BinaryExpressionSyntax)node;
                return ResolveExpression(bes, result_type, into_lvalue, instructions);

            }
            if (node is LiteralExpressionSyntax)
            {
                LiteralExpressionSyntax les = (LiteralExpressionSyntax)node;

                FlatValue val = FlatValue.FromLiteralToken(result_type.ConvertedType, les.Token);
                FlatOperand right = FlatOperand.Immediate(val);

                if (into_lvalue != null)
                {
                    instructions.Add(FlatStatement.REFERENCE(into_lvalue,right));
                    return into_lvalue.AsRValue(val);
                }
                return right;
            }
            if (node is IdentifierNameSyntax)
            {
                IdentifierNameSyntax ins = (IdentifierNameSyntax)node;
                return Resolve(ins, result_type, instructions);
            }
            if (node is InvocationExpressionSyntax)
            {
                InvocationExpressionSyntax ies = (InvocationExpressionSyntax)node;
                return Resolve(ies, result_type, into_lvalue, instructions);

            }
            if (node is MemberAccessExpressionSyntax)
            {
                MemberAccessExpressionSyntax meas = (MemberAccessExpressionSyntax)node;
                return Resolve(meas, result_type, into_lvalue, instructions);
            }
            if (node is ElementAccessExpressionSyntax)
            {
                ElementAccessExpressionSyntax eaes = (ElementAccessExpressionSyntax)node;
                return Resolve(eaes, result_type, into_lvalue, instructions);

            }
            if (node is ObjectCreationExpressionSyntax)
            {
                ObjectCreationExpressionSyntax oces = (ObjectCreationExpressionSyntax)node;
                return Resolve(oces, result_type, into_lvalue, instructions);
            }
            if (node is ArrayCreationExpressionSyntax)
            {
                ArrayCreationExpressionSyntax aces = (ArrayCreationExpressionSyntax)node;
                return Resolve(aces, result_type, into_lvalue, instructions);
            }

            throw new NotImplementedException();
        }
开发者ID:Noob536,项目名称:ls2csc,代码行数:92,代码来源:Function.cs

示例5: ResolveParentExpression

        public FlatOperand ResolveParentExpression(SymbolInfo si,SyntaxNode sn, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (sn is MemberAccessExpressionSyntax)
            {
                return ResolveExpression(((MemberAccessExpressionSyntax)sn).Expression, null, instructions);
            }
            if (sn is IdentifierNameSyntax)
            {
                IdentifierNameSyntax ins = (IdentifierNameSyntax)sn;
                switch (si.Symbol.Kind)
                {
                    case SymbolKind.Field:
                        {
                            // it's a field, with no member access
                            if (si.Symbol.IsStatic)
                            {
                                throw new NotImplementedException();
                            }
                            // and it's not static.

                            // must be from "this".
                            FlatValue val = FlatValue.FromType(si.Symbol.ContainingType);
                            if (into_lvalue != null)
                            {
                                instructions.Add(FlatStatement.REFERENCE(into_lvalue, FlatOperand.ThisRef(val)));
                                return into_lvalue.AsRValue(val);
                            }
                            return FlatOperand.ThisRef(val);
                        }
                        break;
                    case SymbolKind.Property:
                        {
                            // it's a field, with no member access
                            if (si.Symbol.IsStatic)
                            {
                                throw new NotImplementedException();
                            }
                            // and it's not static.

                            // must be from "this".
                            FlatValue val = FlatValue.FromType(si.Symbol.ContainingType);
                            if (into_lvalue != null)
                            {
                                instructions.Add(FlatStatement.REFERENCE(into_lvalue, FlatOperand.ThisRef(val)));
                                return into_lvalue.AsRValue(val);
                            }
                            return FlatOperand.ThisRef(val);
                        }
                    default:
                        throw new NotImplementedException();
                        break;
                }
            }

            throw new NotImplementedException();
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:56,代码来源:Function.cs

示例6: ResolveExpression

        public FlatOperand ResolveExpression(PostfixUnaryExpressionSyntax pues, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                into_lvalue = this.AllocateRegister("");
                into_lvalue = into_lvalue.GetLValue(this, instructions);
            }

            SymbolInfo si = Model.GetSymbolInfo(pues.Operand);
            FlatOperand fop_subject;
            switch (si.Symbol.Kind)
            {
                /*
            case SymbolKind.Field:
                {
                    // need the parent object for the field
                    fop_subject = ResolveParentExpression(si, pues.Operand, null, instructions);

                    TypeSymbol typeSymbol;
                    FieldSymbol ps = (FieldSymbol)si.Symbol;

                    if (ps.IsStatic)
                    {
                        throw new NotImplementedException("static Field assignment");
                    }

                    typeSymbol = ps.Type;
                    int nField;
                    if (!GetRuntimeFieldNumber(ps, out nField))
                    {
                        throw new NotImplementedException("missing field " + ps.ToDisplayString());
                    }

                    FlatOperand fop_fieldnum = FlatOperand.LiteralInteger(nField);

                    FlatOperand fop_currentvalue = this.AllocateRegister("");
                    FlatOperand fop_currentlvalue = fop_currentvalue.GetLValue(this, instructions);

                    // DUPLICATE (to return) the current value of the field
                    // then increment and SETFIELD
                    instructions.Add(FlatStatement.GETFIELD(fop_currentlvalue, fop_subject, fop_fieldnum));

                    instructions.Add(FlatStatement.DUPLICATE(into_lvalue, fop_currentvalue));

                    switch (pues.Kind)
                    {
                        case SyntaxKind.PostIncrementExpression:
                            instructions.Add(FlatStatement.ADD(fop_currentlvalue, fop_currentvalue, FlatOperand.Immediate(FlatValue.Int8(1))));
                            break;
                        case SyntaxKind.PostDecrementExpression:
                            instructions.Add(FlatStatement.SUB(fop_currentlvalue, fop_currentvalue, FlatOperand.Immediate(FlatValue.Int8(1))));
                            break;
                    }

                    instructions.Add(FlatStatement.SETFIELD(fop_subject, fop_fieldnum, fop_currentvalue));
                    return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                }
                break;*/
                case SymbolKind.Field:
                    {
                        fop_subject = ResolveParentExpression(si, pues.Operand, null, instructions);
                        FlatOperand fop_type = TypeOf(fop_subject, null, null, instructions);

                        FlatOperand fop_Field;
                        TypeSymbol typeSymbol;
                        {
                            FieldSymbol ps = (FieldSymbol)si.Symbol;

                            if (ps.IsStatic)
                            {
                                throw new NotImplementedException("static Field assignment");
                            }

                            typeSymbol = ps.Type;
                            fop_Field = Resolve(ps, fop_type, null, instructions);
                        }

                        FlatOperand fop_currentvalue = this.AllocateRegister("");
                        FlatOperand fop_currentlvalue = fop_currentvalue.GetLValue(this, instructions);

                        instructions.Add(FlatStatement.GETFIELD(fop_currentlvalue, fop_Field, fop_subject));
                        instructions.Add(FlatStatement.DUPLICATE(into_lvalue, fop_currentvalue));

                        switch (pues.Kind)
                        {
                            case SyntaxKind.PostIncrementExpression:
                                instructions.Add(FlatStatement.ADD(fop_currentlvalue, fop_currentvalue, FlatOperand.Immediate(FlatValue.Int32(1))));
                                break;
                            case SyntaxKind.PostDecrementExpression:
                                instructions.Add(FlatStatement.SUB(fop_currentlvalue, fop_currentvalue, FlatOperand.Immediate(FlatValue.Int32(1))));
                                break;
                        }

                        instructions.Add(FlatStatement.SETFIELD(fop_Field, fop_subject, fop_currentvalue));
                        return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                    }
                    break;
                case SymbolKind.Property:
                    {
                        fop_subject = ResolveParentExpression(si, pues.Operand, null, instructions);
//.........这里部分代码省略.........
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:101,代码来源:Function.cs

示例7: ResolveArgumentsToArray

        public FlatOperand ResolveArgumentsToArray(ArgumentListSyntax args, FlatOperand return_reference, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }

            FlatValue literalArray;
            FlatOperand fop_array;

            bool allLiteral = (return_reference==null);
            if (allLiteral)
            {
                foreach (ArgumentSyntax ars in args.Arguments)
                {
                    /*
                            // Summary:
                            //     ExpressionSyntax node representing the argument.
                            public ExpressionSyntax Expression { get; }
                            //
                            // Summary:
                            //     NameColonSyntax node representing the optional name arguments.
                            public NameColonSyntax NameColon { get; }
                            //
                            // Summary:
                            //     SyntaxToken representing the optional ref or out keyword.
                            public SyntaxToken RefOrOutKeyword { get; }
                    /**/
                    if (ars.NameColon != null)
                    {
                        throw new NotImplementedException("name : value");
                    }
                    if (ars.RefOrOutKeyword.Kind != SyntaxKind.None)
                    {
                        throw new NotImplementedException("ref/out keywords");
                    }

                    if (!(ars.Expression is LiteralExpressionSyntax))
                    {
                        allLiteral = false;
                    }
                }

                if (allLiteral)
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();

                    foreach (ArgumentSyntax ars in args.Arguments)
                    {
                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)ars.Expression;
                        // get the type
                        TypeInfo ti = Model.GetTypeInfo(les);
                        FlatOperand fop_element = ResolveExpression(les, ti.ConvertedType);
                        fab.Add(fop_element.ImmediateValue);
                    }

                    literalArray = fab.GetFlatValue();
                    instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));
                    fop_array = into_lvalue.AsRValue(literalArray);
                    return fop_array;
                }
            }

            // generate a new array
            literalArray = new FlatValue(FlatValueType.VT_Array, "{ }", null);
            instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));

            fop_array = into_lvalue.AsRValue(literalArray);

            if (return_reference != null)
            {
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, return_reference));
            }

            foreach(ArgumentSyntax ars in args.Arguments)
            {
                /*
                        // Summary:
                        //     ExpressionSyntax node representing the argument.
                        public ExpressionSyntax Expression { get; }
                        //
                        // Summary:
                        //     NameColonSyntax node representing the optional name arguments.
                        public NameColonSyntax NameColon { get; }
                        //
                        // Summary:
                        //     SyntaxToken representing the optional ref or out keyword.
                        public SyntaxToken RefOrOutKeyword { get; }
                /**/
                FlatOperand fop_element = ResolveExpression(ars.Expression, null, instructions);
                instructions.Add(FlatStatement.ADD(into_lvalue,fop_array,fop_element));
            }

            return fop_array;
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:96,代码来源:Function.cs

示例8: ResolveParameter

        public FlatOperand ResolveParameter(ExpressionSyntax expression, FlatOperand into_lvalue, out int numParam, List<FlatStatement> instructions)
        {
            if (!(expression is IdentifierNameSyntax))
            {
                throw new NotSupportedException("Parameter access that isn't an Identifier?");

            }
            IdentifierNameSyntax ins = (IdentifierNameSyntax)expression;

            SymbolInfo si = Model.GetSymbolInfo(expression);

            string name = ins.Identifier.ToString();

            int nParameter = 0;
            if (!IMethodSymbol.ReturnsVoid)
                nParameter++;

            foreach (IParameterSymbol ps in IMethodSymbol.Parameters)
            {
                if (name == ps.Name)
                {
                    numParam = nParameter;
                    FlatValue retval = FlatValue.FromType(ps.Type);
                    FlatOperand fop_input = FlatOperand.InputRef(nParameter, retval);

                    if (ps.RefKind != RefKind.None)
                    {
                        if (into_lvalue == null)
                        {
                            FlatOperand register_fop = AllocateRegister("");
                            into_lvalue = register_fop.GetLValue(this, instructions);
                        }
                        instructions.Add(FlatStatement.DEREFERENCE(into_lvalue, fop_input));

                        return into_lvalue.AsRValue(retval);
                    }

                    if (into_lvalue != null)
                    {
                        instructions.Add(FlatStatement.REFERENCE(into_lvalue, fop_input));
                    }
                    return fop_input;
                }
                nParameter++;
            }

            throw new LS2ILParameterException("parameter '" + name + "' not found");
        }
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:48,代码来源:Function.cs

示例9: ResolveExpressionsToArray

        public FlatOperand ResolveExpressionsToArray(IEnumerable<ExpressionSyntax> expressions, FlatOperand return_reference, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }

            FlatValue literalArray;
            FlatOperand fop_array;

            bool allLiteral = (return_reference == null);
            if (allLiteral)
            {
                foreach (ExpressionSyntax es in expressions)
                {
                    if (!(es is LiteralExpressionSyntax))
                    {
                        allLiteral = false;
                    }
                }

                if (allLiteral)
                {
                    FlatArrayBuilder fab = new FlatArrayBuilder();

                    foreach (ExpressionSyntax es in expressions)
                    {
                        LiteralExpressionSyntax les = (LiteralExpressionSyntax)es;
                        // get the type
                        TypeInfo ti = Model.GetTypeInfo(les);
                        FlatOperand fop_element = ResolveExpression(les, ti.ConvertedType);
                        fab.Add(fop_element.ImmediateValue);
                    }

                    literalArray = fab.GetFlatValue();
                   // if (literalArray.ToString().Length < 192) // max instruction size is 255 bytes, this has to fit
                    {
                        instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));
                        fop_array = into_lvalue.AsRValue(literalArray);
                        return fop_array;
                    }
                }
            }

            // generate a new array
            literalArray = new FlatValue(FlatValueType.VT_Array, "{ }", null);
            instructions.Add(FlatStatement.DUPLICATE(into_lvalue, FlatOperand.Immediate(literalArray)));

            fop_array = into_lvalue.AsRValue(literalArray);

            if (return_reference != null)
            {
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, return_reference));
            }

            foreach (ExpressionSyntax es in expressions)
            {
                /*
                        // Summary:
                        //     ExpressionSyntax node representing the argument.
                        public ExpressionSyntax Expression { get; }
                        //
                        // Summary:
                        //     NameColonSyntax node representing the optional name arguments.
                        public NameColonSyntax NameColon { get; }
                        //
                        // Summary:
                        //     SyntaxToken representing the optional ref or out keyword.
                        public SyntaxToken RefOrOutKeyword { get; }
                /**/
                FlatOperand fop_element = ResolveExpression(es, null, instructions);
                instructions.Add(FlatStatement.ADD(into_lvalue, fop_array, fop_element));
            }

            return fop_array;
        }
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:77,代码来源:Function.cs

示例10: ResolveExpression

        /// <summary>
        /// Resolves an expression into an r-value (where 0 is an l-value meaning register 0, register[0] is its r-value)
        /// </summary>
        /// <param name="node">the expression to resolve</param>
        /// <param name="into_lvalue">Either an existing l-value, or null to auto-generate where necessary</param>
        /// <param name="instructions">the set of instructions to generate any new instructions into</param>
        /// <returns>An r-value with the result</returns>
        public FlatOperand ResolveExpression(ExpressionSyntax node, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            TypeInfo result_type = Model.GetTypeInfo(node);
            // resultant type of the expression
            #if IMPLICIT_CONVERSION_HAS_A_REPLACEMENT_then_i_dont_know_what_it_is
            if (!result_type.ImplicitConversion.IsIdentity && !result_type.ImplicitConversion.IsImplicit)
            {
                throw new NotImplementedException("type conversion");
            }
            #endif
            if (node is PredefinedTypeSyntax)
            {
                /*
             // Summary:
            //     SyntaxToken which represents the keyword corresponding to the predefined
            //     type.
            public SyntaxToken Keyword { get; }*/
                PredefinedTypeSyntax pts = (PredefinedTypeSyntax)node;
                SymbolInfo si = Model.GetSymbolInfo(node);

                switch (si.Symbol.Kind)
                {
                    case SymbolKind.NamedType:
                        {
                            FlatOperand fop_type = Resolve((ITypeSymbol)si.Symbol, into_lvalue, instructions);

                            return fop_type;
                        }
                }
            }
            if (node is ParenthesizedExpressionSyntax)
            {
                ParenthesizedExpressionSyntax pes = (ParenthesizedExpressionSyntax)node;
                return ResolveExpression(pes.Expression, into_lvalue, instructions);
            }
            if (node is PostfixUnaryExpressionSyntax)
            {
                return ResolveExpression((PostfixUnaryExpressionSyntax)node, result_type, into_lvalue, instructions);
            }
            if (node is PrefixUnaryExpressionSyntax)
            {
                PrefixUnaryExpressionSyntax pues = (PrefixUnaryExpressionSyntax)node;
                FlatOperand right = ResolveExpression(pues.Operand, into_lvalue, instructions);
            #if NEGATE_EXPRESSION
                switch (pues.CSharpKind())
                {
                    case SyntaxKind.NegateExpression:
                        if (into_lvalue != null)
                        {
                            instructions.Add(FlatStatement.NEGATE(into_lvalue, right));
                            return into_lvalue.AsRValue(right.ImmediateValue);
                        }
                        FlatOperand left = this.AllocateRegister("");
                        into_lvalue = left.GetLValue(this, instructions);
                        instructions.Add(FlatStatement.NEGATE(into_lvalue, right));
                        return left;
                }
            #endif

                throw new NotImplementedException("Prefix unary " + pues.CSharpKind().ToString());
            }
            if (node is BinaryExpressionSyntax)
            {
                BinaryExpressionSyntax bes = (BinaryExpressionSyntax)node;
                return ResolveExpression(bes, result_type, into_lvalue, null, instructions);

            }
            if (node is LiteralExpressionSyntax)
            {
                LiteralExpressionSyntax les = (LiteralExpressionSyntax)node;

                FlatValue val = FlatValue.FromLiteralToken(result_type.ConvertedType, les.Token);
                FlatOperand right = FlatOperand.Immediate(val);

                if (into_lvalue != null)
                {
                    instructions.Add(FlatStatement.REFERENCE(into_lvalue,right));
                    return into_lvalue.AsRValue(val);
                }
                return right;
            }
            if (node is IdentifierNameSyntax)
            {
                IdentifierNameSyntax ins = (IdentifierNameSyntax)node;
                return Resolve(ins, result_type, into_lvalue, instructions);
            }
            if (node is QualifiedNameSyntax)
            {
                QualifiedNameSyntax qns = (QualifiedNameSyntax)node;
                return Resolve(qns, result_type, into_lvalue, instructions);
            }
            if (node is InvocationExpressionSyntax)
            {
//.........这里部分代码省略.........
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:101,代码来源:Function.cs

示例11: Resolve

        public FlatOperand Resolve(ElementAccessExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            /*
            // Summary:
            //     BracketedArgumentListSyntax node representing the list of arguments of the
            //     element access expression.
            public BracketedArgumentListSyntax ArgumentList { get; }
            //
            // Summary:
            //     ExpressionSyntax node representing the expression which is accessing the
            //     element.
            public ExpressionSyntax Expression { get; }
             */
            // resolve to an Array or Table
            //SymbolInfo si = Model.GetSymbolInfo(node.Expression);
            TypeInfo ti = Model.GetTypeInfo(node.Expression);

            switch (ti.ConvertedType.TypeKind)
            {
                case TypeKind.ArrayType:
                    {
                        FlatOperand fop_array = ResolveExpression(node.Expression, null, instructions);
                        // resolve the array index
                        List<FlatOperand> args = ResolveArguments(node.ArgumentList, instructions);
                        FlatOperand key = ArrayIndexFrom(args, instructions);

                        if (into_lvalue == null)
                        {
                            FlatOperand register_fop = AllocateRegister("");
                            into_lvalue = register_fop.GetLValue(this, instructions);
                        }

                        instructions.Add(FlatStatement.ARRAYGET(into_lvalue, fop_array, key));
                        return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                    }
                    break;
                case TypeKind.Class:
                    {
                        // resolve method and perform method call..
                        // resolve the array index

                        if (ti.ConvertedType.GetFullyQualifiedName() == "LavishScript2.Table")
                        {
                            FlatOperand fop_table = ResolveExpression(node.Expression, null, instructions);

                            /*
                            List<FlatOperand> args = ResolveArguments(node.ArgumentList, instructions);
                            FlatOperand key = ArrayIndexFrom(args, instructions);
                            /**/
                            ArgumentSyntax arg = node.ArgumentList.Arguments.Single();
                            FlatOperand key = ResolveArgument(arg,null,instructions);

                            if (into_lvalue == null)
                            {
                                FlatOperand register_fop = AllocateRegister("");
                                into_lvalue = register_fop.GetLValue(this, instructions);
                            }

                            instructions.Add(FlatStatement.TABLEGET(into_lvalue, fop_table, key));
                            return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                        }

                        SymbolInfo si = Model.GetSymbolInfo(node);
                        if (si.Symbol.Kind != SymbolKind.Property)
                        {
                            throw new NotImplementedException("element access on type " + ti.ConvertedType.GetFullyQualifiedName() + " resolves to " + si.Symbol.Kind.ToString());
                        }

                        IPropertySymbol ps = (IPropertySymbol)si.Symbol;
                        if (ps.IsStatic)
                        {
                            throw new NotSupportedException("static indexer?");
                        }

                        IMethodSymbol ms = ps.GetMethod;
                        if (ms == null)
                        {
                            throw new LS2ILMethodException(ps.Name+" indexer has no get method?");
                        }

                        /*
                        if (into_lvalue == null)
                        {
                            FlatOperand register_fop = AllocateRegister("");
                            into_lvalue = register_fop.GetLValue(this, instructions);
                        }
                        /**/

                        //instructions.Add(FlatStatement.RESOLVEMETHOD());
                        //Resolve(IMethodSymbol method, FlatOperand fop_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
                        FlatOperand fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
                        FlatOperand fop_method = Resolve(ms, fop_type, null, instructions);

                        return Resolve(si,ms,node.Expression,SyntaxFactory.ArgumentList(node.ArgumentList.Arguments),result_type,into_lvalue,instructions);

                        /*
                        instructions.Add(FlatStatement.TABLEGET(into_lvalue, fop_array, key));
                        return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                        /**/

//.........这里部分代码省略.........
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:101,代码来源:Function.cs

示例12: ResolveParentExpression

        public FlatOperand ResolveParentExpression(SymbolInfo si,SyntaxNode sn, FlatOperand into_lvalue, FlatOperand parent_op, List<FlatStatement> instructions)
        {
            if (sn is MemberAccessExpressionSyntax)
            {
                return ResolveExpression(((MemberAccessExpressionSyntax)sn).Expression, null, instructions);
            }
            if (sn is IdentifierNameSyntax)
            {
                IdentifierNameSyntax ins = (IdentifierNameSyntax)sn;
                switch (si.Symbol.Kind)
                {
                    case SymbolKind.Event:
                    case SymbolKind.Field:
                        {
                            // it's a field, with no member access
                            if (si.Symbol.IsStatic)
                            {
                                return Resolve(si.Symbol.ContainingType, into_lvalue, instructions);
                            }
                            // and it's not static.

                            if (parent_op != null)
                            {
                                if (into_lvalue != null)
                                {
                                    instructions.Add(FlatStatement.REFERENCE(into_lvalue, parent_op));
                                }
                                return parent_op;
                            }
                            // must be from "this".
                            FlatValue val = FlatValue.FromType(si.Symbol.ContainingType);
                            if (into_lvalue != null)
                            {
                                instructions.Add(FlatStatement.REFERENCE(into_lvalue, FlatOperand.ThisRef(val)));
                                return into_lvalue.AsRValue(val);
                            }
                            return FlatOperand.ThisRef(val);
                        }
                        break;
                    case SymbolKind.Property:
                        {
                            // it's a property, with no member access
                            if (si.Symbol.IsStatic)
                            {
                                return Resolve(si.Symbol.ContainingType, into_lvalue, instructions);
                            }
                            // and it's not static.

                            if (parent_op != null)
                            {
                                if (into_lvalue != null)
                                {
                                    instructions.Add(FlatStatement.REFERENCE(into_lvalue, parent_op));
                                }
                                return parent_op;
                            }
                            // must be from "this".
                            FlatValue val = FlatValue.FromType(si.Symbol.ContainingType);
                            if (into_lvalue != null)
                            {
                                instructions.Add(FlatStatement.REFERENCE(into_lvalue, FlatOperand.ThisRef(val)));
                                return into_lvalue.AsRValue(val);
                            }
                            return FlatOperand.ThisRef(val);
                        }
                    case SymbolKind.Method:
                        {
                            // it's a method, with no member access
                            if (si.Symbol.IsStatic)
                            {
                                return Resolve(si.Symbol.ContainingType, into_lvalue, instructions);
                            }
                            // and it's not static.

                            if (parent_op != null)
                            {
                                if (into_lvalue != null)
                                {
                                    instructions.Add(FlatStatement.REFERENCE(into_lvalue, parent_op));
                                }
                                return parent_op;
                            }

                            // is it a delegate?
                            IMethodSymbol ms = (IMethodSymbol)si.Symbol;
                            if (ms.MethodKind == MethodKind.DelegateInvoke)
                            {
                                throw new NotImplementedException("DelegateInvoke");
                            }

                            // must be from "this".
                            FlatValue val = FlatValue.FromType(si.Symbol.ContainingType);
                            if (into_lvalue != null)
                            {
                                instructions.Add(FlatStatement.REFERENCE(into_lvalue, FlatOperand.ThisRef(val)));
                                return into_lvalue.AsRValue(val);
                            }
                            return FlatOperand.ThisRef(val);
                        }
                    default:
//.........这里部分代码省略.........
开发者ID:LaxLacks,项目名称:ls2csc,代码行数:101,代码来源:Function.cs

示例13: ResolveBinaryExpression

        public FlatOperand ResolveBinaryExpression(SyntaxKind kind, FlatOperand fop_left, FlatOperand fop_right, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand fop_result = AllocateRegister("");
                into_lvalue = fop_result.GetLValue(this, instructions);
            }

            switch (kind)
            {
                case SyntaxKind.AddAssignExpression:
                case SyntaxKind.AddExpression:
                    {
                        instructions.Add(FlatStatement.ADD(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.BitwiseAndExpression:
                case SyntaxKind.AndAssignExpression:
                    {
                        instructions.Add(FlatStatement.AND(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.DivideExpression:
                case SyntaxKind.DivideAssignExpression:
                    {
                        instructions.Add(FlatStatement.DIV(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.ExclusiveOrExpression:
                case SyntaxKind.ExclusiveOrAssignExpression:
                    {
                        instructions.Add(FlatStatement.XOR(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.LeftShiftExpression:
                case SyntaxKind.LeftShiftAssignExpression:
                    {
                        instructions.Add(FlatStatement.SHL(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.ModuloExpression:
                case SyntaxKind.ModuloAssignExpression:
                    {
                        instructions.Add(FlatStatement.MOD(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.MultiplyExpression:
                case SyntaxKind.MultiplyAssignExpression:
                    {
                        instructions.Add(FlatStatement.MUL(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.BitwiseOrExpression:
                case SyntaxKind.OrAssignExpression:
                    {
                        instructions.Add(FlatStatement.OR(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.RightShiftExpression:
                case SyntaxKind.RightShiftAssignExpression:
                    {
                        instructions.Add(FlatStatement.SHR(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.SubtractExpression:
                case SyntaxKind.SubtractAssignExpression:
                    {
                        instructions.Add(FlatStatement.SUB(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.AsExpression:
                    {
                        instructions.Add(FlatStatement.AS(into_lvalue, fop_left, fop_right));
                    }
                    break;
                case SyntaxKind.IsExpression:
                    {
                        instructions.Add(FlatStatement.IS(into_lvalue, fop_left, fop_right));
                    }
                    break;
                default:
                    throw new NotImplementedException("unhandled assignment operator");
                    break;
            }

            return into_lvalue.AsRValue(fop_left.ImmediateValue);
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:87,代码来源:Function.cs

示例14: TypeOf

        public FlatOperand TypeOf(FlatOperand subject, TypeSymbol known_type_or_null, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            if (into_lvalue == null)
            {
                FlatOperand register_fop = AllocateRegister("");
                into_lvalue = register_fop.GetLValue(this, instructions);
            }

            instructions.Add(FlatStatement.TYPEOF(into_lvalue, subject));
            return into_lvalue.AsRValue(FlatValue.Type(known_type_or_null));
        }
开发者ID:VendanAndrews,项目名称:ls2csc,代码行数:11,代码来源:Function.cs

示例15: Resolve

        public FlatOperand Resolve(ElementAccessExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            /*
            // Summary:
            //     BracketedArgumentListSyntax node representing the list of arguments of the
            //     element access expression.
            public BracketedArgumentListSyntax ArgumentList { get; }
            //
            // Summary:
            //     ExpressionSyntax node representing the expression which is accessing the
            //     element.
            public ExpressionSyntax Expression { get; }
             */
            // resolve to an Array or Table
            //SymbolInfo si = Model.GetSymbolInfo(node.Expression);
            TypeInfo ti = Model.GetTypeInfo(node.Expression);

            FlatOperand fop_array = ResolveExpression(node.Expression, into_lvalue, instructions);

            switch (ti.ConvertedType.TypeKind)
            {
                case TypeKind.ArrayType:
                    {
                        // resolve the array index
                        List<FlatOperand> args = ResolveArguments(node.ArgumentList, instructions);
                        FlatOperand key = ArrayIndexFrom(args, instructions);

                        if (into_lvalue == null)
                        {
                            FlatOperand register_fop = AllocateRegister("");
                            into_lvalue = register_fop.GetLValue(this, instructions);
                        }

                        instructions.Add(FlatStatement.ARRAYGET(into_lvalue, fop_array, key));
                        return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
                    }
                    break;
                default:
                    throw new NotImplementedException("element access on type " + fop_array.ImmediateValue.ValueType.ToString());
            }

            // resolve the index

            /**/
            throw new NotImplementedException();
        }

        public FlatOperand Resolve(MemberAccessExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, List<FlatStatement> instructions)
        {
            SymbolInfo si = Model.GetSymbolInfo(node);
            if (si.Symbol.Kind != SymbolKind.Property)
            {
                throw new NotImplementedException("non-Property member access");
            }

            PropertySymbol property = (PropertySymbol)si.Symbol;

            // check for intrinsics
            string intrinsic;
            if (property.GetIntrinsic(out intrinsic))
            {
                var im = ls2csc.Intrinsics.ResolveProperty(intrinsic);
                if (im == null)
                {
                    throw new NotImplementedException("Unhandled intrinsic method " + intrinsic);
                }
                return im.Resolve(node, result_type, si, into_lvalue, this, instructions);
            }

            if (si.Symbol.IsStatic)
            {
                FlatOperand fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
                FlatOperand fop_property = Resolve(property, fop_type, null, instructions);

                throw new NotImplementedException("static property access");
            }

            {
                FlatOperand fop_subject = ResolveExpression(node.Expression, null, instructions);
                FlatOperand fop_type = TypeOf(fop_subject,null, null, instructions);

                FlatOperand fop_property = Resolve(property, fop_type, null, instructions);

                if (into_lvalue == null)
                {
                    FlatOperand register_fop = AllocateRegister("");
                    into_lvalue = register_fop.GetLValue(this, instructions);
                }

                instructions.Add(FlatStatement.GETPROPERTY(into_lvalue, fop_property, fop_subject));
                return into_lvalue.AsRValue(FlatValue.FromType(result_type.ConvertedType));
            }
            /*
            LS2Property prop = (LS2Property)member;
            return prop.Flatten_Get(subject, this, instructions);
            */

            throw new NotImplementedException("property " + node.ToString());
        }
开发者ID:Noob536,项目名称:ls2csc,代码行数:99,代码来源:Function.cs


注:本文中的LS2IL.FlatOperand.AsRValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。