示例#1
0
        /// <summary>
        /// Converts this expression to a boolean expression.
        ///
        /// Expects that the input expression is an integer expression; produces an expression
        /// that returns <c>true</c> iff the integer value is not 0.
        ///
        /// If negate is true, instead produces an expression that returns <c>true</c> iff the integer value is 0.
        /// </summary>
        public TranslatedExpression ConvertToBoolean(ExpressionBuilder expressionBuilder, bool negate = false)
        {
            if (Type.IsKnownType(KnownTypeCode.Boolean) || Type.Kind == TypeKind.Unknown)
            {
                if (negate)
                {
                    return(expressionBuilder.LogicNot(this).WithoutILInstruction());
                }
                else
                {
                    return(this);
                }
            }
            Debug.Assert(Type.GetStackType().IsIntegerType());
            IType boolType = expressionBuilder.compilation.FindType(KnownTypeCode.Boolean);

            if (ResolveResult.IsCompileTimeConstant && ResolveResult.ConstantValue is int)
            {
                bool val = (int)ResolveResult.ConstantValue != 0;
                val ^= negate;
                return(new PrimitiveExpression(val)
                       .WithILInstruction(this.ILInstructions)
                       .WithRR(new ConstantResolveResult(boolType, val)));
            }
            else if (ResolveResult.IsCompileTimeConstant && ResolveResult.ConstantValue is byte)
            {
                bool val = (byte)ResolveResult.ConstantValue != 0;
                val ^= negate;
                return(new PrimitiveExpression(val)
                       .WithILInstruction(this.ILInstructions)
                       .WithRR(new ConstantResolveResult(boolType, val)));
            }
            else if (Type.Kind == TypeKind.Pointer)
            {
                var nullRef = new NullReferenceExpression()
                              .WithoutILInstruction()
                              .WithRR(new ConstantResolveResult(SpecialType.NullType, null));
                var op = negate ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality;
                return(new BinaryOperatorExpression(Expression, op, nullRef.Expression)
                       .WithoutILInstruction()
                       .WithRR(new OperatorResolveResult(boolType, System.Linq.Expressions.ExpressionType.NotEqual,
                                                         this.ResolveResult, nullRef.ResolveResult)));
            }
            else
            {
                var zero = new PrimitiveExpression(0)
                           .WithoutILInstruction()
                           .WithRR(new ConstantResolveResult(expressionBuilder.compilation.FindType(KnownTypeCode.Int32), 0));
                var op = negate ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality;
                return(new BinaryOperatorExpression(Expression, op, zero.Expression)
                       .WithoutILInstruction()
                       .WithRR(new OperatorResolveResult(boolType, System.Linq.Expressions.ExpressionType.NotEqual,
                                                         this.ResolveResult, zero.ResolveResult)));
            }
        }
 public Expression ConvertConstantValue(IType type, object constantValue)
 {
     if (type == null)
         throw new ArgumentNullException("type");
     if (constantValue == null) {
         if (type.IsReferenceType == true) {
             var expr = new NullReferenceExpression();
             if (AddResolveResultAnnotations)
                 expr.AddAnnotation(new ConstantResolveResult(SpecialType.NullType, null));
             return expr;
         } else {
             var expr = new DefaultValueExpression(ConvertType(type));
             if (AddResolveResultAnnotations)
                 expr.AddAnnotation(new ConstantResolveResult(type, null));
             return expr;
         }
     } else if (type.Kind == TypeKind.Enum) {
         return ConvertEnumValue(type, (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false));
     } else {
         return new PrimitiveExpression(constantValue);
     }
 }
        static void AddArgument(InvocationExpression newNode, IParameter parameterToAdd, bool isNextInSequence)
        {
            Expression defaultValue;

            if (parameterToAdd.ConstantValue == null)
            {
                defaultValue = new NullReferenceExpression();
            }
            else
            {
                defaultValue = new PrimitiveExpression(parameterToAdd.ConstantValue);
            }
            Expression newArgument;

            if (newNode.Arguments.Any(argument => argument is NamedExpression) || !isNextInSequence)
            {
                newArgument = new NamedArgumentExpression(parameterToAdd.Name, defaultValue);
            }
            else
            {
                newArgument = defaultValue;
            }
            newNode.Arguments.Add(newArgument);
        }
		static void AddArgument(InvocationExpression newNode, IParameter parameterToAdd, bool isNextInSequence)
		{
			Expression defaultValue;
			if (parameterToAdd.ConstantValue == null) {
				defaultValue = new NullReferenceExpression();
			}
			else {
				defaultValue = new PrimitiveExpression(parameterToAdd.ConstantValue);
			}
			Expression newArgument;
			if (newNode.Arguments.Any(argument => argument is NamedExpression) || !isNextInSequence) {
				newArgument = new NamedArgumentExpression(parameterToAdd.Name, defaultValue);
			}
			else {
				newArgument = defaultValue;
			}
			newNode.Arguments.Add(newArgument);
		}
示例#5
0
 internal AstNode EmitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator ilGenerator)
 {
     return(new NullReferenceEmitter(nullReferenceExpression, ilGenerator, _instructionIndexer).Emit());
 }
示例#6
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            NullReferenceExpression o = other as NullReferenceExpression;

            return(o != null);
        }
示例#7
0
 public RedILNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, State data)
 {
     return(new NilNode());
 }
示例#8
0
 public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
 }
示例#9
0
 public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator data)
 {
     return(_constructorEmitter.EmitNullReferenceExpression(nullReferenceExpression, data));
 }
示例#11
0
文件: Lower.cs 项目: evanw/minisharp
 public void VisitNullReferenceExpression(NullReferenceExpression node)
 {
     VisitChildren(node);
 }
 public virtual S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data)
 {
     return(VisitChildren(nullReferenceExpression, data));
 }
示例#13
0
 public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, int data)
 {
     throw new ASLException("ASL has no notion of NULL.");
 }
示例#14
0
文件: Lower.cs 项目: evanw/minisharp
        public void VisitBinaryOperatorExpression(BinaryOperatorExpression node)
        {
            VisitChildren(node);

            // Force certain operations on integers to stay integers afterwards.
            // This allows JavaScript JITs to omit overflow deoptimizations.
            if (!WillConvertOperandsToIntegers(node) && !WillConvertOperandsToIntegers(UnparenthesizedParent(node))) {
                var result = resolver.Resolve(node) as OperatorResolveResult;
                if (result != null && IsIntegerTypeCode(TypeCode(result.Type))) {
                    var temp = new NullReferenceExpression();
                    node.ReplaceWith(temp);
                    temp.ReplaceWith(new BinaryOperatorExpression(node, BinaryOperatorType.BitwiseOr, new PrimitiveExpression(0)));
                }
            }
        }
 internal NullReferenceEmitter(NullReferenceExpression nullReferenceExpression, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
     : base(ilGenerator, instructionsIndexer) {
     Type = null;
     _nullReferenceExpression = nullReferenceExpression;
 }
示例#16
0
 public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ICecilArgumentsResolver argumentsResolver)
 {
     return(nullReferenceExpression);
 }
 internal NullReferenceEmitter(NullReferenceExpression nullReferenceExpression, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
     : base(ilGenerator, instructionsIndexer)
 {
     Type = null;
     _nullReferenceExpression = nullReferenceExpression;
 }
		public virtual void VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression)
		{
			VisitChildren (nullReferenceExpression);
		}
示例#19
0
 public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     new NullReferenceBlock(this, nullReferenceExpression).Emit();
 }
示例#20
0
        public override void VisitNullReferenceExpression(NullReferenceExpression e)
        {
            var call = e.Parent as InvocationExpression;
            if (call != null)
            {
                // 解决 null 参数引起的调用不明问题:???? 如何判断有必要
                var ti = e.Annotation<TypeInformation>();
                e.ReplaceWith(e.Clone().CastTo(AstBuilder.ConvertType(ti.ExpectedType)));
            }

            base.VisitNullReferenceExpression(e);
        }
 /// <inheritdoc/>
 public virtual void VisitNullReferenceExpression(NullReferenceExpression syntax)
 {
     VisitNode(syntax);
 }
示例#22
0
 public JNode VisitNullReferenceExpression(NullReferenceExpression node)
 {
     return(J.Null());
 }
示例#23
0
 public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, int data)
 {
     throw new SLSharpException("SL# has no notion of NULL.");
 }
示例#24
0
			public override ConstantExpression VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, object data)
			{
				return new PrimitiveConstantExpression(KnownTypeReference.Object, null);
			}
示例#25
0
 public virtual Node VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     throw new System.NotImplementedException();
 }
示例#26
0
 public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     JsonObject expression = CreateJsonExpression(nullReferenceExpression);
     Push(expression);
 }
 public Node VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     return(CreateDummy(nullReferenceExpression));
 }
示例#28
0
 public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     HandleExpressionNode(nullReferenceExpression);
 }
示例#29
0
 public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator data)
 {
     return(base.VisitNullReferenceExpression(nullReferenceExpression, data));
 }
示例#30
0
 public virtual void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     //throw this.CreateException(nullReferenceExpression);
 }
示例#31
0
 public UnifiedElement VisitNullReferenceExpression(
     NullReferenceExpression expr, object data)
 {
     return(UnifiedNullLiteral.Create());
 }
 public override void VisitNullReferenceExpression(NullReferenceExpression syntax)
 {
     _underlyingVisitor.VisitNullReferenceExpression(syntax);
 }
示例#33
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILTranslationContext data)
 => OnVisiting(data, nullReferenceExpression, VisitingNullReferenceExpression)
 ?? OnVisited(data, nullReferenceExpression, VisitedNullReferenceExpression, TranslateNullReferenceExpresssion(nullReferenceExpression, data));
示例#34
0
 public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     new NullReferenceBlock(this, nullReferenceExpression).Emit();
 }
示例#35
0
 protected virtual Expression TranslateNullReferenceExpresssion(NullReferenceExpression nullReferenceExpression, ILTranslationContext data)
 => new E.NullExpression();
示例#36
0
		public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
		{
			StartNode(nullReferenceExpression);
			writer.WritePrimitiveValue(null);
			EndNode(nullReferenceExpression);
		}
 public Expression ConvertConstantValue(IType type, object constantValue)
 {
     if (type == null)
         throw new ArgumentNullException("type");
     if (constantValue == null) {
         if (type.IsReferenceType == true) {
             var expr = new NullReferenceExpression();
             if (AddResolveResultAnnotations)
                 expr.AddAnnotation(new ConstantResolveResult(SpecialType.NullType, null));
             return expr;
         } else {
             var expr = new DefaultValueExpression(ConvertType(type));
             if (AddResolveResultAnnotations)
                 expr.AddAnnotation(new ConstantResolveResult(type, null));
             return expr;
         }
     } else if (type.Kind == TypeKind.Enum) {
         return ConvertEnumValue(type, (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, constantValue, false));
     } else {
         return new PrimitiveExpression(constantValue);
     }
 }
示例#38
0
            public override void VisitReturnStatement(ReturnStatement returnStatement)
            {
                base.VisitReturnStatement(returnStatement);
                if (skip)
                {
                    return;
                }

                if (returnStatement.Expression.IsNull)
                {
                    var entity = returnStatement.GetParent <EntityDeclaration>();
                    if (entity is Accessor)
                    {
                        entity = entity.GetParent <EntityDeclaration>();
                    }
                    if (entity == null)
                    {
                        return;
                    }
                    AstNode entityNode;
                    var     rr      = GetRequestedReturnType(ctx, returnStatement, out entityNode);
                    var     actions = new List <CodeAction>();
                    if (rr != null)
                    {
                        actions.Add(new CodeAction(ctx.TranslateString("Return default value"), script => {
                            Expression p;
                            if (rr.IsKnownType(KnownTypeCode.Boolean))
                            {
                                p = new PrimitiveExpression(false);
                            }
                            else if (rr.IsKnownType(KnownTypeCode.String))
                            {
                                p = new PrimitiveExpression("");
                            }
                            else if (rr.IsKnownType(KnownTypeCode.Char))
                            {
                                p = new PrimitiveExpression(' ');
                            }
                            else if (rr.IsReferenceType == true)
                            {
                                p = new NullReferenceExpression();
                            }
                            else if (rr.GetDefinition() != null &&
                                     rr.GetDefinition().KnownTypeCode < KnownTypeCode.DateTime)
                            {
                                p = new PrimitiveExpression(0x0);
                            }
                            else
                            {
                                p = new DefaultValueExpression(ctx.CreateTypeSystemAstBuilder(returnStatement).ConvertType(rr));
                            }

                            script.Replace(returnStatement, new ReturnStatement(p));
                        }, returnStatement));
                    }
                    var method = returnStatement.GetParent <MethodDeclaration>();
                    if (method != null)
                    {
                        actions.Add(new CodeAction(ctx.TranslateString("Change method return type to 'void'"), script => {
                            script.Replace(method.ReturnType, new PrimitiveType("void"));
                        }, returnStatement));
                    }

                    AddIssue(
                        returnStatement,
                        string.Format(ctx.TranslateString("`{0}': A return keyword must be followed by any expression when method returns a value"), currentMethodName),
                        actions
                        );
                }
            }
示例#39
0
 public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     throw new NotImplementedException();
 }
示例#40
0
		public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
		{
			StartNode(nullReferenceExpression);
			WriteKeyword("null", nullReferenceExpression.Role);
			EndNode(nullReferenceExpression);
		}
示例#41
0
 public virtual void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression)
 {
     //throw this.CreateException(nullReferenceExpression);
 }