本文整理汇总了C#中ImmutableStack.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableStack.Peek方法的具体用法?C# ImmutableStack.Peek怎么用?C# ImmutableStack.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableStack
的用法示例。
在下文中一共展示了ImmutableStack.Peek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PositionNewUnit
public static PositionedUnit PositionNewUnit(int width, ImmutableStack<Unit> nextUnits)
{
if (nextUnits.IsEmpty) return PositionedUnit.Null;
var u = nextUnits.Peek();
var topmostY = u.Displacements[0].Min(m => m.ToMap().Y);
var pos = new PositionedUnit(u, 0, new Point(0, -topmostY));
var leftMargin = pos.Members.Min(m => m.X);
var rightMargin = width - 1 - pos.Members.Max(m => m.X);
var newX = (rightMargin - leftMargin) / 2;
return new PositionedUnit(u, 0, new Point(newX, -topmostY));
}
示例2: GetFileScope
private static LoggerFileScope GetFileScope(ImmutableStack<string> parents)
{
if (!parents.IsEmpty)
{
var path = StringExtension.ToDisplayPath(parents.Peek());
if (!string.IsNullOrEmpty(path))
{
return new LoggerFileScope(path);
}
}
return null;
}
示例3: 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;
}
示例4: CreateElements
List<InternalObject> CreateElements(ref ImmutableStack<InternalObject> inputObjects)
{
List<InternalObject> objects = new List<InternalObject>();
while (!inputObjects.IsEmpty) {
var obj = inputObjects.Peek();
var tag = obj as InternalTag;
if (tag != null && tag.IsStartTag)
break;
inputObjects = inputObjects.Pop();
if (tag != null && tag.IsEndTag) {
if (inputObjects.Peek() == StartTagPlaceholder) {
objects.Add(tag.AddSyntaxError("Matching opening tag was not found"));
inputObjects = inputObjects.Pop();
} else {
var childElements = CreateElements(ref inputObjects);
var startTag = (InternalTag)inputObjects.Peek();
inputObjects = inputObjects.Pop();
childElements.Add(startTag);
childElements.Reverse();
if (tag != EndTagPlaceholder) {
// add end tag
if (startTag.Name != tag.Name) {
childElements.Add(tag.AddSyntaxError("Expected '</" + startTag.Name + ">'. End tag must have same name as start tag."));
} else {
childElements.Add(tag);
}
}
InternalElement e = new InternalElement(startTag);
e.HasEndTag = (tag != EndTagPlaceholder);
e.NestedObjects = new InternalObject[childElements.Count];
int pos = 0;
for (int i = 0; i < childElements.Count; i++) {
e.NestedObjects[i] = childElements[i].SetStartRelativeToParent(pos);
pos += e.NestedObjects[i].Length;
}
e.Length = pos;
if (tag == EndTagPlaceholder) {
e.SyntaxErrors = new [] { new InternalSyntaxError(pos, pos, "Missing '</" + startTag.Name + ">'") };
}
objects.Add(e);
}
} else {
objects.Add(obj);
}
}
return objects;
}
示例5: GetStateAfterStatement
private Tuple<State, bool> GetStateAfterStatement(StackEntry location, ImmutableStack<StackEntry> stack, ImmutableStack<Tuple<int, string>> finallyStack, State returnState)
{
JsStatement next;
if (location.Index < location.Block.Statements.Count - 1) {
next = location.Block.Statements[location.Index + 1];
}
else if (!stack.IsEmpty) {
var tos = stack.Peek();
next = tos.Block.Statements[tos.Index];
}
else
next = null;
if (next is JsLabelledStatement) {
return Tuple.Create(GetOrCreateStateForLabel((next as JsLabelledStatement).Label, finallyStack), false);
}
else if (next != null) {
return Tuple.Create(CreateNewStateValue(finallyStack), true);
}
else {
return Tuple.Create(returnState, false);
}
}