private void DefineVariable(VariableAction variable) { Debug.Assert(this.Debugger != null); if (variable.IsGlobal) { for (int i = 0; i < globalVars.Count; i++) { VariableAction oldVar = (VariableAction)this.globalVars[i]; if (oldVar.Name == variable.Name) // Duplicate var definition { if (variable.Stylesheetid < oldVar.Stylesheetid) { Debug.Assert(variable.VarKey != -1, "Variable was already placed and it should replace prev var."); this.globalVars[i] = variable; this.globalVarsCache = null; } return; } } this.globalVars.Add(variable); this.globalVarsCache = null; } else { // local variables never conflict localVars.Add(variable); this.localVarsCache = null; } }
internal Object GetVariableValue(VariableAction variable) { int variablekey = variable.VarKey; ActionFrame frame = (ActionFrame)(variable.IsGlobal ? this.actionStack[0] : this.actionStack.Peek()); return(frame.GetVariable(variablekey)); }
private void RecursiveWalk(int index, ArrayList InputList, ref ArrayList OutputList) { SortedList list = InputList[index] as SortedList; if (list.Count == 0) { return; } if (list.Count == 1) { OutputList.Add(index); list.Clear(); return; } if (list.Contains(-1)) { VariableAction action = this.containedActions[index] as VariableAction; throw new XsltException(Res.Xslt_CircularReference, action.NameStr); } list.Add(-1, -1); for (int i = 0; i < list.Count; i++) { int actionindex = (int)list.GetByIndex(i); if (actionindex != -1 && actionindex != index) { RecursiveWalk(actionindex, InputList, ref OutputList); } } OutputList.Add(index); list.Clear(); return; }
// // Variable support // internal int InsertVariable(VariableAction variable) { InputScope varScope; if (variable.IsGlobal) { Debug.Assert(this.rootAction != null); varScope = this.rootScope; } else { Debug.Assert(this.currentTemplate != null); Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter); varScope = this.scopeManager.VariableScope; } VariableAction oldVar = varScope.ResolveVariable(variable.Name); if (oldVar != null) { // Other variable with this name is visible in this scope if (oldVar.IsGlobal) { if (variable.IsGlobal) { // Global Vars replace each other base on import presidens odred if (variable.Stylesheetid == oldVar.Stylesheetid) { // Both vars are in the same stylesheet throw new XsltException(Res.Xslt_DupVarName, variable.NameStr); } else if (variable.Stylesheetid < oldVar.Stylesheetid) { // newly defined var is more importent varScope.InsertVariable(variable); return(oldVar.VarKey); } else { // we egnore new variable return(InvalidQueryKey); // We didn't add this var, so doesn't matter what VarKey we return; } } else { // local variable can shadow global } } else { // Local variable never can be "shadowed" throw new XsltException(Res.Xslt_DupVarName, variable.NameStr); } } varScope.InsertVariable(variable); return(this.currentTemplate.AllocateVariableSlot()); }
internal void InsertVariable(VariableAction variable) { Debug.Assert(variable != null); if (this.variables == null) { this.variables = new Hashtable(); } this.variables[variable.Name] = variable; }
/// <include file='doc\XsltCompileContext.uex' path='docs/doc[@for="XsltCompileContext.EvaluateVariable1"]/*' /> internal object EvaluateVariable(VariableAction variable) { Object result = this.processor.GetVariableValue(variable); if (result != null || variable.IsGlobal) { return result; } VariableAction global = this.manager.VariableScope.ResolveGlobalVariable(variable.Name); if (global != null) { result = this.processor.GetVariableValue(global); } return result; }
public virtual VariableAction CreateVariableAction(VariableType type) { VariableAction action = new VariableAction(type); action.Compile(this); if (action.VarKey != InvalidQueryKey) { return(action); } else { return(null); } }
public VariableAction ResolveVariable(XmlQualifiedName qname) { for (InputScope inputScope = this; inputScope != null; inputScope = inputScope.Parent) { if (inputScope.Variables != null) { VariableAction variable = (VariableAction)inputScope.Variables[qname]; if (variable != null) { return(variable); } } } return(null); }
/// <include file='doc\XsltCompileContext.uex' path='docs/doc[@for="XsltCompileContext.EvaluateVariable1"]/*' /> internal object EvaluateVariable(VariableAction variable) { Object result = this.processor.GetVariableValue(variable); if (result != null || variable.IsGlobal) { return(result); } VariableAction global = this.manager.VariableScope.ResolveGlobalVariable(variable.Name); if (global != null) { result = this.processor.GetVariableValue(global); } return(result); }
private void DefineVariable(VariableAction variable) { Debug.Assert(this.Debugger != null); if (variable.IsGlobal) { for(int i = 0; i < globalVars.Count; i ++) { VariableAction oldVar = (VariableAction)this.globalVars[i]; if(oldVar.Name == variable.Name) { // Duplicate var definition if(variable.Stylesheetid < oldVar.Stylesheetid) { Debug.Assert(variable.VarKey != -1, "Variable was already placed and it should replace prev var."); this.globalVars[i] = variable; this.globalVarsCache = null; } return; } } this.globalVars.Add(variable); this.globalVarsCache = null; } else { // local variables never conflict localVars.Add(variable); this.localVarsCache = null; } }
protected void CompileTopLevelElements(Compiler compiler) { // Navigator positioned at parent root, need to move to child and then back if (compiler.Recurse() == false) { Debug.WriteLine("Nothing to compile, exiting"); return; } NavigatorInput input = compiler.Input; bool notFirstElement = false; do { Debug.Trace(input); switch (input.NodeType) { case XPathNodeType.Element: string name = input.LocalName; string nspace = input.NamespaceURI; if (Keywords.Equals(nspace, input.Atoms.XsltNamespace)) { if (Keywords.Equals(name, input.Atoms.Import)) { if (notFirstElement) { throw new XsltException(Res.Xslt_NotFirstImport); } // We should compile imports in reverse order after all toplevel elements. // remember it now and return to it in CompileImpoorts(); compiler.CompiledStylesheet.Imports.Add(compiler.GetSingleAttribute(compiler.Input.Atoms.Href)); } else if (Keywords.Equals(name, input.Atoms.Include)) { notFirstElement = true; CompileInclude(compiler); } else { notFirstElement = true; compiler.PushNamespaceScope(); if (Keywords.Equals(name, input.Atoms.StripSpace)) { CompileSpace(compiler, false); } else if (Keywords.Equals(name, input.Atoms.PreserveSpace)) { CompileSpace(compiler, true); } else if (Keywords.Equals(name, input.Atoms.Output)) { CompileOutput(compiler); } else if (Keywords.Equals(name, input.Atoms.Key)) { CompileKey(compiler); } else if (Keywords.Equals(name, input.Atoms.DecimalFormat)) { CompileDecimalFormat(compiler); } else if (Keywords.Equals(name, input.Atoms.NamespaceAlias)) { CompileNamespaceAlias(compiler); } else if (Keywords.Equals(name, input.Atoms.AttributeSet)) { compiler.AddAttributeSet(compiler.CreateAttributeSetAction()); } else if (Keywords.Equals(name, input.Atoms.Variable)) { VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable); if (action != null) { AddAction(action); } } else if (Keywords.Equals(name, input.Atoms.Param)) { VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter); if (action != null) { AddAction(action); } } else if (Keywords.Equals(name, input.Atoms.Template)) { compiler.AddTemplate(compiler.CreateTemplateAction()); } else { if (!compiler.ForwardCompatibility) { throw XsltException.UnexpectedKeyword(compiler); } } compiler.PopScope(); } } else if (nspace == input.Atoms.MsXsltNamespace && name == input.Atoms.Script) { AddScript(compiler); } else { if (Keywords.Equals(nspace, input.Atoms.Empty)) { throw new XsltException(Res.Xslt_NullNsAtTopLevel, input.Name); } // Ignoring non-recognized namespace per XSLT spec 2.2 } break; case XPathNodeType.ProcessingInstruction: case XPathNodeType.Comment: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw new XsltException(Res.Xslt_InvalidContents, "xsl:stylesheet"); } }while (compiler.Advance()); compiler.ToParent(); }
// // Variable support // internal int InsertVariable(VariableAction variable) { InputScope varScope; if (variable.IsGlobal) { Debug.Assert(this.rootAction != null); varScope = this.rootScope; } else { Debug.Assert(this.currentTemplate != null); Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter); varScope = this.scopeManager.VariableScope; } VariableAction oldVar = varScope.ResolveVariable(variable.Name); if (oldVar != null) { // Other variable with this name is visible in this scope if (oldVar.IsGlobal) { if (variable.IsGlobal) { // Global Vars replace each other base on import presidens odred if(variable.Stylesheetid == oldVar.Stylesheetid) { // Both vars are in the same stylesheet throw new XsltException(Res.Xslt_DupVarName, variable.NameStr); } else if(variable.Stylesheetid < oldVar.Stylesheetid) { // newly defined var is more importent varScope.InsertVariable(variable); return oldVar.VarKey; } else { // we egnore new variable return InvalidQueryKey; // We didn't add this var, so doesn't matter what VarKey we return; } } else { // local variable can shadow global } } else { // Local variable never can be "shadowed" throw new XsltException(Res.Xslt_DupVarName, variable.NameStr); } } varScope.InsertVariable(variable); return this.currentTemplate.AllocateVariableSlot(); }
public virtual VariableAction CreateVariableAction(VariableType type) { VariableAction action = new VariableAction(type); action.Compile(this); if ( action.VarKey != InvalidQueryKey ) { return action; } else { return null; } }
internal Object GetVariableValue(VariableAction variable) { int variablekey = variable.VarKey; ActionFrame frame = (ActionFrame) (variable.IsGlobal ? this.actionStack[0] : this.actionStack.Peek()); return frame.GetVariable(variablekey); }
internal void SortVariables() { if (this.containedActions == null) { return; } ArrayList InputList = new ArrayList(); ArrayList OutputIndexList; bool flag = false; SortedList list; Hashtable hashtable = new Hashtable(); Action action; int length = this.containedActions.Count; for (int i = 0; i < length; i++) { action = this.containedActions[i] as Action; if (action is VariableAction) { VariableAction var = action as VariableAction; hashtable[var.NameStr] = i; } } for (int i = 0; i < length; i++) { action = this.containedActions[i] as Action; if (action is VariableAction) { VariableAction var = action as VariableAction; list = new SortedList(); if (var.Select != null) { AstNode node = AstNode.NewAstNode(var.Select); ProcessNode(i, node, hashtable, ref list); } else { if (var.containedActions != null) { foreach (Action containedaction in var.containedActions) { if (containedaction.Select != null) { AstNode node = AstNode.NewAstNode(containedaction.Select); ProcessNode(i, node, hashtable, ref list); } } } } list.Add(i, i); flag = list.Count > 1 || flag; InputList.Add(list); } else { list = new SortedList(); list.Add(i, i); InputList.Add(list); } } if (flag) { ArrayList ActionList = new ArrayList(); OutputIndexList = new ArrayList(); for (int i = 0; i < InputList.Count; i++) { RecursiveWalk(i, InputList, ref OutputIndexList); } for (int i = 0; i < OutputIndexList.Count; i++) { ActionList.Add(this.containedActions[(int)OutputIndexList[i]]); } this.containedActions = ActionList; } }
internal void ReplaceVariables(VariableAction[] vars) { this.variables = vars; }