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

            // Get the expressions.
            Expression variableExpr = node.GetVariable();

            // Get the types.
            IChelaType variableType = variableExpr.GetNodeType();
            IChelaType coercionType = node.GetCoercionType();

            // Get the variable.
            Variable variable = (Variable)variableExpr.GetNodeValue();
            variableExpr.Accept(this);

            // Duplicate the variable reference.
            DuplicateReference(node, variable);

            // Read the variable.
            Cast(node, variable, variableType, coercionType);

            // Duplicate the value and reference.
            uint args = GetVariableParameters(node, variable) + 1u;
            if(args == 1u)
                builder.CreateDup1();
            else if(args == 2u)
                builder.CreateDup2();
            else
                builder.CreateDup(args);

            // Send the right operand.
            if(coercionType.IsPointer())
            {
                builder.CreateLoadUInt32(1);
            }
            else
            {
                builder.CreateLoadInt32(1);
                if(ChelaType.GetIntType() != coercionType)
                    Cast(node, null, ChelaType.GetIntType(), coercionType);
            }

            // Perform the operation
            switch(node.GetOperation())
            {
            case PostfixOperation.Increment:
                builder.CreateAdd();
                break;
            case PostfixOperation.Decrement:
                builder.CreateSub();
                break;
            default:
                Error(node, "invalid prefix operation.");
                break;
            }

            // Now, perform the assignment.
            PerformAssignment(node, variable);

            // Remove the extra reference.
            for(uint i = 1; i < args; i++)
                builder.CreateRemove(1u);

            return builder.EndNode();
        }