예제 #1
0
        public override AstNode Visit(FixedStatement node)
        {
            // Begin the node.
            builder.BeginNode(node);

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

            // Create a block for the fixed statement.
            BasicBlock fixedBlock = CreateBasicBlock();
            fixedBlock.SetName("fixed");

            // Enter into the fixed block.
            builder.CreateJmp(fixedBlock);
            builder.SetBlock(fixedBlock);

            // Visit the declarations.
            VisitList(node.GetDeclarations());

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

            // Remove unreachable code.
            if(builder.IsLastTerminator())
            {
                AstNode next = node.GetNext();
                if(next != null)
                    Warning(next, "found unreachable code.");
                node.SetNext(null);
            }
            else
            {
                // Merge the block.
                BasicBlock merge = CreateBasicBlock();
                merge.SetName("fmerge");
                builder.CreateJmp(merge);
                builder.SetBlock(merge);
            }

            // Restore the scope.
            PopScope();

            return builder.EndNode();
        }
예제 #2
0
        public override AstNode Visit(FixedStatement node)
        {
            // Push the scope.
            PushScope(node.GetScope());

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

            // Pop the scope.
            PopScope();

            return node;
        }
예제 #3
0
        public override AstNode Visit(FixedStatement node)
        {
            UnsafeError(node, "cannot use fixed statement under safe contexts.");

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

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

            // Visit the type expression.
            Expression typeExpr = node.GetTypeExpression();
            typeExpr.Accept(this);

            // Read the type expression.
            IChelaType fixedType = typeExpr.GetNodeType();
            fixedType = ExtractActualType(typeExpr, fixedType);

            // Make sure its a pointer.
            if(!fixedType.IsPointer())
                Error(typeExpr, "expected pointer type.");

            // Vist the declarations.
            AstNode decl = node.GetDeclarations();
            while(decl != null)
            {
                // Notify about the type.
                decl.SetNodeType(fixedType);

                // Visit it.
                decl.Accept(this);

                // Visit the next declaration.
                decl = decl.GetNext();
            }

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

            // Restore the scope.
            PopScope();

            return node;
        }