Exemple #1
0
        private MethodDefinitionSymbol BindMethodDefinition(FunctionDefinitionSyntax declaration, TypeSymbol parentType)
        {
            var returnType = _symbolSet.ResolveType(declaration.ReturnType, parentType, null);

            Func <MethodSymbol, IEnumerable <ParameterSymbol> > lazyParameterSymbols = fd =>
            {
                var parameterSymbols = new List <ParameterSymbol>();
                foreach (var parameterSyntax in declaration.ParameterList.Parameters)
                {
                    var parameterValueType = _symbolSet.ResolveType(parameterSyntax.Type, null, null);
                    var parameterDirection = SyntaxFacts.GetParameterDirection(parameterSyntax.Modifiers);

                    parameterSymbols.Add(new SourceParameterSymbol(
                                             parameterSyntax,
                                             fd,
                                             parameterValueType,
                                             parameterDirection));
                }
                return(parameterSymbols);
            };

            var symbol = new SourceMethodDefinitionSymbol(declaration, parentType, returnType, lazyParameterSymbols);

            _bindingResult.AddSymbol(declaration, symbol);

            return(symbol);
        }
        private FunctionSignature BindFunctionDefinitionCore(FunctionDefinitionSyntax syntax)
        {
            //check for duplicate type arguments
            var typeArgumentsGroups = syntax.TypeParameters.GetDuplicates(x => x.FullName);

            foreach (var typeArgumentsGroup in typeArgumentsGroups)
            {
                errors.Add(new MultipleTypeParametersWithTheSameName(typeArgumentsGroup.Select(x => new Location(x.File, x.Line)), typeArgumentsGroup.First().FullName));
            }

            //check for use of nonTypeParameters in constraints
            var invalidTypesUsedInConstraints = syntax.Constraints.SelectMany(x => new[] { x.constrained, x.constrain }).Where(x => !(x is TypeParameterSyntax));

            foreach (var invalid in invalidTypesUsedInConstraints)
            {
                errors.Add(new UseOfNonTypeParameterInConstraint(file: invalid.File,
                                                                 line: invalid.Line,
                                                                 name: invalid.FullName));
            }

            //check for 0 arguments member functions
            if (syntax.IsMember && syntax.Arity == 0)
            {
                errors.Add(new MemberFunctionWithoutArguments(syntax.Location, syntax.Name));
            }


            var returnType = BindType(syntax.ReturnType);

            return(new FunctionSignature(originalDefinitionSyntax: syntax,
                                         typeArguments: syntax.TypeParameters.Distinct().Select(BindType).ToImmutableArray(),
                                         parameters: syntax.Parameters.Select(x => BindType(x.Type !)).ToImmutableArray(),
                                         returnType: returnType));
        }
 internal SourceFunctionSymbol(FunctionDefinitionSyntax syntax, Symbol parent, TypeSymbol returnType, Func <InvocableSymbol, IEnumerable <ParameterSymbol> > lazyParameters = null)
     : base(syntax.Name.GetUnqualifiedName().Name.Text, string.Empty, parent, returnType, lazyParameters)
 {
     DeclarationSyntaxes = new List <FunctionDeclarationSyntax>();
     DefinitionSyntax    = syntax;
     SourceTree          = syntax.SyntaxTree;
 }
        public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
        {
            var symbol = _semanticModel.GetDeclaredSymbol(node);
            if (symbol != null)
                CreateTag(node.Name.GetUnqualifiedName().Name, symbol.Parent != null && symbol.Parent.Kind == SymbolKind.Class
                    ? _classificationService.MethodIdentifier
                    : _classificationService.FunctionIdentifier);

            base.VisitFunctionDefinition(node);
        }
 public FunctionSignature(FunctionDefinitionSyntax originalDefinitionSyntax,
                          ImmutableArray <IType> typeArguments,
                          ImmutableArray <IType> parameters,
                          IType returnType) : base(originalDefinitionSyntax.Name,
                                                   parameters,
                                                   typeArguments,
                                                   returnType)
 {
     OriginalDefinition = originalDefinitionSyntax;
 }
Exemple #6
0
 public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     CreateTag(
         BlockSpanType.Member,
         node.ParameterList.CloseParenToken,
         node.Body.CloseBraceToken,
         node.ReturnType.GetFirstTokenInDescendants(),
         node.ParameterList.CloseParenToken,
         true);
     base.VisitFunctionDefinition(node);
 }
        public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
        {
            var symbol = _semanticModel.GetDeclaredSymbol(node);

            if (symbol != null)
            {
                CreateTag(node.Name.GetUnqualifiedName().Name, symbol.Parent != null && (symbol.Parent.Kind == SymbolKind.Class || symbol.Parent.Kind == SymbolKind.Struct)
                    ? HlslClassificationTypeNames.MethodIdentifier
                    : HlslClassificationTypeNames.FunctionIdentifier);
            }

            base.VisitFunctionDefinition(node);
        }
 public override IEnumerable <EditorNavigationTarget> VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     yield return(CreateTarget(node.Name.GetUnqualifiedName().Name, node.GetDescription(false, true), node.GetTextSpanSafe(), Glyph.Function));
 }
Exemple #9
0
 public FunctionSymbol GetDeclaredSymbol(FunctionDefinitionSyntax syntax)
 {
     var result = _bindingResult.GetBoundNode(syntax) as BoundFunction;
     return result?.FunctionSymbol;
 }
        public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
        {
            CreateTag(node.Name.GetUnqualifiedName().Name, _classificationService.FunctionIdentifier);

            base.VisitFunctionDefinition(node);
        }
 public virtual void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     DefaultVisit(node);
 }
Exemple #12
0
 public string GetNewNameFor(FunctionDefinitionSyntax definition)
 {
     return(definition.IsExtern
                                ? definition.Name
                                : NewCallableNames[FunctionSignaturesBindings[definition]]);
 }
Exemple #13
0
 public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     CreateTag(node.ParameterList.CloseParenToken, node.Body.CloseBraceToken);
 }
 public FunctionSignature GetBindingFor(FunctionDefinitionSyntax syntax) => FunctionSignaturesBindings[syntax];
 public bool AlreadyBound(FunctionDefinitionSyntax syntax) => FunctionSignaturesBindings.ContainsKey(syntax);
Exemple #16
0
        private void UpdateRegions(VSSnapshot snapshot)
        {
            SyntaxTree tree = this.source.Tree;

            if (tree == null || snapshot == null)
            {
                return;
            }

            List <Region> newRegions = new List <Region>();

            foreach (SyntaxNode node in tree.Root.Descendants)
            {
                switch (node.SyntaxType)
                {
                case SyntaxType.FunctionDefinition:
                    FunctionDefinitionSyntax functionDefinition = node as FunctionDefinitionSyntax;

                    if (functionDefinition.FunctionHeader?.RightParentheses != null && functionDefinition.Block?.RightBrace != null)
                    {
                        this.AddRegion(newRegions, snapshot, tree, 1, functionDefinition.FunctionHeader.RightParentheses, functionDefinition.Block.RightBrace);
                    }

                    break;

                case SyntaxType.InterfaceBlock:
                    InterfaceBlockSyntax interfaceBlock = node as InterfaceBlockSyntax;

                    if (interfaceBlock.Identifier != null && interfaceBlock.RightBrace != null)
                    {
                        this.AddRegion(newRegions, snapshot, tree, 1, interfaceBlock.Identifier, interfaceBlock.RightBrace);
                    }

                    break;

                case SyntaxType.StructSpecifier:
                    StructSpecifierSyntax structSpecifier = node as StructSpecifierSyntax;

                    if (structSpecifier.RightBrace != null)
                    {
                        if (structSpecifier.TypeName != null)
                        {
                            this.AddRegion(newRegions, snapshot, tree, 0, structSpecifier.TypeName, structSpecifier.RightBrace);
                        }
                        else if (structSpecifier.StructKeyword != null)
                        {
                            this.AddRegion(newRegions, snapshot, tree, 1, structSpecifier.StructKeyword, structSpecifier.RightBrace);
                        }
                    }

                    break;

                case SyntaxType.IfDefinedPreprocessor:
                    IfDefinedPreprocessorSyntax ifDefined = node as IfDefinedPreprocessorSyntax;

                    if (ifDefined.EndIfKeyword != null)
                    {
                        this.AddRegion(newRegions, snapshot, tree, 1, ifDefined.IfDefinedKeyword, ifDefined.EndIfKeyword);
                    }

                    break;

                case SyntaxType.IfPreprocessor:
                    IfPreprocessorSyntax ifPreprocessor = node as IfPreprocessorSyntax;

                    if (ifPreprocessor.EndIfKeyword != null)
                    {
                        this.AddRegion(newRegions, snapshot, tree, 1, ifPreprocessor.IfKeyword, ifPreprocessor.EndIfKeyword);
                    }

                    break;

                case SyntaxType.IfNotDefinedPreprocessor:
                    IfNotDefinedPreprocessorSyntax ifNotDefined = node as IfNotDefinedPreprocessorSyntax;

                    if (ifNotDefined.EndIfKeyword != null)
                    {
                        this.AddRegion(newRegions, snapshot, tree, 1, ifNotDefined.IfNotDefinedKeyword, ifNotDefined.EndIfKeyword);
                    }

                    break;
                }
            }

            foreach (IfPreprocessor preprocessor in this.source.Settings.Preprocessors)
            {
                if (preprocessor.EndIf != null)
                {
                    this.AddRegion(newRegions, snapshot, tree, 1, preprocessor.Keyword, preprocessor.EndIf.EndIfKeyword);
                }

                for (int i = 0; i < preprocessor.ElsePreprocessors.Count; i++)
                {
                    SyntaxToken next;

                    if (i < preprocessor.ElsePreprocessors.Count - 1)
                    {
                        ElseIfPreprocessorSyntax elseIf = preprocessor.ElsePreprocessors[i].Keyword.Parent as ElseIfPreprocessorSyntax;

                        if (elseIf != null)
                        {
                            next = elseIf.ExcludedCode.Code.Last() as SyntaxToken;
                        }
                        else
                        {
                            next = preprocessor.ElsePreprocessors[i].Keyword;
                        }
                    }
                    else
                    {
                        next = preprocessor.EndIf.EndIfKeyword;
                    }

                    this.AddRegion(newRegions, snapshot, tree, 1, preprocessor.ElsePreprocessors[i].Keyword, next);
                }
            }

            lock (this.lockObject)
            {
                this.regions = newRegions;
            }

            this.TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot.TextSnapshot, snapshot.Span.ToVSSpan())));
        }
Exemple #17
0
 //public IEnumerable<Symbol> LookupSymbols(int position)
 //{
 //    var node = FindClosestNodeWithBinder(_bindingResult.Root, position);
 //    var binder = node == null ? null : _bindingResult.GetBinder(node);
 //    return binder == null
 //        ? Enumerable.Empty<Symbol>()
 //        : LookupSymbols(binder);
 //}
 //private static IEnumerable<Symbol> LookupSymbols(Binder binder)
 //{
 //    // NOTE: We want to only show the *available* symbols. That means, we need to
 //    //       hide symbols from the parent binder that have same name as the ones
 //    //       from a nested binder.
 //    //
 //    //       We do this by simply recording which names we've already seen.
 //    //       Please note that we *do* want to see duplicate names within the
 //    //       *same* binder.
 //    var allNames = new HashSet<string>();
 //    while (binder != null)
 //    {
 //        var localNames = new HashSet<string>();
 //        var localSymbols = binder.LocalSymbols
 //            .Where(s => !string.IsNullOrEmpty(s.Name));
 //        foreach (var symbol in localSymbols)
 //        {
 //            if (!allNames.Contains(symbol.Name))
 //            {
 //                localNames.Add(symbol.Name);
 //                yield return symbol;
 //            }
 //        }
 //        allNames.UnionWith(localNames);
 //        binder = binder.Parent;
 //    }
 //}
 //private SyntaxNode FindClosestNodeWithBinder(SyntaxNode root, int position)
 //{
 //    var token = root.FindTokenContext(position);
 //    return (from n in token.Parent.AncestorsAndSelf()
 //            let bc = _bindingResult.GetBinder(n)
 //            where bc != null
 //            select n).FirstOrDefault();
 //}
 //protected abstract Binder GetEnclosingBinder(TextLocation location);
 //private TextSpan CheckAndAdjustPosition(int position, out SyntaxToken token)
 //{
 //    token = Root.FindToken(position);
 //    return token.Span;
 //}
 public Symbol GetDeclaredSymbol(FunctionDefinitionSyntax syntax)
 {
     return _bindingResult.GetSymbol(syntax);
 }
Exemple #18
0
        public FunctionSymbol GetDeclaredSymbol(FunctionDefinitionSyntax syntax)
        {
            var result = _bindingResult.GetBoundNode(syntax) as BoundFunction;

            return(result?.FunctionSymbol);
        }
Exemple #19
0
 public static string GetDescription(this FunctionDefinitionSyntax syntax, bool includeReturnType, bool includeParameterNames)
 {
     return(GetFunctionDescription(syntax.ReturnType, syntax.Name.GetUnqualifiedName().Name, syntax.ParameterList, includeReturnType, includeParameterNames));
 }
Exemple #20
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (session == null || completionSets == null)
            {
                return;
            }

            List <Completion> completions = new List <Completion>(keywords);

            SyntaxTree tree         = this.source.Tree;
            Snapshot   snapshot     = this.source.CurrentSnapshot;
            int        triggerPoint = session.GetTriggerPoint(this.textBuffer).GetPosition(snapshot);

            if (tree != null)
            {
                List <Definition> definitions = new List <Definition>();

                foreach (string key in tree.Definitions.Keys)
                {
                    Definition definition = tree.Definitions[key].Find(def => def.Scope.Contains(snapshot, triggerPoint));

                    if (definition != null)
                    {
                        definitions.Add(definition);
                    }
                }

                SyntaxNode node            = tree.GetNodeFromPosition(snapshot, triggerPoint);
                Definition currentFunction = null;

                foreach (SyntaxNode ancestor in node.Ancestors)
                {
                    if (ancestor.SyntaxType == SyntaxType.FunctionDefinition)
                    {
                        FunctionDefinitionSyntax function = ancestor as FunctionDefinitionSyntax;

                        currentFunction = function.FunctionHeader.Identifier.Definition;
                        break;
                    }
                }

                for (int i = 0; i < definitions.Count; i++)
                {
                    if (definitions[i].Name != currentFunction?.Name)
                    {
                        int overloads = definitions[i].Overloads.Count;

                        if (BuiltInData.Instance.Definitions.ContainsKey(definitions[i].Name.Text))
                        {
                            overloads += BuiltInData.Instance.Definitions[definitions[i].Name.Text].Count;
                        }

                        completions.Add(new GLSLCompletion(definitions[i].ToTextBlock(this.formatMap, this.provider.TypeRegistry, definitions[i].Overloads.Count - 1), definitions[i], definitions[i].GetImageSource(this.provider.GlyphService)));
                    }
                }
            }

            for (int i = 0; i < builtIn.Count; i++)
            {
                if (!completions.Contains(completion => completion.DisplayText == builtIn[this.source.Type][i].DisplayText))
                {
                    completions.Add(builtIn[this.source.Type][i]);
                }
            }

            ITrackingSpan span = this.FindTokenSpanAtPosition(session);

            completions.Sort((first, second) => string.Compare(first.DisplayText, second.DisplayText, System.StringComparison.Ordinal));

            completionSets.Add(new CompletionSet("GLSL", "GLSL", span, completions, null));
        }
 internal SourceFunctionSymbol(FunctionDefinitionSyntax syntax, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null)
     : base(syntax.Name.GetName(), string.Empty, parent, returnType, lazyParameters)
 {
     DeclarationSyntaxes = new List<FunctionDeclarationSyntax>();
     DefinitionSyntax = syntax;
 }
 public SourceFunctionDefinitionSymbol(FunctionDefinitionSyntax syntax, TypeSymbol returnType, Func<FunctionSymbol, IEnumerable<ParameterSymbol>> lazyParameters)
     : base(syntax.Name.GetName(), string.Empty, returnType, lazyParameters)
 {
     Syntax = syntax;
 }
        private BoundNode BindFunctionDefinition(FunctionDefinitionSyntax declaration, Symbol parent)
        {
            BindAttributes(declaration.Attributes);

            var boundReturnType = Bind(declaration.ReturnType, x => BindType(x, parent));

            var isQualifiedName = false;

            ContainerSymbol containerSymbol;
            Symbol          functionOwner;

            switch (declaration.Name.Kind)
            {
            case SyntaxKind.IdentifierDeclarationName:
                containerSymbol = null;
                functionOwner   = parent;
                break;

            case SyntaxKind.QualifiedDeclarationName:
                containerSymbol = LookupContainer(((QualifiedDeclarationNameSyntax)declaration.Name).Left);
                if (containerSymbol == null)
                {
                    return(new BoundErrorNode());
                }
                isQualifiedName = true;
                functionOwner   = containerSymbol;
                break;

            default:
                throw new InvalidOperationException();
            }

            var containerBinder = containerSymbol?.Binder ?? this;

            var symbolTable = containerBinder.LocalSymbols;

            var functionSymbol = symbolTable
                                 .SelectMany(x => x.Value)
                                 .OfType <SourceFunctionSymbol>()
                                 .FirstOrDefault(x => SyntaxFacts.HaveMatchingSignatures(
                                                     x.DefinitionSyntax as FunctionSyntax ?? x.DeclarationSyntaxes[0],
                                                     declaration));

            if (functionSymbol != null)
            {
                if (functionSymbol.DefinitionSyntax != null)
                {
                    Diagnostics.ReportSymbolRedefined(declaration.Name.SourceRange, functionSymbol);
                }
                else
                {
                    functionSymbol.DefinitionSyntax = declaration;
                }
            }
            else
            {
                if (isQualifiedName)
                {
                    Diagnostics.ReportUndeclaredFunctionInNamespaceOrClass((QualifiedDeclarationNameSyntax)declaration.Name);
                }
                functionSymbol = new SourceFunctionSymbol(declaration, parent, boundReturnType.TypeSymbol);
                containerBinder.AddSymbol(functionSymbol, declaration.Name.SourceRange, true);
            }

            if (declaration.Semantic != null)
            {
                Bind(declaration.Semantic, BindVariableQualifier);
            }

            var functionBinder = (functionOwner != null && (functionOwner.Kind == SymbolKind.Class || functionOwner.Kind == SymbolKind.Struct))
                ? new StructMethodBinder(_sharedBinderState, this, (StructSymbol)functionOwner, functionSymbol)
                : new FunctionBinder(_sharedBinderState, this, functionSymbol);

            if (isQualifiedName)
            {
                functionBinder = new ContainedFunctionBinder(_sharedBinderState, functionBinder, containerSymbol.Binder, functionSymbol);
            }

            var boundParameters = BindParameters(declaration.ParameterList, functionBinder, functionSymbol);
            var boundBody       = functionBinder.Bind(declaration.Body, x => functionBinder.BindBlock(x, functionSymbol));

            if (boundReturnType.Type != IntrinsicTypes.Void && !ContainsReturnStatement(boundBody))
            {
                Diagnostics.Report(declaration.Name.SourceRange, DiagnosticId.ReturnExpected, functionSymbol.Name);
            }

            return(new BoundFunctionDefinition(functionSymbol, boundReturnType, boundParameters.ToImmutableArray(), boundBody));
        }
Exemple #24
0
 public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     ProcessItem(node.Name.GetUnqualifiedName().Name, node.GetDescription(false, false), node.GetTextSpanSafe(), NavigateToItemKind.Method, node.Parent, Glyph.Function);
 }
Exemple #25
0
        public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
        {
            CreateTag(node.Name.GetUnqualifiedName().Name, _classificationService.FunctionIdentifier);

            base.VisitFunctionDefinition(node);
        }
Exemple #26
0
        //public IEnumerable<Symbol> LookupSymbols(int position)
        //{
        //    var node = FindClosestNodeWithBinder(_bindingResult.Root, position);
        //    var binder = node == null ? null : _bindingResult.GetBinder(node);
        //    return binder == null
        //        ? Enumerable.Empty<Symbol>()
        //        : LookupSymbols(binder);
        //}

        //private static IEnumerable<Symbol> LookupSymbols(Binder binder)
        //{
        //    // NOTE: We want to only show the *available* symbols. That means, we need to
        //    //       hide symbols from the parent binder that have same name as the ones
        //    //       from a nested binder.
        //    //
        //    //       We do this by simply recording which names we've already seen.
        //    //       Please note that we *do* want to see duplicate names within the
        //    //       *same* binder.

        //    var allNames = new HashSet<string>();

        //    while (binder != null)
        //    {
        //        var localNames = new HashSet<string>();
        //        var localSymbols = binder.LocalSymbols
        //            .Where(s => !string.IsNullOrEmpty(s.Name));

        //        foreach (var symbol in localSymbols)
        //        {
        //            if (!allNames.Contains(symbol.Name))
        //            {
        //                localNames.Add(symbol.Name);
        //                yield return symbol;
        //            }
        //        }

        //        allNames.UnionWith(localNames);
        //        binder = binder.Parent;
        //    }
        //}

        //private SyntaxNode FindClosestNodeWithBinder(SyntaxNode root, int position)
        //{
        //    var token = root.FindTokenContext(position);
        //    return (from n in token.Parent.AncestorsAndSelf()
        //            let bc = _bindingResult.GetBinder(n)
        //            where bc != null
        //            select n).FirstOrDefault();
        //}

        //protected abstract Binder GetEnclosingBinder(TextLocation location);

        //private TextSpan CheckAndAdjustPosition(int position, out SyntaxToken token)
        //{
        //    token = Root.FindToken(position);
        //    return token.Span;
        //}

        public Symbol GetDeclaredSymbol(FunctionDefinitionSyntax syntax)
        {
            return(_bindingResult.GetSymbol(syntax));
        }
 public FunctionSignature MakeBindingFor(FunctionDefinitionSyntax syntax, FunctionSignature value)
 {
     FunctionSignaturesBindings[syntax] = value;
     return(value);
 }
 public virtual void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     DefaultVisit(node);
 }
Exemple #29
0
 public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     CreateTag(node.ParameterList.CloseParenToken, node.Body.CloseBraceToken);
 }
Exemple #30
0
 public SourceFunctionDefinitionSymbol(FunctionDefinitionSyntax syntax, TypeSymbol returnType, Func <FunctionSymbol, IEnumerable <ParameterSymbol> > lazyParameters)
     : base(syntax.Name.GetName(), string.Empty, returnType, lazyParameters)
 {
     Syntax = syntax;
 }
        private BoundNode BindFunctionDefinition(FunctionDefinitionSyntax declaration, Symbol parent)
        {
            BindAttributes(declaration.Attributes);

            var boundReturnType = Bind(declaration.ReturnType, x => BindType(x, parent));

            var isQualifiedName = false;

            ContainerSymbol containerSymbol;
            Symbol functionOwner;
            switch (declaration.Name.Kind)
            {
                case SyntaxKind.IdentifierDeclarationName:
                    containerSymbol = null;
                    functionOwner = parent;
                    break;
                case SyntaxKind.QualifiedDeclarationName:
                    containerSymbol = LookupContainer(((QualifiedDeclarationNameSyntax) declaration.Name).Left);
                    if (containerSymbol == null)
                        return new BoundErrorNode();
                    isQualifiedName = true;
                    functionOwner = containerSymbol;
                    break;
                default:
                    throw new InvalidOperationException();
            }

            var containerBinder = containerSymbol?.Binder ?? this;

            var symbolTable = containerBinder.LocalSymbols;

            var functionSymbol = symbolTable
                .SelectMany(x => x.Value)
                .OfType<SourceFunctionSymbol>()
                .FirstOrDefault(x => SyntaxFacts.HaveMatchingSignatures(
                    x.DefinitionSyntax as FunctionSyntax ?? x.DeclarationSyntaxes[0],
                    declaration));

            if (functionSymbol != null)
            {
                if (functionSymbol.DefinitionSyntax != null)
                    Diagnostics.ReportSymbolRedefined(declaration.Name.GetTextSpanSafe(), functionSymbol);
                else
                    functionSymbol.DefinitionSyntax = declaration;
            }
            else
            {
                if (isQualifiedName)
                    Diagnostics.ReportUndeclaredFunctionInNamespaceOrClass((QualifiedDeclarationNameSyntax) declaration.Name);
                functionSymbol = new SourceFunctionSymbol(declaration, parent, boundReturnType.TypeSymbol);
                containerBinder.AddSymbol(functionSymbol, declaration.Name.GetTextSpanSafe(), true);
            }

            if (declaration.Semantic != null)
                Bind(declaration.Semantic, BindVariableQualifier);

            var functionBinder = (functionOwner != null && functionOwner.Kind == SymbolKind.Class)
                ? new ClassMethodBinder(_sharedBinderState, this, (ClassSymbol) functionOwner)
                : new Binder(_sharedBinderState, this);

            if (isQualifiedName)
                functionBinder = new ContainedFunctionBinder(_sharedBinderState, functionBinder, containerSymbol.Binder);

            var boundParameters = BindParameters(declaration.ParameterList, functionBinder, functionSymbol);
            var boundBody = functionBinder.Bind(declaration.Body, x => functionBinder.BindBlock(x, functionSymbol));

            return new BoundFunctionDefinition(functionSymbol, boundReturnType, boundParameters.ToImmutableArray(), boundBody);
        }
        private MethodDefinitionSymbol BindMethodDefinition(FunctionDefinitionSyntax declaration, TypeSymbol parentType)
        {
            var returnType = _symbolSet.ResolveType(declaration.ReturnType, parentType, null);

            Func<MethodSymbol, IEnumerable<ParameterSymbol>> lazyParameterSymbols = fd =>
            {
                var parameterSymbols = new List<ParameterSymbol>();
                foreach (var parameterSyntax in declaration.ParameterList.Parameters)
                {
                    var parameterValueType = _symbolSet.ResolveType(parameterSyntax.Type, null, null);
                    var parameterDirection = SyntaxFacts.GetParameterDirection(parameterSyntax.Modifiers);

                    parameterSymbols.Add(new SourceParameterSymbol(
                        parameterSyntax,
                        fd,
                        parameterValueType,
                        parameterDirection));
                }
                return parameterSymbols;
            };

            var symbol = new SourceMethodDefinitionSymbol(declaration, parentType, returnType, lazyParameterSymbols);
            _bindingResult.AddSymbol(declaration, symbol);

            return symbol;
        }
 public override void VisitFunctionDefinition(FunctionDefinitionSyntax node)
 {
     ProcessItem(node.Name.GetUnqualifiedName().Name, node.GetDescription(false, false), node.GetTextSpanSafe(), NavigateToItemKind.Method, node.Parent, Glyph.Function);
 }
 private FunctionSignature BindFunctionDefinition(FunctionDefinitionSyntax syntax)
 {
     return(symbols.AlreadyBound(syntax)
                                ? symbols.GetBindingFor(syntax)
                                : symbols.MakeBindingFor(syntax, BindFunctionDefinitionCore(syntax)));
 }