Exemplo n.º 1
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret)
        {
            var Result = Code.StartsWith(Operators, Skip, IdCharCheck: new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State  = Container.State;
                var ChildC = Code.TrimmedSubstring(State, Result.String.Length, Options.EnableMessages);
                if (!ChildC.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                var TOptions = Options;
                TOptions.Func = x => x.RealId is Type;

                var Child = Identifiers.Recognize(Container, ChildC, TOptions);
                if (Child == null)
                {
                    return(SimpleRecResult.Failed);
                }

                var RChild = Child.RealId as Type;
                if (RChild == null || (RChild.TypeFlags & TypeFlags.CanBeReference) == 0)
                {
                    if (Options.EnableMessages)
                    {
                        State.Messages.Add(MessageId.UnknownId, Code);
                    }

                    return(SimpleRecResult.Failed);
                }

                ReferenceMode Mode;
                if (Result.Index == 0)
                {
                    Mode = ReferenceMode.Unsafe;
                }
                else if (Result.Index == 1)
                {
                    Mode = ReferenceMode.IdMustBeAssigned;
                }
                else if (Result.Index == 2)
                {
                    Mode = ReferenceMode.IdGetsAssigned;
                }
                else
                {
                    throw new ApplicationException();
                }

                Ret = new ReferenceType(Container, Child, Mode);
                if (Options.Func == null || Options.Func(Ret))
                {
                    return(SimpleRecResult.Succeeded);
                }
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                for (var i = 0; i < Out.Count; i++)
                {
                    if (Out[i] is CallingConventionModifier)
                    {
                        State.Messages.Add(MessageId.NotExpected, ModCode);
                        return(SimpleRecResult.Failed);
                    }
                }

                CallingConvention Conv;
                if (Result.Index == 0)
                {
                    Conv = CallingConvention.StdCall;
                }
                else if (Result.Index == 1)
                {
                    Conv = CallingConvention.CDecl;
                }
                else if (Result.Index == 2)
                {
                    Conv = CallingConvention.ZinniaCall;
                }
                else
                {
                    throw new NotImplementedException();
                }

                Out.Add(new CallingConventionModifier(ModCode, Conv));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 4
0
        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 Scope = new CodeScopeNode(Plugin.Container, Right);
                if (!Scope.ProcessCode())
                {
                    return(ExprRecResult.Failed);
                }

                var List   = Scope.GetContainerId("retvar", x => x is LocalVariable);
                var RetVar = Identifiers.SelectIdentifier(State, List, Code) as LocalVariable;
                if (RetVar == null)
                {
                    return(ExprRecResult.Failed);
                }

                Out = new ScopeExpressionNode(Scope, Code)
                {
                    ReturnVar = RetVar,
                };

                return(ExprRecResult.Succeeded);
            }

            return(ExprRecResult.Unknown);
        }
Exemplo n.º 5
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            if (Code.StartsWith(String, new IdCharCheck(true)))
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, String.Length);

                for (var i = 0; i < Out.Count; i++)
                {
                    if (Out[i] is NoBaseModifier)
                    {
                        State.Messages.Add(MessageId.NotExpected, ModCode);
                        return(SimpleRecResult.Failed);
                    }
                }

                Out.Add(new NoBaseModifier(ModCode));
                Code = Code.Substring(String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 6
0
        public CodeString BetweenOperatos(CodeString Code)
        {
            if (UseMarker)
            {
                var StrLength = Code.Length;
                if (StrLength < 2 || Code[0] != Marker || Code[StrLength - 1] != Marker)
                {
                    return(new CodeString());
                }
            }

            var StartRes = Code.StartsWith(Operators, Skip);
            var EndRes   = Code.EndsWith(Operators, Skip);

            if (StartRes.Index == -1 || EndRes.Index == -1)
            {
                return(new CodeString());
            }
            if (StartRes.Index != EndRes.Index)
            {
                return(new CodeString());
            }

            var Length = StartRes.String.Length;

            if (EndRes.Position < Length)
            {
                return(new CodeString());
            }

            Code = Code.Substring(Length, Code.Length - Length * 2);
            if (Code.Find(Operators, Skip).Index != -1)
            {
                return(new CodeString());
            }
            return(Code);
        }
Exemplo n.º 7
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                ParameterFlags Flags;
                if (Result.Index == 0)
                {
                    Flags = ParameterFlags.ParamArray;
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = 0; i < Out.Count; i++)
                {
                    var FlagMod = Out[i] as ParamFlagModifier;
                    if (FlagMod != null && (FlagMod.Flags & Flags) != 0)
                    {
                        State.Messages.Add(MessageId.NotExpected, ModCode);
                        return(SimpleRecResult.Failed);
                    }
                }

                Out.Add(new ParamFlagModifier(ModCode, Flags));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 8
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret)
        {
            if (Code.StartsWith(Operators, Skip, IdCharCheck: new IdCharCheck(true)).Index == 0)
            {
                var State = Container.State;
                if (Code[Code.Length - 1] != ')')
                {
                    if (Options.EnableMessages)
                    {
                        State.Messages.Add(MessageId.NotExpected, Code);
                    }

                    return(SimpleRecResult.Failed);
                }

                var BracketPos = Code.GetBracketPos(State, true, Options.EnableMessages);
                if (BracketPos == -1)
                {
                    return(SimpleRecResult.Failed);
                }

                var Left = Code.TrimmedSubstring(State, 3, BracketPos - 3, Options.EnableMessages);
                if (!Left.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                CallingConvention CallConv;
                if (!Modifiers.GetCallConv(Container, ref Left, out CallConv))
                {
                    return(SimpleRecResult.Failed);
                }

                if (CallConv == CallingConvention.Unknown)
                {
                    CallConv = Container.DefaultCallConv;
                }

                var TOptions = Options;
                TOptions.Func = x => x.RealId is Type;

                var RetType   = Identifiers.Recognize(Container, Left, TOptions);
                var StrParams = Code.Substring(BracketPos + 1, Code.Length - BracketPos - 2).Trim();

                var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue;
                if (Options.EnableMessages)
                {
                    Flags |= VarDeclarationListFlags.EnableMessages;
                }
                var DeclList = VarDeclarationList.Create(Container, StrParams, null, Flags);
                if (DeclList == null || RetType == null)
                {
                    return(SimpleRecResult.Failed);
                }

                if (!(RetType.RealId is Type))
                {
                    State.Messages.Add(MessageId.UnknownType, Left);
                    return(SimpleRecResult.Failed);
                }

                var Params = DeclList.ToFuncParams(Container.GetPlugin());
                if (Params == null || Params.Contains(null))
                {
                    return(SimpleRecResult.Failed);
                }

                Ret = new TypeOfFunction(Container, CallConv, RetType, Params);
                if (Options.Func == null || Options.Func(Ret))
                {
                    return(SimpleRecResult.Succeeded);
                }
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 9
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                IdentifierFlags Flags;
                if (Result.Index == 0)
                {
                    Flags = IdentifierFlags.Virtual;
                }
                else if (Result.Index == 1)
                {
                    Flags = IdentifierFlags.Override;
                }
                else if (Result.Index == 2)
                {
                    Flags = IdentifierFlags.Abstract;
                }
                else if (Result.Index == 3)
                {
                    Flags = IdentifierFlags.Sealed;
                }
                else if (Result.Index == 4)
                {
                    Flags = IdentifierFlags.Static;
                }
                else if (Result.Index == 5)
                {
                    Flags = IdentifierFlags.Extern;
                }
                else if (Result.Index == 6)
                {
                    Flags = IdentifierFlags.ReadOnly;
                }
                else if (Result.Index == 7)
                {
                    Flags = IdentifierFlags.HideBaseId;
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = 0; i < Out.Count; i++)
                {
                    var FlagMod = Out[i] as FlagModifier;
                    if (FlagMod != null && (FlagMod.Flags & Flags) != 0)
                    {
                        State.Messages.Add(MessageId.NotExpected, ModCode);
                        return(SimpleRecResult.Failed);
                    }
                }

                Out.Add(new FlagModifier(ModCode, Flags));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 10
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                IdentifierAccess Access;
                if (Result.Index == 0)
                {
                    Access = IdentifierAccess.Public;
                }
                else if (Result.Index == 1)
                {
                    Access = IdentifierAccess.Protected;
                }
                else if (Result.Index == 2)
                {
                    Access = IdentifierAccess.Private;
                }
                else if (Result.Index == 3)
                {
                    Access = IdentifierAccess.Internal;
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = 0; i < Out.Count; i++)
                {
                    var AccessMod = Out[i] as AccessModifier;
                    if (AccessMod != null)
                    {
                        var Allowed = false;
                        if (Access == IdentifierAccess.Internal)
                        {
                            Allowed = AccessMod.Access == IdentifierAccess.Protected;
                        }
                        else if (Access == IdentifierAccess.Protected)
                        {
                            Allowed = AccessMod.Access == IdentifierAccess.Internal;
                        }

                        if (!Allowed)
                        {
                            State.Messages.Add(MessageId.NotExpected, ModCode);
                            return(SimpleRecResult.Failed);
                        }
                    }
                }

                Out.Add(new AccessModifier(ModCode, Access));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Exemplo n.º 11
0
        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);
        }