/// <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); }
internal AstNode EmitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator ilGenerator) { return(new NullReferenceEmitter(nullReferenceExpression, ilGenerator, _instructionIndexer).Emit()); }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { NullReferenceExpression o = other as NullReferenceExpression; return(o != null); }
public RedILNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, State data) { return(new NilNode()); }
public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { }
public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { throw new NotImplementedException(); }
public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator data) { return(_constructorEmitter.EmitNullReferenceExpression(nullReferenceExpression, data)); }
public void VisitNullReferenceExpression(NullReferenceExpression node) { VisitChildren(node); }
public virtual S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data) { return(VisitChildren(nullReferenceExpression, data)); }
public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, int data) { throw new ASLException("ASL has no notion of NULL."); }
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; }
public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ICecilArgumentsResolver argumentsResolver) { return(nullReferenceExpression); }
public virtual void VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression) { VisitChildren (nullReferenceExpression); }
public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { new NullReferenceBlock(this, nullReferenceExpression).Emit(); }
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); }
public JNode VisitNullReferenceExpression(NullReferenceExpression node) { return(J.Null()); }
public StringBuilder VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, int data) { throw new SLSharpException("SL# has no notion of NULL."); }
public override ConstantExpression VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, object data) { return new PrimitiveConstantExpression(KnownTypeReference.Object, null); }
public virtual Node VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { throw new System.NotImplementedException(); }
public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { JsonObject expression = CreateJsonExpression(nullReferenceExpression); Push(expression); }
public Node VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { return(CreateDummy(nullReferenceExpression)); }
public override void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { HandleExpressionNode(nullReferenceExpression); }
public override AstNode VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILGenerator data) { return(base.VisitNullReferenceExpression(nullReferenceExpression, data)); }
public virtual void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { //throw this.CreateException(nullReferenceExpression); }
public UnifiedElement VisitNullReferenceExpression( NullReferenceExpression expr, object data) { return(UnifiedNullLiteral.Create()); }
public override void VisitNullReferenceExpression(NullReferenceExpression syntax) { _underlyingVisitor.VisitNullReferenceExpression(syntax); }
IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, ILTranslationContext data) => OnVisiting(data, nullReferenceExpression, VisitingNullReferenceExpression) ?? OnVisited(data, nullReferenceExpression, VisitedNullReferenceExpression, TranslateNullReferenceExpresssion(nullReferenceExpression, data));
protected virtual Expression TranslateNullReferenceExpresssion(NullReferenceExpression nullReferenceExpression, ILTranslationContext data) => new E.NullExpression();
public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { StartNode(nullReferenceExpression); writer.WritePrimitiveValue(null); EndNode(nullReferenceExpression); }
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 ); } }
public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { throw new NotImplementedException(); }
public void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) { StartNode(nullReferenceExpression); WriteKeyword("null", nullReferenceExpression.Role); EndNode(nullReferenceExpression); }