Inheritance: ContainerAction, IXsltContextVariable
Exemplo n.º 1
0
 private void DefineVariable(VariableAction variable)
 {
     Debug.Assert(this.Debugger != null);
     if (variable.IsGlobal)
     {
         for (int i = 0; i < _globalVars.Count; i++)
         {
             VariableAction oldVar = (VariableAction)_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.");
                     _globalVars[i]   = variable;
                     _globalVarsCache = null;
                 }
                 return;
             }
         }
         _globalVars.Add(variable);
         _globalVarsCache = null;
     }
     else
     {
         // local variables never conflict
         _localVars.Add(variable);
         _localVarsCache = null;
     }
 }
Exemplo n.º 2
0
        internal void InsertVariable(VariableAction variable) {
            Debug.Assert(variable != null);

            if (this.variables == null) {
                this.variables = new Hashtable();
            }
            this.variables[variable.Name] = variable;
        }
Exemplo n.º 3
0
        //
        // Variable support
        //

        internal int InsertVariable(VariableAction variable)
        {
            InputScope varScope;

            if (variable.IsGlobal)
            {
                Debug.Assert(_rootAction != null);
                varScope = _rootScope;
            }
            else
            {
                Debug.Assert(_currentTemplate != null);
                Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter);
                varScope = _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 XsltException.Create(SR.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 XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
                }
            }

            varScope.InsertVariable(variable);
            return(_currentTemplate.AllocateVariableSlot());
        }
Exemplo n.º 4
0
        internal void InsertVariable(VariableAction variable)
        {
            Debug.Assert(variable != null);

            if (_variables == null)
            {
                _variables = new Hashtable();
            }
            _variables[variable.Name !] = variable;
Exemplo n.º 5
0
        internal void InsertVariable(VariableAction variable)
        {
            Debug.Assert(variable != null);

            if (this.variables == null)
            {
                this.variables = new Hashtable();
            }
            this.variables[variable.Name] = variable;
        }
Exemplo n.º 6
0
        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 EvaluateVariable(VariableAction variable) {
     Object result = this.processor.GetVariableValue(variable);
     if (result == null && ! variable.IsGlobal) {
         // This was uninitialized local variable. May be we have sutable global var too?
         VariableAction global = this.manager.VariableScope.ResolveGlobalVariable(variable.Name);
         if (global != null) {
             result = this.processor.GetVariableValue(global);
         }
     }
     if (result == null) {
         throw XsltException.Create(Res.Xslt_InvalidVariable, variable.Name.ToString());
     }
     return result;
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        internal object EvaluateVariable(VariableAction variable)
        {
            Object result = this.processor.GetVariableValue(variable);

            if (result == null && !variable.IsGlobal)
            {
                // This was uninitialized local variable. May be we have sutable global var too?
                VariableAction global = this.manager.VariableScope.ResolveGlobalVariable(variable.Name);
                if (global != null)
                {
                    result = this.processor.GetVariableValue(global);
                }
            }
            if (result == null)
            {
                throw XsltException.Create(Res.Xslt_InvalidVariable, variable.Name.ToString());
            }
            return(result);
        }
Exemplo n.º 10
0
        internal object GetVariableValue(VariableAction variable)
        {
            int variablekey = variable.VarKey;

            if (variable.IsGlobal)
            {
                ActionFrame rootFrame = (ActionFrame)this.actionStack[0];
                object      result    = rootFrame.GetVariable(variablekey);
                if (result != null)
                {
                    return(result);
                }
                // Variable wasn't evaluated yet
                if (variable.Stylesheetid == -1)
                {
                    throw XsltException.Create(Res.Xslt_CircularReference, variable.NameStr);
                }
                int         saveStackSize = this.actionStack.Length;
                ActionFrame varFrame      = PushNewFrame();
                varFrame.Inherit(rootFrame);
                varFrame.Init(variable, rootFrame.NodeSet);
                do
                {
                    bool endOfFrame = ((ActionFrame)this.actionStack.Peek()).Execute(this);
                    if (endOfFrame)
                    {
                        this.actionStack.Pop();
                    }
                } while (saveStackSize < this.actionStack.Length);
                Debug.Assert(saveStackSize == this.actionStack.Length);
                result = rootFrame.GetVariable(variablekey);
                Debug.Assert(result != null, "Variable was just calculated and result can't be null");
                return(result);
            }
            else
            {
                return(((ActionFrame)this.actionStack.Peek()).GetVariable(variablekey));
            }
        }
Exemplo n.º 11
0
 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;
     }
 }
Exemplo n.º 12
0
        //
        // Variable support
        //

        internal int InsertVariable(VariableAction variable)
        {
            InputScope varScope;
            if (variable.IsGlobal)
            {
                Debug.Assert(_rootAction != null);
                varScope = _rootScope;
            }
            else
            {
                Debug.Assert(_currentTemplate != null);
                Debug.Assert(variable.VarType == VariableType.LocalVariable || variable.VarType == VariableType.LocalParameter || variable.VarType == VariableType.WithParameter);
                varScope = _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 XsltException.Create(SR.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 XsltException.Create(SR.Xslt_DupVarName, variable.NameStr);
                }
            }

            varScope.InsertVariable(variable);
            return _currentTemplate.AllocateVariableSlot();
        }
Exemplo n.º 13
0
 public virtual VariableAction CreateVariableAction(VariableType type)
 {
     VariableAction action = new VariableAction(type);
     action.Compile(this);
     if (action.VarKey != InvalidQueryKey)
     {
         return action;
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 14
0
        // SxS: This method does not take any resource name and does not expose any resources to the caller.
        // It's OK to suppress the SxS warning.
        protected void CompileTopLevelElements(Compiler compiler)
        {
            // Navigator positioned at parent root, need to move to child and then back
            if (compiler.Recurse() == false)
            {
                return;
            }

            NavigatorInput input           = compiler.Input;
            bool           notFirstElement = false;

            do
            {
                switch (input.NodeType)
                {
                case XPathNodeType.Element:
                    string name   = input.LocalName;
                    string nspace = input.NamespaceURI;

                    if (Ref.Equal(nspace, input.Atoms.UriXsl))
                    {
                        if (Ref.Equal(name, input.Atoms.Import))
                        {
                            if (notFirstElement)
                            {
                                throw XsltException.Create(SR.Xslt_NotFirstImport);
                            }
                            // We should compile imports in reverse order after all toplevel elements.
                            // remember it now and return to it in CompileImpoorts();
                            Uri    uri      = compiler.ResolveUri(compiler.GetSingleAttribute(compiler.Input.Atoms.Href));
                            string resolved = uri.ToString();
                            if (compiler.IsCircularReference(resolved))
                            {
                                throw XsltException.Create(SR.Xslt_CircularInclude, resolved);
                            }
                            compiler.CompiledStylesheet.Imports.Add(uri);
                            CheckEmpty(compiler);
                        }
                        else if (Ref.Equal(name, input.Atoms.Include))
                        {
                            notFirstElement = true;
                            CompileInclude(compiler);
                        }
                        else
                        {
                            notFirstElement = true;
                            compiler.PushNamespaceScope();
                            if (Ref.Equal(name, input.Atoms.StripSpace))
                            {
                                CompileSpace(compiler, false);
                            }
                            else if (Ref.Equal(name, input.Atoms.PreserveSpace))
                            {
                                CompileSpace(compiler, true);
                            }
                            else if (Ref.Equal(name, input.Atoms.Output))
                            {
                                CompileOutput(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.Key))
                            {
                                CompileKey(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.DecimalFormat))
                            {
                                CompileDecimalFormat(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.NamespaceAlias))
                            {
                                CompileNamespaceAlias(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.AttributeSet))
                            {
                                compiler.AddAttributeSet(compiler.CreateAttributeSetAction());
                            }
                            else if (Ref.Equal(name, input.Atoms.Variable))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Param))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Template))
                            {
                                compiler.AddTemplate(compiler.CreateTemplateAction());
                            }
                            else
                            {
                                if (!compiler.ForwardCompatibility)
                                {
                                    throw compiler.UnexpectedKeyword();
                                }
                            }
                            compiler.PopScope();
                        }
                    }
                    else if (nspace == input.Atoms.UrnMsxsl && name == input.Atoms.Script)
                    {
                        AddScript(compiler);
                    }
                    else
                    {
                        if (nspace.Length == 0)
                        {
                            throw XsltException.Create(SR.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 XsltException.Create(SR.Xslt_InvalidContents, "stylesheet");
                }
            }while (compiler.Advance());

            compiler.ToParent();
        }
Exemplo n.º 15
0
 internal object GetVariableValue(VariableAction variable) {
     int variablekey = variable.VarKey;
     if (variable.IsGlobal) {
         ActionFrame rootFrame = (ActionFrame) this.actionStack[0];
         object result = rootFrame.GetVariable(variablekey);
         if (result == VariableAction.BeingComputedMark) {
             throw XsltException.Create(Res.Xslt_CircularReference, variable.NameStr);
         }
         if (result != null) {
             return result;
         }
         // Variable wasn't evaluated yet
         int saveStackSize = this.actionStack.Length;
         ActionFrame varFrame = PushNewFrame();
         varFrame.Inherit(rootFrame);
         varFrame.Init(variable, rootFrame.NodeSet);
         do {
             bool endOfFrame = ((ActionFrame) this.actionStack.Peek()).Execute(this);
             if (endOfFrame) {
                 this.actionStack.Pop();
             }
         } while (saveStackSize < this.actionStack.Length);
         Debug.Assert(saveStackSize == this.actionStack.Length);
         result = rootFrame.GetVariable(variablekey);
         Debug.Assert(result != null, "Variable was just calculated and result can't be null");
         return result;
     } else {
         return ((ActionFrame) this.actionStack.Peek()).GetVariable(variablekey);
     }
 }
Exemplo n.º 16
0
 internal void ReplaceVariables(VariableAction[] vars) { this.variables = vars; }