/// <summary> /// Returns the correct results, either by executing the scriptblock or consulting the cache /// </summary> /// <returns></returns> public string[] Invoke() { if (!ShouldExecute) { return(LastResult); } List <string> results = new List <string>(); IEnumerable <CallStackFrame> _callStack = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Debugger.GetCallStack(); CallStackFrame callerFrame = null; if (_callStack.Count() > 0) { callerFrame = _callStack.First(); } ScriptBlock scriptBlock = ScriptBlock.Create(ScriptBlock.ToString()); foreach (PSObject item in scriptBlock.Invoke(callerFrame.InvocationInfo.MyCommand.Name, "", "", null, callerFrame.InvocationInfo.BoundParameters)) { results.Add((string)item.Properties["CompletionText"].Value); } return(results.ToArray()); }
/// <summary> /// Constructs the detailed information needed from a CallStackFrame /// </summary> /// <param name="Frame">The frame to parse</param> public CallerInfo(CallStackFrame Frame) { if (Frame.InvocationInfo == null) { CallerFunction = Frame.FunctionName; } else if (Frame.InvocationInfo.MyCommand == null) { CallerFunction = Frame.InvocationInfo.InvocationName; } else if (Frame.InvocationInfo.MyCommand.Name != "") { CallerFunction = Frame.InvocationInfo.MyCommand.Name; } else { CallerFunction = Frame.FunctionName; } if ((Frame.InvocationInfo != null) && (Frame.InvocationInfo.MyCommand != null) && (!String.IsNullOrEmpty(Frame.InvocationInfo.MyCommand.ModuleName))) { CallerModule = Frame.InvocationInfo.MyCommand.ModuleName; } if (!String.IsNullOrEmpty(Frame.Position.File)) { CallerFile = Frame.Position.File; } CallerLine = Frame.Position.EndLineNumber; }
/// <summary> /// Returns the caller CallStackFrame item /// </summary> /// <param name="Level">How many levels to peek into the callstack</param> /// <returns>Returns the caller CallStackFrame item</returns> public CallStackFrame GetCaller(int Level = 0) { IEnumerable <CallStackFrame> callStack = Utility.UtilityHost.Callstack; CallStackFrame callerFrame = null; if (callStack.Count() > Level) { callerFrame = callStack.ElementAt(Level); } return(callerFrame); }
private void PushCallFrame(int captureNum, int returnPos) { _callStack = new CallStackFrame() { next = _callStack, runMatchBackup = this.runmatch.DeepClone(), captureNum = captureNum, runTrackPos = Trackpos(), returnPos = returnPos }; }
/// <summary> /// Returns the caller CallStackFrame item /// </summary> /// <returns>Returns the caller CallStackFrame item</returns> public CallStackFrame GetCaller() { IEnumerable <CallStackFrame> callStack = Utility.UtilityHost.Callstack; CallStackFrame callerFrame = null; if (callStack.Count() > 0) { callerFrame = callStack.First(); } return(callerFrame); }
public ScriptStackFrame(ScriptProgramNode node, CallStackFrame frame) { if (node == null) { throw new ArgumentNullException("node"); } _node = node; _debugger = node.Debugger; // VS is zero based, PS is 1 based _docContext = new ScriptDocumentContext(frame.ScriptName, frame.ScriptLineNumber - 1, 0, frame.ToString()); _frame = frame; }
/// <summary> /// Creates an instance of the StackFrameDetails class from a /// CallStackFrame instance provided by the PowerShell engine. /// </summary> /// <param name="callStackFrame"> /// The original CallStackFrame instance from which details will be obtained. /// </param> /// <returns>A new instance of the StackFrameDetails class.</returns> static internal StackFrameDetails Create( CallStackFrame callStackFrame) { Dictionary <string, PSVariable> localVariables = callStackFrame.GetFrameVariables(); return(new StackFrameDetails { ScriptPath = callStackFrame.ScriptName, FunctionName = callStackFrame.FunctionName, LineNumber = callStackFrame.Position.StartLineNumber, ColumnNumber = callStackFrame.Position.StartColumnNumber }); }
/// <summary> /// Creates an instance of the StackFrameDetails class from a /// CallStackFrame instance provided by the PowerShell engine. /// </summary> /// <param name="callStackFrame"> /// The original CallStackFrame instance from which details will be obtained. /// </param> /// <param name="autoVariables"> /// A variable container with all the filtered, auto variables for this stack frame. /// </param> /// <param name="localVariables"> /// A variable container with all the local variables for this stack frame. /// </param> /// <returns>A new instance of the StackFrameDetails class.</returns> static internal StackFrameDetails Create( CallStackFrame callStackFrame, VariableContainerDetails autoVariables, VariableContainerDetails localVariables) { return(new StackFrameDetails { ScriptPath = callStackFrame.ScriptName ?? "<No File>", FunctionName = callStackFrame.FunctionName, LineNumber = callStackFrame.Position.StartLineNumber, ColumnNumber = callStackFrame.Position.StartColumnNumber, AutoVariables = autoVariables, LocalVariables = localVariables }); }
StackFrame CreateFrame(CallStackFrame magoFrame) { string fn; uint ln; ulong address = magoFrame.InstructionPointer; session.SymbolResolver.GetCodeLineFromAddress(address, out fn, out ln); //string methodName = session.SymbolResolver.GetFunctionNameFromAddress(address, threadId); string methodName = magoFrame.FunctionName; SourceLocation loc = new SourceLocation(methodName, fn, (int)ln); return(new StackFrame((long)address, loc, "Native")); }
/// <summary> /// Processes the begin phase of the cmdlet /// </summary> protected override void BeginProcessing() { _timestamp = DateTime.Now; #region Resolving Meta Information _callStack = Utility.UtilityHost.Callstack; CallStackFrame callerFrame = null; if (_callStack.Count() > 0) { callerFrame = _callStack.First(); } _stackDepth = _callStack.Count(); if (callerFrame != null) { if (String.IsNullOrEmpty(FunctionName)) { if (callerFrame.InvocationInfo == null) { FunctionName = callerFrame.FunctionName; } else if (callerFrame.InvocationInfo.MyCommand == null) { FunctionName = callerFrame.InvocationInfo.InvocationName; } else if (callerFrame.InvocationInfo.MyCommand.Name != "") { FunctionName = callerFrame.InvocationInfo.MyCommand.Name; } else { FunctionName = callerFrame.FunctionName; } } if (String.IsNullOrEmpty(ModuleName)) { if ((callerFrame.InvocationInfo != null) && (callerFrame.InvocationInfo.MyCommand != null)) { ModuleName = callerFrame.InvocationInfo.MyCommand.ModuleName; } } if (String.IsNullOrEmpty(File)) { File = callerFrame.Position.File; } if (Line <= 0) { Line = callerFrame.Position.EndLineNumber; } if (callerFrame.FunctionName == "Stop-PSFFunction") { _fromStopFunction = true; } } if (String.IsNullOrEmpty(FunctionName)) { FunctionName = "<Unknown>"; } if (String.IsNullOrEmpty(ModuleName)) { ModuleName = "<Unknown>"; } if (MessageHost.DisableVerbosity) { _silent = true; } if (Tag != null) { foreach (string item in Tag) { _Tags.Add(item); } } _isDebug = (_callStack.Count() > 1) && _callStack.ElementAt(_callStack.Count() - 2).InvocationInfo.BoundParameters.ContainsKey("Debug"); #endregion Resolving Meta Information }
private void PopCallFrame() { this.runmatch = _callStack.runMatchBackup; Trackto(_callStack.runTrackPos); _callStack = _callStack.next; }
StackFrame CreateFrame(CallStackFrame magoFrame) { string fn; uint ln; ulong address = magoFrame.InstructionPointer; session.SymbolResolver.GetCodeLineFromAddress(address, out fn, out ln); //string methodName = session.SymbolResolver.GetFunctionNameFromAddress(address, threadId); string methodName = magoFrame.FunctionName; SourceLocation loc = new SourceLocation(methodName, fn, (int)ln); return new StackFrame((long)address, loc, "Native"); }
/// <summary> /// Returns the correct results, either by executing the scriptblock or consulting the cache /// </summary> /// <returns></returns> public string[] Invoke() { if (!ShouldExecute) { return(LastResult); } List <string> results = new List <string>(); CallStackFrame callerFrame = null; InvocationInfo info = null; try { object CurrentCommandProcessor = UtilityHost.GetPrivateProperty("CurrentCommandProcessor", UtilityHost.GetExecutionContextFromTLS()); object CommandObject = UtilityHost.GetPrivateProperty("Command", CurrentCommandProcessor); info = UtilityHost.GetPublicProperty("MyInvocation", CommandObject) as InvocationInfo; } catch (Exception e) { if (PSFCore.PSFCoreHost.DebugMode) { PSFCore.PSFCoreHost.WriteDebug(String.Format("Script Container {0} | Error accessing Current Command Processor", Name), e); } } if (info == null) { IEnumerable <CallStackFrame> _callStack = Utility.UtilityHost.Callstack; object errorItem = null; try { if (_callStack.Count() > 0) { callerFrame = _callStack.Where(frame => frame.InvocationInfo != null && frame.InvocationInfo.MyCommand != null).First(); } } catch (Exception e) { errorItem = e; } if (PSFCore.PSFCoreHost.DebugMode) { PSFCore.PSFCoreHost.WriteDebug(String.Format("Script Container {0} | Callframe selected", Name), callerFrame); PSFCore.PSFCoreHost.WriteDebug(String.Format("Script Container {0} | Script Callstack", Name), new Message.CallStack(Utility.UtilityHost.Callstack)); if (errorItem != null) { PSFCore.PSFCoreHost.WriteDebug(String.Format("Script Container {0} | Error when selecting Callframe", Name), errorItem); } } } if (info == null && callerFrame != null) { info = callerFrame.InvocationInfo; } // ScriptBlock scriptBlock = ScriptBlock.Create(ScriptBlock.ToString()); if (info != null) { foreach (PSObject item in ScriptBlock.Invoke(info.MyCommand.Name, "", "", null, info.BoundParameters)) { results.Add((string)item.Properties["CompletionText"].Value); } } else { foreach (PSObject item in ScriptBlock.Invoke("<ScriptBlock>", "", "", null, new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase))) { results.Add((string)item.Properties["CompletionText"].Value); } } return(results.ToArray()); }
protected override void Go(ref int bump) { int origTextPos = Textpos(); Goto(0); int advance = -1; while (true) { if (advance >= 0) { // https://github.com/dotnet/coreclr/pull/14850#issuecomment-342256447 // Single common Advance call to reduce method size; and single method inline point Advance(advance); advance = -1; } #if DEBUG if (runmatch.Debug) { DumpState(); } #endif //CheckTimeout(); switch (Operator()) { case RegexCode.Stop: return; case RegexCode.Nothing: break; case RegexCode.Goto: Goto(Operand(0)); continue; case RegexCode.Testref: if (!IsMatched(Operand(0))) { break; } advance = 1; continue; case RegexCode.Lazybranch: TrackPush(Textpos()); advance = 1; continue; case RegexCode.Lazybranch | RegexCode.Back: TrackPop(); Textto(TrackPeek()); Goto(Operand(0)); continue; case RegexCode.Setmark: StackPush(Textpos()); TrackPush(); advance = 0; continue; case RegexCode.Nullmark: StackPush(-1); TrackPush(); advance = 0; continue; case RegexCode.Setmark | RegexCode.Back: case RegexCode.Nullmark | RegexCode.Back: StackPop(); break; case RegexCode.Getmark: StackPop(); TrackPush(StackPeek()); Textto(StackPeek()); advance = 0; continue; case RegexCode.Getmark | RegexCode.Back: TrackPop(); StackPush(TrackPeek()); break; case RegexCode.Capturemark: if (Operand(1) != -1 && !IsMatched(Operand(1))) { break; } StackPop(); if (Operand(1) != -1) { TransferCapture(Operand(0), Operand(1), StackPeek(), Textpos()); } else if (_callStack != null && _callStack.captureNum == Operand(0)) { // Successful return from a subroutine int returnPos = _callStack.returnPos; PopCallFrame(); Goto(returnPos); continue; } else { Capture(Operand(0), StackPeek(), Textpos()); } TrackPush(StackPeek()); advance = 2; continue; case RegexCode.Capturemark | RegexCode.Back: TrackPop(); StackPush(TrackPeek()); Uncapture(); if (Operand(0) != -1 && Operand(1) != -1) { Uncapture(); } break; case RegexCode.Branchmark: { int matched; StackPop(); matched = Textpos() - StackPeek(); if (matched != 0) { // Nonempty match -> loop now TrackPush(StackPeek(), Textpos()); // Save old mark, textpos StackPush(Textpos()); // Make new mark Goto(Operand(0)); // Loop } else { // Empty match -> straight now TrackPush2(StackPeek()); // Save old mark advance = 1; // Straight } continue; } case RegexCode.Branchmark | RegexCode.Back: TrackPop(2); StackPop(); Textto(TrackPeek(1)); // Recall position TrackPush2(TrackPeek()); // Save old mark advance = 1; // Straight continue; case RegexCode.Branchmark | RegexCode.Back2: TrackPop(); StackPush(TrackPeek()); // Recall old mark break; // Backtrack case RegexCode.Lazybranchmark: { // We hit this the first time through a lazy loop and after each // successful match of the inner expression. It simply continues // on and doesn't loop. StackPop(); int oldMarkPos = StackPeek(); if (Textpos() != oldMarkPos) { // Nonempty match -> try to loop again by going to 'back' state if (oldMarkPos != -1) { TrackPush(oldMarkPos, Textpos()); // Save old mark, textpos } else { TrackPush(Textpos(), Textpos()); } } else { // The inner expression found an empty match, so we'll go directly to 'back2' if we // backtrack. In this case, we need to push something on the stack, since back2 pops. // However, in the case of ()+? or similar, this empty match may be legitimate, so push the text // position associated with that empty match. StackPush(oldMarkPos); TrackPush2(StackPeek()); // Save old mark } advance = 1; continue; } case RegexCode.Lazybranchmark | RegexCode.Back: { // After the first time, Lazybranchmark | RegexCode.Back occurs // with each iteration of the loop, and therefore with every attempted // match of the inner expression. We'll try to match the inner expression, // then go back to Lazybranchmark if successful. If the inner expression // fails, we go to Lazybranchmark | RegexCode.Back2 int pos; TrackPop(2); pos = TrackPeek(1); TrackPush2(TrackPeek()); // Save old mark StackPush(pos); // Make new mark Textto(pos); // Recall position Goto(Operand(0)); // Loop continue; } case RegexCode.Lazybranchmark | RegexCode.Back2: // The lazy loop has failed. We'll do a true backtrack and // start over before the lazy loop. StackPop(); TrackPop(); StackPush(TrackPeek()); // Recall old mark break; case RegexCode.Setcount: StackPush(Textpos(), Operand(0)); TrackPush(); advance = 1; continue; case RegexCode.Nullcount: StackPush(-1, Operand(0)); TrackPush(); advance = 1; continue; case RegexCode.Setcount | RegexCode.Back: StackPop(2); break; case RegexCode.Nullcount | RegexCode.Back: StackPop(2); break; case RegexCode.Branchcount: // StackPush: // 0: Mark // 1: Count { StackPop(2); int mark = StackPeek(); int count = StackPeek(1); int matched = Textpos() - mark; if (count >= Operand(1) || (matched == 0 && count >= 0)) { // Max loops or empty match -> straight now TrackPush2(mark, count); // Save old mark, count advance = 2; // Straight } else { // Nonempty match -> count+loop now TrackPush(mark); // remember mark StackPush(Textpos(), count + 1); // Make new mark, incr count Goto(Operand(0)); // Loop } continue; } case RegexCode.Branchcount | RegexCode.Back: // TrackPush: // 0: Previous mark // StackPush: // 0: Mark (= current pos, discarded) // 1: Count TrackPop(); StackPop(2); if (StackPeek(1) > 0) { // Positive -> can go straight Textto(StackPeek()); // Zap to mark TrackPush2(TrackPeek(), StackPeek(1) - 1); // Save old mark, old count advance = 2; // Straight continue; } StackPush(TrackPeek(), StackPeek(1) - 1); // recall old mark, old count break; case RegexCode.Branchcount | RegexCode.Back2: // TrackPush: // 0: Previous mark // 1: Previous count TrackPop(2); StackPush(TrackPeek(), TrackPeek(1)); // Recall old mark, old count break; // Backtrack case RegexCode.Lazybranchcount: // StackPush: // 0: Mark // 1: Count { StackPop(2); int mark = StackPeek(); int count = StackPeek(1); if (count < 0) { // Negative count -> loop now TrackPush2(mark); // Save old mark StackPush(Textpos(), count + 1); // Make new mark, incr count Goto(Operand(0)); // Loop } else { // Nonneg count -> straight now TrackPush(mark, count, Textpos()); // Save mark, count, position advance = 2; // Straight } continue; } case RegexCode.Lazybranchcount | RegexCode.Back: // TrackPush: // 0: Mark // 1: Count // 2: Textpos { TrackPop(3); int mark = TrackPeek(); int textpos = TrackPeek(2); if (TrackPeek(1) < Operand(1) && textpos != mark) { // Under limit and not empty match -> loop Textto(textpos); // Recall position StackPush(textpos, TrackPeek(1) + 1); // Make new mark, incr count TrackPush2(mark); // Save old mark Goto(Operand(0)); // Loop continue; } else { // Max loops or empty match -> backtrack StackPush(TrackPeek(), TrackPeek(1)); // Recall old mark, count break; // backtrack } } case RegexCode.Lazybranchcount | RegexCode.Back2: // TrackPush: // 0: Previous mark // StackPush: // 0: Mark (== current pos, discarded) // 1: Count TrackPop(); StackPop(2); StackPush(TrackPeek(), StackPeek(1) - 1); // Recall old mark, count break; // Backtrack case RegexCode.Setjump: StackPush(Trackpos(), Crawlpos()); TrackPush(); advance = 0; continue; case RegexCode.Setjump | RegexCode.Back: StackPop(2); break; case RegexCode.Backjump: // StackPush: // 0: Saved trackpos // 1: Crawlpos StackPop(2); Trackto(StackPeek()); while (Crawlpos() != StackPeek(1)) { Uncapture(); } break; case RegexCode.Forejump: // StackPush: // 0: Saved trackpos // 1: Crawlpos StackPop(2); Trackto(StackPeek()); TrackPush(StackPeek(1)); advance = 0; continue; case RegexCode.Forejump | RegexCode.Back: // TrackPush: // 0: Crawlpos TrackPop(); while (Crawlpos() != TrackPeek()) { Uncapture(); } break; case RegexCode.Bol: if (Leftchars() > 0 && CharAt(Textpos() - 1) != '\n') { break; } advance = 0; continue; case RegexCode.Eol: if (Rightchars() > 0 && CharAt(Textpos()) != '\n') { break; } advance = 0; continue; case RegexCode.Boundary: if (!IsBoundary(Textpos(), runtextbeg, runtextend)) { break; } advance = 0; continue; case RegexCode.Nonboundary: if (IsBoundary(Textpos(), runtextbeg, runtextend)) { break; } advance = 0; continue; case RegexCode.ECMABoundary: if (!IsECMABoundary(Textpos(), runtextbeg, runtextend)) { break; } advance = 0; continue; case RegexCode.NonECMABoundary: if (IsECMABoundary(Textpos(), runtextbeg, runtextend)) { break; } advance = 0; continue; case RegexCode.Beginning: if (Leftchars() > 0) { break; } advance = 0; continue; case RegexCode.Start: if (Textpos() != Textstart()) { break; } advance = 0; continue; case RegexCode.EndZ: if (Rightchars() > 1 || Rightchars() == 1 && CharAt(Textpos()) != '\n') { break; } advance = 0; continue; case RegexCode.End: if (Rightchars() > 0) { break; } advance = 0; continue; case RegexCode.One: if (Forwardchars() < 1 || Forwardcharnext() != (char)Operand(0)) { break; } advance = 1; continue; case RegexCode.Notone: if (Forwardchars() < 1 || Forwardcharnext() == (char)Operand(0)) { break; } advance = 1; continue; case RegexCode.Set: if (Forwardchars() < 1 || !RegexCharClass.CharInClass(Forwardcharnext(), _code._strings[Operand(0)])) { break; } advance = 1; continue; case RegexCode.Multi: { if (!Stringmatch(_code._strings[Operand(0)])) { break; } advance = 1; continue; } case RegexCode.Ref: { int capnum = Operand(0); if (IsMatched(capnum)) { if (!Refmatch(MatchIndex(capnum), MatchLength(capnum))) { break; } } else { if ((runregex.roptions & RegexOptions.ECMAScript) == 0) { break; } } advance = 1; continue; } case RegexCode.Onerep: { int c = Operand(1); if (Forwardchars() < c) { break; } char ch = (char)Operand(0); while (c-- > 0) { if (Forwardcharnext() != ch) { goto BreakBackward; } } advance = 2; continue; } case RegexCode.Notonerep: { int c = Operand(1); if (Forwardchars() < c) { break; } char ch = (char)Operand(0); while (c-- > 0) { if (Forwardcharnext() == ch) { goto BreakBackward; } } advance = 2; continue; } case RegexCode.Setrep: { int c = Operand(1); if (Forwardchars() < c) { break; } string set = _code._strings[Operand(0)]; while (c-- > 0) { if (!RegexCharClass.CharInClass(Forwardcharnext(), set)) { goto BreakBackward; } } advance = 2; continue; } case RegexCode.Oneloop: { int c = Operand(1); if (c > Forwardchars()) { c = Forwardchars(); } char ch = (char)Operand(0); int i; for (i = c; i > 0; i--) { if (Forwardcharnext() != ch) { Backwardnext(); break; } } if (c > i) { TrackPush(c - i - 1, Textpos() - Bump()); } advance = 2; continue; } case RegexCode.Notoneloop: { int c = Operand(1); if (c > Forwardchars()) { c = Forwardchars(); } char ch = (char)Operand(0); int i; for (i = c; i > 0; i--) { if (Forwardcharnext() == ch) { Backwardnext(); break; } } if (c > i) { TrackPush(c - i - 1, Textpos() - Bump()); } advance = 2; continue; } case RegexCode.Setloop: { int c = Operand(1); if (c > Forwardchars()) { c = Forwardchars(); } string set = _code._strings[Operand(0)]; int i; for (i = c; i > 0; i--) { if (!RegexCharClass.CharInClass(Forwardcharnext(), set)) { Backwardnext(); break; } } if (c > i) { TrackPush(c - i - 1, Textpos() - Bump()); } advance = 2; continue; } case RegexCode.Oneloop | RegexCode.Back: case RegexCode.Notoneloop | RegexCode.Back: { TrackPop(2); int i = TrackPeek(); int pos = TrackPeek(1); Textto(pos); if (i > 0) { TrackPush(i - 1, pos - Bump()); } advance = 2; continue; } case RegexCode.Setloop | RegexCode.Back: { TrackPop(2); int i = TrackPeek(); int pos = TrackPeek(1); Textto(pos); if (i > 0) { TrackPush(i - 1, pos - Bump()); } advance = 2; continue; } case RegexCode.Onelazy: case RegexCode.Notonelazy: { int c = Operand(1); if (c > Forwardchars()) { c = Forwardchars(); } if (c > 0) { TrackPush(c - 1, Textpos()); } advance = 2; continue; } case RegexCode.Setlazy: { int c = Operand(1); if (c > Forwardchars()) { c = Forwardchars(); } if (c > 0) { TrackPush(c - 1, Textpos()); } advance = 2; continue; } case RegexCode.Onelazy | RegexCode.Back: { TrackPop(2); int pos = TrackPeek(1); Textto(pos); if (Forwardcharnext() != (char)Operand(0)) { break; } int i = TrackPeek(); if (i > 0) { TrackPush(i - 1, pos + Bump()); } advance = 2; continue; } case RegexCode.Notonelazy | RegexCode.Back: { TrackPop(2); int pos = TrackPeek(1); Textto(pos); if (Forwardcharnext() == (char)Operand(0)) { break; } int i = TrackPeek(); if (i > 0) { TrackPush(i - 1, pos + Bump()); } advance = 2; continue; } case RegexCode.Setlazy | RegexCode.Back: { TrackPop(2); int pos = TrackPeek(1); Textto(pos); if (!RegexCharClass.CharInClass(Forwardcharnext(), _code._strings[Operand(0)])) { break; } int i = TrackPeek(); if (i > 0) { TrackPush(i - 1, pos + Bump()); } advance = 2; continue; } case RegexCode.ResetMatchStart: TrackPush(MatchStart()); // Enable backtracking, saving the current match start SetMatchStart(Textpos()); // Set the match start to the current position in text advance = 0; continue; case RegexCode.ResetMatchStart | RegexCode.Back: TrackPop(); SetMatchStart(TrackPeek()); // Restore the previously saved value as the match start break; // Continue backtracking case RegexCode.CallSubroutine: { int captureNum = Operand(0); PushCallFrame(captureNum, returnPos: _codepos + 2); TrackPush(); // This TrackPush will be forgotten after it returns or backtracks Goto(_code._capPositions[captureNum]); continue; } case RegexCode.CallSubroutine | RegexCode.Back: PopCallFrame(); // It must have been from the called subroutine break; case RegexCode.SkipVerb: TrackPush(Textpos()); // Store the current text position to be used in backtrack advance = 0; continue; case RegexCode.SkipVerb | RegexCode.Back: // TODO: Make it work correctly inside negative lookarounds if necessary TrackPop(); bump = CalculateBumpToPos(origTextPos, TrackPeek()); // Adjust the bump so that the next search starts from the current position Textto(origTextPos); // Restore the text position to the original one _callStack = null; // Erase possible call stack due to earlier return (other stacks are handled by the caller) return; // Exit this scan prematurely default: throw new NotImplementedException(SR.UnimplementedState); } BreakBackward: ; // "break Backward" comes here: Backtrack(); } }
/// <summary> /// Processes the begin phase of the cmdlet /// </summary> protected override void BeginProcessing() { _timestamp = DateTime.Now; #region Resolving Meta Information CallStackFrame callerFrame = null; foreach (CallStackFrame frame in System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Debugger.GetCallStack()) { callerFrame = frame; break; } _stackDepth = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Debugger.GetCallStack().Count(); if (callerFrame != null) { if (String.IsNullOrEmpty(FunctionName)) { if (callerFrame.InvocationInfo == null) { FunctionName = callerFrame.FunctionName; } else if (callerFrame.InvocationInfo.MyCommand == null) { FunctionName = callerFrame.InvocationInfo.InvocationName; } else if (callerFrame.InvocationInfo.MyCommand.Name != "") { FunctionName = callerFrame.InvocationInfo.MyCommand.Name; } else { FunctionName = callerFrame.FunctionName; } } if (String.IsNullOrEmpty(ModuleName)) { if ((callerFrame.InvocationInfo != null) && (callerFrame.InvocationInfo.MyCommand != null)) { ModuleName = callerFrame.InvocationInfo.MyCommand.ModuleName; } } if (String.IsNullOrEmpty(File)) { File = callerFrame.Position.File; } if (Line <= 0) { Line = callerFrame.Position.EndLineNumber; } if (callerFrame.FunctionName == "Stop-PSFFunction") { _fromStopFunction = true; } } if (String.IsNullOrEmpty(FunctionName)) { FunctionName = "<Unknown>"; } if (String.IsNullOrEmpty(ModuleName)) { ModuleName = "<Unknown>"; } if (MessageHost.DisableVerbosity) { _silent = true; } if (Tag != null) { foreach (string item in Tag) { _Tags.Add(item); } } #endregion Resolving Meta Information }