Beispiel #1
0
        public override AstNode Visit(CatchStatement node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Read the exception.
            Structure exception = (Structure)node.GetNodeType();

            // Create the block.
            BasicBlock block = CreateBasicBlock();
            block.SetName("catch");
            builder.SetBlock(block);

            // Add the catch to the context.
            ExceptionContext context = node.GetContext();
            context.AddCatch(exception, block);

            // Load the exception.
            LocalVariable local = node.GetVariable();
            if(local != null)
                builder.CreateStoreLocal(local);
            else
                builder.CreatePop();

            // Update the scope.
            PushScope(node.GetScope());

            // Visit the children.
            VisitList(node.GetChildren());

            // Restore the scope.
            PopScope();

            return builder.EndNode();
        }
Beispiel #2
0
        public override AstNode Visit(CatchStatement node)
        {
            // Update the scope.
            PushScope(node.GetScope());

            // Visit the children.
            VisitList(node.GetChildren());

            // Restore the scope.
            PopScope();

            return node;
        }
Beispiel #3
0
        public override AstNode Visit(CatchStatement node)
        {
            // Get the type expression.
            Expression typeExpression = node.GetExceptionType();

            // Visit the type node.
            typeExpression.Accept(this);

            // Get the type of the type expression.
            IChelaType type = typeExpression.GetNodeType();
            IChelaType objectType = ExtractActualType(typeExpression, type);

            // Only accept classes.
            if(!objectType.IsClass())
                Error(node, "only class instances can be exceptions.");

            // Set the node type.
            node.SetNodeType(objectType);

            // Create the catch lexical scope.
            LexicalScope scope = CreateLexicalScope(node);
            node.SetScope(scope);

            // Create the exception variable.
            string exceptName = node.GetName();
            if(exceptName != null && exceptName != "")
            {
                LocalVariable exceptLocal = new LocalVariable(exceptName, scope,
                                                              ReferenceType.Create(objectType));
                node.SetVariable(exceptLocal);
            }

            // Enter into the catch scope.
            PushScope(scope);

            // Visit the children.
            node.GetChildren().Accept(this);

            // Restore the scope.
            PopScope();

            return node;
        }