Esempio n. 1
0
        public override Node VisitFuncDecl([NotNull] TigerParser.FuncDeclContext context)
        {
            var node = new FuncDeclNode(context);

            // ID
            node.Children.Add(
                new IdNode(context.id.Line, context.id.Column, context.id.Text));

            // PARAMS ?
            TigerParser.Type_fieldsContext typeFields = context.type_fields();
            node.Children.Add(
                typeFields == null ?
                null :
                Visit(typeFields));

            // RETURN TYPE ?
            node.Children.Add(
                context.typeId == null ?
                null :
                new IdNode(context.typeId.Line, context.typeId.Column, context.typeId.Text));

            // BODY
            node.Children.Add(Visit(context.expr()));

            return(node);
        }
Esempio n. 2
0
 public FunctionType(string methodname, ClassType owner, FuncDeclNode declOrigin, HSharpType returnType, List <HSharpType> parameters)
 {
     this.Name           = methodname;
     this.Origin         = declOrigin;
     this.Owner          = owner;
     this.ReturnType     = returnType;
     this.ParameterTypes = parameters;
 }
Esempio n. 3
0
 private static CompileResult DefineType(ASTNode node, Domain domain)
 {
     return(node switch
     {
         NamespaceDirectiveNode namespaceDirective => DefineNamespaceElements(namespaceDirective, domain),
         ClassDeclNode classDecl => DefineClass(classDecl, domain),
         FuncDeclNode funcDecl => DefineFunc(funcDecl, domain),
         _ => new CompileResult(true)
     });
 public static DeclaredSymbol From(DeclSpecsNode specs, DeclNode decl)
 {
     return(decl switch
     {
         VarDeclNode var => new DeclaredVariableSymbol(decl.Identifier, specs, var, var.Initializer),
         ArrDeclNode arr => new DeclaredArraySymbol(decl.Identifier, specs, arr, arr.SizeExpression, arr.Initializer),
         FuncDeclNode f => new DeclaredFunctionSymbol(decl.Identifier, specs, f),
         _ => throw new NotImplementedException("Declarator node type not yet implemented"),
     });
        public override ASTNode VisitFunctionDefinition([NotNull] FunctionDefinitionContext ctx)
        {
            DeclSpecsNode declSpecs = this.Visit(ctx.declarationSpecifiers()).As <DeclSpecsNode>();
            ASTNode       decl      = this.Visit(ctx.declarator());

            if (decl is IdNode fname)
            {
                decl = new FuncDeclNode(fname.Line, fname);
            }
            FuncDeclNode  fdecl = decl.As <FuncDeclNode>();
            BlockStatNode body  = this.Visit(ctx.compoundStatement()).As <BlockStatNode>();

            return(new FuncDefNode(ctx.Start.Line, declSpecs, fdecl, body));
        }
Esempio n. 6
0
        private LinkerResult LinkExternalMethod(ClassType klass, FuncDeclNode funcDecl, ExternalFunctionType type, LinkingType lnkType)
        {
            // Get best external match
            var external = klass is null?this.GetDllFunction(type.Name) : this.GetDllFunction(klass.Name, type.Name);

            // Make sure there's an external to bind to
            if (!external.HasValue)
            {
                return(new LinkerResult(false));
            }
            else
            {
                DllFunction func = external.Value;
                if (lnkType is not null)
                {
                    lnkType.MethodPtrs.Add(type.Name, this.m_bindings.Register(func));
                }
            }

            // Return true (Fails by following bail-out-fast, so when reaching this point it's always success)
            return(new LinkerResult(true));
        }
 public MissingFunctionDefinitionError(DeclSpecsNode declarationSpecifiers, FuncDeclNode fdecl)
 {
     this.DeclarationSpecifiers = declarationSpecifiers;
     this.Declarator            = fdecl;
 }
Esempio n. 8
0
 public virtual TResult Visit(FuncDeclNode node) => this.VisitChildren(node);
Esempio n. 9
0
 public ExternalFunctionType(string methodname, ClassType owner, FuncDeclNode declOrigin, HSharpType returnType, List <HSharpType> parameters)
     : base(methodname, owner, declOrigin, returnType, parameters)
 {
 }