Example #1
0
        public static AbstractType[] Resolve(ITypeDeclaration declaration, ResolutionContext ctxt)
        {
            if (declaration is IdentifierDeclaration)
            {
                return(Resolve((IdentifierDeclaration)declaration, ctxt));
            }
            else if (declaration is TemplateInstanceExpression)
            {
                return(ExpressionTypeEvaluation.GetOverloads((TemplateInstanceExpression)declaration, ctxt));
            }

            var t = ResolveSingle(declaration, ctxt);

            return(t == null ? null : new[] { t });
        }
        public AbstractType TryGetDType(IDBacktraceSymbol s)
        {
            if (!s.HasParent)
            {
                TryUpdateStackFrameInfo();

                if (ctxt == null)
                {
                    return(null);
                }

                return(AmbiguousType.Get(ExpressionTypeEvaluation.GetOverloads(new IdentifierExpression(s.Name), ctxt, null)));
            }

            return(null);
        }
        public void Visit(TemplateInstanceExpression tix)
        {
            res.IsTemplateInstanceArguments = true;

            res.MethodIdentifier           = tix;
            ctxt.ContextIndependentOptions = ResolutionOptions.NoTemplateParameterDeduction;
            res.ResolvedTypesOrMethods     = ExpressionTypeEvaluation.GetOverloads(tix, ctxt, null, false);

            if (tix.Arguments != null)
            {
                res.CurrentlyTypedArgumentIndex = tix.Arguments.Length;
            }
            else
            {
                res.CurrentlyTypedArgumentIndex = 0;
            }
        }
Example #4
0
        static void HandleTemplateInstance(TemplateInstanceExpression tix,
                                           ArgumentsResolutionResult res,
                                           IEditorData Editor,
                                           ResolutionContext ctxt,
                                           IBlockNode curBlock,
                                           IEnumerable <AbstractType> resultBases = null)
        {
            res.IsTemplateInstanceArguments = true;

            res.MethodIdentifier       = tix;
            res.ResolvedTypesOrMethods = ExpressionTypeEvaluation.GetOverloads(tix, ctxt, resultBases, false);

            if (tix.Arguments != null)
            {
                res.CurrentlyTypedArgumentIndex = tix.Arguments.Length;
            }
            else
            {
                res.CurrentlyTypedArgumentIndex = 0;
            }
        }
Example #5
0
        public static AbstractType ResolveSingle(ITypeDeclaration declaration, ResolutionContext ctxt)
        {
            if (declaration is IdentifierDeclaration)
            {
                return(ResolveSingle(declaration as IdentifierDeclaration, ctxt));
            }
            else if (declaration is TemplateInstanceExpression)
            {
                var a = ExpressionTypeEvaluation.GetOverloads(declaration as TemplateInstanceExpression, ctxt);
                ctxt.CheckForSingleResult(a, declaration);
                return(a != null && a.Length != 0 ? a[0] : null);
            }

            AbstractType t = null;

            if (declaration is DTokenDeclaration)
            {
                t = Resolve(declaration as DTokenDeclaration);
            }
            else if (declaration is TypeOfDeclaration)
            {
                t = Resolve(declaration as TypeOfDeclaration, ctxt);
            }
            else if (declaration is MemberFunctionAttributeDecl)
            {
                t = Resolve(declaration as MemberFunctionAttributeDecl, ctxt);
            }
            else if (declaration is ArrayDecl)
            {
                t = Resolve(declaration as ArrayDecl, ctxt);
            }
            else if (declaration is PointerDecl)
            {
                t = Resolve(declaration as PointerDecl, ctxt);
            }
            else if (declaration is DelegateDeclaration)
            {
                t = Resolve(declaration as DelegateDeclaration, ctxt);
            }

            //TODO: VarArgDeclaration
            else if (declaration is ITemplateParameterDeclaration)
            {
                var tpd = declaration as ITemplateParameterDeclaration;

                var templateParameter = tpd.TemplateParameter;

                //TODO: Is this correct handling?
                while (templateParameter is TemplateThisParameter)
                {
                    templateParameter = (templateParameter as TemplateThisParameter).FollowParameter;
                }

                if (tpd.TemplateParameter is TemplateValueParameter)
                {
                    // Return a member result -- it's a static variable
                }
                else
                {
                    // Return a type result?
                }
            }

            return(t);
        }
Example #6
0
        public static AbstractType[] ResolveTypeLoosely(IEditorData editor, out NodeResolutionAttempt resolutionAttempt, ResolutionContext ctxt = null)
        {
            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor);
            }

            var o = GetScopedCodeObject(editor);

            var optionBackup = ctxt.CurrentContext.ContextDependentOptions;

            ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;
            resolutionAttempt = NodeResolutionAttempt.Normal;

            AbstractType[] ret;

            if (o is IExpression)
            {
                ret = ExpressionTypeEvaluation.EvaluateTypes((IExpression)o, ctxt);
            }
            else if (o is ITypeDeclaration)
            {
                ret = TypeDeclarationResolver.Resolve((ITypeDeclaration)o, ctxt);
            }
            else if (o is INode)
            {
                ret = new[] { TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt, null, o) }
            }
            ;
            else
            {
                ret = null;
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.NoParameterOrTemplateDeduction;

                if (o is PostfixExpression_MethodCall)
                {
                    o = (o as PostfixExpression_MethodCall).PostfixForeExpression;
                }

                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.NoTemplateParameterDeduction;

                if (o is IdentifierExpression)
                {
                    ret = ExpressionTypeEvaluation.GetOverloads(o as IdentifierExpression, ctxt, deduceParameters: false);
                }
                else if (o is ITypeDeclaration)
                {
                    ret = TypeDeclarationResolver.Resolve(o as ITypeDeclaration, ctxt);
                }
                else if (o is IExpression)
                {
                    ret = ExpressionTypeEvaluation.EvaluateTypes(o as IExpression, ctxt);
                }
            }

            if (ret == null)
            {
                resolutionAttempt = NodeResolutionAttempt.RawSymbolLookup;
                ret = TypeDeclarationResolver.HandleNodeMatches(LookupIdRawly(editor, o as ISyntaxRegion), ctxt, null, o);
            }

            if (ret != null)
            {
                foreach (var r in ret)
                {
                    if (r != null)
                    {
                        r.DeclarationOrExpressionBase = o;
                    }
                }
            }

            ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            return(ret);
        }
Example #7
0
        public static AbstractType ResolveTypeLoosely(IEditorData editor, out NodeResolutionAttempt resolutionAttempt, ResolutionContext ctxt = null)
        {
            var o = GetScopedCodeObject(editor);

            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor, false);
            }

            AbstractType          ret        = null;
            NodeResolutionAttempt resAttempt = NodeResolutionAttempt.Normal;

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
            {
                ctxt.Push(editor);

                var optionBackup = ctxt.CurrentContext.ContextDependentOptions;
                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly | ResolutionOptions.DontResolveAliases;

                if (o is IExpression)
                {
                    ret = ExpressionTypeEvaluation.EvaluateType((IExpression)o, ctxt, false);
                }
                else if (o is ITypeDeclaration)
                {
                    ret = TypeDeclarationResolver.ResolveSingle((ITypeDeclaration)o, ctxt);
                }
                else if (o is INode)
                {
                    ret = TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt, null, o);
                }
                else
                {
                    ret = null;
                }

                if (ret == null)
                {
                    resAttempt = NodeResolutionAttempt.NoParameterOrTemplateDeduction;

                    if (o is PostfixExpression_MethodCall)
                    {
                        o = (o as PostfixExpression_MethodCall).PostfixForeExpression;
                    }

                    ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.NoTemplateParameterDeduction | ResolutionOptions.DontResolveAliases;

                    if (o is IdentifierExpression)
                    {
                        ret = AmbiguousType.Get(ExpressionTypeEvaluation.GetOverloads(o as IdentifierExpression, ctxt, deduceParameters: false), o);
                    }
                    else if (o is ITypeDeclaration)
                    {
                        ret = TypeDeclarationResolver.ResolveSingle(o as ITypeDeclaration, ctxt);
                    }
                    else if (o is IExpression)
                    {
                        ret = ExpressionTypeEvaluation.EvaluateType(o as IExpression, ctxt, false);
                    }
                }

                if (ret == null)
                {
                    resAttempt    = NodeResolutionAttempt.RawSymbolLookup;
                    var overloads = TypeDeclarationResolver.HandleNodeMatches(LookupIdRawly(editor, o as ISyntaxRegion), ctxt, null, o);
                    ret           = AmbiguousType.Get(overloads, o);
                }

                ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            });

            resolutionAttempt = resAttempt;

            if (ret != null)
            {
                ret.DeclarationOrExpressionBase = o;
            }

            return(ret);
        }