Esempio n. 1
0
		} // ExpressionStmt
	
	
	// Return an if/then or if/then/else statement.  If there was no else
	// clause, elseClause will be null.
	public StmtFrag IfThenElse( SrcLoc loc, ExprFrag condition,
								StmtFrag ifClause, StmtFrag elseClause )
		{
		CSharpStmtFrag frag = new CSharpStmtFrag(loc);
		
		CSharpExprFrag csCondition = (CSharpExprFrag)condition;
		frag.Append("if (Support.BoolTest(" + csCondition.GenerateRHS() + "))");
		frag.AppendIndentedBody(ifClause);
		
		if (elseClause != null)
			{
			frag.Append("else");
			frag.AppendIndentedBody(elseClause);
			}
		
		return frag;
		} // IfThenElse
Esempio n. 2
0
		} // Switch
	
	
	// Return a try...catch, try...finally, or try...catch...finally
	// statement.  If there was no "catch" clause, then catchVar, catchWithInfo,
	// and catchBody will be null.  If there was no "finally" clause, then
	// finallyBody will be null.  These parameters can't all be null (i.e.
	// at least one of the "catch" and "finally" clauses must have been
	// present).
	public StmtFrag TryCatchFinally( SrcLoc loc,
									 StmtFrag tryBody, string catchVar,
									 WithInfo catchWithInfo,
									 StmtFrag catchBody,
									 StmtFrag finallyBody )
		{
		CSharpStmtFrag frag = new CSharpStmtFrag(loc);
		
		frag.Append("try");
		frag.AppendIndentedBody(tryBody);
		
		if (catchBody != null)
			{
			CSharpWithInfo csWithInfo = (CSharpWithInfo)catchWithInfo;
			
			frag.Append("catch (Exception catchTemp_{0})", csWithInfo.index+1);
			frag.Indent();
			frag.Append("{");
			
			frag.Append( "JObject withTemp_{0} = Support.CreateCatchScope(catchTemp_{0}, \"{1}\");",
						 csWithInfo.index+1, catchVar );
			
			frag.Append(catchBody);
			
			frag.Append("}");
			frag.Outdent();
			}
		
		if (finallyBody != null)
			{
			frag.Append("finally");
			frag.AppendIndentedBody(finallyBody);
			}
		
		return frag;
		} // TryCatchFinally
Esempio n. 3
0
		} // NewSwitchInfo
	
	
	// Return a statement which evaluates the given expression.
	public StmtFrag ExpressionStmt(ExprFrag expr)
		{
		CSharpStmtFrag frag = new CSharpStmtFrag(expr.loc);
		frag.Append(((CSharpExprFrag)expr).GenerateRHS() + ";");
		return frag;
		} // ExpressionStmt
Esempio n. 4
0
		} // Return
	
	
	// Return a throw statement.
	public StmtFrag Throw(SrcLoc loc, ExprFrag value)
		{
		CSharpStmtFrag frag = new CSharpStmtFrag(loc);
		frag.Append("throw Support.WrapException(" + ((CSharpExprFrag)value).GenerateRHS() + ");");
		return frag;
		} // Throw
Esempio n. 5
0
		} // Throw
	
	
	// Return a with statement.
	public StmtFrag With(WithInfo withInfo, ExprFrag value, StmtFrag body)
		{
		CSharpWithInfo csWithInfo = (CSharpWithInfo)withInfo;
		CSharpStmtFrag frag = new CSharpStmtFrag(csWithInfo.loc);
		
		frag.Append( "object withTemp_{0} = ({1});",
					 csWithInfo.index+1, ((CSharpExprFrag)value).GenerateRHS() );
		frag.Append(body);
		
		return frag;
		} // With
Esempio n. 6
0
		} // LabeledStmt
	
	
	// Return a return statement.  value will be null if no value was
	// specified in the statement.
	public StmtFrag Return(SrcLoc loc, ExprFrag value)
		{
		CSharpStmtFrag frag = new CSharpStmtFrag(loc);
		
		if (value != null)
			frag.Append("return " + ((CSharpExprFrag)value).GenerateRHS() + ";");
		else
			frag.Append("return;");
		
		return frag;
		} // Return
Esempio n. 7
0
		} // Break
	
	
	// Return a statement which associated the specified LoopInfo with
	// an enclosing statement.  This should be called for switch statements,
	// and for any labeled statement which is not a loop statement.
	public StmtFrag LabeledStmt(LoopInfo loopInfo, StmtFrag stmt)
		{
		CSharpLoopInfo csLoopInfo = (CSharpLoopInfo)loopInfo;
		CSharpStmtFrag frag = new CSharpStmtFrag(csLoopInfo.loc);
		
		frag.Append(stmt);
		frag.Append("breakTarget_{0}: {1}", csLoopInfo.index + 1, "{}");
		
		return frag;
		} // LabeledStmt
Esempio n. 8
0
		} // Continue
	
	
	// Return a break statement.  label will be null if no label was
	// specified in the statement.  enclosingLoops should be a stack of
	// LoopInfo objects for all enclosing loops and labeled statements.
	public StmtFrag Break(SrcLoc loc, string label, Stack enclosingLoops)
		{
		CSharpLoopInfo targetLoop = null;
		foreach (object curLoop in enclosingLoops)
			{
			CSharpLoopInfo curCSLoop = (CSharpLoopInfo)curLoop;
			if ( (label == null && (curCSLoop.isLoop || curCSLoop.isSwitch)) ||
				 curCSLoop.labels.Contains(label) )
				{
				targetLoop = curCSLoop;
				break;
				}
			
			} // curLoop loop
		
		if (targetLoop == null)
			throw new ParseError( "can't find enclosing loop to match break label \"" + label + "\"",
								  loc );
		
		CSharpStmtFrag frag = new CSharpStmtFrag(loc);
		frag.Append(String.Format("goto breakTarget_{0};", targetLoop.index + 1));
		return frag;
		} // Break
Esempio n. 9
0
		} // WhileDo
	
	
	// Return a for statement.  init is the loop initializer, cond is the
	// loop control expression, and step is the loop increment expression.
	// Any or all of init, cond, and step can be null.
	public StmtFrag For( LoopInfo loopInfo, StmtFrag init,
						 ExprFrag cond, ExprFrag step, StmtFrag body )
		{
		CSharpLoopInfo csLoopInfo = (CSharpLoopInfo)loopInfo;
		CSharpStmtFrag frag = new CSharpStmtFrag(csLoopInfo.loc);
		
		frag.Append(init);
		
		CSharpExprFrag csCondition = (CSharpExprFrag)cond;
		frag.Append("while (Support.BoolTest(" + csCondition.GenerateRHS() + "))");
		((CSharpStmtFrag)body).Append("continueTarget_{0}:", csLoopInfo.index + 1);
		((CSharpStmtFrag)body).Append(ExpressionStmt(step));
		frag.AppendIndentedBody(body);
		frag.Append("breakTarget_{0}: {1}", csLoopInfo.index + 1, "{}");
		
		return frag;
		} // For
Esempio n. 10
0
		} // IfThenElse
	
	
	// Return a do...while statement.
	public StmtFrag DoWhile( LoopInfo loopInfo, StmtFrag body,
							 ExprFrag condition )
		{
		CSharpLoopInfo csLoopInfo = (CSharpLoopInfo)loopInfo;
		CSharpStmtFrag frag = new CSharpStmtFrag(csLoopInfo.loc);
		
		CSharpExprFrag csCondition = (CSharpExprFrag)condition;
		frag.Append("do");
		((CSharpStmtFrag)body).Append("continueTarget_{0}:", csLoopInfo.index + 1);
		frag.AppendIndentedBody(body);
		frag.Append("while (Support.BoolTest(" + csCondition.GenerateRHS() + "))");
		frag.Append("breakTarget_{0}: {1}", csLoopInfo.index + 1, "{}");
		
		return frag;
		} // DoWhile