public IEnumerable <Symbol> GetSymbols() { var submission = this; var seenSymbolNames = new HashSet <string>(); var builtinFunctions = BuiltinFunctions.GetAll(); while (submission != null) { foreach (var function in submission.Functions) { if (seenSymbolNames.Add(function.Name)) { yield return(function); } } foreach (var variable in submission.Variables) { if (seenSymbolNames.Add(variable.Name)) { yield return(variable); } } foreach (var builtin in builtinFunctions) { if (seenSymbolNames.Add(builtin.Name)) { yield return(builtin); } } submission = submission.Previous; } }
public IEnumerable <Symbol> GetSymbols() { var submission = this; var seenSymbolNames = new HashSet <string>(); var builtinFunctions = BuiltinFunctions.GetAll().ToList(); while (submission != null) { foreach (var @class in submission.Classes.Where(@class => seenSymbolNames.Add(@class.Name))) { yield return(@class); } foreach (var function in submission.Functions.Where(function => seenSymbolNames.Add(function.Name))) { yield return(function); } foreach (var variable in submission.Variables.Where(variable => seenSymbolNames.Add(variable.Name))) { yield return(variable); } foreach (var builtin in builtinFunctions.Where(builtin => seenSymbolNames.Add(builtin.Name))) { yield return(builtin); } submission = submission.Previous; } }
private BoundExpression BindCallExpression(CallExpressionSyntax syntax) { if (syntax.Arguments.Count == 1 && TypeSymbol.Lookup(syntax.Identifier.Text) is TypeSymbol type) { return(this.BindConversion(syntax.Arguments[0], type, allowExplicit: true)); } var functions = BuiltinFunctions.GetAll(); var function = functions.SingleOrDefault(_ => _.Name == syntax.Identifier.Text); if (function == null) { this.Diagnostics.ReportUndefinedFunction(syntax.Identifier); return(new BoundErrorExpression(syntax)); } if (syntax.Arguments.Count != function.Parameters.Length) { this.Diagnostics.ReportWrongArgumentCount(syntax.Location, function.Name, function.Parameters.Length, syntax.Arguments.Count); return(new BoundErrorExpression(syntax)); } var boundArguments = ImmutableArray.CreateBuilder <BoundExpression>(); foreach (var argument in syntax.Arguments) { var boundArgument = this.BindExpression(argument); boundArguments.Add(boundArgument); } for (var i = 0; i < syntax.Arguments.Count; i++) { var argumentLocation = syntax.Arguments[i].Location; var argument = boundArguments[i]; var parameter = function.Parameters[i]; boundArguments[i] = this.BindConversion(argumentLocation, argument, parameter.Type); } if (function == BuiltinFunctions.E || function == BuiltinFunctions.N) { if (boundArguments[0] is BoundLiteralExpression literalArgument && literalArgument.Type == TypeSymbol.Integer) { var targetLineNumber = (BigInteger)literalArgument.Value; this.LineNumberValidations.Add((targetLineNumber, syntax.Arguments[0].Location)); } } if (function == BuiltinFunctions.Defer) { this.deferWasInvoked = syntax; this.doesStatementExistAfterDefer = false; } return(new BoundCallExpression(syntax, function, boundArguments.ToImmutable())); }
private static BoundScope CreateRootScope() { var result = new BoundScope(null); foreach (var f in BuiltinFunctions.GetAll()) { result.TryDeclareFunction(f); } return(result); }
private BoundExpression BindCallExpression(CallExpressionSyntax syntax) { var arguments = ImmutableArray.CreateBuilder <BoundExpression>(); foreach (var argument in syntax.Arguments) { var boundArgument = BindExpression(argument); arguments.Add(boundArgument); } var functions = BuiltinFunctions.GetAll(); var function = functions.SingleOrDefault(f => f.Name == syntax.IdentifierToken.Text); if (function == null) { _diagnostics.ReportUndefinedFunction(syntax.IdentifierToken.Span, syntax.IdentifierToken.Text); return(new BoundErrorExpression()); } if (syntax.Arguments.Count != function.Parameters.Length) { _diagnostics.ReportIncorrectArgumentCount(syntax.Span, function.Name, function.Parameters.Length, syntax.Arguments.Count); return(new BoundErrorExpression()); } for (var i = 0; i < function.Parameters.Length; i++) { var parameter = function.Parameters[i]; var argument = arguments[i]; if (parameter.Type != argument.Type) { _diagnostics.ReportTypeMismatch(syntax.Span, argument.Type, function.Parameters[i].Type); return(new BoundErrorExpression()); } } return(new BoundCallExpression(function, arguments.ToImmutable())); }