Пример #1
0
        public FunctionParameter ToFuncParam(PluginRoot Plugin, VarDeclConvMode Mode = VarDeclConvMode.Nothing)
        {
            if (!CheckName(Plugin.State))
            {
                return(null);
            }

            var Ret = new FunctionParameter(Plugin.Container, Name, Type);

            Ret.Declaration = Declaration;
            Ret.InitString  = InitString;

            if (Modifiers != null && !Zinnia.Modifiers.Apply(Modifiers, Ret))
            {
                return(null);
            }

            if (Mode != VarDeclConvMode.Nothing)
            {
                if (!Ret.CalcValue(Plugin, BeginEndMode.Both, Mode == VarDeclConvMode.Assignment))
                {
                    return(null);
                }
            }

            return(Ret);
        }
Пример #2
0
        public ExpressionNode CreateConstNode(ConstExpressionNode ConstNode, PluginRoot Plugin)
        {
            var Glb = CreateExprConst(ConstNode);

            if (Glb == null)
            {
                return(null);
            }

            return(Plugin.NewNode(new IdExpressionNode(Glb, ConstNode.Code)));
        }
Пример #3
0
        public bool MakeMemberOf(PluginRoot Plugin, Identifier Id)
        {
            var Node = Plugin.NewNode(new IdExpressionNode(Id, Code));

            if (Node == null)
            {
                return(false);
            }

            MakeMemberOf(Node);
            return(true);
        }
Пример #4
0
        public FunctionParameter[] ToFuncParams(PluginRoot Plugin, VarDeclConvMode Mode = VarDeclConvMode.Nothing)
        {
            var Ret = new FunctionParameter[Count];

            for (var i = 0; i < Count; i++)
            {
                Plugin.Reset();
                Ret[i] = this[i].ToFuncParam(Plugin, Mode);
            }

            return(Ret);
        }
Пример #5
0
        public ExpressionNode GetNode(PluginRoot Plugin)
        {
            var MemberCh = new ExpressionNode[]
            {
                MakeCasts(Plugin, MemberOf),
                Member,
            };

            if (MemberCh[0] == null)
            {
                return(null);
            }

            return(Plugin.NewNode(new OpExpressionNode(Operator.Member,
                                                       MemberCh, Code, ExpressionFlags.DisableVirtualMember)));
        }
Пример #6
0
        public Variable[] ToVariables(PluginRoot Plugin, BeginEndMode BEMode = BeginEndMode.Both,
                                      VarDeclConvMode Mode = VarDeclConvMode.Nothing, bool UsePlugin = false, bool Declare = false, bool EnableUntyped = false)
        {
            var Ret = new Variable[Count];

            for (var i = 0; i < Count; i++)
            {
                if ((BEMode & BeginEndMode.Begin) != 0)
                {
                    Plugin.Reset();
                }
                Ret[i] = this[i].ToVariable(Plugin, BEMode, Mode, UsePlugin, Declare, EnableUntyped);
            }

            return(Ret);
        }
Пример #7
0
        public static ExpressionNode AlignWithDecrease(PluginRoot Plugin, ExpressionNode Node, int Align, CodeString Code)
        {
            var RType       = Node.Type.RealId as Type;
            var Mask        = GetAlignmentMask(RType.Size, Align);
            var AndCh1Value = new IntegerValue(Mask);

            var AndCh1 = Plugin.NewNode(new ConstExpressionNode(Node.Type, AndCh1Value, Code));

            if (AndCh1 == null)
            {
                return(null);
            }

            var AndCh = new ExpressionNode[] { Node, AndCh1 };

            return(Plugin.NewNode(new OpExpressionNode(Operator.BitwiseAnd, AndCh, Code)));
        }
Пример #8
0
        public ExpressionNode Copy(PluginRoot Plugin, PluginFunc Func = null,
                                   BeginEndMode Mode = BeginEndMode.Both, CodeString Code = new CodeString(), bool LeftType = false)
        {
            if ((Mode & BeginEndMode.Begin) != 0 && !Plugin.Begin())
            {
                return(null);
            }

            if (!Code.IsValid)
            {
                Code = this.Code;
            }

            var Ret = Copy(Plugin.State, Code, x =>
            {
                if (Func != null)
                {
                    var Res = Func(ref x);
                    if (Res == PluginResult.Failed)
                    {
                        return(null);
                    }
                    if (Res == PluginResult.Interrupt || Res == PluginResult.Ready)
                    {
                        return(x);
                    }
                }

                return(Plugin.NewNode(x));
            });

            if ((Mode & BeginEndMode.End) != 0 && Ret != null)
            {
                Ret = Plugin.End(Ret);
            }

            if (Ret != null && LeftType)
            {
                Ret.Type = Type;
            }

            return(Ret);
        }
Пример #9
0
        public Variable ToVariable(PluginRoot Plugin, BeginEndMode BEMode = BeginEndMode.Both,
                                   VarDeclConvMode Mode = VarDeclConvMode.Nothing, bool UsePlugin = false, bool Declare = false, bool EnableUntyped = false)
        {
            if (!CheckName(Plugin.State))
            {
                return(null);
            }

            Variable Ret;

            if (UsePlugin)
            {
                Ret = Plugin.CreateVariable(Type, Name);
                if (Ret == null)
                {
                    return(null);
                }

                Ret.InitString = InitString;
                if (Declare && !Plugin.DeclareIdentifier(Ret))
                {
                    return(null);
                }
            }
            else
            {
                Ret = ToVariable(Plugin.Container, Declare);
                if (Ret == null)
                {
                    return(null);
                }
            }

            if (Mode != VarDeclConvMode.Nothing)
            {
                if (!Ret.CalcValue(Plugin, BEMode, Mode == VarDeclConvMode.Assignment, EnableUntyped))
                {
                    return(null);
                }
            }

            return(Ret);
        }
Пример #10
0
        public ExpressionNode MakeCasts(PluginRoot Plugin, ExpressionNode Node)
        {
            if (Static)
            {
                throw new InvalidOperationException();
            }

            Node = Plugin.FinishNode(Node);
            if (Node == null)
            {
                return(null);
            }

            var State       = Plugin.State;
            var CurrentType = MemberOf.Type;

            for (var i = 0; i < Scopes.Length; i++)
            {
                var Base = GetBaseForNode(CurrentType, Scopes[i]);
                if (Base == null)
                {
                    return(null);
                }

                var CastCh1 = Plugin.NewNode(new IdExpressionNode(Base, Node.Code));
                if (CastCh1 == null)
                {
                    return(null);
                }

                var CastCh = new ExpressionNode[] { Node, CastCh1 };
                Node = Plugin.NewNode(new OpExpressionNode(Operator.Cast, CastCh, Node.Code));
                if (Node == null)
                {
                    return(null);
                }

                CurrentType = Base;
            }

            return(Node);
        }
Пример #11
0
        public ExpressionNode CallNewNode(PluginRoot Plugin, BeginEndMode Mode = BeginEndMode.Both)
        {
            if ((Mode & BeginEndMode.Begin) != 0 && !Plugin.Begin())
            {
                return(null);
            }

            var RetValue = this;
            var Res      = CallNewNode_NoBeginEnd(ref RetValue, Plugin);

            if (Res == PluginResult.Failed)
            {
                return(null);
            }

            if ((Mode & BeginEndMode.End) != 0)
            {
                RetValue = Plugin.End(RetValue);
            }

            return(RetValue);
        }
Пример #12
0
        static PluginResult CallNewNode_NoBeginEnd(ref ExpressionNode Node, PluginRoot Plugin)
        {
            return(ReplaceNodes(ref Node, Plugin, (ref ExpressionNode x) =>
            {
                var OldType = x.Type;
                var Res = Plugin.NewNodeDontCallAll(ref x);
                if (Res == PluginResult.Failed)
                {
                    return Res;
                }

                if (OldType != null && x.Type != null && x.Type.RealId != OldType.RealId)
                {
                    if (x.Type.UnderlyingStructureOrRealId is StructuredType)
                    {
                        throw new ApplicationException("Cannot change structured type of a node");
                    }
                }

                return Res;
            }, true));
        }
Пример #13
0
        public static ExpressionNode AlignWithIncrease(PluginRoot Plugin, ExpressionNode Node, int Align, CodeString Code)
        {
            var RType       = Node.Type.RealId as Type;
            var AddCh1Value = new IntegerValue(Align - 1);

            var AddCh1 = Plugin.NewNode(new ConstExpressionNode(Node.Type, AddCh1Value, Code));

            if (AddCh1 == null)
            {
                return(null);
            }

            var AddCh   = new ExpressionNode[] { Node, AddCh1 };
            var AddNode = Plugin.NewNode(new OpExpressionNode(Operator.Add, AddCh, Code));

            if (AddNode == null)
            {
                return(null);
            }

            return(AlignWithDecrease(Plugin, AddNode, Align, Code));
        }
Пример #14
0
        public static PluginResult ReplaceNodes(ref ExpressionNode Node, PluginRoot Plugin,
                                                PluginFunc Func, bool NoReplaceOnPluginCall = false)
        {
            var CallPluginOnce = false;

            for (var i = 0; i < Node.LinkedNodes.Count; i++)
            {
                var LNode   = Node.LinkedNodes[i];
                var OldNode = LNode.Node;
                var Res     = ReplaceNodes(ref LNode.Node, Plugin, Func, NoReplaceOnPluginCall);

                if (Res == PluginResult.Failed)
                {
                    return(Res);
                }
                if (Res != PluginResult.Succeeded || LNode.Node != OldNode)
                {
                    CallPluginOnce = true;
                }
            }

            if (Node.Children != null)
            {
                for (var i = 0; i < Node.Children.Length; i++)
                {
                    var OldNode = Node.Children[i];
                    var Res     = ReplaceNodes(ref Node.Children[i], Plugin, Func, NoReplaceOnPluginCall);
                    if (Res == PluginResult.Failed)
                    {
                        return(Res);
                    }

                    if (Res != PluginResult.Succeeded || Node.Children[i] != OldNode)
                    {
                        CallPluginOnce = true;
                    }
                }
            }

            if (!CallPluginOnce || (CallPluginOnce && !NoReplaceOnPluginCall))
            {
                var Res = Func(ref Node);
                if (Res != PluginResult.Succeeded)
                {
                    return(Res);
                }
            }

            if (CallPluginOnce)
            {
                var OldType = Node.Type;
                var Res     = Plugin.NewNode(ref Node);
                if (Res == PluginResult.Failed)
                {
                    return(Res);
                }

                if (OldType != null && Node.Type != null && Node.Type.RealId != OldType.RealId)
                {
                    if (Node.Type.UnderlyingStructureOrRealId is StructuredType)
                    {
                        throw new ApplicationException("Cannot change structured type of a node");
                    }
                }

                return(Res);
            }

            return(PluginResult.Succeeded);
        }
Пример #15
0
 public IdRecognizerPlugin(PluginRoot Parent, bool DoNotFail = false)
     : base(Parent)
 {
     this.DoNotFail = DoNotFail;
 }
Пример #16
0
 public ExpressionPlugin(PluginRoot Parent)
 {
     this.Parent    = Parent;
     this.Container = Parent.Container;
     this.State     = Parent.State;
 }
Пример #17
0
        public ExpressionNode CreateConstNode(CodeString Code, ConstValue Value, Type Type, PluginRoot Plugin)
        {
            var Glb = CreateExprConst(Value, Type);

            if (Glb == null)
            {
                return(null);
            }

            return(Plugin.NewNode(new IdExpressionNode(Glb, Code)));
        }
Пример #18
0
 public ExpressionNode GetVal(PluginRoot Plugin, BeginEndMode Mode = BeginEndMode.Both)
 {
     return(Expressions.CreateExpression(InitString, Plugin, Mode));
 }
Пример #19
0
        static bool CallStaticConstructors(IdContainer Container, CodeScopeNode Scope, PluginRoot Plugin, CodeString Code)
        {
            for (var i = 0; i < Container.Children.Count; i++)
            {
                if (!CallStaticConstructors(Container.Children[i], Scope, Plugin, Code))
                {
                    return(false);
                }
            }

            for (var i = 0; i < Container.IdentifierList.Count; i++)
            {
                var Ctor = Container.IdentifierList[i] as Constructor;
                if (Ctor == null || (Ctor.Flags & IdentifierFlags.Static) == 0)
                {
                    continue;
                }

                if (!Plugin.Begin())
                {
                    return(false);
                }

                var CtorNode = Plugin.NewNode(new IdExpressionNode(Ctor, Code));
                if (CtorNode == null)
                {
                    Plugin.Reset(); return(false);
                }

                var NodeCh = new ExpressionNode[] { CtorNode };
                var Node   = Plugin.NewNode(new OpExpressionNode(Operator.Call, NodeCh, Code));
                if (Node == null || Plugin.End(ref Node) == PluginResult.Failed)
                {
                    Plugin.Reset(); return(false);
                }

                Scope.Children.Add(new Command(Scope, Code, CommandType.Expression)
                {
                    Expressions = new List <ExpressionNode>()
                    {
                        Node
                    },
                });
            }

            return(true);
        }
Пример #20
0
        public bool CalcValue(PluginRoot Plugin, BeginEndMode Mode = BeginEndMode.Both, bool CreateAssignNodes = false, bool EnableUntyped = false)
        {
            InitValue = null;
            if (InitString.IsValid)
            {
                var NMode = Mode & BeginEndMode.Begin;
                InitValue = Expressions.CreateExpression(InitString, Plugin, NMode);
                if (InitValue == null)
                {
                    return(false);
                }

                if (CreateAssignNodes)
                {
                    var Node = Expressions.CreateReference(Plugin.Container, this, Plugin, InitString);
                    if (Node == null)
                    {
                        return(false);
                    }

                    InitValue = Expressions.SetValue(Node, InitValue, Plugin, InitString, false);
                    if (InitValue == null)
                    {
                        return(false);
                    }
                }

                InitValue = Plugin.FinishNode(InitValue);
                if (InitValue == null)
                {
                    return(false);
                }

                if (!CreateAssignNodes && TypeOfSelf.RealId is AutomaticType)
                {
                    if (!EnableUntyped && InitValue.Type.RealId is AutomaticType)
                    {
                        Plugin.State.Messages.Add(MessageId.Untyped, Name);
                        return(false);
                    }

                    Children[0] = InitValue.Type;
                }

                var TypeMgrnPlugin = Plugin.GetPlugin <TypeMngrPlugin>();
                if (!TypeOfSelf.IsEquivalent(InitValue.Type) && !(TypeOfSelf.RealId is AutomaticType))
                {
                    InitValue = TypeMgrnPlugin.Convert(InitValue, TypeOfSelf, InitString);
                    if (InitValue == null)
                    {
                        return(false);
                    }
                }

                if ((Mode & BeginEndMode.End) != 0)
                {
                    InitValue = Plugin.End(InitValue);
                    if (InitValue == null)
                    {
                        return(false);
                    }
                }

                var ConstVal = InitValue as ConstExpressionNode;
                if (ConstVal != null)
                {
                    ConstInitValue = ConstVal.Value;
                }
            }
            else if (TypeOfSelf.RealId is AutomaticType)
            {
                if (!EnableUntyped)
                {
                    Plugin.State.Messages.Add(MessageId.Untyped, Name);
                    return(false);
                }
            }

            return(true);
        }
Пример #21
0
 public CompilerPlugin(PluginRoot Parent)
     : base(Parent)
 {
 }
Пример #22
0
 public PreProcPlugin(PluginRoot Parent, bool IfDef)
     : base(Parent)
 {
     this.IfDef = IfDef;
 }
Пример #23
0
 public MacroArgPlugin(PluginRoot Parent, List <string> Parameters)
     : base(Parent)
 {
     this.Parameters = Parameters;
 }
Пример #24
0
 public EvaluatorPlugin(PluginRoot Parent, bool MustBeConst)
     : base(Parent)
 {
     this.MustBeConst = MustBeConst;
 }