public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params, CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out) { if (Function.IsEqual("defined")) { 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 Preprocessor = State.GlobalContainer.Preprocessor; var Defined = Preprocessor.GetMacro(Params[0].ToString()) != null; Out = Constants.GetBoolValue(Plugin.Container, Defined, Code); if (Out == null) { return(ExprRecResult.Failed); } return(ExprRecResult.Succeeded); } return(ExprRecResult.Unknown); }
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); }
bool CallInitializerWithoutCmp(CodeScopeNode Scope, ref int Index, PluginRoot Plugin, ExpressionNode Size, CodeString Code) { var Self = Scope.FunctionScope.SelfVariable; if (!AllocateObject(Scope, ref Index, Self, Size, Plugin, Code)) { return(false); } var StructuredType = Scope.StructuredScope.StructuredType; var ObjectType = Identifiers.GetByFullNameFast <ClassType>(Scope.GlobalContainer, "System.Object"); if (Identifiers.IsSubtypeOrEquivalent(StructuredType, ObjectType)) { if (!SetFunctionTable(Scope, ref Index, Self, Code)) { return(false); } if (!SetTypePointer(Scope, ref Index, Self, Code)) { return(false); } } return(true); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { var InnerCode = BetweenOperatos(Code); if (!InnerCode.IsValid) { return(ExprRecResult.Unknown); } var String = RecognizerHelper.ProcessString(InnerCode, Plugin, '~'); if (String == null) { return(ExprRecResult.Failed); } if (String.Length != 1) { Plugin.State.Messages.Add(MessageId.CharInvalidLength, Code); return(ExprRecResult.Failed); } var Global = Plugin.Container.GlobalContainer; Ret = new ConstExpressionNode(Global.CommonIds.Char, new CharValue(String[0]), Code); return(ExprRecResult.Succeeded); }
public static NodeGroup GetGroups(PluginRoot Plugin, CodeString Code, char BracketLeft = '{', char BracketRight = '}') { var Ret = new NodeGroup(Code); var State = Plugin.State; var List = RecognizerHelper.SplitToParameters(State, Code, ','); if (List == null) { return(null); } for (var i = 0; i < List.Length; i++) { var Param = List[i]; if (Param.Length > 1 && Param[0] == BracketLeft && Param[Param.Length] == BracketLeft) { Param = Param.Substring(1, Param.Length - 1).Trim(); Ret.Children.Add(Expressions.GetGroups(Plugin, Param)); } else { var Node = Expressions.Recognize(Param, Plugin); if (Node == null) { return(null); } Ret.Children.Add(Node); } } return(Ret); }
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 ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params, CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out) { if (Function.IsEqual("default")) { 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 Container = Plugin.Container; var Type = Container.RecognizeIdentifier(Params[0], GetIdOptions.DefaultForType); if (Type == null) { return(ExprRecResult.Failed); } Out = Constants.GetDefaultValue(Plugin, Type, Code); return(Out == null ? ExprRecResult.Failed : ExprRecResult.Ready); } return(ExprRecResult.Unknown); }
public static ExpressionNode IsInRange(PluginRoot Plugin, ExpressionNode Node, ExpressionNode Min, ExpressionNode Max, CodeString Code) { var Nodes = new ExpressionNode[] { Min, Node, Max }; var Operators = new Operator[] { Operator.LessEqual, Operator.LessEqual }; return(Expressions.ChainedRelation(Plugin, Nodes, Operators, Code)); }
public bool ProcessContainer(IdContainer Container, bool NoExtract = false) { if (Container is Command) { var Old = Container; var OldParent = Old.Parent; Container = ProcessCommand(Container as Command, NoExtract); if (Container == null) { return(false); } if (Container != Old && OldParent.Children.Contains(Old)) { throw new ApplicationException(); } } else if (Container is FunctionScope) { if (!ProcessFunctionScope(Container as FunctionScope)) { return(false); } } if (!NCArch.ProcessContainer(Container)) { return(false); } if (Container is Command) { var Command = Container as Command; if (Command.Expressions != null) { var Plugin = this.Plugin; if (Plugin.CurrentlyUsing) { Plugin = CreatePlugin(); } Plugin.Container = Command; for (var i = 0; i < Command.Expressions.Count; i++) { var Expr = Command.Expressions[i].CallNewNode(Plugin); if (Expr == null) { Plugin.Reset(); return(false); } Command.Expressions[i] = Expr; } } } return(true); }
public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params, CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out) { var State = Plugin.State; var Container = Plugin.Container; int Func; if (Function.IsEqual("incbin_ptr")) { Func = 0; } else if (Function.IsEqual("incbin_size")) { Func = 1; } else { return(ExprRecResult.Unknown); } 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 IncBin = GetIncBin(Params[0], Plugin); if (IncBin == null) { return(ExprRecResult.Failed); } if (Func == 0) { Out = new DataPointerNode(Code, IncBin); } else if (Func == 1) { var Type = Container.GlobalContainer.CommonIds.UIntPtr; Out = new ConstExpressionNode(Type, new IntegerValue(IncBin.Length), Code); } else { throw new ApplicationException(); } return(ExprRecResult.Succeeded); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { if (Code.IsValidIdentifierName) { Ret = new StrExpressionNode(Code); return(ExprRecResult.Succeeded); } return(ExprRecResult.Unknown); }
bool CallInitializerWithCmp(CodeScopeNode Scope, ref int Index, PluginRoot Plugin, ExpressionNode Size, CodeString Code) { var CondComm = new Command(Scope, Code, CommandType.If); Scope.Children.Insert(Index, CondComm); Index++; var ThenScope = new CodeScopeNode(CondComm, new CodeString()); CondComm.Children = new List <IdContainer>() { ThenScope }; var CmpPlugin = ThenScope.GetPlugin(); if (!CmpPlugin.Begin()) { return(false); } var FS = Scope.FunctionScope; var Self = CmpPlugin.NewNode(new IdExpressionNode(FS.SelfVariable, Code)); var Null = CmpPlugin.NewNode(Constants.GetNullValue(Scope, Code)); if (Self == null || Null == null) { return(false); } var CmpCh = new ExpressionNode[] { Self, Null }; var CmpNode = CmpPlugin.NewNode(new OpExpressionNode(Operator.RefEquality, CmpCh, Code)); if (CmpNode == null || (CmpNode = CmpPlugin.End(CmpNode)) == null) { return(false); } CondComm.Expressions = new List <ExpressionNode>() { CmpNode }; var NewIndex = ThenScope.Children.Count; if (!CallInitializerWithoutCmp(ThenScope, ref NewIndex, Plugin, Size, Code)) { return(false); } if (!ProcessContainer(ThenScope)) { return(false); } return(ProcessContainer(CondComm)); }
public static ExpressionNode ThrowSystemException(PluginRoot Plugin, string ExceptionType, CodeString Code, BeginEndMode BEMode = BeginEndMode.Both) { var System = Identifiers.GetByFullNameFast <Namespace>(Plugin.State, "System"); if (System == null) { return(null); } return(Throw(Plugin, System, new CodeString(ExceptionType), Code, BEMode)); }
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 IsInRange(PluginRoot Plugin, ExpressionNode Node, BigInteger Min, BigInteger Max, CodeString Code) { if (!(Node.Type.RealId is NonFloatType)) { throw new ArgumentException("Node"); } var MinValue = new IntegerValue(Min); var MaxValue = new IntegerValue(Max); return(IsInRange(Plugin, Node, MinValue, MaxValue, Code)); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Out) { var Result = Code.StartsWith(Operators, Skip, new IdCharCheck(true)); if (Result.Position != -1) { var State = Plugin.State; var Right = Code.Substring(Result.String.Length).Trim(); Right = Right.TrimOneBracket(SkippingHandlers); if (Right.Length == 0) { State.Messages.Add(MessageId.DeficientExpr, Code); return(ExprRecResult.Failed); } var TypeMngrPlugin = Plugin.GetPlugin <TypeMngrPlugin>(); if (TypeMngrPlugin == null) { return(ExprRecResult.Unknown); } var OldCheckingMode = TypeMngrPlugin.CheckingMode; if (Result.Index == 0) { TypeMngrPlugin.CheckingMode = CheckingMode.Checked; } else if (Result.Index == 1) { TypeMngrPlugin.CheckingMode = CheckingMode.Unchecked; } else { throw new ApplicationException(); } Out = Expressions.Recognize(Right, Plugin); TypeMngrPlugin.CheckingMode = OldCheckingMode; if (Out == null) { return(ExprRecResult.Failed); } else { return(ExprRecResult.Ready); } } return(ExprRecResult.Unknown); }
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 Throw(PluginRoot Plugin, ExpressionNode Node, CodeString Code, bool End = true) { var Global = Plugin.Container.GlobalContainer; var Func = Identifiers.GetByFullNameFast <Function>(Global, "Internals.ThrowException"); if (Func == null) { return(null); } Node = Expressions.Call(Code, Plugin, Func, Node); return(Node == null || !End ? Node : Plugin.End(Node)); }
public ExpressionNode Recognize(CodeString Code, PluginRoot Plugin) { ExpressionNode Out; var Res = Expressions.Recognize(Code, Plugin, RunBefore, out Out); if (Res == SimpleRecResult.Unknown) { return(CreateFuncCallNode(Plugin, Code)); } else { return(Res == SimpleRecResult.Succeeded ? Out : null); } }
public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params, CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out) { if (Function.IsEqual("sizeof")) { 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 Options = GetIdOptions.Default; Options.Func = x => x.RealId is Type || (x.RealId is Variable && AllowVariables); var Id = Plugin.Container.RecognizeIdentifier(Params[0], Options); if (Id == null) { return(ExprRecResult.Failed); } Type Type = null; if (Id.RealId is Variable && AllowVariables) { Type = Id.TypeOfSelf.RealId as Type; } else { Type = Id.RealId as Type; } if (Type == null) { State.Messages.Add(MessageId.CannotGetSize, Params[0]); return(ExprRecResult.Failed); } Out = Constants.GetIntValue(Plugin.Container, Type.Size, Code, true); return(ExprRecResult.Succeeded); } return(ExprRecResult.Unknown); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { if (Code.IsValidIdentifierName) { foreach (var e in List) { if (Code.IsEqual(e.Key)) { return(e.Value(Code, Plugin, ref Ret)); } } } return(ExprRecResult.Unknown); }
public static ExpressionNode Throw(PluginRoot Plugin, Identifier ContainerId, CodeString ExceptionType, CodeString Code, BeginEndMode BEMode = BeginEndMode.Both) { var Options = new GetIdOptions() { EnableMessages = true, Func = x => x.RealId is ClassType }; var IdExceptionType = Identifiers.GetFromMembers(ContainerId, ExceptionType, Options); if (IdExceptionType == null) { return(null); } return(Throw(Plugin, IdExceptionType, Code, BEMode)); }
public static ExpressionNode FlattenIndicesWithoutTempVar(PluginRoot Plugin, ExpressionNode Node, CodeString Code, Identifier IndexType = null) { var Indices = GetArrayIndices(Plugin, Node, Code, IndexType); var ArrayType = Node.Children[0].Type.RealId as ArrayType; if (ArrayType.Dimensions == 1) { return(Indices[0]); } var Dimensions = GetArrayDimensions(Plugin, Node, Code); return(FlattenIndicesWithoutTempVar(Plugin, Indices, Dimensions, Code)); }
public static bool ProcessCode(FunctionScope Scope) { var NCArch = Scope.State.Arch as INCArchitecture; var NCProcessor = new NCProcessor(Scope, NCArch); NCProcessor.Plugin = NCProcessor.CreatePlugin(); var NSData = Scope.Data.Create <NCFuncScopeData>(); if (!NCProcessor.ProcessRecursively(Scope)) { return(false); } Scope.Data.Remove <NCFuncScopeData>(); return(true); }
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 static ExpressionNode[] GetArrayDimensions(PluginRoot Plugin, ExpressionNode Node, CodeString Code) { var Ch = Node.Children; var Dimensions = new ExpressionNode[Ch.Length - 1]; for (var i = 0; i < Dimensions.Length; i++) { Dimensions[i] = GetArrayDimension(Plugin, Ch[0], i, Code); if (Dimensions[i] == null) { return(null); } } return(Dimensions); }
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 static ExpressionNode IsInRange(PluginRoot Plugin, ExpressionNode Node, NonFloatType Type, CodeString Code) { if (Node.InterrupterPlugin != -1 && Node.Type == null) { Node = Plugin.FinishNode(Node); if (Node == null) { return(null); } } var NodeType = Node.Type.RealId as NonFloatType; var Min = BigInteger.Max(Type.MinValue, NodeType.MinValue); var Max = BigInteger.Min(Type.MaxValue, NodeType.MaxValue); return(IsInRange(Plugin, Node, Min, Max, Code)); }
bool CallInitializer(CodeScopeNode Scope, ref int Index, PluginRoot Plugin, ExpressionNode Size, CodeString Code) { var FS = Scope.FunctionScope; var Structured = FS.Parent as StructuredScope; var Type = Structured.StructuredType; var FType = Scope.FunctionScope.Function.Children[0]; var NoCondition = FType.Children[0].RealId is VoidType; if (NoCondition) { return(CallInitializerWithoutCmp(Scope, ref Index, Plugin, Size, Code)); } else { return(CallInitializerWithCmp(Scope, ref Index, Plugin, Size, Code)); } }
private IncludedBinary GetIncBin(CodeString Code, PluginRoot Plugin) { string String; if (!Constants.RecognizeString(Code, Plugin, out String)) { return(null); } var Global = Plugin.Container.GlobalContainer; var IncBin = Global.GetIncludedBinary(String); if (IncBin == null) { Plugin.State.Messages.Add(MessageId.UnknownId, Code); return(null); } return(IncBin); }