public static bool IsLogicalCondition(Expression node)
 {
     Node condition = node;
     while (IsLogicalExpression(condition.ParentNode))
         condition = condition.ParentNode;
     return IsConditionOfConditionalStatement(condition);
 }
 public static Expression ComparisonFor(Expression local, IEnumerable<Expression> expressions)
 {
     BinaryExpression expression;
     IEnumerator<Expression> enumerator = expressions.GetEnumerator();
     if (!enumerator.MoveNext())
     {
         throw new AssertionFailedException("e.MoveNext()");
     }
     BinaryExpression expression1 = expression = new BinaryExpression(LexicalInfo.Empty);
     expression.set_Operator(11);
     expression.set_Left(Expression.Lift(local));
     expression.set_Right(Expression.Lift(enumerator.Current));
     Expression expression2 = expression;
     while (enumerator.MoveNext())
     {
         BinaryExpression expression3;
         BinaryExpression expression4;
         BinaryExpression expression11 = expression4 = new BinaryExpression(LexicalInfo.Empty);
         expression4.set_Operator(0x1c);
         expression4.set_Left(Expression.Lift(expression2));
         BinaryExpression expression12 = expression3 = new BinaryExpression(LexicalInfo.Empty);
         expression3.set_Operator(11);
         expression3.set_Left(Expression.Lift(local));
         expression3.set_Right(Expression.Lift(enumerator.Current));
         expression4.set_Right(expression3);
         expression2 = expression4;
     }
     return expression2;
 }
Example #3
0
 public Slice(LexicalInfo lexicalInfo, Expression begin, Expression end, Expression step)
     : base(lexicalInfo)
 {
     this.Begin = begin;
     this.End = end;
     this.Step = step;
 }
        private Expression ExplicitBooleanContext(Expression expression)
        {
            var type = GetExpressionType(expression);
            if (type == TypeSystemServices.BoolType)
            {
            return expression;
            }

            // happening
            //Trace.Assert(!TypeSystemServices.IsError(expression), "shouldn't have error boolean expression.");

            if (TypeSystemServices.IsNumber(type) || type.IsEnum)
            {
            return CodeBuilder.CreateBoundBinaryExpression(
                TypeSystemServices.BoolType,
                BinaryOperatorType.Equality,
                expression,
                CodeBuilder.CreateIntegerLiteral(0));
            }
            else if (TypeSystemServices.IsReferenceType(type))
            {
            return CodeBuilder.CreateBoundBinaryExpression(
                TypeSystemServices.BoolType,
                BinaryOperatorType.Equality,
                expression,
                CodeBuilder.CreateNullLiteral());
            }

            return expression;
        }
Example #5
0
 public BinaryExpression(LexicalInfo lexicalInfoProvider, BinaryOperatorType operator_, Expression left, Expression right)
     : base(lexicalInfoProvider)
 {
     this.Operator = operator_;
     this.Left = left;
     this.Right = right;
 }
 public override void PropagateChanges(MethodInvocationExpression eval, List chain)
 {
     ExpressionCollection expressions = new ExpressionCollection();
     foreach (object local1 in chain.Reversed)
     {
         if (!(local1 is ProcessAssignmentsToSpecialMembers.ChainItem))
         {
         }
         ProcessAssignmentsToSpecialMembers.ChainItem item = (ProcessAssignmentsToSpecialMembers.ChainItem) RuntimeServices.Coerce(local1, typeof(ProcessAssignmentsToSpecialMembers.ChainItem));
         if (item.Container is MethodInvocationExpression)
         {
             break;
         }
         if (item.Container is SlicingExpression)
         {
             SlicingExpression expression = item.Container;
             Expression[] expressionArray1 = new Expression[] { expression.get_Target().CloneNode(), expression.get_Indices().get_Item(0).get_Begin().CloneNode(), this.get_CodeBuilder().CreateReference(item.Local) };
             expressions.Add(this.CreateConstructorInvocation(this._sliceValueTypeChangeConstructor, expressionArray1));
             break;
         }
         MemberReferenceExpression container = item.Container;
         Expression[] args = new Expression[] { container.get_Target().CloneNode(), this.get_CodeBuilder().CreateStringLiteral(container.get_Name()), this.get_CodeBuilder().CreateReference(item.Local) };
         expressions.Add(this.CreateConstructorInvocation(this._valueTypeChangeConstructor, args));
     }
     MethodInvocationExpression expression3 = this.get_CodeBuilder().CreateMethodInvocation(this._propagateChanges);
     IArrayType type = this._valueTypeChangeType.MakeArrayType(1);
     expression3.get_Arguments().Add(this.get_CodeBuilder().CreateArray(type, expressions));
     eval.get_Arguments().Add(expression3);
 }
Example #7
0
 public IfStatement(LexicalInfo token, Expression condition, Block trueBlock, Block falseBlock)
     : base(token)
 {
     this.Condition = condition;
     this.TrueBlock = trueBlock;
     this.FalseBlock = falseBlock;
 }
 public Expression Reify(Expression node)
 {
     if (ShouldReify())
     {
         RunExpansionIterations();
     }
     return node;
 }
        private static bool IsTryGetParameterInvocation(Expression condition)
        {
            var expression = condition as ReferenceExpression;
            if (expression == null)
                return false;

            return expression.Name.StartsWith("?");
        }
Example #10
0
 public static MethodInvocationExpression CreateMethodInvocationExpression(LexicalInfo li, Expression target, Expression arg)
 {
     MethodInvocationExpression mie = new MethodInvocationExpression(li);
     mie.Target = (Expression)target.Clone();
     mie.Arguments.Add((Expression)arg.Clone());
     mie.IsSynthetic = true;
     return mie;
 }
		private Expression FixCondition(Expression condition)
		{
			if (IsTryGetParameterInvocation(condition) == false)
				return condition;

			var isNull =
				new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_");
			return isNull;
		}
		protected override bool IsSpecialMemberTarget(Expression container)
		{
			if (container.NodeType == NodeType.UnaryExpression)
			{
				UnaryExpression ue = container as UnaryExpression;
				if (ue.Operator == UnaryOperatorType.Indirection)
					return false; //indirected value type, no need to process it specially
			}
			return null != container.ExpressionType && container.ExpressionType.IsValueType;
		}
Example #13
0
		public static Expression when(Expression expression)
		{
			BlockExpression right = new BlockExpression();
			right.Body.Add(new ReturnStatement(expression));
			return new BinaryExpression(
				BinaryOperatorType.Assign,
				new ReferenceExpression("condition"),
				right
			);
		}
		private static bool IsTryGetParameterInvocation(Expression condition)
		{
			var mie = condition as MethodInvocationExpression;
			if (mie == null)
				return false;
			var expression = mie.Target as ReferenceExpression;
			if (expression == null)
				return false;
			return expression.Name == "TryGetParameter";
		}
		public static Expression when(Expression expression, Expression action)
		{
			BlockExpression condition = new BlockExpression();
			condition.Body.Add(new ReturnStatement(expression));
			return new MethodInvocationExpression(
				new ReferenceExpression("When"),
				condition,
				action
			);
		}
        protected static void RegisterExtension(MacroStatement macro, Expression extension)
        {
            var extenstions = macro[ExtensionsKey] as List<Expression>;
            if (extenstions == null)
            {
                extenstions = new List<Expression>();
                macro[ExtensionsKey] = extenstions;
            }

            extenstions.Add(extension);
        }
Example #17
0
		private static string ParameterNameFrom(Expression target)
		{
			switch (target.NodeType)
			{
				case NodeType.ReferenceExpression:
					return ((ReferenceExpression) target).Name;
				case NodeType.SelfLiteralExpression:
					return "self";
			}
			throw new ArgumentException(target.ToCodeString());
		}
Example #18
0
		public static ParameterDeclaration Lift(Expression e)
		{
			if (e == null) return null;
			switch (e.NodeType)
			{
				case NodeType.TryCastExpression:
					return Lift((TryCastExpression)e);
				case NodeType.ReferenceExpression:
					return Lift((ReferenceExpression)e);
			}
			throw new NotImplementedException(e.ToCodeString());
		}
Example #19
0
 public static Statement when(Expression expression)
 {
     var body = new Block(expression.LexicalInfo);
     body.Add(new ReturnStatement(expression));
     var result = new BlockExpression(body);
     result.Parameters.Add(
         new ParameterDeclaration("order",
                                  CurrentContext.CodeBuilder.CreateTypeReference(typeof(Order))));
     result.Parameters.Add(
         new ParameterDeclaration("customer",
                                  CurrentContext.CodeBuilder.CreateTypeReference(typeof(Customer))));
     return new ReturnStatement(result);
 }
Example #20
0
        public static bool IsCompoundAssignment(Expression expression,
												out ArrayLiteralExpression assignments)
        {
            assignments = expression as ArrayLiteralExpression;

            if (assignments != null)
            {
                BinaryExpression assignment;
                return (assignments.Items.Count > 1 &&
                        IsAssignment(assignments.Items[1], out assignment));
            }

            return false;
        }
        private Expression ReplaceExpression(Expression expression)
        {
            if ((expression is MethodInvocationExpression) == false)
                return expression;

            var mie = (MethodInvocationExpression)expression;
            var expressionType = mie.ExpressionType as ExternalType;
            if (expressionType != null && typeof(IRegisterable).IsAssignableFrom(expressionType.ActualType))
            {
                return CodeBuilder.CreateMethodInvocation(mie, RegisterMethod);
            }

            return expression;
        }
 public static bool IsRhsOfAssignment(Expression node)
 {
     Expression expression2;
     Node node2 = node.get_ParentNode();
     if (node2 is BinaryExpression)
     {
         BinaryExpression expression;
         BinaryExpression expression1 = expression = node2;
         if ((1 != 0) && (expression.get_Operator() == 15))
         {
             Expression expression3 = expression2 = expression.get_Right();
         }
     }
     return ((1 != 0) && (expression2 == node));
 }
Example #23
0
 public static TypeReference Lift(Expression e)
 {
     switch (e.NodeType)
     {
         case NodeType.TypeofExpression:
             return Lift((TypeofExpression) e);
         case NodeType.GenericReferenceExpression:
             return Lift((GenericReferenceExpression) e);
         case Ast.NodeType.ReferenceExpression:
             return Lift((ReferenceExpression) e);
         case Ast.NodeType.MemberReferenceExpression:
             return Lift((MemberReferenceExpression) e);
     }
     throw new NotImplementedException(e.ToCodeString());
 }
Example #24
0
		private string NamespaceFrom(Expression e)
		{
			if (e == null)
				return null;

			var reference = e as ReferenceExpression;
			if (reference != null)
				return reference.ToString();

			var s = e as StringLiteralExpression;
			if (s != null)
				return s.Value;

			return NamespaceFrom(((MethodInvocationExpression) e).Target);
		}
Example #25
0
 public static Statement read (Expression expression){
     Declaration declaraion = new Declaration();
     declaraion.Name = "readedContent";
     Expression arg = null;
     
     if (expression is BinaryExpression){
         var ass = expression as BinaryExpression;
         declaraion.Name=ass.Left.LiftToString();
         arg = ass.Right;
     }else{
         arg = expression;
     }
     MethodInvocationExpression assign = AstUtil.CreateMethodInvocationExpression(AstUtil.CreateReferenceExpression("System.IO.File.ReadAllText"), arg);
     var result =  new DeclarationStatement(declaraion, assign);
     return result;
 }
Example #26
0
        public bool IsRunnable(Expression expression)
        {
            var method = expression as MethodInvocationExpression;
            if (method == null) return false;

            var reference = method.Target as ReferenceExpression;
            if (reference == null) return false;

            var targetType = nameResolutionService.Resolve(reference.Name, EntityType.Type) as IType;
            if (targetType == null) return false;

            var interfaces = targetType.GetInterfaces();
            if (!interfaces.Any(IsRunnable)) return false;

            return true;
        }
        private Expression FixCondition(Expression condition)
        {
            if (IsTryGetParameterInvocation(condition) == false)
                return condition;

            string name = ((ReferenceExpression) condition).Name.Substring(1);
            condition = new MethodInvocationExpression(
                new MemberReferenceExpression(new SuperLiteralExpression(), "TryGetParameter"),
                new StringLiteralExpression(name)
                );

            var isNull =
                new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_");

            return isNull;
        }
        public bool GetNode(Expression expression, bool asAttribute,
		                    CompilerErrorCollection compileErrors)
        {
            _isAttribute = asAttribute;
            _compileErrors = compileErrors;

            Visit(expression);

            if (_node == null)
            {
                _compileErrors.Add(CompilerErrorFactory.CustomError(expression.LexicalInfo,
                    "Unrecgonized configuration node syntax"));
                return false;
            }

            return true;
        }
        public override void OnMemberReferenceExpression(MemberReferenceExpression node)
        {
            ReferenceExpression reference = node.Target as ReferenceExpression;

            if (reference != null && reference.Name.StartsWith("@"))
            {
                _component = reference;
            }
            else
            {
                _component = AstUtil.CreateMethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(ComponentReference).FullName),
                    node.Target
                    );
            }

            _method = new StringLiteralExpression(node.Name);
            _found = true;
        }
Example #30
0
        private Block extractMainItemBlock(MacroStatement macro, Func<MacroStatement, Block> extract,
                                           MacroStatement onitem_macro, Expression item, string prefix, string suffix){
            Block onitem = null;
            if (onitem_macro == macro && (macro.Body == null || macro.Body.IsEmpty)){
                Expression outer = item;
                if (prefix != "" || suffix != ""){
                    outer = new ExpressionInterpolationExpression()
                        .append(prefix)
                        .append(item)
                        .append(suffix);
                }
                onitem = new Block().add(BrailBuildingHelper.WriteOut(outer));
            }
            else{
                onitem = extract(onitem_macro);
            }

            return onitem;
        }