提交 4a416a9a 编写于 作者: N Neal Gafter

Snapshot of working status

上级 805ca66a
......@@ -110,7 +110,7 @@ private void LowerDecisionTree(DecisionTree.ByType byType, HashSet<LabelSymbol>
BoundExpression notNull = byType.Type.IsNullableType()
? this.RewriteNullableNullEquality(_factory.Syntax, BinaryOperatorKind.NullableNullNotEqual, byType.Expression, nullValue, _factory.SpecialType(SpecialType.System_Boolean))
: _factory.ObjectNotEqual(byType.Expression, nullValue);
result.Add(_factory.If(notNull, _factory.Goto(notNullLabel)));
result.Add(_factory.ConditionalGoto(notNull, notNullLabel, true));
LowerDecisionTree(byType.WhenNull, usedLabels, usedTemps, result);
result.Add(_factory.Goto(defaultLabel));
result.Add(_factory.Label(notNullLabel));
......@@ -125,8 +125,8 @@ private void LowerDecisionTree(DecisionTree.ByType byType, HashSet<LabelSymbol>
var type = td.Key;
var decision = td.Value;
var failLabel = _factory.GenerateLabel("failedDecision");
grep("if there is a fresh temp needed, copy to it and add the temp from ", decision.Expression, " to ", usedTemps);
grep("test for the type ", type, " into that temp and goto failLabel when that fails");
var testAndCopy = TypeTestAndCopyToTemp(byType.Expression, decision.Expression);
result.Add(_factory.ConditionalGoto(testAndCopy, failLabel, false));
LowerDecisionTree(decision, usedLabels, usedTemps, result);
result.Add(_factory.Label(failLabel));
}
......@@ -135,6 +135,18 @@ private void LowerDecisionTree(DecisionTree.ByType byType, HashSet<LabelSymbol>
LowerDecisionTree(byType.Default, usedLabels, usedTemps, result);
}
private BoundExpression TypeTestAndCopyToTemp(BoundExpression input, BoundExpression temp)
{
if (input == temp)
{
// if the expression is the same, no need to type test and copy to temp
return _factory.Literal(true);
}
Debug.Assert(temp.Kind == BoundKind.Local);
return MakeDeclarationPattern(_factory.Syntax, input, ((BoundLocal)temp).LocalSymbol);
}
private void LowerDecisionTree(DecisionTree.ByValue byValue, HashSet<LabelSymbol> usedLabels, HashSet<LocalSymbol> usedTemps, ArrayBuilder<BoundStatement> result)
{
throw new NotImplementedException();
......
......@@ -646,6 +646,11 @@ public BoundStatement If(BoundExpression condition, BoundStatement thenClause, B
return If(condition, ImmutableArray<LocalSymbol>.Empty, thenClause, elseClauseOpt);
}
public BoundStatement ConditionalGoto(BoundExpression condition, LabelSymbol label, bool jumpIfTrue)
{
return new BoundConditionalGoto(Syntax, condition, jumpIfTrue, label) { WasCompilerGenerated = true };
}
public BoundStatement If(BoundExpression condition, ImmutableArray<LocalSymbol> locals, BoundStatement thenClause, BoundStatement elseClauseOpt = null)
{
// We translate
......@@ -668,7 +673,7 @@ public BoundStatement If(BoundExpression condition, ImmutableArray<LocalSymbol>
{
var alt = new GeneratedLabelSymbol("alternative");
statements.Add(new BoundConditionalGoto(Syntax, condition, false, alt) { WasCompilerGenerated = true });
statements.Add(ConditionalGoto(condition, alt, false));
statements.Add(thenClause);
statements.Add(Goto(afterif));
if (!locals.IsDefaultOrEmpty)
......@@ -683,7 +688,7 @@ public BoundStatement If(BoundExpression condition, ImmutableArray<LocalSymbol>
}
else
{
statements.Add(new BoundConditionalGoto(Syntax, condition, false, afterif) { WasCompilerGenerated = true });
statements.Add(ConditionalGoto(condition, afterif, false));
statements.Add(thenClause);
if (!locals.IsDefaultOrEmpty)
{
......@@ -697,34 +702,6 @@ public BoundStatement If(BoundExpression condition, ImmutableArray<LocalSymbol>
return Block(statements.ToImmutableAndFree());
}
public BoundStatement For(BoundExpression initialization, BoundExpression termination, BoundExpression increment, BoundStatement body)
{
// for(<initialization>; <increment>; <termination>)
// {
// <body>;
// }
// Lowered form:
// <initialization>;
// goto LoopCondition;
// LoopStart:
// <body>
// <increment>
// LoopCondition:
// if(<termination>)
// goto LoopStart;
var lLoopStart = GenerateLabel("LoopStart");
var lLoopCondition = GenerateLabel("LoopCondition");
return Block(ExpressionStatement(initialization),
Goto(lLoopCondition),
Label(lLoopStart),
body,
ExpressionStatement(increment),
Label(lLoopCondition),
If(termination, Goto(lLoopStart)));
}
public BoundThrowStatement Throw(BoundExpression e = null)
{
return new BoundThrowStatement(Syntax, e) { WasCompilerGenerated = true };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册