Esempio n. 1
0
        public override void ExitDestructor_definition(CSharpParser.Destructor_definitionContext context)
        {
            Console.WriteLine("Exiting destructor_definition context.");

            // Exiting the destructor scope:
            symbolTable.ExitScope();
        }
Esempio n. 2
0
        public override void EnterDestructor_definition(CSharpParser.Destructor_definitionContext context)
        {
            Console.WriteLine("Entering descrutor_definition context.");

            // Getting the current class node from symbol table in scope:
            Node        currentClassScopeNode = ast.GetNode(symbolTable.CurrentScopeNode);
            ClassType   classType             = (ClassType)(currentClassScopeNode.Type);
            ClassSymbol classSymbol           = classType.Symbol;
            IToken      classToken            = currentClassScopeNode.Token;

            // Getting the destructor modifiers:
            Symbol.ModifierFlag modFlags = TreatModTokens();
            modifiersTokens.Clear();

            // Creating the destructor symbol:
            DestructorSymbol destructorSymbol = new DestructorSymbol(modFlags, classSymbol);

            // Creating the destructor AST node:
            BuiltInType destructorType  = new BuiltInType(classToken, TypeTag.Destructor);
            IToken      destructorToken = context.TILDE().Symbol;
            Node        destructorNode  = new Node(destructorToken, Node.Kind.Destructor, destructorType, destructorSymbol);

            ast.AddNode(destructorNode);

            // Adding the new node as a child of the class node:
            currentClassScopeNode.AddChildIndex(ast.NodeIndex(destructorNode));

            // Adding the destructor symbol to the symbol table:
            int destructorNodeIndex = ast.NodeIndex(destructorNode);

            symbolTable.EnterScope(destructorNodeIndex);
            symbolTable.AddSymbol(destructorToken, destructorSymbol);
        }