Beispiel #1
0
        public override AstNode Visit(PostfixOperation node)
        {
            // Get the variable.
            Expression variableExpr = node.GetVariable();

            // Visit the variable.
            variableExpr.Accept(this);

            // Check the types.
            IChelaType variableType = variableExpr.GetNodeType();

            // The variable must be a reference.
            if(!variableType.IsReference())
                Error(node, "trying to set something that isn't a reference.");

            // Check the operation type.
            IChelaType coercionType = DeReferenceType(variableType);
            if(coercionType.IsConstant())
                Error(node, "cannot modify constants.");

            // TODO: Add operator overloading.
            if(!coercionType.IsInteger() && !coercionType.IsFloat() && !coercionType.IsPointer())
                Error(node, "increment/decrement operator expected an integer/float/pointer variable.");

            // Set the node types.
            node.SetCoercionType(coercionType);
            node.SetNodeType(coercionType);

            return node;
        }