From 48edf159e9ce98fcf21f0b1da9721c5f9f9a987f Mon Sep 17 00:00:00 2001 From: ishmal Date: Sun, 23 Apr 2006 21:47:31 +0000 Subject: [PATCH] Move contextual info to Stack --- src/dom/dom.h | 11 ++++++- src/dom/xpathparser.cpp | 21 +++++++++++- src/dom/xpathtoken.cpp | 52 +++++++++++++++++++++++++++-- src/dom/xpathtoken.h | 73 +++++++++++++++++++++++++++-------------- 4 files changed, 127 insertions(+), 30 deletions(-) diff --git a/src/dom/dom.h b/src/dom/dom.h index 046e63dd8..4117f91b7 100644 --- a/src/dom/dom.h +++ b/src/dom/dom.h @@ -12,7 +12,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005 Bob Jamison + * Copyright (C) 2006 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -835,6 +835,15 @@ public: nodes = other.nodes; } + /** + * + */ + NodeList &operator=(const NodeList &other) + { + nodes = other.nodes; + return *this; + } + /** * */ diff --git a/src/dom/xpathparser.cpp b/src/dom/xpathparser.cpp index 6baaea9c5..f3c57f6f5 100644 --- a/src/dom/xpathparser.cpp +++ b/src/dom/xpathparser.cpp @@ -10,7 +10,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005 Bob Jamison + * Copyright (C) 2006 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,6 +31,7 @@ #include "charclass.h" #include "xpathparser.h" + namespace org { namespace w3c @@ -45,6 +46,8 @@ namespace xpath //# M E S S A G E S //######################################################################### + + void XPathParser::trace(const char *fmt, ...) { if (!debug) @@ -60,6 +63,8 @@ void XPathParser::trace(const char *fmt, ...) va_end(args); } + + void XPathParser::error(const char *fmt, ...) { FILE *f = stdout; @@ -77,6 +82,8 @@ void XPathParser::error(const char *fmt, ...) fprintf(f, "^\n"); } + + void XPathParser::traceStack(const char *name, int pos, int depth) { if (!debug) @@ -94,6 +101,7 @@ void XPathParser::traceStack(const char *name, int pos, int depth) //######################################################################### //# L E X I C A L S C A N N I N G //######################################################################### + void XPathParser::lexTokAdd(int type, int loc) { LexTok tok(type, loc); @@ -296,6 +304,8 @@ int XPathParser::getNumber(int p0, double &dresult) return p; } + + int XPathParser::getLiteral(int p0, DOMString &result) { int p = p0; @@ -326,6 +336,10 @@ int XPathParser::getLiteral(int p0, DOMString &result) } + +/** + * NCName is a 'non-colonized' name + */ int XPathParser::getNCName(int p0, DOMString &result) { int p = p0; @@ -352,6 +366,11 @@ int XPathParser::getNCName(int p0, DOMString &result) return p; } + + +/** + * Name parsing with post-parsing + */ int XPathParser::getNameTest(int p0, DOMString &result) { int p = p0; diff --git a/src/dom/xpathtoken.cpp b/src/dom/xpathtoken.cpp index 9d2b86215..0254266d0 100644 --- a/src/dom/xpathtoken.cpp +++ b/src/dom/xpathtoken.cpp @@ -10,7 +10,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005 Bob Jamison + * Copyright (C) 2006 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -94,6 +94,25 @@ Stack::Stack() */ Stack::Stack(const Stack &other) { + assign(other); +} + + +/** + * + */ +Stack::~Stack() +{ +} + + +/** + * + */ +void Stack::assign(const Stack &other) +{ + root = other.root; + nodeList = other.nodeList; size = other.size; for (int i=0 ; i::iterator iter; for (iter = tokens.begin() ; iter != tokens.end() ; iter++) { Token *tok = *iter; - tok->execute(stack, list); + tok->execute(stack); } + list = stack.getNodeList(); + return list; } diff --git a/src/dom/xpathtoken.h b/src/dom/xpathtoken.h index 50bca1ef1..9b9259e06 100644 --- a/src/dom/xpathtoken.h +++ b/src/dom/xpathtoken.h @@ -13,7 +13,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005 Bob Jamison + * Copyright (C) 2006 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -113,6 +113,16 @@ public: */ virtual ~Stack(); + /** + * Assign our values to those of the other + */ + virtual void assign(const Stack &other); + + /** + * Reset the stack to its original settings + */ + virtual void reset(); + /** * Push a stack item onto the stack */ @@ -123,9 +133,22 @@ public: */ virtual StackItem pop(); + /** + * Set the root node + */ + virtual void setRootNode(const Node *node); + + /** + * Get the current node list; + */ + virtual NodeList &getNodeList(); + private: + Node *root; + NodeList nodeList; + StackItem items[STACK_SIZE]; int size; }; @@ -221,7 +244,7 @@ public: * Let this token execute itself on the given stack, * possibly adding Nodes to the node list. */ - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } /** @@ -286,7 +309,7 @@ public: stype = "str"; sval = val; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item; item.sval = sval; @@ -304,7 +327,7 @@ public: stype = "float"; dval = val; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item; item.dval = dval; @@ -322,7 +345,7 @@ public: stype = "int"; ival = val; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item; item.ival = ival; @@ -339,7 +362,7 @@ public: type = TOK_AND; stype = "and"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -357,7 +380,7 @@ public: type = TOK_OR; stype = "or"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -375,7 +398,7 @@ public: type = TOK_MOD; stype = "mod"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -393,7 +416,7 @@ public: type = TOK_DIV; stype = "div"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -411,7 +434,7 @@ public: type = TOK_MULTIPLY; stype = "mul"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -429,7 +452,7 @@ public: type = TOK_PLUS; stype = "plus"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -447,7 +470,7 @@ public: type = TOK_MINUS; stype = "minus"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -465,7 +488,7 @@ public: type = TOK_NEG; stype = "neg"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item; item.dval = -dval; @@ -483,7 +506,7 @@ public: type = TOK_EQUALS; stype = "equals"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -501,7 +524,7 @@ public: type = TOK_NOT_EQUALS; stype = "neq"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -519,7 +542,7 @@ public: type = TOK_LESS_THAN_EQUALS; stype = "lt_eq"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -537,7 +560,7 @@ public: type = TOK_LESS_THAN; stype = "lt"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -555,7 +578,7 @@ public: type = TOK_GREATER_THAN_EQUALS; stype = "gt"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -573,7 +596,7 @@ public: type = TOK_GREATER_THAN; stype = "gt_eq"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { StackItem item1 = stack.pop(); StackItem item2 = stack.pop(); @@ -596,7 +619,7 @@ public: type = TOK_ABSOLUTE; stype = "absolute"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } @@ -610,7 +633,7 @@ public: type = TOK_RELATIVE; stype = "relative"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } @@ -624,7 +647,7 @@ public: type = TOK_STEP; stype = "step"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } @@ -638,7 +661,7 @@ public: type = TOK_EXPR; stype = "token"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } @@ -652,7 +675,7 @@ public: type = TOK_UNION; stype = "union"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } @@ -672,7 +695,7 @@ public: type = TOK_POSITION; stype = "position"; } - virtual bool execute(Stack &stack, NodeList &list) + virtual bool execute(Stack &stack) { return true; } -- 2.30.2