From fe40d482f5b084a476e1e808d3d9e744319263a1 Mon Sep 17 00:00:00 2001 From: jez <> Date: Mon, 24 Nov 2008 23:11:22 +0000 Subject: [PATCH] Aha! The push/pop precedence thing is, of course, wrongly wrong. Need to assign the new precedence at the point we encounter the xsl:import, then set that precedence as current when we actually load it. I'll sort that out next time, because it's bedtime for programmers now. --- .../XSLT/impl/xslt_compilation_context.hpp | 4 ++ include/XSLT/impl/xslt_precedence.hpp | 50 +++++++++++++------ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/include/XSLT/impl/xslt_compilation_context.hpp b/include/XSLT/impl/xslt_compilation_context.hpp index f7ae4698..380de094 100755 --- a/include/XSLT/impl/xslt_compilation_context.hpp +++ b/include/XSLT/impl/xslt_compilation_context.hpp @@ -149,6 +149,10 @@ public: precedenceStack_.pop(); } // pop_import_precedence + // void set_precedence(const Prcedence& prec) + + // const Precedence& next_precedence() + const Precedence& precedence() const { return precedenceStack_.top(); diff --git a/include/XSLT/impl/xslt_precedence.hpp b/include/XSLT/impl/xslt_precedence.hpp index 1dc7f022..3256f71c 100755 --- a/include/XSLT/impl/xslt_precedence.hpp +++ b/include/XSLT/impl/xslt_precedence.hpp @@ -28,12 +28,17 @@ public: } // Precedence private: - //Precedence(const std::vector precedence) : - Precedence(int precedence) : + Precedence(const std::vector precedence) : precedence_(precedence) { } // Precedence + Precedence(int precedence) : + precedence_() + { + precedence_.push_back(precedence); + } // Precedence + public: ~Precedence() { } @@ -49,37 +54,48 @@ public: Precedence& operator=(const Precedence& rhs) { - //std::vector other(rhs.precedence_); - //precedence_.swap(other); - precedence_ = rhs.precedence_; + std::vector other(rhs.precedence_); + precedence_.swap(other); return *this; } // operator= Precedence nextGeneration(int p) const { - Precedence next(p); - //Precedence next(precedence_); - //next.precedence_.push_back(p); + Precedence next(precedence_); + next.precedence_.push_back(p); return next; } // nextGeneration private: - // std::vector precedence_; - int precedence_; + std::vector precedence_; friend bool operator<(const Precedence& lhs, const Precedence& rhs); + friend std::ostream& operator<<(std::ostream& os, const Precedence& prec); }; // class Precedence bool operator<(const Precedence& lhs, const Precedence& rhs) { - return lhs.precedence_ < rhs.precedence_; + return lhs.precedence_.back() < rhs.precedence_.back(); } // PrecedenceCompare +std::ostream& operator<<(std::ostream& os, const Precedence& prec) +{ + os << "("; + for(std::vector::const_iterator p = prec.precedence_.begin(), pe = prec.precedence_.end(); p != pe; ++p) + { + if(p != prec.precedence_.begin()) + os << ","; + os << *p; + } // for .. + os << ")"; +} // operator<< + class PrecedenceStack { public: PrecedenceStack() : - stack_() + stack_(), + count_(1) { stack_.push(Precedence::InitialPrecedence()); } // PrecedenceStack @@ -90,7 +106,11 @@ public: } // PrecedenceStack const Precedence& top() const { return stack_.top(); } - void push() { stack_.push(top().nextGeneration(count_++)); } + void push() + { + stack_.push(top().nextGeneration(count_++)); + std::cout << "Pushed " << top() << std::endl; + } void pop() { stack_.pop(); } void freeze() { @@ -101,8 +121,6 @@ public: private: std::stack stack_; - static int count_; + int count_; }; // class PrecedenceStack - -int PrecedenceStack::count_ = 0; #endif