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 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 ExpressionNode CreateConstNode(ConstExpressionNode ConstNode, PluginRoot Plugin) { var Glb = CreateExprConst(ConstNode); if (Glb == null) { return(null); } return(Plugin.NewNode(new IdExpressionNode(Glb, ConstNode.Code))); }
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); } var Global = Plugin.Container.GlobalContainer; Ret = new ConstExpressionNode(Global.CommonIds.String, new StringValue(String), Code); return(ExprRecResult.Succeeded); }
public bool VerifyArrayLength(CompilerState State, ConstExpressionNode ConstNode, CodeString Code, bool EnableMessages) { if (ConstNode.Integer < 0) { if (EnableMessages) { State.Messages.Add(MessageId.ArrayLengthTooSmall, Code); } return(false); } else if (ConstNode.Integer > int.MaxValue) { if (EnableMessages) { State.Messages.Add(MessageId.ArrayLengthTooBig, Code); } return(false); } return(true); }
public void Declare(ConstExpressionNode Value) { Declare(Value.Type.RealId as Type, Value.Value); }
ExpressionNode MoveConstantToGlobal(ConstExpressionNode Node) { var RetValue = Container.GlobalContainer.CreateConstNode(Node, Parent); return(RetValue == null ? null : Parent.FinishNode(RetValue)); }
public GlobalVariable CreateExprConst(ConstExpressionNode Node) { return(CreateExprConst(Node.Value, Node.Type)); }
public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret) { if (Code.Length == 0) { return(ExprRecResult.Unknown); } var OldCode = Code; var State = Plugin.State; var Container = Plugin.Container; var Global = Container.GlobalContainer; var RadixSpecified = false; var Radix = 10; var Sign = RecognizerHelper.GetSign(ref Code); if (Code.Length == 0) { return(ExprRecResult.Unknown); } if (AtStartStrings != null) { var Result = Code.StartsWith(AtStartStrings, Skip); if (Result.Index != -1) { Code = Code.TrimmedSubstring(State, Result.String.Length); if (!Code.IsValid) { return(ExprRecResult.Failed); } RadixSpecified = true; Radix = AtStart[Result.Index].Radix; } } if (AtEndStrings != null) { var Result = Code.EndsWith(AtEndStrings, Skip); if (Result.Index != -1) { if (Radix != -1) { State.Messages.Add(MessageId.MultipleRadix, Code); return(ExprRecResult.Failed); } Code = Code.TrimmedSubstring(State, Result.String.Length); if (!Code.IsValid) { return(ExprRecResult.Failed); } RadixSpecified = true; Radix = AtStart[Result.Index].Radix; } } if (RecognizerHelper.GetSign(ref Code)) { Sign = !Sign; } if (Code.Length == 0 || (!char.IsDigit(Code[0]) && !RadixSpecified)) { return(ExprRecResult.Unknown); } var Options = new ConvStrToNumberOptions(); var Type = TypeExtractor(Container, ref Code); if (Type == null) { Options.Type = ConstValueType.Unknown; } else { var RType = Type.RealId as Type; Options.Type = RType.ConstValueType; } Code = Code.Trim(); if (Code.Length == 0) { return(ExprRecResult.Unknown); } Options.Radix = Radix; Options.Number = Code.String; Options.LetterCase = LetterCase.OnlyUpper; Options.EnableENotation = true; Options.Sign = Sign; ConstValue Value; var Res = RecognizerHelper.ConvStrToNumber(State, Code, Options, out Value); if (Res == SimpleRecResult.Unknown) { return(ExprRecResult.Unknown); } else if (Res == SimpleRecResult.Failed) { return(ExprRecResult.Failed); } if (Type == null) { Type = Constants.GetDefaultType(Container, Value.Type); if (Type.RealId is NumberType && !Value.CheckBounds(Type)) { var SystemType = Type.GetType(); do { var RType = Type.RealId as Type; Type = Global.CommonIds.GetIdentifier(SystemType, RType.Size * 2); if (Type == null) { if (typeof(SignedType).IsEquivalentTo(SystemType)) { Type = Global.CommonIds.GetLargestType(typeof(UnsignedType)); } else { Type = Global.CommonIds.GetLargestType(typeof(SignedType)); } break; } } while (!Value.CheckBounds(Type)); } } if (!Value.CheckBounds(State, Type, OldCode)) { return(ExprRecResult.Failed); } var Flags = Options.Type == ConstValueType.Unknown ? ExpressionFlags.AutoConvert : ExpressionFlags.None; Ret = new ConstExpressionNode(Type, Value, OldCode, Flags); return(ExprRecResult.Succeeded); }
PluginResult ProcessParams(ref ExpressionNode Node) { var Ch = Node.Children; var Type = Ch[0].Type; if (Type == null) { var IdCh0 = Ch[0] as IdExpressionNode; if (IdCh0 != null) { Type = IdCh0.Identifier.TypeOfSelf; } else { return(PluginResult.Succeeded); } } var FuncType = Type.RealId as TypeOfFunction; if (FuncType == null) { return(PluginResult.Succeeded); } if (FuncType.Children.Length < Ch.Length) { if ((State.Language.Flags & LangaugeFlags.ConvertParametersToTuple) != 0) { if (FuncType.Children.Length == 2 && Ch.TrueForAll(x => !(x is NamedParameterNode))) { var Param0 = FuncType.Children[1] as FunctionParameter; if (Param0.TypeOfSelf.RealId is TupleType) { var NewCh1 = Parent.NewNode(new OpExpressionNode(Operator.Tuple, Ch.Slice(1), Node.Code)); if (NewCh1 == null || ResolveNode(ref NewCh1) == PluginResult.Failed) { return(PluginResult.Failed); } Node.Children = Ch = new ExpressionNode[] { Ch[0], NewCh1 }; return(PluginResult.Succeeded); } } } } var ExtraParams = new AutoAllocatedList <ExpressionNode>(); var Ret = new ExpressionNode[FuncType.Children.Length]; Ret[0] = Ch[0]; var RetValue = true; var NamedParameter = false; for (var i = 1; i < Ch.Length; i++) { if (Ch[i] is NamedParameterNode) { var Chi = Ch[i] as NamedParameterNode; var Param = FuncType.GetParameter(Chi.Name.ToString()); if (Param == null) { State.Messages.Add(MessageId.UnknownId, Chi.Name); RetValue = false; continue; } var Index = FuncType.GetChildIndex(Param); if (Ret[Index] != null) { State.Messages.Add(MessageId.ParamAlreadySpecified, Chi.Code); RetValue = false; continue; } Ret[Index] = Chi.Children[0]; NamedParameter = true; } else { if (NamedParameter) { State.Messages.Add(MessageId.UnnamedParamAfterNamed, Ch[i].Code); RetValue = false; continue; } if (i >= Ret.Length) { ExtraParams.Add(Ch[i]); } else { Ret[i] = Ch[i]; } } } var LastParam = FuncType.Children[FuncType.Children.Length - 1] as FunctionParameter; if (LastParam != null && (LastParam.ParamFlags & ParameterFlags.ParamArray) != 0) { var First = Ret[Ret.Length - 1]; if (ExtraParams.Count > 0 || NeedToCreateParamArray(First, LastParam)) { ExtraParams.Insert(0, First); var ArrCh = ExtraParams.ToArray(); var Arr = Parent.NewNode(new OpExpressionNode(Operator.Array, ArrCh, Node.Code)); if (Arr == null) { return(PluginResult.Failed); } Ret[Ret.Length - 1] = Arr; } } else if (ExtraParams.Count > 0) { State.Messages.Add(MessageId.ParamCount, Node.Code); return(PluginResult.Failed); } for (var i = 1; i < Ret.Length; i++) { if (Ret[i] == null) { var Param = FuncType.Children[i] as FunctionParameter; if (Param.ConstInitValue != null) { Ret[i] = new ConstExpressionNode(Param.TypeOfSelf, Param.ConstInitValue, Node.Code); if ((Ret[i] = Parent.NewNode(Ret[i])) == null) { RetValue = false; continue; } } else { State.Messages.Add(MessageId.ParamNotSpecified, Node.Code, Param.Name.ToString()); RetValue = false; continue; } } } Node.Children = Ret; return(RetValue ? PluginResult.Succeeded : PluginResult.Failed); }