private void InferResult(Expression expr, string name, LexicalInfo lexicalInfo, bool useElementType)
		{
			if (expr == null)
				return;
			// Prevent creating an infinite number of InferredReturnTypes in inferring cycles
			IReturnType returnType;
			if (expr.ContainsAnnotation("DomReturnType")) {
				returnType = (IReturnType)expr["DomReturnType"];
			} else {
				returnType = new BooInferredReturnType(expr, resolver.CallingClass);
				expr.Annotate("DomReturnType", returnType);
			}
			if (useElementType)
				returnType = new ElementReturnType(resolver.ProjectContent, returnType);
			result = new DefaultField.LocalVariableField(returnType, name,
			                                             new DomRegion(lexicalInfo.Line, lexicalInfo.Column),
			                                             resolver.CallingClass);
		}
Beispiel #2
0
 private IEnumerable<Expression> FindNullableExpressions(Expression exp)
 {
     if (exp.ContainsAnnotation("nullableTarget"))
     {
         yield return ((MemberReferenceExpression) exp).Target;
     }
     else
     {
         BinaryExpression bex = exp as BinaryExpression;
         if (null != bex)
         {
             foreach (Expression inner in FindNullableExpressions(bex.Left))
                 yield return inner;
             foreach (Expression inner in FindNullableExpressions(bex.Right))
                 yield return inner;
         }
     }
 }
        static bool IsConstant(Expression e)
        {
            if (e.NodeType == NodeType.UnaryExpression)
                return IsConstant(((UnaryExpression)e).Operand);

            if (e.NodeType == NodeType.BinaryExpression)
            {
                var be = (BinaryExpression)e;
                if (AstUtil.GetBinaryOperatorKind(be) == BinaryOperatorKind.Logical)
                    return IsConstant(be.Left) && IsConstant(be.Right);
            }

            if ((e as LiteralExpression) != null
                && !e.ContainsAnnotation(ConstantFolding.FoldedExpression))
                return true;

            if (IsImplicitCallable(e))
                return true;

            if (IsConstantInternalField(e.Entity as IField, e))
                return true;

            return false;
        }