dbertoni    2002/08/04 21:57:50

  Modified:    c/src/XSLT StylesheetHandler.cpp StylesheetHandler.hpp
  Log:
  Detect duplicate variable definitions.
  
  Revision  Changes    Path
  1.84      +95 -14    xml-xalan/c/src/XSLT/StylesheetHandler.cpp
  
  Index: StylesheetHandler.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.cpp,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- StylesheetHandler.cpp     26 Jul 2002 18:36:29 -0000      1.83
  +++ StylesheetHandler.cpp     5 Aug 2002 04:57:50 -0000       1.84
  @@ -152,8 +152,11 @@
        m_LXSLTScriptLang(),
        m_LXSLTScriptSrcURL(),
        m_pLXSLTExtensionNSH(0),
  -     m_locatorsPushed(0)
  +     m_locatorsPushed(0),
  +     m_globalVariableNames(),
  +     m_inScopeVariableNamesStack()
   {
  +     m_inScopeVariableNamesStack.reserve(eVariablesStackDefault);
   }
   
   
  @@ -201,6 +204,12 @@
                         m_strayElements.end(),
                         DeleteFunctor<ElemTemplateElement>());
   
  +     // Clean up any template that's left over...
  +     if (m_pTemplate != m_stylesheet.getWrapperlessTemplate())
  +     {
  +             delete m_pTemplate;
  +     }
  +
        m_elemStackParentedElements.clear();
   }
   
  @@ -511,9 +520,19 @@
                                        break;
             
                                case Constants::ELEMNAME_VARIABLE:
  -                                     elem = new 
ElemVariable(m_constructionContext,
  -                                                                             
  m_stylesheet,
  -                                                                             
  atts, lineNumber, columnNumber);
  +                                     {
  +                                             XalanAutoPtr<ElemVariable>      
newVar(
  +                                                     new ElemVariable(
  +                                                                     
m_constructionContext,
  +                                                                     
m_stylesheet,
  +                                                                     atts,
  +                                                                     
lineNumber,
  +                                                                     
columnNumber));
  +
  +                                             
checkForOrAddVariableName(newVar->getName(), locator);
  +
  +                                             elem = newVar.release();
  +                                     }
                                        break;
   
                                case Constants::ELEMNAME_PARAMVARIABLE:
  @@ -690,6 +709,8 @@
                                                }
                                        }
                                }
  +
  +                             
m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
                        }
                }
                else if (!m_inTemplate && startsWith(ns, 
m_constructionContext.getXalanXSLNameSpaceURL()))
  @@ -716,6 +737,8 @@
                        }
                        else
                        {
  +                             
m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
  +
                                // BEGIN SANJIVA CODE
                                // is this an extension element call?
                                ExtensionNSHandler*             nsh = 0;
  @@ -837,7 +860,9 @@
   
        m_pTemplate->appendChildElem(pElem);
        m_inTemplate = true;
  -     
  +
  +     m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
  +
        m_stylesheet.setWrapperlessTemplate(m_pTemplate);
   
        m_foundStylesheet = true;
  @@ -931,6 +956,7 @@
                m_elemStack.push_back(m_pTemplate);
                m_elemStackParentedElements.insert(m_pTemplate);
                m_inTemplate = true;
  +             
m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
                break;
   
        case Constants::ELEMNAME_EXTENSION:
  @@ -953,10 +979,18 @@
                                                                                
                                        atts, 
                                                                                
                                        lineNumber, columnNumber);
   
  +                     XalanAutoPtr<ElemVariable>      newVar(varelem);
  +
  +                     checkForOrAddVariableName(varelem->getName(), locator);
  +
                        m_elemStack.push_back(varelem);
                        m_inTemplate = true; // fake it out
  +                     
m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
                        m_stylesheet.setTopLevelVariable(varelem);
                        m_elemStackParentedElements.insert(varelem);
  +
  +                     newVar.release();
  +
                        varelem->setTopLevel(true);
                }
        break;
  @@ -981,6 +1015,7 @@
        case Constants::ELEMNAME_DEFINEATTRIBUTESET:
                {
                        m_inTemplate = true; // fake it out
  +                     
m_inScopeVariableNamesStack.push_back(QNameSetVectorType::value_type());
   
                        ElemAttributeSet* attrSet = new 
ElemAttributeSet(m_constructionContext,
                                                                                
                                           m_stylesheet,
  @@ -1272,6 +1307,53 @@
   
   
   void
  +StylesheetHandler::checkForOrAddVariableName(
  +                     const XalanQName&       theVariableName,
  +                     const Locator*          theLocator)
  +{
  +     XalanQNameByValue       theLocalVariableName(theVariableName);
  +
  +     if (m_inTemplate == false)
  +     {
  +             assert(m_inScopeVariableNamesStack.empty() == true);
  +
  +             if (m_globalVariableNames.find(theLocalVariableName) != 
m_globalVariableNames.end())
  +             {
  +                     error("A global variable with this name has already 
been declared", theLocator);
  +             }
  +             else
  +             {
  +                     m_globalVariableNames.insert(theLocalVariableName);
  +             }
  +     }
  +     else
  +     {
  +             assert(m_inScopeVariableNamesStack.empty() == false);
  +
  +             QNameSetVectorType::iterator            theCurrent = 
m_inScopeVariableNamesStack.begin();
  +             const QNameSetVectorType::iterator      theEnd = 
m_inScopeVariableNamesStack.end();
  +
  +             while(theCurrent != theEnd)
  +             {
  +                     QNameSetVectorType::value_type  theLocalScope = 
*theCurrent;
  +
  +                     if (theLocalScope.find(theLocalVariableName) != 
theLocalScope.end())
  +                     {
  +                             error("A variable with this name has already 
been declared in this template", theLocator);
  +                     }
  +
  +                     ++theCurrent;
  +             }
  +
  +             assert(theCurrent == theEnd);
  +
  +             m_inScopeVariableNamesStack.back().insert(theLocalVariableName);
  +     }
  +}
  +
  +
  +
  +void
   StylesheetHandler::processPreserveStripSpace(
                        const XalanDOMChar*             name,
                        const AttributeList&    atts,
  @@ -1611,6 +1693,13 @@
   
        const int tok = m_lastPopped->getXSLToken();
   
  +     if (m_inTemplate == true)
  +     {
  +             assert(m_inScopeVariableNamesStack.empty() == false);
  +
  +             m_inScopeVariableNamesStack.pop_back();
  +     }
  +
        if(Constants::ELEMNAME_TEMPLATE == tok)
        {
                m_inTemplate = false;
  @@ -1817,15 +1906,12 @@
                {
                        while(!m_whiteSpaceElems.empty())
                        {
  -#if 1
                                assert(m_whiteSpaceElems.back() != 0);
   
                                appendChildElementToParent(
                                        parent,
                                        m_whiteSpaceElems.back());
  -#else
  -                             
parent->appendChildElem(m_whiteSpaceElems.back());
  -#endif
  +
                                m_whiteSpaceElems.pop_back();
                        }
   
  @@ -1852,14 +1938,9 @@
   
                                if(isPrevCharData && ! isLastPoppedXSLText)
                                {
  -#if 1
                                        appendChildElementToParent(
                                                parent,
                                                elem.get());
  -
  -#else
  -                                     parent->appendChildElem(elem.get());
  -#endif
   
                                        elem.release();
   
  
  
  
  1.33      +21 -2     xml-xalan/c/src/XSLT/StylesheetHandler.hpp
  
  Index: StylesheetHandler.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.hpp,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- StylesheetHandler.hpp     14 May 2002 15:47:15 -0000      1.32
  +++ StylesheetHandler.hpp     5 Aug 2002 04:57:50 -0000       1.33
  @@ -79,6 +79,10 @@
   
   
   
  +#include <XPath/XalanQNameByValue.hpp>
  +
  +
  +
   #include <XSLT/NamespacesHandler.hpp>
   #include <XSLT/Stylesheet.hpp>
   
  @@ -89,7 +93,6 @@
   class ElemTextLiteral;
   class ExtensionNSHandler;
   class StylesheetConstructionContext;
  -class XalanQName;
   
   
   
  @@ -110,11 +113,16 @@
        typedef set<ElemTemplateElement*,
                                less<ElemTemplateElement*> >    
ElemTemplateSetType;
        typedef vector<bool>                                            
BoolStackType;
  +     typedef set<XalanQNameByValue,
  +                             less<XalanQNameByValue> >               
QNameSetType;
  +     typedef vector<QNameSetType>                            
QNameSetVectorType;
   #else
        typedef std::vector<ElemTemplateElement*>       ElemTemplateStackType;
        typedef std::vector<ElemTextLiteral*>           
ElemTextLiteralStackType;
        typedef std::set<ElemTemplateElement*>          ElemTemplateSetType;
        typedef std::vector<bool>                                       
BoolStackType;
  +     typedef std::set<XalanQNameByValue>                     QNameSetType;
  +     typedef std::vector<QNameSetType>                       
QNameSetVectorType;
   #endif
   
        /**
  @@ -517,6 +525,11 @@
                        const AttributeList&    atts,
                        const Locator*                  locator);
   
  +     void
  +     checkForOrAddVariableName(
  +                     const XalanQName&       theVariableName,
  +                     const Locator*          theLocator);
  +
        // Data members...
   
        /**
  @@ -601,9 +614,15 @@
        XalanDOMString                  m_LXSLTScriptSrcURL;
        ExtensionNSHandler*             m_pLXSLTExtensionNSH;
   
  -     // Note that this variable must not be saved by
  +     // Note that these variables must not be saved by
        // PushPopIncludeState...
        unsigned long   m_locatorsPushed;
  +
  +     QNameSetType            m_globalVariableNames;
  +
  +     enum { eVariablesStackDefault = 20 };
  +
  +     QNameSetVectorType      m_inScopeVariableNamesStack;
   
        /**
         * Init the wrapperless template
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to