public void Accept(UnaryOperationNode node) { }
public void Accept(UnaryOperationNode node) { switch (node.UnaryOperation) { case UnaryOperation.BitwiseNot: node.Target.Visit(this); method.Emit(node.SourceLocation, InstructionType.UnaryOperation, (int)UnaryOperation.BitwiseNot); break; case UnaryOperation.Dereference: node.Target.Visit(this); method.Emit(node.SourceLocation, InstructionType.Dereference); break; case UnaryOperation.LogicalNot: node.Target.Visit(this); method.Emit(node.SourceLocation, InstructionType.UnaryOperation, (int)UnaryOperation.LogicalNot); break; case UnaryOperation.Negate: node.Target.Visit(this); method.Emit(node.SourceLocation, InstructionType.UnaryOperation, (int)UnaryOperation.Negate); break; case UnaryOperation.PostDecrement: case UnaryOperation.PostIncrement: case UnaryOperation.PreDecrement: case UnaryOperation.PreIncrement: if (node.Target is IdentifierNode) { string identifier = ((IdentifierNode)node.Target).Identifier; Instruction loadInstruction, storeInstruction; if (table.ContainsGlobalSymbol(identifier)) { loadInstruction = new Instruction(node.SourceLocation, InstructionType.LoadGlobalVariable, table.GetGlobalSymbol(identifier)); storeInstruction = new Instruction(node.SourceLocation, InstructionType.StoreGlobalVariable, table.GetGlobalSymbol(identifier)); } else { loadInstruction = new Instruction(node.SourceLocation, InstructionType.LoadLocal, table.GetSymbol(identifier)); storeInstruction = new Instruction(node.SourceLocation, InstructionType.StoreLocal, table.GetSymbol(identifier)); } method.Instructions.Add(loadInstruction); if (node.UnaryOperation == UnaryOperation.PostDecrement || node.UnaryOperation == UnaryOperation.PostIncrement) method.Emit(node.SourceLocation, InstructionType.Duplicate); method.Emit(node.SourceLocation, InstructionType.Push, 1); method.Emit(node.SourceLocation, InstructionType.BinaryOperation, node.UnaryOperation == UnaryOperation.PostIncrement || node.UnaryOperation == UnaryOperation.PreIncrement ? (int)BinaryOperation.Addition : (int)BinaryOperation.Subraction); method.Instructions.Add(storeInstruction); if (node.UnaryOperation == UnaryOperation.PreDecrement || node.UnaryOperation == UnaryOperation.PreIncrement) method.Instructions.Add(loadInstruction); } break; case UnaryOperation.Reference: string variable = ((IdentifierNode)node.Target).Identifier; method.Emit(node.SourceLocation, InstructionType.Reference, table.GetSymbol(variable)); break; } }