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(); }
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; }