Пример #1
0
            private List <FunctionDeclaration> GetDeclarationCandidates(string identifier)
            {
                var declarationCandidates = new List <FunctionDeclaration>();

                foreach (var functionDeclaration in this.functions[identifier].Peek())
                {
                    if (!declarationCandidates.Any(
                            addedFun =>
                            FunctionDeclaration.ParametersTypesEquals(addedFun, functionDeclaration)))
                    {
                        declarationCandidates.Add(functionDeclaration);
                    }
                }

                return(declarationCandidates);
            }
Пример #2
0
            private void ProcessFunctionDeclaration(FunctionDeclaration fun, IDiagnostics diagnostics)
            {
                var id = fun.Identifier;

                fun.ReturnType = this.ResolveDataType(fun.ReturnType, diagnostics);

                // It is important to do it here, so FunctionDeclaration.ParametersTypesEquals below works correctly
                for (int i = 0; i < fun.Parameters.Count; i++)
                {
                    fun.Parameters[i].VariableType = this.ResolveDataType(fun.Parameters[i].VariableType, diagnostics);
                }

                if (this.functionBlocks.Peek().ContainsKey(id))
                {
                    foreach (var f in this.functionBlocks.Peek()[id])
                    {
                        if (FunctionDeclaration.ParametersTypesEquals(f, fun))
                        {
                            var diagnostic = new Diagnostic(
                                DiagnosticStatus.Error,
                                MultipleDeclarationsDiagnostic,
                                $"Multiple declarations of function name {id}",
                                new List <Range> {
                                fun.InputRange
                            });
                            diagnostics.Add(diagnostic);
                            this.exceptions.Add(
                                new NameResolverInternalException($"Multiple declarations of name {id}"));
                        }
                    }
                }

                if (!this.functions.ContainsKey(id))
                {
                    this.functions.Add(id, new Stack <List <FunctionDeclaration> >());
                }

                this.AddToPeek(id, fun);
                this.functionBlocks.Push(new Dictionary <string, List <FunctionDeclaration> >());
                this.variableBlocks.Push(new HashSet <string>());
                this.structBlocks.Push(new HashSet <string>());
            }