public void Visit(ClassAst ast)
        {
            if (Global == null)
            {
                Global = Current;
            }

            var classSymbol = ScopeUtil.DefineClassSymbol(ast);

            Current.Define(classSymbol);

            SetScopeType(ScopeType.Class);

            SetScopeSource(classSymbol);

            ScopeTree.CreateScope();

            ast.Body.Visit(this);

            classSymbol.Symbols = ast.Body.CurrentScope.Symbols;

            //redefine the class symbol now with actual symbols
            Current.Define(classSymbol);

            ast.Body.CurrentScope.AllowAllForwardReferences = true;

            ScopeTree.PopScope();

            if (ast.Global == null)
            {
                ast.Global = Global;
            }

            SetScopeType(ScopeType.Global);
        }
Example #2
0
 public static Symbol DefineClassSymbol(ClassAst ast)
 {
     return(new ClassSymbol(ast.Token.TokenValue)
     {
         Src = ast,
         ScopeName = ast.Token.TokenValue
     });
 }
Example #3
0
    ClassAst Class(string[] metadata, Visibility visibility)
    {
        Match(TokenKind.ClassKeyword);
        Token name = Match(TokenKind.Identifier);

        Match(TokenKind.LeftBrace);

        List <FieldAst> fields = new List <FieldAst>();

        while (current.kind is not TokenKind.Eof and not TokenKind.Semicol)
        {
            int start = pos;
            fields.Add(Field(fields));

            // maybe made function?
            if (current.kind is TokenKind.LeftParen)
            {
                BadCode.Report(new SyntaxError("func is not field", tokens[start]));
                break;
            }

            if (current.kind is not TokenKind.Semicol)
            {
                Match(TokenKind.Comma);
            }
        }

        EndLine();

        List <FuncAst> funcs = new List <FuncAst>();

        while (current.kind is not TokenKind.Eof and not TokenKind.RightBrace)
        {
            funcs.Add(Func(name.text, fields.ToArray()));
        }

        Match(TokenKind.RightBrace);
        MaybeEndLine();
        var clazz = new ClassAst(metadata, visibility, name, fields.ToArray(), funcs.ToArray());

        ctnrs.Add(clazz);
        return(clazz);
    }
 public void Visit(ClassAst ast)
 {
     Exec(ast);
 }
 private void ClassDo(ClassAst classAst)
 {
     // nothing to do here
 }
 public static MethodDeclr GetConstructorForClass(ClassAst ast)
 {
     return
         (ast.Body.ScopedStatements.Where(i => i is MethodDeclr)
          .FirstOrDefault(i => (i as MethodDeclr).MethodName.Token.TokenValue == SpecialNames.CONSTRUCTOR_NAME) as MethodDeclr);
 }
 public void Visit(ClassAst ast)
 {
     throw new NotImplementedException();
 }