Exemplo n.º 1
0
        public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params,
                                       CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out)
        {
            if (Function.IsEqual("stackalloc"))
            {
                var State = Plugin.State;

                if (GenericParams != null && GenericParams.Length != 0)
                {
                    State.Messages.Add(MessageId.NonGenericIdentifier, Function);
                    return(ExprRecResult.Failed);
                }

                if (Params.Length != 1)
                {
                    State.Messages.Add(MessageId.ParamCount, Code);
                    return(ExprRecResult.Failed);
                }

                var Bytes = Expressions.Recognize(Params[0], Plugin, true);
                if (Bytes == null)
                {
                    return(ExprRecResult.Failed);
                }

                var Ch = new ExpressionNode[] { Bytes };
                Out = new OpExpressionNode(Operator.StackAlloc, Ch, Code);
                return(ExprRecResult.Succeeded);
            }

            return(ExprRecResult.Unknown);
        }
Exemplo n.º 2
0
 public static bool IsCondition(OpExpressionNode Node)
 {
     if (Node.Operator == Operator.Unknown)
     {
         var Data = Node.Data.Get <x86NodeData>();
         return(IsConditionOp(Data.Operator));
     }
     else
     {
         return(Operators.IsBoolRet(Node.Operator));
     }
 }
Exemplo n.º 3
0
        public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params,
                                       CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out)
        {
            if (Function.IsEqual("reinterpret_cast"))
            {
                var State     = Plugin.State;
                var Container = Plugin.Container;

                if (GenericParams == null || GenericParams.Length != 1)
                {
                    State.Messages.Add(MessageId.GenericParamCount, Code);
                    return(ExprRecResult.Failed);
                }

                if (Params.Length != 1)
                {
                    State.Messages.Add(MessageId.ParamCount, Code);
                    return(ExprRecResult.Failed);
                }

                var Options = GetIdOptions.DefaultForType;
                var Type    = Identifiers.Recognize(Container, GenericParams[0], Options);
                if (Type == null)
                {
                    return(ExprRecResult.Failed);
                }

                var Child    = Expressions.Recognize(Params[0], Plugin, true);
                var TypeNode = Plugin.NewNode(new IdExpressionNode(Type, GenericParams[0]));
                if (Child == null || TypeNode == null)
                {
                    return(ExprRecResult.Failed);
                }

                Out          = new OpExpressionNode(Operator.Reinterpret, Code);
                Out.Children = new ExpressionNode[] { Child, TypeNode };
                return(ExprRecResult.Succeeded);
            }

            return(ExprRecResult.Unknown);
        }
Exemplo n.º 4
0
        public static ExpressionNode FlattenIndices(PluginRoot Plugin, ExpressionNode[] Indices,
                                                    ExpressionNode[] Dimensions, CodeString Code, Identifier TempVarType = null)
        {
            if (Dimensions.Length == 1)
            {
                return(Indices[0]);
            }

            var Ret       = (ExpressionNode)null;
            var MulVar    = (Identifier)null;
            var Container = Plugin.Container;
            var State     = Plugin.State;

            if (Dimensions.Length >= 2)
            {
                var NCPlugin      = Plugin.GetPlugin <NCPlugin>();
                var DeclContainer = NCPlugin.DeclContainer;
                MulVar = DeclContainer.CreateAndDeclareVariable(State.AutoVarName, TempVarType);
                if (MulVar == null)
                {
                    return(null);
                }
            }

            for (var i = Dimensions.Length - 1; i >= 0; i--)
            {
                var Chi        = Indices[i];
                var LinkedNode = (LinkedExprNode)null;
                if (MulVar != null && i != 1)
                {
                    ExpressionNode[] AssignmentCh;
                    if (i == Dimensions.Length - 1)
                    {
                        var Dst = Plugin.NewNode(new IdExpressionNode(MulVar, Code));
                        if (Dst == null)
                        {
                            return(null);
                        }

                        AssignmentCh = new ExpressionNode[] { Dst, Dimensions[i] };
                    }
                    else
                    {
                        var Dst    = Plugin.NewNode(new IdExpressionNode(MulVar, Code));
                        var MulSrc = Plugin.NewNode(new IdExpressionNode(MulVar, Code));
                        if (Dst == null || MulSrc == null)
                        {
                            return(null);
                        }

                        var MulCh   = new ExpressionNode[] { MulSrc, Dimensions[i] };
                        var MulNode = Plugin.NewNode(new OpExpressionNode(Operator.Multiply, MulCh, Code));
                        if (MulNode == null)
                        {
                            return(null);
                        }

                        AssignmentCh = new ExpressionNode[] { Dst, MulNode };
                    }

                    var Assignment = Plugin.NewNode(new OpExpressionNode(Operator.Assignment, AssignmentCh, Code));
                    if (Assignment == null)
                    {
                        return(null);
                    }

                    LinkedNode = new LinkedExprNode(Assignment, LinkedNodeFlags.NotRemovable);
                }

                if (MulVar != null && i != Dimensions.Length - 1)
                {
                    var MulNode = Plugin.NewNode(new IdExpressionNode(MulVar, Code));
                    if (MulNode == null)
                    {
                        return(null);
                    }

                    var MulCh = new ExpressionNode[] { Chi, MulNode };
                    Chi = Plugin.NewNode(new OpExpressionNode(Operator.Multiply, MulCh, Code));
                    if (Chi == null)
                    {
                        return(null);
                    }
                }

                if (Ret != null)
                {
                    var AddCh   = new ExpressionNode[] { Ret, Chi };
                    var AddNode = new OpExpressionNode(Operator.Add, AddCh, Code);
                    if (LinkedNode != null)
                    {
                        AddNode.LinkedNodes.Add(LinkedNode);
                    }

                    Ret = Plugin.NewNode(AddNode);
                    if (Ret == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    Ret = Chi;
                    if (LinkedNode != null)
                    {
                        Ret.LinkedNodes.Add(LinkedNode);
                    }
                }
            }

            return(Ret);
        }