Beispiel #1
0
 public virtual void WriteCallUnOp(CallUnOp s, ExpressionUsage u)
 {
     Begin(u.IsObject());
     Write(s.Operator.Symbol);
     WriteExpression(s.Operand, ExpressionUsage.Object);
     End(u.IsObject());
 }
Beispiel #2
0
        public static bool TryTransformEnumUnOpToIntUnOp(this CallUnOp s, Log log, ref Expression result)
        {
            // Enum.UnOps -> Int.UnOps
            if (s.Operator.DeclaringType is EnumType)
            {
                var bt = s.Operator.DeclaringType.Base;

                foreach (var o in bt.Operators)
                {
                    if (o.UnoName == s.Operator.UnoName)
                    {
                        result = new CallUnOp(s.Source, o,
                                              new CastOp(s.Source, bt, s.Operand));

                        if (s.ReturnType == s.Operator.DeclaringType)
                        {
                            result = new CastOp(s.Source, s.Operator.DeclaringType, result);
                        }

                        return(true);
                    }
                }

                log.Error(s.Source, ErrorCode.I0071, "'" + bt + "." + s.Operator.UnoName + "(" + bt + ")' was not found");
            }

            return(false);
        }
Beispiel #3
0
        public void CompileUnOp(CallUnOp s, bool pop)
        {
            var builtInOp = Opcodes.Null;

            switch (s.Operator.DeclaringType.BuiltinType)
            {
            case BuiltinType.Bool:
            case BuiltinType.Char:
            case BuiltinType.Byte:
            case BuiltinType.SByte:
            case BuiltinType.UShort:
            case BuiltinType.Short:
            case BuiltinType.ULong:
            case BuiltinType.Long:
            case BuiltinType.UInt:
            case BuiltinType.Int:
            case BuiltinType.Float:
            case BuiltinType.Double:
                switch (s.Operator.Type)
                {
                case OperatorType.OnesComplement: builtInOp = Opcodes.BitwiseNot; break;

                case OperatorType.LogicalNot: builtInOp = Opcodes.LogNot; break;

                case OperatorType.UnaryNegation: builtInOp = Opcodes.Neg; break;
                }
                break;
            }

            if (builtInOp != Opcodes.Null)
            {
                CompileExpression(s.Operand);
                Emit(builtInOp);
                return;
            }

            CompileExpression(s.Operand);
            Call(null, s.Operator);

            if (pop && !s.Operator.ReturnType.IsVoid)
            {
                Pop();
            }
        }