예제 #1
0
 public override void EnterFunctionDecl([NotNull] PigeonParser.FunctionDeclContext context)
 {
     scope = new Scope(GlobalScope);
     GlobalScope.TryGetFunction(context.ID().GetText(), out var function);
     foreach (var parameter in function.Parameters)
     {
         scope.DeclareVariable(parameter.Type, parameter.Name, parameter.ReadOnly);
     }
 }
예제 #2
0
        public override void EnterFunctionDecl([NotNull] PigeonParser.FunctionDeclContext context)
        {
            var parameters     = new List <Variable>();
            var returnType     = PigeonType.FromName(context.TYPE().GetText());
            var parameterCount = context.functionParams()?.ID()?.Length ?? 0;

            for (var i = 0; i < parameterCount; ++i)
            {
                var parameterType = PigeonType.FromName(context.functionParams().TYPE(i).GetText());
                var parameterName = context.functionParams().ID(i).GetText();

                if (parameters.Any(v => v.Name == parameterName))
                {
                    errorBag.ReportDuplicatedArgument(context.functionParams().GetTextSpan(), parameterName);
                }

                parameters.Add(new Variable(parameterType, parameterName, false));
            }

            globalScope.DeclareFunction(returnType, context.ID().GetText(), parameters.ToArray(), context.stmtBlock());
        }