本文整理汇总了C#中ImmutableStack.Push方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableStack.Push方法的具体用法?C# ImmutableStack.Push怎么用?C# ImmutableStack.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableStack
的用法示例。
在下文中一共展示了ImmutableStack.Push方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewStateValue
private State CreateNewStateValue(ImmutableStack<Tuple<int, string>> finallyStack, string finallyHandlerToPush = null) {
int value = _nextStateIndex++;
finallyStack = finallyHandlerToPush != null ? finallyStack.Push(Tuple.Create(value, finallyHandlerToPush)) : finallyStack;
var result = new State(_currentLoopLabel, value, finallyStack);
_allStates.Add(result);
return result;
}
示例2: Blender
public Blender(Lexer lexer, CSharp.CSharpSyntaxNode oldTree, IEnumerable<TextChangeRange> changes)
{
Debug.Assert(lexer != null);
_lexer = lexer;
_changes = ImmutableStack.Create<TextChangeRange>();
if (changes != null)
{
// TODO: Consider implementing NormalizedChangeCollection for TextSpan. the real
// reason why we are collapsing is because we want to extend change ranges and
// cannot allow them to overlap. This does not seem to be a big deal since multiple
// changes are infrequent and typically close to each other. However if we have
// NormalizedChangeCollection for TextSpan we can have both - we can extend ranges
// and not require collapsing them. NormalizedChangeCollection would also ensure
// that changes are always normalized.
// TODO: this is a temporary measure to prevent individual change spans from
// overlapping after they are widened to effective width (+1 token at the start).
// once we have normalized collection for TextSpan we will not need to collapse all
// the change spans.
var collapsed = TextChangeRange.Collapse(changes);
// extend the change to its affected range. This will make it easier
// to filter out affected nodes since we will be able simply check
// if node intersects with a change.
var affectedRange = ExtendToAffectedRange(oldTree, collapsed);
_changes = _changes.Push(affectedRange);
}
if (oldTree == null)
{
// start at lexer current position if no nodes specified
_oldTreeCursor = new Cursor();
_newPosition = lexer.TextWindow.Position;
}
else
{
_oldTreeCursor = Cursor.FromRoot(oldTree).MoveToFirstChild();
_newPosition = 0;
}
_changeDelta = 0;
_newDirectives = default(DirectiveStack);
_oldDirectives = default(DirectiveStack);
_newLexerDrivenMode = 0;
}
示例3: RecEnumerateOutcomes
RecEnumerateOutcomes(
ImmutableStack<Func<DiscriminatedUnionCaseParameter, DestructureMethodParameter>> results,
Func<DiscriminatedUnionCaseParameter, DestructureMethodParameter>[] resultTypes,
int numIterations)
{
if (results.Count() >= numIterations)
{
yield return results;
}
else
{
foreach (var resultType in resultTypes)
{
foreach (var a in RecEnumerateOutcomes(results.Push(resultType), resultTypes, numIterations))
{
yield return a;
}
}
}
}
示例4: PushFollowing
private ImmutableStack<StackEntry> PushFollowing(ImmutableStack<StackEntry> stack, StackEntry location)
{
return location.Index < location.Block.Statements.Count - 1 ? stack.Push(new StackEntry(location.Block, location.Index + 1)) : stack;
}
示例5: HandleWhileStatement
private bool HandleWhileStatement(JsWhileStatement stmt, StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState, IList<JsStatement> currentBlock)
{
if (currentBlock.Count > 0) {
// We have to create a new block for the statement.
var topOfLoopState = CreateNewStateValue(currentState.FinallyStack);
Enqueue(stack.Push(location), breakStack, continueStack, topOfLoopState, returnState);
currentBlock.Add(new JsGotoStateStatement(topOfLoopState, currentState));
return false;
}
else {
var afterLoopState = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
currentBlock.Add(new JsIfStatement(JsExpression.LogicalNot(stmt.Condition), new JsGotoStateStatement(afterLoopState.Item1, currentState), null));
var currentName = GetLabelForState(currentState);
currentBlock.AddRange(Handle(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(stmt.Body, 0)), breakStack.Push(Tuple.Create(currentName, afterLoopState.Item1)), continueStack.Push(Tuple.Create(currentName, currentState)), currentState, currentState));
if (!stack.IsEmpty || location.Index < location.Block.Statements.Count - 1) {
Enqueue(PushFollowing(stack, location), breakStack, continueStack, afterLoopState.Item1, returnState);
}
return false;
}
}
示例6: HandleSwitchStatement
private bool HandleSwitchStatement(JsSwitchStatement stmt, StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState, IList<JsStatement> currentBlock)
{
var stateAfter = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
JsExpression expression = stmt.Expression;
if (_isExpressionComplexEnoughForATemporaryVariable(expression)) {
string newName = _allocateTempVariable();
currentBlock.Add(new JsVariableDeclarationStatement(newName, expression));
expression = JsExpression.Identifier(newName);
}
var clauses = new List<Tuple<JsExpression, JsBlockStatement>>();
JsStatement defaultClause = null;
State? currentFallthroughState = null;
for (int i = 0; i < stmt.Sections.Count; i++) {
var clause = stmt.Sections[i];
var origBody = new List<JsStatement>();
origBody.AddRange(clause.Body.Statements);
State? nextFallthroughState;
if (i < stmt.Sections.Count - 1 && (origBody.Count == 0 || IsNextStatementReachable(origBody[origBody.Count - 1]))) {
// Fallthrough
var nextBody = stmt.Sections[i + 1].Body.Statements;
if (nextBody.Count > 0 && nextBody[0] is JsLabelledStatement)
nextFallthroughState = GetOrCreateStateForLabel(((JsLabelledStatement)nextBody[0]).Label, currentState.FinallyStack);
else
nextFallthroughState = CreateNewStateValue(currentState.FinallyStack);
}
else {
nextFallthroughState = null;
}
breakStack = breakStack.Push(Tuple.Create(GetLabelForState(currentState), stateAfter.Item1));
IList<JsStatement> body;
if (currentFallthroughState != null) {
body = new List<JsStatement>();
body.Add(new JsGotoStateStatement(currentFallthroughState.Value, currentState));
Enqueue(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(new JsBlockStatement(origBody), 0)), breakStack, continueStack, currentFallthroughState.Value, stateAfter.Item1);
}
else {
body = Handle(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(new JsBlockStatement(origBody), 0)), breakStack, continueStack, currentState, nextFallthroughState ?? stateAfter.Item1);
}
if (clause.Values.Any(v => v == null)) {
defaultClause = new JsBlockStatement(body);
}
else {
JsExpression test = clause.Values.Select(v => JsExpression.Same(expression, v)).Aggregate((o, e) => o != null ? JsExpression.LogicalOr(o, e) : e);
clauses.Add(Tuple.Create(test, new JsBlockStatement(body)));
}
currentFallthroughState = nextFallthroughState;
}
clauses.Reverse();
currentBlock.Add(clauses.Where(c => c.Item1 != null).Aggregate(defaultClause, (o, n) => new JsIfStatement(n.Item1, n.Item2, o)));
currentBlock.Add(new JsGotoStateStatement(stateAfter.Item1, currentState));
if (stateAfter.Item2) {
Enqueue(PushFollowing(stack, location), breakStack, continueStack, stateAfter.Item1, returnState);
return false;
}
return true;
}
示例7: HandleDoWhileStatement
private bool HandleDoWhileStatement(JsDoWhileStatement stmt, StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState, IList<JsStatement> currentBlock)
{
if (currentBlock.Count > 0) {
// We have to create a new block for the statement.
var topOfLoopState = CreateNewStateValue(currentState.FinallyStack);
Enqueue(stack.Push(location), breakStack, continueStack, topOfLoopState, returnState);
currentBlock.Add(new JsGotoStateStatement(topOfLoopState, currentState));
return false;
}
else {
var beforeConditionState = CreateNewStateValue(currentState.FinallyStack);
Tuple<State, bool> afterLoopState;
string currentName = GetLabelForState(currentState);
if (new ContainsBreakVisitor().Analyze(stmt.Body, currentName)) {
afterLoopState = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
breakStack = breakStack.Push(Tuple.Create(currentName, afterLoopState.Item1));
}
else {
afterLoopState = Tuple.Create(returnState, false);
}
currentBlock.AddRange(Handle(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(stmt.Body, 0)), breakStack, continueStack.Push(Tuple.Create(GetLabelForState(currentState), beforeConditionState)), currentState, beforeConditionState));
if (afterLoopState.Item2) {
Enqueue(PushFollowing(stack, location), breakStack, continueStack, afterLoopState.Item1, returnState);
Enqueue(stack.Push(new StackEntry(new JsBlockStatement(new JsIfStatement(stmt.Condition, new JsGotoStateStatement(currentState, currentState), null)), 0)), breakStack, continueStack, beforeConditionState, afterLoopState.Item1);
}
else {
Enqueue(PushFollowing(stack, location).Push(new StackEntry(new JsBlockStatement(new JsIfStatement(stmt.Condition, new JsGotoStateStatement(currentState, currentState), null)), 0)), breakStack, continueStack, beforeConditionState, returnState);
}
return false;
}
}
示例8: Handle
private List<JsStatement> Handle(ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState)
{
var currentBlock = new List<JsStatement>();
while (!stack.IsEmpty) {
var tos = stack.Peek();
stack = stack.Pop();
var stmt = tos.Block.Statements[tos.Index];
var lbl = stmt as JsLabelledStatement;
if (lbl != null) {
if (_processedStates.Contains(GetOrCreateStateForLabel(lbl.Label, currentState.FinallyStack))) {
// First statement in the new block
stmt = lbl.Statement;
}
else {
// A label that terminates the current block.
Enqueue(stack.Push(new StackEntry(tos.Block, tos.Index)), breakStack, continueStack, GetOrCreateStateForLabel(lbl.Label, currentState.FinallyStack), returnState);
if (currentBlock.Count == 0 || IsNextStatementReachable(currentBlock[currentBlock.Count - 1]))
currentBlock.Add(new JsGotoStateStatement(GetOrCreateStateForLabel(lbl.Label, currentState.FinallyStack), currentState));
return currentBlock;
}
}
if (stmt is JsYieldStatement) {
var ystmt = (JsYieldStatement)stmt;
if (ystmt.Value != null) {
if (!HandleYieldReturnStatement(ystmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else {
currentBlock.AddRange(new NestedJumpStatementRewriter(breakStack, continueStack, currentState, _exitState.Value).Process(stmt));
stack = PushFollowing(stack, tos);
}
}
else if (stmt is JsTryStatement) {
if (!HandleTryStatement((JsTryStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
stack = PushFollowing(stack, tos);
}
else if (FindInterestingConstructsVisitor.Analyze(stmt, InterestingConstruct.YieldReturn | InterestingConstruct.Label)) {
if (stmt is JsBlockStatement) {
stack = PushFollowing(stack, tos).Push(new StackEntry((JsBlockStatement)stmt, 0));
}
else {
if (stmt is JsIfStatement) {
if (!HandleIfStatement((JsIfStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else if (stmt is JsDoWhileStatement) {
if (!HandleDoWhileStatement((JsDoWhileStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else if (stmt is JsWhileStatement) {
if (!HandleWhileStatement((JsWhileStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else if (stmt is JsForStatement) {
if (!HandleForStatement((JsForStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else if (stmt is JsSwitchStatement) {
if (!HandleSwitchStatement((JsSwitchStatement)stmt, tos, stack, breakStack, continueStack, currentState, returnState, currentBlock))
return currentBlock;
}
else {
throw new NotSupportedException("Statement " + stmt + " cannot contain labels.");
}
stack = PushFollowing(stack, tos);
}
}
else {
currentBlock.AddRange(new NestedJumpStatementRewriter(breakStack, continueStack, currentState, _exitState.Value).Process(stmt));
stack = PushFollowing(stack, tos);
}
}
if (currentBlock.Count == 0 || IsNextStatementReachable(currentBlock[currentBlock.Count - 1]))
currentBlock.Add(new JsGotoStateStatement(returnState, currentState));
return currentBlock;
}
示例9: HandleForStatement
private bool HandleForStatement(JsForStatement stmt, StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState, IList<JsStatement> currentBlock, bool isFirstStatement) {
if (!(isFirstStatement && (stmt.InitStatement is JsEmptyStatement || location.AfterForInitializer))) {
// We have to create a new block for the statement.
var topOfLoopState = CreateNewStateValue(currentState.FinallyStack);
Enqueue(stack.Push(new StackEntry(location.Block, location.Index, true)), breakStack, continueStack, topOfLoopState, returnState);
if (!(stmt.InitStatement is JsEmptyStatement))
currentBlock.Add(stmt.InitStatement);
currentBlock.Add(new JsGotoStateStatement(topOfLoopState, currentState));
return false;
}
else {
var iteratorState = (stmt.IteratorExpression != null ? CreateNewStateValue(currentState.FinallyStack) : currentState);
var afterLoopState = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
if (stmt.ConditionExpression != null)
currentBlock.Add(JsStatement.If(JsExpression.LogicalNot(stmt.ConditionExpression), new JsGotoStateStatement(afterLoopState.Item1, currentState), null));
string currentName = GetLabelForState(currentState);
currentBlock.AddRange(Handle(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(stmt.Body, 0)), breakStack.Push(Tuple.Create(currentName, afterLoopState.Item1)), continueStack.Push(Tuple.Create(currentName, iteratorState)), currentState, iteratorState, false, false));
if (stmt.IteratorExpression != null) {
Enqueue(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(JsStatement.Block(stmt.IteratorExpression), 0)), breakStack, continueStack, iteratorState, currentState);
}
if (!stack.IsEmpty || location.Index < location.Block.Statements.Count - 1) {
Enqueue(PushFollowing(stack, location), breakStack, continueStack, afterLoopState.Item1, returnState);
}
return false;
}
}
示例10: HandleTryStatement
private bool HandleTryStatement(JsTryStatement stmt, StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<string, State>> breakStack, ImmutableStack<Tuple<string, State>> continueStack, State currentState, State returnState, IList<JsStatement> currentBlock, bool isFirstStatement) {
if (_isIteratorBlock && (FindInterestingConstructsVisitor.Analyze(stmt.GuardedStatement, InterestingConstruct.YieldReturn) || (stmt.Finally != null && stmt.Catch == null && !currentState.FinallyStack.IsEmpty))) {
if (stmt.Catch != null)
throw new InvalidOperationException("Cannot yield return from try with catch");
string handlerName = _allocateFinallyHandler();
JsBlockStatement handler;
if (FindInterestingConstructsVisitor.Analyze(stmt.Finally, InterestingConstruct.Label)) {
var inner = ProcessInner(stmt.Finally, breakStack, continueStack, currentState.FinallyStack, currentState.StateValue);
handler = JsStatement.Block(new[] { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1));
handler = new FinalizerRewriter(_stateVariableName, _labelStates).Process(handler);
}
else {
handler = stmt.Finally;
}
_finallyHandlers.Add(Tuple.Create(handlerName, handler));
var stateAfter = GetStateAfterStatement(location, stack, currentState.FinallyStack, returnState);
var innerState = CreateNewStateValue(currentState.FinallyStack, handlerName);
var stateBeforeFinally = CreateNewStateValue(innerState.FinallyStack);
currentBlock.Add(new JsSetNextStateStatement(innerState.StateValue));
currentBlock.AddRange(Handle(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(stmt.GuardedStatement, 0)), breakStack, continueStack, new State(currentState.LoopLabelName, currentState.StateValue, innerState.FinallyStack), stateBeforeFinally, false, false));
Enqueue(ImmutableStack<StackEntry>.Empty.Push(new StackEntry(JsStatement.Block(JsStatement.BlockMerged(new JsStatement[0])), 0)), breakStack, continueStack, stateBeforeFinally, stateAfter.Item1);
if (!stack.IsEmpty || location.Index < location.Block.Statements.Count - 1) {
Enqueue(PushFollowing(stack, location), breakStack, continueStack, stateAfter.Item1, returnState);
}
return false;
}
else if (_isIteratorBlock && stmt.Finally != null && !currentState.FinallyStack.IsEmpty) {
// This is necessary to special-case in order to ensure that the inner finally block is executed before all outer ones.
return HandleTryStatement(JsStatement.Try(JsStatement.Try(stmt.GuardedStatement, stmt.Catch, null), null, stmt.Finally), location, stack, breakStack, continueStack, currentState, returnState, currentBlock, isFirstStatement);
}
else {
var rewriter = new NestedStatementFixer(breakStack, continueStack, currentState, _exitState.Value, _makeSetResult);
JsBlockStatement guarded;
var guardedConstructs = FindInterestingConstructsVisitor.Analyze(stmt.GuardedStatement);
if ((guardedConstructs & (InterestingConstruct.Label | InterestingConstruct.Await)) != InterestingConstruct.None) {
if (!isFirstStatement) {
var sv = CreateNewStateValue(currentState.FinallyStack);
Enqueue(stack.Push(location), breakStack, continueStack, sv, returnState);
currentBlock.Add(new JsGotoStateStatement(sv, currentState));
return false;
}
var inner = ProcessInner(stmt.GuardedStatement, breakStack, continueStack, currentState.FinallyStack, currentState.StateValue);
guarded = JsStatement.Block(inner.Item1);
currentBlock.Add(new JsSetNextStateStatement(inner.Item2));
}
else {
guarded = rewriter.Process(stmt.GuardedStatement);
}
JsCatchClause @catch;
if (stmt.Catch != null) {
if (FindInterestingConstructsVisitor.Analyze(stmt.Catch.Body, InterestingConstruct.Label)) {
var inner = ProcessInner(stmt.Catch.Body, breakStack, continueStack, currentState.FinallyStack, null);
@catch = JsStatement.Catch(stmt.Catch.Identifier, JsStatement.Block(new[] { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1)));
}
else {
var body = rewriter.Process(stmt.Catch.Body);
@catch = ReferenceEquals(body, stmt.Catch.Body) ? stmt.Catch : JsStatement.Catch(stmt.Catch.Identifier, body);
}
}
else
@catch = null;
JsBlockStatement @finally;
if (stmt.Finally != null) {
if (FindInterestingConstructsVisitor.Analyze(stmt.Finally, InterestingConstruct.Label)) {
var inner = ProcessInner(stmt.Finally, breakStack, continueStack, currentState.FinallyStack, null);
@finally = JsStatement.Block(new[] { new JsSetNextStateStatement(inner.Item2) }.Concat(inner.Item1));
}
else
@finally = rewriter.Process(stmt.Finally);
if ((guardedConstructs & InterestingConstruct.Await) != InterestingConstruct.None) {
// Wrap the finally block inside an 'if (doFinallyBlocks) {}'
@finally = JsStatement.Block(JsStatement.If(JsExpression.Identifier(_doFinallyBlocksVariableName), @finally, null));
}
}
else
@finally = null;
if (currentBlock.Count > 0 && _childStates.ContainsKey(currentState.StateValue)) {
var newBlock = JsStatement.If(JsExpression.Same(JsExpression.Identifier(_stateVariableName), JsExpression.Number(currentState.StateValue)), JsStatement.Block(currentBlock), null);
currentBlock.Clear();
currentBlock.Add(newBlock);
}
currentBlock.Add(JsStatement.Try(guarded, @catch, @finally));
return true;
}
}