Code

Move contextual info to Stack
authorishmal <ishmal@users.sourceforge.net>
Sun, 23 Apr 2006 21:47:31 +0000 (21:47 +0000)
committerishmal <ishmal@users.sourceforge.net>
Sun, 23 Apr 2006 21:47:31 +0000 (21:47 +0000)
src/dom/dom.h
src/dom/xpathparser.cpp
src/dom/xpathtoken.cpp
src/dom/xpathtoken.h

index 046e63dd8ada39b789173315a12bb1ff3cc5a144..4117f91b70a977eefcc450b767595c14231edd45 100644 (file)
@@ -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;
+        }
+
     /**
      *
      */
index 6baaea9c5946eb3386be9f380f9c8b812fc8c1b6..f3c57f6f51bbfbc50eb72bd09c18d18789de27f9 100644 (file)
@@ -10,7 +10,7 @@
  * Authors:\r
  *   Bob Jamison\r
  *\r
- * Copyright (C) 2005 Bob Jamison\r
+ * Copyright (C) 2006 Bob Jamison\r
  *\r
  *  This library is free software; you can redistribute it and/or\r
  *  modify it under the terms of the GNU Lesser General Public\r
@@ -31,6 +31,7 @@
 #include "charclass.h"\r
 #include "xpathparser.h"\r
 \r
+\r
 namespace org\r
 {\r
 namespace w3c\r
@@ -45,6 +46,8 @@ namespace xpath
 //# M E S S A G E S\r
 //#########################################################################\r
 \r
+\r
+\r
 void XPathParser::trace(const char *fmt, ...)\r
 {\r
     if (!debug)\r
@@ -60,6 +63,8 @@ void XPathParser::trace(const char *fmt, ...)
     va_end(args);\r
 }\r
 \r
+\r
+\r
 void XPathParser::error(const char *fmt, ...)\r
 {\r
     FILE *f = stdout;\r
@@ -77,6 +82,8 @@ void XPathParser::error(const char *fmt, ...)
     fprintf(f, "^\n");\r
 }\r
 \r
+\r
+\r
 void XPathParser::traceStack(const char *name, int pos, int depth)\r
 {\r
     if (!debug)\r
@@ -94,6 +101,7 @@ void XPathParser::traceStack(const char *name, int pos, int depth)
 //#########################################################################\r
 //# L E X I C A L    S C A N N I N G\r
 //#########################################################################\r
+\r
 void XPathParser::lexTokAdd(int type, int loc)\r
 {\r
     LexTok tok(type, loc);\r
@@ -296,6 +304,8 @@ int XPathParser::getNumber(int p0, double &dresult)
     return p;\r
 }\r
 \r
+\r
+\r
 int XPathParser::getLiteral(int p0, DOMString &result)\r
 {\r
     int p = p0;\r
@@ -326,6 +336,10 @@ int XPathParser::getLiteral(int p0, DOMString &result)
 }\r
 \r
 \r
+\r
+/**\r
+ * NCName is a 'non-colonized' name\r
+ */\r
 int XPathParser::getNCName(int p0, DOMString &result)\r
 {\r
     int p = p0;\r
@@ -352,6 +366,11 @@ int XPathParser::getNCName(int p0, DOMString &result)
     return p;\r
 }\r
 \r
+\r
+\r
+/**\r
+ * Name parsing with post-parsing\r
+ */\r
 int XPathParser::getNameTest(int p0, DOMString &result)\r
 {\r
     int p = p0;\r
index 9d2b86215921014c9cb59db01c48d0e88927cd34..0254266d0a4c1271c1fb21f961a4adf915e0dc3e 100644 (file)
@@ -10,7 +10,7 @@
  * Authors:\r
  *   Bob Jamison\r
  *\r
- * Copyright (C) 2005 Bob Jamison\r
+ * Copyright (C) 2006 Bob Jamison\r
  *\r
  *  This library is free software; you can redistribute it and/or\r
  *  modify it under the terms of the GNU Lesser General Public\r
@@ -94,6 +94,25 @@ Stack::Stack()
  */\r
 Stack::Stack(const Stack &other)\r
 {\r
+    assign(other);\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+Stack::~Stack()\r
+{\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void Stack::assign(const Stack &other)\r
+{\r
+    root = other.root;\r
+    nodeList = other.nodeList;\r
     size = other.size;\r
     for (int i=0 ; i<size ; i++)\r
         items[i] = other.items[i];\r
@@ -103,10 +122,17 @@ Stack::Stack(const Stack &other)
 /**\r
  *\r
  */\r
-Stack::~Stack()\r
+void Stack::reset()\r
 {\r
+    root = NULL;\r
+    NodeList n; /*no "clear" in api*/\r
+    nodeList = n;\r
+    size = 0;\r
 }\r
 \r
+\r
+\r
+\r
 /**\r
  *\r
  */\r
@@ -132,6 +158,22 @@ StackItem Stack::pop()
     return items[--size];\r
 }\r
 \r
+/**\r
+ * Set the root node\r
+ */\r
+void Stack::setRootNode(const Node *node)\r
+{\r
+    root = (Node *)node;\r
+}\r
+\r
+\r
+/**\r
+ * Get the current node list;\r
+ */\r
+NodeList &Stack::getNodeList()\r
+{\r
+    return nodeList;\r
+}\r
 \r
 \r
 //########################################################################\r
@@ -187,14 +229,18 @@ NodeList TokenList::execute(const Node *root)
         return list;\r
 \r
     Stack stack;\r
+    stack.setRootNode(root);\r
+\r
     //### Execute the token list\r
     std::vector<Token *>::iterator iter;\r
     for (iter = tokens.begin() ; iter != tokens.end() ; iter++)\r
         {\r
         Token *tok = *iter;\r
-        tok->execute(stack, list);\r
+        tok->execute(stack);\r
         }\r
 \r
+    list = stack.getNodeList();\r
+\r
     return list;\r
 }\r
 \r
index 50bca1ef198b11a15e44e4f3dd70eb90c85cd4eb..9b9259e06c5a2f5eae075d49d43c363010c2235e 100644 (file)
@@ -13,7 +13,7 @@
  * Authors:\r
  *   Bob Jamison\r
  *\r
- * Copyright (C) 2005 Bob Jamison\r
+ * Copyright (C) 2006 Bob Jamison\r
  *\r
  *  This library is free software; you can redistribute it and/or\r
  *  modify it under the terms of the GNU Lesser General Public\r
@@ -113,6 +113,16 @@ public:
      */\r
     virtual ~Stack();\r
 \r
+    /**\r
+     *  Assign our values to those of the other\r
+     */\r
+    virtual void assign(const Stack &other);\r
+\r
+    /**\r
+     * Reset the stack to its original settings\r
+     */\r
+    virtual void reset();\r
+\r
     /**\r
      * Push a stack item onto the stack\r
      */\r
@@ -123,9 +133,22 @@ public:
      */\r
     virtual StackItem pop();\r
 \r
+    /**\r
+     * Set the root node\r
+     */\r
+    virtual void setRootNode(const Node *node);\r
+\r
+    /**\r
+     * Get the current node list;\r
+     */\r
+    virtual NodeList &getNodeList();\r
+\r
 \r
 private:\r
 \r
+    Node *root;\r
+    NodeList nodeList;\r
+\r
     StackItem items[STACK_SIZE];\r
     int size;\r
 };\r
@@ -221,7 +244,7 @@ public:
      *  Let this token execute itself on the given stack,\r
      *  possibly adding Nodes to the node list.\r
      */\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         { return true; }\r
 \r
     /**\r
@@ -286,7 +309,7 @@ public:
         stype = "str";\r
         sval = val;\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item;\r
         item.sval = sval;\r
@@ -304,7 +327,7 @@ public:
         stype = "float";\r
         dval = val;\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item;\r
         item.dval = dval;\r
@@ -322,7 +345,7 @@ public:
         stype = "int";\r
         ival = val;\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item;\r
         item.ival = ival;\r
@@ -339,7 +362,7 @@ public:
         type = TOK_AND;\r
         stype = "and";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -357,7 +380,7 @@ public:
         type = TOK_OR;\r
         stype = "or";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -375,7 +398,7 @@ public:
         type = TOK_MOD;\r
         stype = "mod";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -393,7 +416,7 @@ public:
         type = TOK_DIV;\r
         stype = "div";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -411,7 +434,7 @@ public:
         type = TOK_MULTIPLY;\r
         stype = "mul";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -429,7 +452,7 @@ public:
         type = TOK_PLUS;\r
         stype = "plus";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -447,7 +470,7 @@ public:
         type = TOK_MINUS;\r
         stype = "minus";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -465,7 +488,7 @@ public:
         type = TOK_NEG;\r
         stype = "neg";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item;\r
         item.dval = -dval;\r
@@ -483,7 +506,7 @@ public:
         type = TOK_EQUALS;\r
         stype = "equals";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -501,7 +524,7 @@ public:
         type = TOK_NOT_EQUALS;\r
         stype = "neq";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -519,7 +542,7 @@ public:
         type = TOK_LESS_THAN_EQUALS;\r
         stype = "lt_eq";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -537,7 +560,7 @@ public:
         type = TOK_LESS_THAN;\r
         stype = "lt";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -555,7 +578,7 @@ public:
         type = TOK_GREATER_THAN_EQUALS;\r
         stype = "gt";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -573,7 +596,7 @@ public:
         type = TOK_GREATER_THAN;\r
         stype = "gt_eq";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         StackItem item1 = stack.pop();\r
         StackItem item2 = stack.pop();\r
@@ -596,7 +619,7 @@ public:
         type = TOK_ABSOLUTE;\r
         stype = "absolute";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r
@@ -610,7 +633,7 @@ public:
         type = TOK_RELATIVE;\r
         stype = "relative";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r
@@ -624,7 +647,7 @@ public:
         type = TOK_STEP;\r
         stype = "step";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r
@@ -638,7 +661,7 @@ public:
         type = TOK_EXPR;\r
         stype = "token";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r
@@ -652,7 +675,7 @@ public:
         type = TOK_UNION;\r
         stype = "union";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r
@@ -672,7 +695,7 @@ public:
         type = TOK_POSITION;\r
         stype = "position";\r
         }\r
-    virtual bool execute(Stack &stack, NodeList &list)\r
+    virtual bool execute(Stack &stack)\r
         {\r
         return true;\r
         }\r