Exemple #1
0
        public override TypeLibrary.FoundType VisitTypeTypeOrVoid([NotNull] DoshikParser.TypeTypeOrVoidContext context)
        {
            if (context.VOID() != null)
            {
                return(new TypeLibrary.FoundType()
                {
                    SourceText = context.GetText(),
                    DataType = _compilationContext.TypeLibrary.FindVoid()
                });
            }

            return(Visit(context.typeType()));
        }
        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;
        }
Exemple #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DoshikParser.typeTypeOrVoid"/>.
 /// <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 VisitTypeTypeOrVoid([NotNull] DoshikParser.TypeTypeOrVoidContext context)
 {
     return(VisitChildren(context));
 }
Exemple #4
0
 /// <summary>
 /// Возвращает тип. Может вернуться void
 /// </summary>
 public static TypeLibrary.FoundType Apply(CompilationContext compilationContext, DoshikParser.TypeTypeOrVoidContext context)
 {
     return(context.Accept(new GetTypeNameVisitor(compilationContext)));
 }
 /// <summary>
 /// Enter a parse tree produced by <see cref="DoshikParser.typeTypeOrVoid"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void EnterTypeTypeOrVoid([NotNull] DoshikParser.TypeTypeOrVoidContext context)
 {
 }