public static ExpressionNode Throw(PluginRoot Plugin, Identifier ExceptionType, CodeString Code, BeginEndMode BEMode = BeginEndMode.Both) { var GlobalContainer = Plugin.Container.GlobalContainer; if ((BEMode & BeginEndMode.Begin) != 0 && !Plugin.Begin()) { return(null); } var IdNode = Plugin.NewNode(new IdExpressionNode(ExceptionType, Code)); if (IdNode == null) { return(null); } var Ch = new ExpressionNode[] { IdNode }; var Node = Plugin.NewNode(new OpExpressionNode(Operator.NewObject, Ch, Code)); if (Node == null) { return(null); } return(Throw(Plugin, Node, Code, (BEMode & BeginEndMode.End) != 0)); }
public static ExpressionNode IsInRange(PluginRoot Plugin, ExpressionNode Node, ConstValue Min, ConstValue Max, CodeString Code) { var MinNode = Plugin.NewNode(new ConstExpressionNode(Node.Type, Min, Code)); var MaxNode = Plugin.NewNode(new ConstExpressionNode(Node.Type, Max, Code)); if (MinNode == null || MaxNode == null) { return(null); } return(IsInRange(Plugin, Node, MinNode, MaxNode, Code)); }
public static ExpressionNode GetArrayDimension(PluginRoot Plugin, ExpressionNode Array, int Index, CodeString Code) { var Container = Plugin.Container; var Type = Array.Type.RealId; if (Type is NonrefArrayType) { var Arr = Type as NonrefArrayType; if (Arr.Lengths == null) { throw new ArgumentOutOfRangeException("Index"); } return(Plugin.NewNode(Constants.GetUIntPtrValue(Container, Arr.Lengths[Index], Code))); } else if (Type is RefArrayType) { var Arr = Type as RefArrayType; var DimensionsId = Identifiers.GetMember(Plugin.State, Arr, "Dimensions", Code); if (DimensionsId == null) { return(null); } var DimensionsIdNode = Plugin.NewNode(new IdExpressionNode(DimensionsId, Code)); if (DimensionsIdNode == null) { return(null); } var DimensionsCh = new ExpressionNode[] { Array, DimensionsIdNode }; var Dimensions = Plugin.NewNode(new OpExpressionNode(Operator.Member, DimensionsCh, Code)); if (Dimensions == null) { return(null); } var IndexValue = Plugin.NewNode(Constants.GetIntValue(Container, Index, Code)); if (IndexValue == null) { return(null); } var IndexCh = new ExpressionNode[] { Dimensions, IndexValue }; return(Plugin.NewNode(new OpExpressionNode(Operator.Index, IndexCh, Code))); } else { throw new NotImplementedException(); } }
public static ExpressionNode FlattenIndicesWithoutTempVar(PluginRoot Plugin, ExpressionNode[] Indices, ExpressionNode[] Dimensions, CodeString Code) { if (Dimensions.Length == 1) { return(Indices[0]); } var Ret = (ExpressionNode)null; for (var i = Dimensions.Length - 1; i >= 0; i--) { var Chi = Indices[i]; for (var j = i + 1; j < Dimensions.Length; j++) { var MulCh = new ExpressionNode[] { Chi, Dimensions[j] }; Chi = Plugin.NewNode(new OpExpressionNode(Operator.Multiply, MulCh, Code)); if (Chi == null) { return(null); } } if (Ret != null) { var AddCh = new ExpressionNode[] { Ret, Chi }; Ret = Plugin.NewNode(new OpExpressionNode(Operator.Add, AddCh, Code)); if (Ret == null) { return(null); } } else { Ret = Chi; } } return(Ret); }
public static ExpressionNode Negate(PluginRoot Plugin, ExpressionNode Node, CodeString Code, bool End = false) { var Ch = new ExpressionNode[] { Node }; Node = Plugin.NewNode(new OpExpressionNode(Operator.Not, Ch, Code)); if (Node == null) { return(null); } if (End && Plugin.End(ref Node) == PluginResult.Failed) { return(null); } return(Node); }
public ExpressionNode CreateFuncCallNode(PluginRoot Plugin, CodeString Code) { CodeString Function, Parameters; if (!GetParameters(Plugin.State, Code, out Function, out Parameters)) { return(null); } var Ch = CallRecognizer.ProcessParameters(Plugin, Function, Parameters); if (Ch == null) { return(null); } return(Plugin.NewNode(new OpExpressionNode(Operator.Call, Ch, Code))); }
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); }
private bool AllocateObject(CodeScopeNode Scope, ref int Index, SelfVariable Self, ExpressionNode Size, PluginRoot Plugin, CodeString Code) { var TypeMngrPlugin = Plugin.GetPlugin <TypeMngrPlugin>(); TypeMngrPlugin.Flags |= TypeMngrPluginFlags.NoWarningOnCastingToSameType; TypeMngrPlugin.Flags |= TypeMngrPluginFlags.EnableReadonlyWriting; var Func = Identifiers.GetByFullNameFast <Function>(Scope.State, "Internals.ObjectHelper.Allocate"); if (Func == null) { return(false); } var FuncNode = Plugin.NewNode(new IdExpressionNode(Func, Code)); if (Func == null) { return(false); } var FuncType = Func.Children[0] as TypeOfFunction; var SizeParam = FuncType.Children[1] as FunctionParameter; if (Size.Type == null || !Size.Type.IsEquivalent(SizeParam.TypeOfSelf)) { Size = Expressions.Convert(Size, SizeParam.TypeOfSelf, Plugin, Code); if (Size == null) { return(false); } } var CallCh = new ExpressionNode[] { FuncNode, Size }; var Call = Plugin.NewNode(new OpExpressionNode(Operator.Call, CallCh, Code)); if (Call == null) { return(false); } var Node = Expressions.Reinterpret(Call, Self.TypeOfSelf, Plugin, Code); if (Node == null) { return(false); } var FS = Scope.FunctionScope; var Assignment = Expressions.SetValue(FS.SelfVariable, Node, Plugin, Code, true); if (Assignment == null) { return(false); } var Command = new Command(Scope, Code, CommandType.Expression); Command.Expressions = new List <ExpressionNode>() { Assignment }; Scope.Children.Insert(Index, Command); Index++; return(ProcessContainer(Command)); }
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); }