예제 #1
0
        public override ASTNode VisitParameterDeclaration([NotNull] ParameterDeclarationContext ctx)
        {
            DeclSpecsNode declSpecs = this.Visit(ctx.declarationSpecifiers()).As <DeclSpecsNode>();
            DeclNode      decl      = this.Visit(ctx.declarator()).As <DeclNode>();

            return(new FuncParamNode(ctx.Start.Line, declSpecs, decl));
        }
예제 #2
0
        public override ASTNode VisitDeclaration([NotNull] DeclarationContext ctx)
        {
            switch (ctx.children.First().GetText())
            {
            case "declare":
                var      declSpecs = new DeclSpecsNode(ctx.Start.Line, GetTypeName());
                var      name      = new IdNode(ctx.Start.Line, ctx.NAME().GetText());
                DeclNode decl;
                if (ctx.type().typename().children.Count > 1)
                {
                    switch (ctx.type().typename().children.Last().GetText())
                    {
                    case "array":
                    case "list":
                    case "set":
                        if (ctx.exp() is { })
                        {
                            ExprNode init = this.Visit(ctx.exp()).As <ExprNode>();
                            decl = new ArrDeclNode(ctx.Start.Line, name, init);
                        }
                        else
                        {
                            decl = new ArrDeclNode(ctx.Start.Line, name);
                        }
                        break;

                    default:
                        throw new SyntaxErrorException("Invalid complex type");
                    }
                }
 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"),
     });
예제 #4
0
 public DeclSpecsMismatchWarning(DeclNode declarator, DeclSpecsNode expected, DeclSpecsNode actual)
 {
     if (expected.Equals(actual))
     {
         throw new ArgumentException("Expected different objects");
     }
     this.Expected   = expected;
     this.Actual     = actual;
     this.Declarator = declarator;
 }
예제 #5
0
        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));
        }
 public MissingFunctionDefinitionError(DeclSpecsNode declarationSpecifiers, FuncDeclNode fdecl)
 {
     this.DeclarationSpecifiers = declarationSpecifiers;
     this.Declarator            = fdecl;
 }
 public ExtraDeclarationWarning(DeclSpecsNode declarationSpecifiers, DeclNode declarator)
 {
     this.DeclarationSpecifiers = declarationSpecifiers;
     this.Declarator            = declarator;
 }
예제 #8
0
 public virtual TResult Visit(DeclSpecsNode node) => this.VisitChildren(node);
 public DeclaredArraySymbol(string name, DeclSpecsNode specs, ArrDeclNode decl, ExprNode?size = null, ArrInitExprNode?init = null)
     : base(name, specs, decl)
 {
     this.ArrayDeclarator = decl;
     if (size is { })
 public DeclaredVariableSymbol(string name, DeclSpecsNode specs, VarDeclNode decl, ExprNode?init = null)
     : base(name, specs, decl)
 {
     this.VariableDeclarator = decl;
     if (init is { })