public FunctionContainer(UserFunctionDefinition definition, ITextProvider text)
        {
            Definition = definition;
            Start      = Math.Max(definition.Start, ((definition.Body != null && definition.Body.OpenCurlyBrace != null) ? definition.Body.OpenCurlyBrace.Start : 0));
            End        = definition.End;

            foreach (var variable in definition.Arguments.Select(x => x.Variable))
            {
                AddVariable(variable, text);
            }
        }
Example #2
0
        public Definition AddDefinition(SyntaxNode node, IdentifierSyntax identifier, DefinitionKind type)
        {
            if (this.testModeLayer > 0)
            {
                return(null);
            }

            if (identifier == null || node == null)
            {
                return(null);
            }

            Scope      definitionScope = new Scope(this.snapshot.CreateTrackingPoint(identifier.Span.GetSpan(this.snapshot).Start), this.scope.Peek().End);
            Definition definition      = null;

            switch (type)
            {
            case DefinitionKind.Function:
                definition = this.lastFunctionDefinition = new UserFunctionDefinition(node as FunctionHeaderSyntax, identifier, string.Empty, definitionScope);
                break;

            case DefinitionKind.Parameter:
                definition = new UserParameterDefinition(node as ParameterSyntax, identifier, string.Empty, definitionScope);
                this.lastFunctionDefinition?.InternalParameters.Add(definition as UserParameterDefinition);
                break;

            case DefinitionKind.Field:
                definition = new UserFieldDefinition(node as StructDeclaratorSyntax, identifier, string.Empty, definitionScope);

                if (this.lastStructDefinition is UserTypeNameDefinition)
                {
                    (this.lastStructDefinition as UserTypeNameDefinition)?.InternalFields.Add(definition as UserFieldDefinition);
                }
                else
                {
                    (this.lastStructDefinition as UserTypeNameDefinition)?.InternalFields.Add(definition as UserFieldDefinition);
                }

                break;

            case DefinitionKind.GlobalVariable:
            case DefinitionKind.LocalVariable:

                switch (node.SyntaxType)
                {
                case SyntaxType.InitPart:
                    definition = new UserVariableDefinition(node as InitPartSyntax, identifier, string.Empty, type, definitionScope);
                    break;

                case SyntaxType.Condition:
                    definition = new UserVariableDefinition(node as ConditionSyntax, identifier, string.Empty, type, definitionScope);
                    break;

                case SyntaxType.StructDeclarator:
                    definition = new UserVariableDefinition(node as StructDeclaratorSyntax, identifier, string.Empty, type, definitionScope);
                    break;
                }

                break;

            case DefinitionKind.Macro:
                definition = new UserMacroDefinition(node as DefinePreprocessorSyntax, identifier, string.Empty, definitionScope);
                break;

            case DefinitionKind.TypeName:
                definition = new UserTypeNameDefinition(identifier, string.Empty, definitionScope);
                this.lastStructDefinition = definition;
                break;

            case DefinitionKind.InterfaceBlock:
                definition = new UserInterfaceBlockDefinition(node as InterfaceBlockSyntax, identifier, string.Empty, definitionScope);
                this.lastStructDefinition = definition;
                break;
            }

            if (this.definitions.ContainsKey(definition.Name.Text))
            {
                this.definitions[definition.Name.Text].Add(definition);
            }
            else
            {
                this.definitions.Add(definition.Name.Text, new List <Definition> {
                    definition
                });
            }

            definition.Overloads = this.definitions[definition.Name.Text];

            return(definition);
        }