public TemplateRewriterContext Write(ScriptNode node) { if (node != null) { bool pushedWhileLoop = false; if (node is ScriptLoopStatementBase) { _isWhileLoop.Push(node is ScriptWhileStatement); pushedWhileLoop = true; } try { WriteBegin(node); node.Write(this); WriteEnd(node); } finally { if (pushedWhileLoop) { _isWhileLoop.Pop(); } if (!IsBlockOrPage(node)) { _previousRawStatement = node as ScriptRawStatement; } } } return(this); }
/// <summary> /// Notifies this context when exiting a loop. /// </summary> internal void ExitLoop(ScriptLoopStatementBase loop) { OnExitLoop(loop); PopVariableScope(ScriptVariableScope.Loop); _loops.Pop(); _loopStep = 0; }
internal object PopCase() { if (_caseValues.Count == 0) { throw new InvalidOperationException(RS.PopCaseOverflow); } return(_caseValues.Pop()); }
/// <summary> /// Pops the source file being executed. /// </summary> /// <returns>The source file that was executed</returns> /// <exception cref="InvalidOperationException">Cannot PopSourceFile more than PushSourceFile</exception> public string PopSourceFile() { if (_sourceFiles.Count == 0) { throw new InvalidOperationException(RS.PopSourceFileOverflow); } return(_sourceFiles.Pop()); }
internal void PushPipeArguments() { ScriptPipeArguments pipeArguments = _availablePipeArguments.Count > 0 ? _availablePipeArguments.Pop() : new ScriptPipeArguments(4); _pipeArguments.Push(pipeArguments); _currentPipeArguments = pipeArguments; }
/// <summary> /// Pops the current culture used on the stack. /// </summary> /// <returns></returns> public CultureInfo PopCulture() { if (_cultures.Count == 0) { throw new InvalidOperationException(RS.PopCultureOverflow); } return(_cultures.Pop()); }
/// <summary> /// Pops a previous output. /// </summary> public IScriptOutput PopOutput() { if (_outputs.Count == 1) { throw new InvalidOperationException(RS.PopOutputError); } var previous = _outputs.Pop(); _output = _outputs.Peek(); return(previous); }
/// <summary> /// Pops the previous object context. /// </summary> /// <returns>The previous object context</returns> /// <exception cref="InvalidOperationException">Unexpected PopGlobal not matching a PushGlobal</exception> public IScriptObject PopGlobal() { if (_globalStores.Count == 1) { throw new InvalidOperationException(RS.PopGlobalOverflow); } var store = _globalStores.Pop(); PopVariableScope(ScriptVariableScope.Local); return(store); }
internal void PopPipeArguments() { if (_pipeArguments.Count == 1) { throw new InvalidOperationException(RS.PopPipeArgOverflow); } ScriptPipeArguments pipeArguments = _pipeArguments.Pop(); // Might be not null in case of an exception pipeArguments.Clear(); _availablePipeArguments.Push(pipeArguments); _currentPipeArguments = _pipeArguments.Peek(); }
/// <summary> /// Pops a previous <see cref="ScriptVariableScope"/>. /// </summary> internal void PopVariableScope(ref FastStack <ScriptObject> stores) { if (stores.Count == 0) { // Should not happen at runtime throw new InvalidOperationException(RS.PopVariableScopeOverflow); } ScriptObject store = stores.Pop(); // The store is cleanup once it is pushed back store.Clear(); _availableStores.Push(store); }
/// <summary> /// Push a new <see cref="ScriptVariableScope"/> for variables /// </summary> /// <param name="scope"></param> internal void PushVariableScope(ScriptVariableScope scope) { ScriptObject store = _availableStores.Count > 0 ? _availableStores.Pop() : new ScriptObject(); Dictionary <object, object> tags = _availableTags.Count > 0 ? _availableTags.Pop() : new Dictionary <object, object>(); if (scope == ScriptVariableScope.Local) { _localStores.Push(store); _localTagsStack.Push(tags); } else { _loopStores.Push(store); _loopTagsStack.Push(tags); } }
/// <summary> /// Pops a previous <see cref="ScriptVariableScope"/>. /// </summary> /// <param name="scope"></param> internal void PopVariableScope(ScriptVariableScope scope) { Dictionary <object, object> tags; if (scope == ScriptVariableScope.Local) { PopVariableScope(ref _localStores); tags = _localTagsStack.Pop(); } else { PopVariableScope(ref _loopStores); tags = _loopTagsStack.Pop(); } // Make sure that tags are clear tags.Clear(); _availableTags.Push(tags); }