private void HandleEventDeclaration(
            DoshikParser.TypeTypeOrVoidContext eventReturnTypeCtx,
            string eventCodeName,
            DoshikParser.FormalParametersContext eventParametersCtx,
            DoshikParser.BlockContext eventBodyCtx
            )
        {
            var eventDeclaration = new EventDeclaration(_compilationContext.CompilationUnit);

            eventDeclaration.Parameters = new MethodDeclarationParameters(eventDeclaration, _compilationContext.CompilationUnit.Scope);

            _currentMethodDeclaration = eventDeclaration;

            eventDeclaration.Name = eventCodeName;

            var foundType = GetTypeNameVisitor.Apply(_compilationContext, eventReturnTypeCtx);

            foundType.ThrowIfNotFound(_compilationContext);
            eventDeclaration.ReturnTypeOrVoid = foundType.DataType;

            eventDeclaration.ExternalEvent = _compilationContext.FindExternalApiEventByCodeName(eventDeclaration.Name);

            if (_compilationContext.CompilationUnit.Events.ContainsKey(eventDeclaration.Name))
            {
                throw _compilationContext.ThrowCompilationError($"event handler { eventDeclaration.Name } is already defined");
            }

            eventDeclaration.Parameters.Parameters.AddRange((List <MethodDeclarationParameter>)Visit(eventParametersCtx));

            eventDeclaration.AntlrBody = eventBodyCtx;

            if (eventDeclaration.IsCustom)
            {
                ValidateCustomEvent(eventDeclaration);
            }
            else
            {
                ValidateBuiltInEvent(eventDeclaration);
            }

            _compilationContext.CompilationUnit.Events[eventDeclaration.Name] = eventDeclaration;
        }
        // возвращает BlockOfStatements
        public override object VisitBlock([NotNull] DoshikParser.BlockContext context)
        {
            _compilationContext.SetParsingAntlrContext(context);

            var block = new BlockOfStatements(_currentNode, _currentScope);

            // Помечаем текущий блок и заходим в его scope

            _currentNode  = block;
            _currentScope = block.Scope;

            foreach (var blockStatementCtx in context.statementInBlock())
            {
                var statement = (Statement)Visit(blockStatementCtx);
                block.Statements.Add(statement);
            }

            // Возвращаем предыдущий блок и заходим в рдоительский scope
            _currentScope = _currentScope.ParentScope;
            _currentNode  = _currentNode.Parent;

            return(block);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DoshikParser.block"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitBlock([NotNull] DoshikParser.BlockContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="DoshikParser.block"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitBlock([NotNull] DoshikParser.BlockContext context)
 {
 }