public override IExpression VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node) { var o = this.semanticModel.GetTypeInfo(node); var t = this.mapper.Map(o.Type); var operand = this.Visit(node.Operand); UnaryOperation op = null; switch (node.Kind) { case SyntaxKind.BitwiseNotExpression: op = new OnesComplement(); break; case SyntaxKind.UnaryMinusExpression: op = new UnaryNegation(); op.Type = operand.Type; break; case SyntaxKind.PreDecrementExpression: case SyntaxKind.PreIncrementExpression: BinaryOperation bo; if (node.OperatorToken.Kind == SyntaxKind.MinusMinusToken) { bo = new Subtraction(); } else { bo = new Addition(); } object one = GetConstantOneOfMatchingTypeForIncrementDecrement(operand.Type.ResolvedType); // REVIEW: Do we really need to resolve? bo.LeftOperand = operand; bo.RightOperand = new CompileTimeConstant() { Type = operand.Type, Value = one, }; bo.Type = operand.Type; var assign = new Assignment() { Source = bo, Target = Helper.MakeTargetExpression(operand), Type = operand.Type, }; return(assign); case SyntaxKind.LogicalNotExpression: op = new LogicalNot(); break; default: var typeName = node.GetType().ToString(); var msg = String.Format("Was unable to convert a {0} node to CCI because the kind '{1}' wasn't handled", typeName, node.Kind.ToString()); throw new ConverterException(msg); } op.Operand = operand; return(op); }
void UnaryOperator(out Expression exp) { Token tok = null; string op = null; if (la.kind == 41 || la.kind == 45 || la.kind == 46) { if (la.kind == 41) { Get(); tok = t; op = t.val; } else if (la.kind == 45) { Get(); tok = t; op = t.val; } else { Get(); tok = t; op = t.val; } } Terminal(out exp); if (op == "-") { if (!ExpectInt(exp, tok, true)) { return; } exp = new UnaryMinus((TypedExpression <int>)exp); } else if (op == "~") { if (!ExpectInt((TypedExpression <int>)exp, tok, true)) { return; } exp = new OnesComplement((TypedExpression <int>)exp); } else if (op == "not") { if (!ExpectBool(exp, tok, true)) { return; } exp = new Not((TypedExpression <bool>)exp); } }
public static T Complement <T>(T value) => OnesComplement <T, T> .Invoke(value);
public static R Complement <T, R>(T value) => OnesComplement <T, R> .Invoke(value);
public virtual void Visit(OnesComplement node) { }
void UnaryOperator(out Expression exp) { Token tok = null; string op = null; if (la.kind == 41 || la.kind == 45 || la.kind == 46) { if (la.kind == 41) { Get(); tok = t; op = t.val; } else if (la.kind == 45) { Get(); tok = t; op = t.val; } else { Get(); tok = t; op = t.val; } } Terminal(out exp); if (op == "-") { if (!ExpectInt(exp, tok, true)) { return; } exp = new UnaryMinus((TypedExpression<int>)exp); } else if (op == "~") { if (!ExpectInt((TypedExpression<int>)exp, tok, true)) { return; } exp = new OnesComplement((TypedExpression<int>)exp); } else if (op == "not") { if (!ExpectBool(exp, tok, true)) { return; } exp = new Not((TypedExpression<bool>)exp); } }