Beispiel #1
0
 public IfStatement(LexicalInfo token, Expression condition, Block trueBlock, Block falseBlock)
     : base(token)
 {
     this.Condition = condition;
     this.TrueBlock = trueBlock;
     this.FalseBlock = falseBlock;
 }
Beispiel #2
0
 public Slice(LexicalInfo lexicalInfo, Expression begin, Expression end, Expression step)
     : base(lexicalInfo)
 {
     this.Begin = begin;
     this.End = end;
     this.Step = step;
 }
 public static bool IsLogicalCondition(Expression node)
 {
     Node condition = node;
     while (IsLogicalExpression(condition.ParentNode))
         condition = condition.ParentNode;
     return IsConditionOfConditionalStatement(condition);
 }
Beispiel #4
0
        public object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data)
        {
            if (currentSwitchTempName == null)
            {
                AddError(gotoCaseStatement, "goto case cannot be used outside switch");
                return(null);
            }
            string labelName;

            if (gotoCaseStatement.IsDefaultCase)
            {
                labelName = "default";
            }
            else
            {
                B.Expression expr = ConvertExpression(gotoCaseStatement.Expression);
                if (expr == null)
                {
                    return(null);
                }
                labelName = expr.ToCodeString().GetHashCode().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            return(new B.GotoStatement(GetLexicalInfo(gotoCaseStatement),
                                       new B.ReferenceExpression(currentSwitchTempName + "_" + labelName)));
        }
Beispiel #5
0
        public IReturnType GetTypeOfExpression(AST.Expression expr, IClass callingClass)
        {
            AST.Node        node = expr;
            AST.LexicalInfo lexInfo;
            do
            {
                if (node == null)
                {
                    return(null);
                }
                lexInfo = node.LexicalInfo;
                node    = node.ParentNode;
            } while (lexInfo == null || lexInfo.FileName == null);
            if (!Initialize(ParserService.GetParseInformation(lexInfo.FileName), lexInfo.Line, lexInfo.Column))
            {
                return(null);
            }
            if (callingClass != null)
            {
                this.callingClass = callingClass;
            }
            ResolveVisitor visitor = new ResolveVisitor(this);

            visitor.Visit(expr);
            if (visitor.ResolveResult == null)
            {
                return(null);
            }
            else
            {
                return(visitor.ResolveResult.ResolvedType);
            }
        }
        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;
        }
Beispiel #7
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);
 }
 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;
 }
Beispiel #10
0
 public object VisitInvocationExpression(InvocationExpression ie, object data)
 {
     B.Expression e = ConvertExpression(ie.TargetObject);
     if (e == null)
     {
         return(null);
     }
     if (settings.IsVisualBasic && ie.TargetObject is IdentifierExpression && currentStatement != null)
     {
         VariableResolver resolver = new VariableResolver(nameComparer);
         TypeReference    typeRef  = resolver.FindType((ie.TargetObject as IdentifierExpression).Identifier, currentStatement);
         if (typeRef != null && typeRef.IsArrayType)
         {
             // Visual Basic: indexer expression
             B.SlicingExpression s = new B.SlicingExpression(GetLexicalInfo(ie));
             s.Target = e;
             foreach (Expression expr in ie.Arguments)
             {
                 s.Indices.Add(new B.Slice(ConvertExpression(expr)));
             }
             return(s);
         }
     }
     B.MethodInvocationExpression r = new B.MethodInvocationExpression(GetLexicalInfo(ie), e);
     foreach (Expression expr in ie.Arguments)
     {
         e = ConvertExpression(expr);
         if (e != null)
         {
             r.Arguments.Add(e);
         }
     }
     return(r);
 }
        private static bool IsTryGetParameterInvocation(Expression condition)
        {
            var expression = condition as ReferenceExpression;
            if (expression == null)
                return false;

            return expression.Name.StartsWith("?");
        }
Beispiel #12
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;
 }
 public Expression Reify(Expression node)
 {
     if (ShouldReify())
     {
         RunExpansionIterations();
     }
     return node;
 }
		private Expression FixCondition(Expression condition)
		{
			if (IsTryGetParameterInvocation(condition) == false)
				return condition;

			var isNull =
				new MemberReferenceExpression(condition, "_IsIgnoreNullReferencingNotNullObject_");
			return isNull;
		}
		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";
		}
Beispiel #16
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
			);
		}
		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;
		}
		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
			);
		}
Beispiel #19
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());
		}
        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);
        }
Beispiel #21
0
 void ConvertExpressions(IEnumerable input, B.ExpressionCollection output)
 {
     foreach (Expression e in input)
     {
         B.Expression expr = ConvertExpression(e);
         if (expr != null)
         {
             output.Add(expr);
         }
     }
 }
Beispiel #22
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());
		}
Beispiel #23
0
        public object VisitEraseStatement(EraseStatement eraseStatement, object data)
        {
            ArrayList statements = new ArrayList();

            foreach (Expression expr in eraseStatement.Expressions)
            {
                B.Expression e = ConvertExpression(expr);
                e = new B.BinaryExpression(B.BinaryOperatorType.Assign, e, new B.NullLiteralExpression());
                statements.Add(new B.ExpressionStatement(e));
            }
            return(statements);
        }
 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);
 }
        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;
        }
 B.TypeReference ConvertTypeReference(B.Expression expr)
 {
     B.TypeofExpression te = expr as B.TypeofExpression;
     if (te != null)
     {
         return(te.Type);
     }
     if (expr is B.ReferenceExpression)
     {
         return(new B.SimpleTypeReference(expr.ToCodeString()));
     }
     AddError(expr.LexicalInfo, "Expected type, but found expression.");
     return(null);
 }
Beispiel #27
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;
        }
Beispiel #28
0
 public object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute a, object data)
 {
     B.Attribute att = new B.Attribute(GetLexicalInfo(a), a.Name);
     att.EndSourceLocation = GetLocation(a.EndLocation);
     ConvertExpressions(a.PositionalArguments, att.Arguments);
     foreach (NamedArgumentExpression nae in a.NamedArguments)
     {
         B.Expression expr = ConvertExpression(nae.Expression);
         if (expr != null)
         {
             att.NamedArguments.Add(new B.ExpressionPair(new B.ReferenceExpression(nae.Name), expr));
         }
     }
     return(att);
 }
Beispiel #29
0
        public object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
        {
            B.Expression         left  = ConvertExpression(binaryOperatorExpression.Left);
            B.Expression         right = ConvertExpression(binaryOperatorExpression.Right);
            B.BinaryOperatorType op    = ConvertOperator(binaryOperatorExpression.Op);
            if (op == B.BinaryOperatorType.None)
            {
                AddError(binaryOperatorExpression, "Unknown operator.");
                return(null);
            }
//			if (binaryOperatorExpression.Op == BinaryOperatorType.DivideInteger) {
//				AddWarning(binaryOperatorExpression, "Integer division converted to normal division.");
//			}
            return(new B.BinaryExpression(GetLexicalInfo(binaryOperatorExpression), op, left, right));
        }
Beispiel #30
0
 public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
 {
     B.Expression expr = ConvertExpression(unaryOperatorExpression.Expression);
     if (unaryOperatorExpression.Op == UnaryOperatorType.Plus)
     {
         return(expr);
     }
     B.UnaryOperatorType op = ConvertOperator(unaryOperatorExpression.Op);
     if (op == B.UnaryOperatorType.None)
     {
         AddError(unaryOperatorExpression, "Unknown operator.");
         return(null);
     }
     return(new B.UnaryExpression(GetLexicalInfo(unaryOperatorExpression), op, expr));
 }
Beispiel #31
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());
 }
Beispiel #32
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);
		}
 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));
 }
        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;
        }
Beispiel #35
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;
        }
Beispiel #36
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;
 }
        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;
        }
        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;
        }
Beispiel #40
0
        public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
        {
            B.Expression left  = ConvertExpression(assignmentExpression.Left);
            B.Expression right = ConvertExpression(assignmentExpression.Right);
            bool         isInPlace;

            B.BinaryOperatorType op = ConvertOperator(assignmentExpression.Op, out isInPlace);
            if (op == B.BinaryOperatorType.None)
            {
                AddError(assignmentExpression, "Unknown operator.");
                return(null);
            }
            if (!isInPlace)
            {
                // convert L <OP>= R to L = L OP R
                right = new B.BinaryExpression(GetLexicalInfo(assignmentExpression), op, left, right);
                op    = B.BinaryOperatorType.Assign;
            }
            return(new B.BinaryExpression(GetLexicalInfo(assignmentExpression), op, left, right));
        }
Beispiel #41
0
 public object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
 {
     module             = new B.Module();
     module.LexicalInfo = new B.LexicalInfo(fileName, 1, 1);
     compilationUnit.AcceptChildren(this, data);
     if (entryPointMethod != null)
     {
         bool allMembersAreStatic = true;
         foreach (B.TypeMember member in entryPointMethod.DeclaringType.Members)
         {
             allMembersAreStatic &= member.IsStatic;
         }
         if (allMembersAreStatic)
         {
             entryPointMethod.DeclaringType.Attributes.Add(MakeAttribute(("module")));
         }
         else
         {
             lastLexicalInfo = entryPointMethod.LexicalInfo;
             B.Expression expr = MakeReferenceExpression(entryPointMethod.DeclaringType.Name + ".Main");
             B.MethodInvocationExpression mie = new B.MethodInvocationExpression(lastLexicalInfo, expr);
             if (entryPointMethod.Parameters.Count > 0)
             {
                 mie.Arguments.Add(MakeReferenceExpression("argv"));
             }
             B.SimpleTypeReference ret = entryPointMethod.ReturnType as B.SimpleTypeReference;
             if (ret.Name == "void" || ret.Name == "System.Void")
             {
                 module.Globals.Add(new B.ExpressionStatement(mie));
             }
             else
             {
                 module.Globals.Add(new B.ReturnStatement(lastLexicalInfo, mie, null));
             }
         }
     }
     B.Module tmp = module;
     module = null;
     return(tmp);
 }
Beispiel #42
0
        public object VisitForNextStatement(ForNextStatement forNextStatement, object data)
        {
            if (forNextStatement.TypeReference.IsNull)
            {
                return(MakeManualLoop(forNextStatement));
            }
            B.ForStatement fs = new B.ForStatement(GetLexicalInfo(forNextStatement));
            fs.Block = ConvertBlock(forNextStatement.EmbeddedStatement);
            fs.Declarations.Add(new B.Declaration(forNextStatement.VariableName, null));
            B.Expression start = ConvertExpression(forNextStatement.Start);
            Expression   end   = forNextStatement.End;

            if (forNextStatement.Step == null || forNextStatement.Step.IsNull)
            {
                // range only goes to end - 1, so increment end
                end         = Expression.AddInteger(end, 1);
                fs.Iterator = MakeMethodCall("range", start, ConvertExpression(end));
            }
            else
            {
                PrimitiveExpression stepPE = forNextStatement.Step as PrimitiveExpression;
                if (stepPE == null || !(stepPE.Value is int))
                {
                    AddError(forNextStatement, "Step must be an integer literal");
                }
                else
                {
                    if ((int)stepPE.Value < 0)
                    {
                        end = Expression.AddInteger(end, -1);
                    }
                    else
                    {
                        end = Expression.AddInteger(end, 1);
                    }
                }
                fs.Iterator = MakeMethodCall("range", start, ConvertExpression(end), ConvertExpression(forNextStatement.Step));
            }
            return(fs);
        }
Beispiel #43
0
 public object VisitMemberReferenceExpression(MemberReferenceExpression mre, object data)
 {
     B.Expression target = null;
     if (mre.TargetObject is TypeReferenceExpression)
     {
         // not typeof, so this is something like int.Parse() or Class<string>.StaticMethod
         TypeReference typeRef = ((TypeReferenceExpression)mre.TargetObject).TypeReference;
         if (!typeRef.IsArrayType)
         {
             target = MakeReferenceExpression(typeRef);
         }
     }
     if (target == null)
     {
         target = (B.Expression)mre.TargetObject.AcceptVisitor(this, data);
         if (target == null)
         {
             return(null);
         }
     }
     return(new B.MemberReferenceExpression(GetLexicalInfo(mre), target, mre.MemberName));
 }
Beispiel #44
0
 protected static AST.Expression output_binding(AST.Expression vname, AST.Expression expr)
 {
     AST.BlockExpression condition = new AST.BlockExpression();
     condition.Body.Add(new AST.ReturnStatement(expr));
     return(new AST.MethodInvocationExpression(new AST.ReferenceExpression("add_output_binding"), vname, condition, new AST.StringLiteralExpression(expr.ToCodeString())));
 }
Beispiel #45
0
		public static Expression Lift(Expression e)
		{
			if (e == null) return null;
			return e.CloneNode();
		}
Beispiel #46
0
 protected static AST.Expression task_output_data(AST.Expression expr)
 {
     AST.BlockExpression condition = new AST.BlockExpression();
     condition.Body.Add(new AST.ReturnStatement(expr));
     return(new AST.MethodInvocationExpression(new AST.ReferenceExpression("output_bindings_code"), condition, new AST.StringLiteralExpression(expr.ToCodeString())));
 }
Beispiel #47
0
 public static AST.Expression default_value(AST.Expression expr)
 {
     AST.BlockExpression condition = new AST.BlockExpression();
     condition.Body.Add(new AST.ReturnStatement(expr));
     return(new AST.MethodInvocationExpression(new AST.ReferenceExpression("variable_default"), condition, new AST.StringLiteralExpression(expr.ToCodeString())));
 }
Beispiel #48
0
        public object VisitSwitchSection(SwitchSection switchSection, object data)
        {
            B.IfStatement surroundingIf = (B.IfStatement)data;
            bool          isDefault     = false;
            ArrayList     conditions    = new ArrayList();
            ArrayList     labels        = new ArrayList();

            foreach (CaseLabel caseLabel in switchSection.SwitchLabels)
            {
                if (caseLabel.IsDefault)
                {
                    isDefault = true;
                }
                else
                {
                    if (caseLabel.BinaryOperatorType != BinaryOperatorType.None)
                    {
                        AddError(caseLabel, "VB's Case Is currently not supported (Daniel's too lazy for VB stuff)");
                    }
                    else
                    {
                        B.Expression expr = ConvertExpression(caseLabel.Label);
                        if (expr != null)
                        {
                            conditions.Add(new B.BinaryExpression(B.BinaryOperatorType.Equality,
                                                                  new B.ReferenceExpression(currentSwitchTempName),
                                                                  expr));
                            string labelName = expr.ToCodeString().GetHashCode().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
                            labels.Add(MakeLabel(currentSwitchTempName + "_" + labelName));
                        }
                    }
                }
            }
            B.IfStatement s = null;
            if (conditions.Count > 0)
            {
                s = new B.IfStatement(GetLexicalInfo(switchSection));
                if (surroundingIf != null)
                {
                    s.FalseBlock             = surroundingIf.FalseBlock;
                    surroundingIf.FalseBlock = new B.Block();
                    surroundingIf.FalseBlock.Add(s);
                }
                s.TrueBlock = new B.Block();
                foreach (B.Statement stmt in labels)
                {
                    s.TrueBlock.Add(stmt);
                }
                B.Expression combined = (B.Expression)conditions[0];
                for (int i = 1; i < conditions.Count; i++)
                {
                    combined = new B.BinaryExpression(B.BinaryOperatorType.Or, combined, (B.Expression)conditions[i]);
                }
                s.Condition = combined;
                foreach (Statement node in switchSection.Children)
                {
                    AddToBlock(node, s.TrueBlock);
                }
            }
            if (s == null)
            {
                s = surroundingIf;
            }
            if (isDefault)
            {
                if (s.FalseBlock == null)
                {
                    s.FalseBlock = new B.Block();
                }
                s.FalseBlock.Add(MakeLabel(currentSwitchTempName + "_default"));
                foreach (Statement node in switchSection.Children)
                {
                    AddToBlock(node, s.FalseBlock);
                }
            }
            return(s);
        }
Beispiel #49
0
 protected void init_parameter(AST.Expression pref, AST.Expression expr)
 {
 }
Beispiel #50
0
 public static AST.Expression when(AST.Expression expr)
 {
     AST.BlockExpression condition = new AST.BlockExpression();
     condition.Body.Add(new AST.ReturnStatement(expr));
     return(new AST.MethodInvocationExpression(new AST.ReferenceExpression("flow_condition"), condition, new AST.StringLiteralExpression(expr.ToCodeString())));
 }
Beispiel #51
0
 protected static AST.Expression multi_instance_split(AST.Expression expr)
 {
     AST.BlockExpression condition = new AST.BlockExpression();
     condition.Body.Add(new AST.ReturnStatement(expr));
     return(new AST.MethodInvocationExpression(new AST.ReferenceExpression("multi_instance_split_expression"), condition, new AST.StringLiteralExpression(expr.ToCodeString())));
 }