Example #1
0
        public static ScopeResolutions Get(ExpressionNode Node)
        {
            var Ret = new ScopeResolutions();

            Ret.Code = Node.Code;

            var List  = new List <ExpressionNode>();
            var First = true;

            while (true)
            {
                var Op = Expressions.GetOperator(Node);
                var Ch = Node.Children;

                if (Op != Operator.ScopeResolution)
                {
                    if (Op != Operator.Member || !(Ch[0].Type.RealId is Type))
                    {
                        Ret.Scopes   = List.ToArray();
                        Ret.MemberOf = Node;
                        Ret.Static   = true;
                        return(Ret);
                    }

                    if (!First)
                    {
                        List.Insert(0, Ch[1]);
                    }
                    else
                    {
                        Ret.Member = Ch[1];
                    }

                    Ret.Scopes   = List.ToArray();
                    Ret.MemberOf = Ch[0];
                    return(Ret);
                }
                else
                {
                    if (!First)
                    {
                        List.Insert(0, Ch[1]);
                    }
                    else
                    {
                        Ret.Member = Ch[1];
                    }
                    First = false;
                }

                Node = Ch[0];
            }
        }
Example #2
0
        PluginResult ForceContinue_ScopeResolution(ref ExpressionNode Node,
                                                   OverloadSelectionData OverloadData = new OverloadSelectionData())
        {
            var Ch         = Node.Children;
            var ScopeReses = ScopeResolutions.Get(Node);

            if (ScopeReses.Static)
            {
                if (Ch[0] is StrExpressionNode)
                {
                    var Options = GetIdOptions.DefaultForType;
                    Options.OverloadData = OverloadData;

                    var Id = Container.RecognizeIdentifier(Ch[0].Code, Options);
                    if (Id == null)
                    {
                        return(PluginResult.Failed);
                    }

                    Ch[0] = Parent.NewNode(new IdExpressionNode(Id, Ch[0].Code));
                    if (Ch[0] == null)
                    {
                        return(PluginResult.Failed);
                    }
                }

                Ch[0] = ResolveNode(Ch[0]);
                if (Ch[0] == null)
                {
                    return(PluginResult.Failed);
                }

                if (!(Ch[0].Type.RealId is TypeOfType))
                {
                    State.Messages.Add(MessageId.MustBeType, Ch[0].Code);
                    return(PluginResult.Failed);
                }

                var FScope = Container.FunctionScope;
                if (FScope != null && FScope.SelfVariable != null)
                {
                    var FuncContainer   = FScope.Function.Container;
                    var StructuredScope = FuncContainer.RealContainer as StructuredScope;
                    var Structure       = StructuredScope.StructuredType;
                    var Ch0Id           = Expressions.GetIdentifier(Ch[0]);

                    if (Structure.IsEquivalent(Ch0Id) || Structure.IsSubstructureOf(Ch0Id))
                    {
                        if (!ScopeReses.MakeMemberOf(Parent, FScope.SelfVariable))
                        {
                            return(PluginResult.Failed);
                        }
                    }
                }

                if (ScopeReses.Static)
                {
                    return(ForceContinue_MemberNode(ref Node, OverloadData));
                }
            }

            Node = ScopeReses.GetNode(Parent);
            if (Node == null || ResolveNode(ref Node) == PluginResult.Failed)
            {
                return(PluginResult.Failed);
            }

            return(PluginResult.Ready);
        }