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); }
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))); }
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); }
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))); }
public ExpressionNode CreateConstNode(ConstExpressionNode ConstNode, PluginRoot Plugin) { var Glb = CreateExprConst(ConstNode); if (Glb == null) { return(null); } return(Plugin.NewNode(new IdExpressionNode(Glb, ConstNode.Code))); }
public bool MakeMemberOf(PluginRoot Plugin, Identifier Id) { var Node = Plugin.NewNode(new IdExpressionNode(Id, Code)); if (Node == null) { return(false); } MakeMemberOf(Node); return(true); }
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)); }
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))); }
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); }
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); }