Ejemplo n.º 1
0
        public static Statement MapStatementModifier(StatementModifier modifier, out Block block)
        {
            switch (modifier.Type)
            {
                case StatementModifierType.If:
                {
                    IfStatement stmt = new IfStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    stmt.TrueBlock = new Block();
                    block = stmt.TrueBlock;
                    return stmt;
                }

                case StatementModifierType.Unless:
                {
                    UnlessStatement stmt = new UnlessStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    block = stmt.Block;
                    return stmt;
                }

                case StatementModifierType.While:
                {
                    WhileStatement stmt = new WhileStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    block = stmt.Block;
                    return stmt;
                }
            }
            throw CompilerErrorFactory.NotImplemented(modifier, string.Format("modifier {0} supported", modifier.Type));
        }
Ejemplo n.º 2
0
        public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data)
        {
            bool frontCondition  = doLoopStatement.ConditionPosition != ConditionPosition.End;
            bool negateCondition = doLoopStatement.ConditionType == ConditionType.Until;

            if (frontCondition && negateCondition)
            {
                // VB: Do Unless * : ** : Loop
                B.UnlessStatement u = new B.UnlessStatement(GetLexicalInfo(doLoopStatement));
                u.Condition = ConvertExpression(doLoopStatement.Condition);
                u.Block     = ConvertBlock(doLoopStatement.EmbeddedStatement);
                return(u);
            }
            // While and Do loop
            B.WhileStatement w = new B.WhileStatement(GetLexicalInfo(doLoopStatement));
            if (frontCondition)
            {
                w.Condition = ConvertExpression(doLoopStatement.Condition);
            }
            else
            {
                w.Condition = new B.BoolLiteralExpression(true);
            }
            w.Block = ConvertBlock(doLoopStatement.EmbeddedStatement);
            if (!frontCondition)
            {
                B.BreakStatement breakStatement = new B.BreakStatement();
                breakStatement.Modifier = new B.StatementModifier(negateCondition ? B.StatementModifierType.If : B.StatementModifierType.Unless,
                                                                  ConvertExpression(doLoopStatement.Condition));
                w.Block.Add(breakStatement);
            }
            return(w);
        }
Ejemplo n.º 3
0
        override public object Clone()
        {
            UnlessStatement clone = (UnlessStatement)FormatterServices.GetUninitializedObject(typeof(UnlessStatement));

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }

            if (null != _modifier)
            {
                clone._modifier = _modifier.Clone() as StatementModifier;
                clone._modifier.InitializeParent(clone);
            }
            if (null != _condition)
            {
                clone._condition = _condition.Clone() as Expression;
                clone._condition.InitializeParent(clone);
            }
            if (null != _block)
            {
                clone._block = _block.Clone() as Block;
                clone._block.InitializeParent(clone);
            }
            return(clone);
        }
Ejemplo n.º 4
0
        override public object Clone()
        {
            UnlessStatement clone = new UnlessStatement();

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }
            if (null != _modifier)
            {
                clone._modifier = _modifier.Clone() as StatementModifier;
                clone._modifier.InitializeParent(clone);
            }
            if (null != _condition)
            {
                clone._condition = _condition.Clone() as Expression;
                clone._condition.InitializeParent(clone);
            }
            if (null != _block)
            {
                clone._block = _block.Clone() as Block;
                clone._block.InitializeParent(clone);
            }
            return(clone);
        }
Ejemplo n.º 5
0
	protected UnlessStatement  unless_stmt() //throws RecognitionException, TokenStreamException
{
		UnlessStatement us;
		
		IToken  u = null;
		
				us = null;
				Expression condition = null;
			
		
		try {      // for error handling
			u = LT(1);
			match(UNLESS);
			condition=expression();
			if (0==inputState.guessing)
			{
				
						us = new UnlessStatement(ToLexicalInfo(u));
						us.Condition = condition;
					
			}
			compound_stmt(us.Block);
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "unless_stmt");
				recover(ex,tokenSet_84_);
			}
			else
			{
				throw ex;
			}
		}
		return us;
	}
Ejemplo n.º 6
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     Label endLabel = _il.DefineLabel();
     EmitDebugInfo(node);
     EmitBranchTrue(node.Condition, endLabel);
     node.Block.Accept(this);
     _il.MarkLabel(endLabel);
 }
		public override void OnUnlessStatement(UnlessStatement node)
		{
			base.OnUnlessStatement(node);
			node.Condition = FixCondition(node.Condition);
		}
Ejemplo n.º 8
0
 public override void LeaveUnlessStatement(UnlessStatement node)
 {
     node.Condition = AssertBoolContext(node.Condition);
 }
Ejemplo n.º 9
0
 public override void LeaveUnlessStatement(UnlessStatement node)
 {
     node.Condition = ExplicitBooleanContext(node.Condition);
 }
Ejemplo n.º 10
0
		override public object Clone()
		{
		
			UnlessStatement clone = new UnlessStatement();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			if (null != _modifier)
			{
				clone._modifier = _modifier.Clone() as StatementModifier;
				clone._modifier.InitializeParent(clone);
			}
			if (null != _condition)
			{
				clone._condition = _condition.Clone() as Expression;
				clone._condition.InitializeParent(clone);
			}
			if (null != _block)
			{
				clone._block = _block.Clone() as Block;
				clone._block.InitializeParent(clone);
			}
			return clone;


		}
Ejemplo n.º 11
0
		void CreateMoveNext()
		{
			BooMethodBuilder method = _enumerator.AddVirtualMethod("MoveNext", TypeSystemServices.BoolType);
			
			Expression moveNext = CodeBuilder.CreateMethodInvocation(
				CodeBuilder.CreateReference((InternalField)_enumeratorField.Entity),
				TypeSystemServices.Map(Methods.InstanceFunctionOf<IEnumerator, bool>(e => e.MoveNext)));
						
			Expression current = CodeBuilder.CreateMethodInvocation(
				CodeBuilder.CreateReference((InternalField)_enumeratorField.Entity),
				((IProperty)GetMember(_sourceEnumeratorType, "Current", EntityType.Property)).GetGetMethod());
			
			Statement filter = null;
			Statement stmt = null;
			Block outerBlock = null;
			Block innerBlock = null;
			
			if (null == _generator.Filter)
			{
				IfStatement istmt = new IfStatement(moveNext, new Block(), null);
				outerBlock = innerBlock = istmt.TrueBlock;
				
				stmt = istmt;
			}
			else
			{
				WhileStatement wstmt = new WhileStatement(moveNext);
				outerBlock = wstmt.Block;
				
				if (StatementModifierType.If == _generator.Filter.Type)
				{
					IfStatement ifstmt = new IfStatement(_generator.Filter.Condition, new Block(), null);
					innerBlock = ifstmt.TrueBlock;
					filter = ifstmt;
				}
				else
				{
					UnlessStatement ustmt = new UnlessStatement(_generator.Filter.Condition);
					innerBlock = ustmt.Block;
					filter = ustmt;
				}
				
				stmt = wstmt;
			}
												
			DeclarationCollection declarations = _generator.Declarations;
			if (declarations.Count > 1)
			{
				NormalizeIterationStatements.UnpackExpression(CodeBuilder,
				                                              method.Method,
				                                              outerBlock,
				                                              current,
				                                              declarations);
												
				foreach (Declaration declaration in declarations)
				{
					method.Locals.Add(((InternalLocal)declaration.Entity).Local);
				}
			}
			else
			{
				InternalLocal local = (InternalLocal)declarations[0].Entity;
				method.Locals.Add(local.Local);
				outerBlock.Add(CodeBuilder.CreateAssignment(
				               	CodeBuilder.CreateReference(local),
				               	current));
			}
			
			if (null != filter)
			{
				outerBlock.Add(filter);
			}
			
			innerBlock.Add(CodeBuilder.CreateAssignment(
			               	CodeBuilder.CreateReference((InternalField)_current.Entity),
			               	_generator.Expression));
			innerBlock.Add(new ReturnStatement(new BoolLiteralExpression(true)));
			
			method.Body.Add(stmt);
			method.Body.Add(new ReturnStatement(new BoolLiteralExpression(false)));
		}
		public override void OnUnlessStatement(UnlessStatement node) { }
Ejemplo n.º 13
0
 public override void LeaveUnlessStatement(UnlessStatement node)
 {
     CheckNotConstant(node.Condition);
 }
Ejemplo n.º 14
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     WriteConditionalBlock("unless", node.Condition, node.Block);
 }
		public object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data)
		{
			bool frontCondition = doLoopStatement.ConditionPosition != ConditionPosition.End;
			bool negateCondition = doLoopStatement.ConditionType == ConditionType.Until;
			if (frontCondition && negateCondition) {
				// VB: Do Unless * : ** : Loop
				B.UnlessStatement u = new B.UnlessStatement(GetLexicalInfo(doLoopStatement));
				u.Condition = ConvertExpression(doLoopStatement.Condition);
				u.Block = ConvertBlock(doLoopStatement.EmbeddedStatement);
				return u;
			}
			// While and Do loop
			B.WhileStatement w = new B.WhileStatement(GetLexicalInfo(doLoopStatement));
			if (frontCondition)
				w.Condition = ConvertExpression(doLoopStatement.Condition);
			else
				w.Condition = new B.BoolLiteralExpression(true);
			w.Block = ConvertBlock(doLoopStatement.EmbeddedStatement);
			if (!frontCondition) {
				B.BreakStatement breakStatement = new B.BreakStatement();
				breakStatement.Modifier = new B.StatementModifier(negateCondition ? B.StatementModifierType.If : B.StatementModifierType.Unless,
				                                                  ConvertExpression(doLoopStatement.Condition));
				w.Block.Add(breakStatement);
			}
			return w;
		}