From 4df23ac8a8490d70610ba828b088f675d69b6a2d Mon Sep 17 00:00:00 2001 From: ishmal Date: Fri, 7 Jul 2006 01:26:05 +0000 Subject: [PATCH] rearrange axis/context structure. make tokens more robust --- src/dom/Makefile.mingw | 5 +- src/dom/xpathparser.cpp | 126 ++-- src/dom/xpathparser.h | 2 +- src/dom/xpathtoken.cpp | 1040 +++++++++++++++++++++-------- src/dom/xpathtoken.h | 1364 +++++++++------------------------------ 5 files changed, 1146 insertions(+), 1391 deletions(-) diff --git a/src/dom/Makefile.mingw b/src/dom/Makefile.mingw index e1842ec11..58fdf1b5e 100644 --- a/src/dom/Makefile.mingw +++ b/src/dom/Makefile.mingw @@ -81,8 +81,8 @@ else # NATIVE COMPILER SETTINGS ########################################################################## -CC = mingw32-gcc -CXX = mingw32-g++ +CC = i686-pc-mingw32-gcc +CXX = i686-pc-mingw32-g++ AS = as AR = mingw32-ar RANLIB = ranlib @@ -160,7 +160,6 @@ io/uristream.o \ io/socket.o \ odf/odfdocument.o \ svg/svgimpl.o \ -svg/svglsimpl.o \ svg/svgparser.o \ util/thread.o \ util/ziptool.o diff --git a/src/dom/xpathparser.cpp b/src/dom/xpathparser.cpp index f0617795e..2c7c85d83 100644 --- a/src/dom/xpathparser.cpp +++ b/src/dom/xpathparser.cpp @@ -619,7 +619,7 @@ int XPathParser::lexicalScan() //######################################################################### -void XPathParser::tokAdd(Token *tok) +void XPathParser::tokAdd(const Token &tok) { tokens.add(tok); } @@ -639,14 +639,14 @@ int XPathParser::getLocationPath(int p0, int depth) int p2 = getAbsoluteLocationPath(p, depth+1); if (p2 > p) { - tokens.add(new TokAbsolute()); + tokens.add(Token::create(Token::TOK_ABSOLUTE)); return p2; } p2 = getRelativeLocationPath(p, depth+1); if (p2 > p) { - tokens.add(new TokRelative()); + tokens.add(Token::create(Token::TOK_RELATIVE)); return p2; } @@ -731,7 +731,7 @@ int XPathParser::getRelativeLocationPath(int p0, int depth) { p++; // a '//' is an abbreviation for /descendant-or-self:node()/ - tokAdd(new TokAxisDescendantOrSelf()); + tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT_OR_SELF)); p2 = getRelativeLocationPath(p, depth+1); if (p2 < 0) { @@ -831,31 +831,31 @@ int XPathParser::getAxisSpecifier(int p0, int depth) switch (axisType) { case ANCESTOR_OR_SELF: - tokAdd(new TokAxisAncestorOrSelf()); + tokAdd(Token::create(Token::TOK_AXIS_ANCESTOR_OR_SELF)); case ANCESTOR: - tokAdd(new TokAxisAncestor()); + tokAdd(Token::create(Token::TOK_AXIS_ANCESTOR)); case ATTRIBUTE: - tokAdd(new TokAxisAttribute()); + tokAdd(Token::create(Token::TOK_AXIS_ATTRIBUTE)); case CHILD: - tokAdd(new TokAxisChild()); + tokAdd(Token::create(Token::TOK_AXIS_CHILD)); case DESCENDANT_OR_SELF: - tokAdd(new TokAxisDescendantOrSelf()); + tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT_OR_SELF)); case DESCENDANT: - tokAdd(new TokAxisDescendant()); + tokAdd(Token::create(Token::TOK_AXIS_DESCENDANT)); case FOLLOWING_SIBLING: - tokAdd(new TokAxisFollowingSibling()); + tokAdd(Token::create(Token::TOK_AXIS_FOLLOWING_SIBLING)); case FOLLOWING: - tokAdd(new TokAxisFollowing()); + tokAdd(Token::create(Token::TOK_AXIS_FOLLOWING)); case NAMESPACE: - tokAdd(new TokAxisNamespace()); + tokAdd(Token::create(Token::TOK_AXIS_NAMESPACE)); case PARENT: - tokAdd(new TokAxisParent()); + tokAdd(Token::create(Token::TOK_AXIS_PARENT)); case PRECEDING_SIBLING: - tokAdd(new TokAxisPrecedingSibling()); + tokAdd(Token::create(Token::TOK_AXIS_PRECEDING_SIBLING)); case PRECEDING: - tokAdd(new TokAxisPreceding()); + tokAdd(Token::create(Token::TOK_AXIS_PRECEDING)); case SELF: - tokAdd(new TokAxisSelf()); + tokAdd(Token::create(Token::TOK_AXIS_SELF)); default: { error("unknown axis type %d", axisType); @@ -917,7 +917,7 @@ int XPathParser::getNodeTest(int p0, int depth) if (t.getType() == NAME_TEST) { p++; - tokAdd(new TokNameTest(t.getStringValue())); + tokAdd(Token::create(Token::TOK_NAME_TEST, t.getStringValue())); return p; } if (t.getType() == NODE_TYPE) @@ -1110,14 +1110,16 @@ int XPathParser::getPrimaryExpr(int p0, int depth) if (lexTokType(p) == LITERAL) { - tokens.add(new TokStr(lexTok(p).getStringValue())); + tokens.add(Token::create(Token::TOK_STR, + lexTok(p).getStringValue())); p++; return p; } if (lexTokType(p) == NUMBER) { - tokens.add(new TokFloat(lexTok(p).getDoubleValue())); + tokens.add(Token::create(Token::TOK_FLOAT, + lexTok(p).getDoubleValue())); p++; return p; } @@ -1195,59 +1197,59 @@ int XPathParser::getFunctionCall(int p0, int depth) // Function names from http://www.w3.org/TR/xpath#NT-FunctionName if (name == "last") - tokens.add(new TokFuncLast()); + tokens.add(Token::create(Token::TOK_FUNC_LAST)); else if (name == "position") - tokens.add(new TokFuncPosition()); + tokens.add(Token::create(Token::TOK_FUNC_POSITION)); else if (name == "count") - tokens.add(new TokFuncCount()); + tokens.add(Token::create(Token::TOK_FUNC_COUNT)); else if (name == "id") - tokens.add(new TokFuncId()); + tokens.add(Token::create(Token::TOK_FUNC_ID)); else if (name == "local-name") - tokens.add(new TokFuncLocalName()); + tokens.add(Token::create(Token::TOK_FUNC_LOCAL_NAME)); else if (name == "namespace-uri") - tokens.add(new TokFuncNamespaceUri()); + tokens.add(Token::create(Token::TOK_FUNC_NAMESPACE_URI)); else if (name == "name") - tokens.add(new TokFuncName()); + tokens.add(Token::create(Token::TOK_FUNC_NAME)); else if (name == "string") - tokens.add(new TokFuncString()); + tokens.add(Token::create(Token::TOK_FUNC_STRING)); else if (name == "concat") - tokens.add(new TokFuncConcat()); + tokens.add(Token::create(Token::TOK_FUNC_CONCAT)); else if (name == "starts-with") - tokens.add(new TokFuncStartsWith()); + tokens.add(Token::create(Token::TOK_FUNC_STARTS_WITH)); else if (name == "contains") - tokens.add(new TokFuncContains()); + tokens.add(Token::create(Token::TOK_FUNC_CONTAINS)); else if (name == "substring-before") - tokens.add(new TokFuncSubstringBefore()); + tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING_BEFORE)); else if (name == "substring-after") - tokens.add(new TokFuncSubstringAfter()); + tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING_AFTER)); else if (name == "substring") - tokens.add(new TokFuncSubstring()); + tokens.add(Token::create(Token::TOK_FUNC_SUBSTRING)); else if (name == "string-length") - tokens.add(new TokFuncStringLength()); + tokens.add(Token::create(Token::TOK_FUNC_STRING_LENGTH)); else if (name == "normalize-space") - tokens.add(new TokFuncNormalizeSpace()); + tokens.add(Token::create(Token::TOK_FUNC_NORMALIZE_SPACE)); else if (name == "translate") - tokens.add(new TokFuncTranslate()); + tokens.add(Token::create(Token::TOK_FUNC_TRANSLATE)); else if (name == "boolean") - tokens.add(new TokFuncBoolean()); + tokens.add(Token::create(Token::TOK_FUNC_BOOLEAN)); else if (name == "not") - tokens.add(new TokFuncNot()); + tokens.add(Token::create(Token::TOK_FUNC_NOT)); else if (name == "true") - tokens.add(new TokFuncTrue()); + tokens.add(Token::create(Token::TOK_FUNC_TRUE)); else if (name == "false") - tokens.add(new TokFuncFalse()); + tokens.add(Token::create(Token::TOK_FUNC_FALSE)); else if (name == "lang") - tokens.add(new TokFuncLang()); + tokens.add(Token::create(Token::TOK_FUNC_LANG)); else if (name == "number") - tokens.add(new TokFuncNumber()); + tokens.add(Token::create(Token::TOK_FUNC_NUMBER)); else if (name == "sum") - tokens.add(new TokFuncSum()); + tokens.add(Token::create(Token::TOK_FUNC_SUM)); else if (name == "floor") - tokens.add(new TokFuncFloor()); + tokens.add(Token::create(Token::TOK_FUNC_FLOOR)); else if (name == "ceiling") - tokens.add(new TokFuncCeiling()); + tokens.add(Token::create(Token::TOK_FUNC_CEILING)); else if (name == "round") - tokens.add(new TokFuncRound()); + tokens.add(Token::create(Token::TOK_FUNC_ROUND)); else { error("unknown function name:'%s'", name.c_str()); @@ -1302,7 +1304,7 @@ int XPathParser::getUnionExpr(int p0, int depth) error("OR (|) requires union expression on the left"); return -1; } - tokens.add(new TokUnion()); + tokens.add(Token::create(Token::TOK_UNION)); p = p2; } return p; @@ -1446,7 +1448,7 @@ int XPathParser::getOrExpr(int p0, int depth) p = p2; return p; } - tokens.add(new TokOr()); + tokens.add(Token::create(Token::TOK_OR)); return p; } @@ -1485,7 +1487,7 @@ int XPathParser::getAndExpr(int p0, int depth) p = p2; return p; } - tokens.add(new TokAnd()); + tokens.add(Token::create(Token::TOK_AND)); return p; } @@ -1522,7 +1524,7 @@ int XPathParser::getEqualityExpr(int p0, int depth) error("Equality expression expected after =="); return -1; } - tokens.add(new TokEquals()); + tokens.add(Token::create(Token::TOK_EQUALS)); p = p2; return p; } @@ -1536,7 +1538,7 @@ int XPathParser::getEqualityExpr(int p0, int depth) error("Equality expression expected after !="); return -1; } - tokens.add(new TokNotEquals()); + tokens.add(Token::create(Token::TOK_NOT_EQUALS)); p = p2; return p; } @@ -1580,7 +1582,7 @@ int XPathParser::getRelationalExpr(int p0, int depth) error("Relational expression after '>'"); return -1; } - tokens.add(new TokGreaterThan()); + tokens.add(Token::create(Token::TOK_GREATER_THAN)); p = p2; return p; } @@ -1593,7 +1595,7 @@ int XPathParser::getRelationalExpr(int p0, int depth) error("Relational expression after '<'"); return -1; } - tokens.add(new TokLessThan()); + tokens.add(Token::create(Token::TOK_LESS_THAN)); p = p2; return p; } @@ -1606,7 +1608,7 @@ int XPathParser::getRelationalExpr(int p0, int depth) error("Relational expression after '>='"); return -1; } - tokens.add(new TokGreaterThanEquals()); + tokens.add(Token::create(Token::TOK_GREATER_THAN_EQUALS)); p = p2; return p; } @@ -1619,7 +1621,7 @@ int XPathParser::getRelationalExpr(int p0, int depth) error("Relational expression after '<='"); return -1; } - tokens.add(new TokLessThanEquals()); + tokens.add(Token::create(Token::TOK_LESS_THAN_EQUALS)); p = p2; return p; } @@ -1662,7 +1664,7 @@ int XPathParser::getAdditiveExpr(int p0, int depth) error("Additive expression after '+'"); return -1; } - tokens.add(new TokPlus()); + tokens.add(Token::create(Token::TOK_PLUS)); p = p2; return p; } @@ -1675,7 +1677,7 @@ int XPathParser::getAdditiveExpr(int p0, int depth) error("Additive expression after '-'"); return -1; } - tokens.add(new TokMinus()); + tokens.add(Token::create(Token::TOK_MINUS)); p = p2; return p; } @@ -1719,7 +1721,7 @@ int XPathParser::getMultiplicativeExpr(int p0, int depth) error("Multiplicative expression after '*'"); return -1; } - tokens.add(new TokMul()); + tokens.add(Token::create(Token::TOK_MUL)); p = p2; return p; } @@ -1733,7 +1735,7 @@ int XPathParser::getMultiplicativeExpr(int p0, int depth) error("Multiplicative expression after 'div'"); return -1; } - tokens.add(new TokDiv()); + tokens.add(Token::create(Token::TOK_DIV)); p = p2; return p; } @@ -1747,7 +1749,7 @@ int XPathParser::getMultiplicativeExpr(int p0, int depth) error("Multiplicative expression after 'mod'"); return -1; } - tokens.add(new TokMod()); + tokens.add(Token::create(Token::TOK_MOD)); p = p2; return p; } @@ -1790,7 +1792,7 @@ int XPathParser::getUnaryExpr(int p0, int depth) error("Unary expression after '-'"); return -1; } - tokens.add(new TokNeg()); + tokens.add(Token::create(Token::TOK_NEG)); p = p2; return p; } diff --git a/src/dom/xpathparser.h b/src/dom/xpathparser.h index 25001016e..4bf19b72f 100644 --- a/src/dom/xpathparser.h +++ b/src/dom/xpathparser.h @@ -515,7 +515,7 @@ private: /** * Add a newly derived token to the token list; */ - void tokAdd(Token *token); + void tokAdd(const Token &token); /** * The grammar definitions marked [1]-[39] are directly diff --git a/src/dom/xpathtoken.cpp b/src/dom/xpathtoken.cpp index 41b7ad39d..cf51bf9ba 100644 --- a/src/dom/xpathtoken.cpp +++ b/src/dom/xpathtoken.cpp @@ -42,354 +42,883 @@ namespace dom namespace xpath { + + //######################################################################## //# X P A T H T O K E N //######################################################################## -typedef struct +//######################################################################## +//# X P A T H T O K E N T Y P E S +//######################################################################## + + + +//########################### +//# V A L U E S +//########################### + +static bool tokStr(Token &tok, TokenExecutor &exec) { - int ival; - char *sval; -} TokenStringPair; - -static TokenStringPair tokenStrings[] = -{ - //primitives - { Token::TOK_NOP, "nop" }, - { Token::TOK_STR, "str" }, - { Token::TOK_INT, "int" }, - { Token::TOK_FLOAT, "float" }, - //operators - { Token::TOK_AND, "and" }, - { Token::TOK_OR, "or" }, - { Token::TOK_MOD, "mod" }, - { Token::TOK_DIV, "div" }, - { Token::TOK_MULTIPLY, "multiply" }, - { Token::TOK_DOUBLE_SLASH, "double-slash" }, - { Token::TOK_SLASH, "slash" }, - { Token::TOK_PIPE, "pipe" }, - { Token::TOK_PLUS, "plus" }, - { Token::TOK_MINUS, "minus" }, - { Token::TOK_NEG, "neg" }, - { Token::TOK_EQUALS, "equals" }, - { Token::TOK_NOT_EQUALS, "not-equals" }, - { Token::TOK_LESS_THAN_EQUALS, "less-than-equals" }, - { Token::TOK_LESS_THAN, "less-than" }, - { Token::TOK_GREATER_THAN_EQUALS, "greater-than-equals" }, - { Token::TOK_GREATER_THAN, "greater-than" }, - //path types - { Token::TOK_ABSOLUTE, "absolute" }, - { Token::TOK_RELATIVE, "relative" }, - { Token::TOK_STEP, "step" }, - { Token::TOK_NAME_TEST, "name-test" }, - { Token::TOK_EXPR, "expr" }, - { Token::TOK_UNION, "union" }, - //axis types - { Token::TOK_AXIS_ANCESTOR_OR_SELF, "axis-ancestor-or-self" }, - { Token::TOK_AXIS_ANCESTOR, "axis-ancestor" }, - { Token::TOK_AXIS_ATTRIBUTE, "axis-attribute" }, - { Token::TOK_AXIS_CHILD, "axis-child" }, - { Token::TOK_AXIS_DESCENDANT_OR_SELF, "axis-descendant-or-self" }, - { Token::TOK_AXIS_DESCENDANT, "axis-descendant" }, - { Token::TOK_AXIS_FOLLOWING_SIBLING, "axis-following-sibling" }, - { Token::TOK_AXIS_FOLLOWING, "axis-following" }, - { Token::TOK_AXIS_NAMESPACE, "axis-namespace" }, - { Token::TOK_AXIS_PARENT, "axis-parent" }, - { Token::TOK_AXIS_PRECEDING_SIBLING, "axis-preceding-sibling" }, - { Token::TOK_AXIS_PRECEDING, "axis-preceding" }, - { Token::TOK_AXIS_SELF, "axis-self" }, - //function types - { Token::TOK_FUNC_LAST, "func-last" }, - { Token::TOK_FUNC_POSITION, "func-position" }, - { Token::TOK_FUNC_COUNT, "func-count" }, - { Token::TOK_FUNC_ID, "func-id" }, - { Token::TOK_FUNC_LOCAL_NAME, "func-local-name" }, - { Token::TOK_FUNC_NAMESPACE_URI, "func-namespace-uri" }, - { Token::TOK_FUNC_NAME, "func-name" }, - { Token::TOK_FUNC_STRING, "func-string" }, - { Token::TOK_FUNC_CONCAT, "func-concat" }, - { Token::TOK_FUNC_STARTS_WITH, "func-starts-with" }, - { Token::TOK_FUNC_CONTAINS, "func-contains" }, - { Token::TOK_FUNC_SUBSTRING_BEFORE, "func-substring-before" }, - { Token::TOK_FUNC_SUBSTRING_AFTER, "func-substring-after" }, - { Token::TOK_FUNC_SUBSTRING, "func-substring" }, - { Token::TOK_FUNC_STRING_LENGTH, "func-string-length" }, - { Token::TOK_FUNC_NORMALIZE_SPACE, "func-normalize-space" }, - { Token::TOK_FUNC_TRANSLATE, "func-translate" }, - { Token::TOK_FUNC_BOOLEAN, "func-boolean" }, - { Token::TOK_FUNC_NOT, "func-not" }, - { Token::TOK_FUNC_TRUE, "func-true" }, - { Token::TOK_FUNC_FALSE, "func-false" }, - { Token::TOK_FUNC_LANG, "func-lang" }, - { Token::TOK_FUNC_NUMBER, "func-number" }, - { Token::TOK_FUNC_SUM, "func-sum" }, - { Token::TOK_FUNC_FLOOR, "func-floor" }, - { Token::TOK_FUNC_CEILING, "func-ceiling" }, - { Token::TOK_FUNC_ROUND, "func-round" }, - { -1, (char *)0 } -}; + StackItem item; + item.sval = tok.sval; + exec.push(item); + return true; +} +static bool tokFloat(Token &tok, TokenExecutor &exec) +{ + StackItem item; + item.dval = tok.dval; + exec.push(item); + return true; +} -/** - * Return the string TokenType of this token - * (in the .cpp file) - */ -DOMString Token::getTypeString() +static bool tokInt(Token &tok, TokenExecutor &exec) { - DOMString ret = "unknown"; - for (TokenStringPair *pair = tokenStrings ; pair->sval ; pair++) - { - if (pair->ival == type) - { - ret = pair->sval; - break; - } - } - return ret; + StackItem item; + item.ival = tok.ival; + exec.push(item); + return true; } +static bool tokAnd(Token &tok, TokenExecutor &exec) +{ + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = item1.ival && item2.ival; + exec.push(item1); + return true; +} +static bool tokOr(Token &tok, TokenExecutor &exec) +{ + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = item1.ival || item2.ival; + exec.push(item1); + return true; +} -//######################################################################## -//# X P A T H A X I S -//######################################################################## +static bool tokMod(Token &tok, TokenExecutor &exec) +{ + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.dval = fmod(item1.dval, item2.dval); + exec.push(item1); + return true; +} -/** - * - */ -Axis::Axis() + +static bool tokDiv(Token &tok, TokenExecutor &exec) { - init(); + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.dval /= item2.dval; + exec.push(item1); + return true; } +static bool tokMul(Token &tok, TokenExecutor &exec) +{ + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.dval *= item2.dval; + exec.push(item1); + return true; +} -/** - * - */ -Axis::Axis(int tokPos) +static bool tokPlus(Token &tok, TokenExecutor &exec) { - init(); - tokenPosition = tokPos; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.dval += item2.dval; + exec.push(item1); + return true; } +static bool tokMinus(Token &tok, TokenExecutor &exec) +{ + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.dval -= item2.dval; + exec.push(item1); + return true; +} -/** - * - */ -Axis::Axis(const Axis &other) + +static bool tokNeg(Token &tok, TokenExecutor &exec) { - init(); - assign(other); + StackItem item = exec.pop(); + item.dval = -item.dval; + item.ival = -item.ival; + exec.push(item); + return true; } -/** - * - */ -Axis::~Axis() +static bool tokEquals(Token &tok, TokenExecutor &exec) { + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval == item2.dval); + exec.push(item1); + return true; } -/** - * - */ -Axis &Axis::operator=(const Axis &other) +static bool tokNotEquals(Token &tok, TokenExecutor &exec) { - assign(other); - return *this; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval != item2.dval); + exec.push(item1); + return true; } -/** - * - */ -void Axis::init() + +static bool tokLessThan(Token &tok, TokenExecutor &exec) { - tokenPosition = 0; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval < item2.dval); + exec.push(item1); + return true; } -/** - * - */ -void Axis::assign(const Axis &other) + +static bool tokLessThanEquals(Token &tok, TokenExecutor &exec) { - tokenPosition = other.tokenPosition; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval <= item2.dval); + exec.push(item1); + return true; } -/** - * - */ -void Axis::setPosition(unsigned int val) + +static bool tokGreaterThanEquals(Token &tok, TokenExecutor &exec) { - tokenPosition = val; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval >= item2.dval); + exec.push(item1); + return true; } -/** - * - */ -unsigned int Axis::getPosition() + +static bool tokGreaterThan(Token &tok, TokenExecutor &exec) { - return tokenPosition; + StackItem item1 = exec.pop(); + StackItem item2 = exec.pop(); + item1.ival = (item1.dval > item2.dval); + exec.push(item1); + return true; } -/** - * - */ -void Axis::setNode(const Node *val) + + + + + +//########################### +//# X P A T H I T E M S +//########################### + +static bool tokAbsolute(Token &tok, TokenExecutor &exec) { - node = (Node *)val; + return true; } -/** - * - */ -Node *Axis::getNode() +static bool tokRelative(Token &tok, TokenExecutor &exec) { - return node; + return true; } -//######################################################################## -//# X P A T H S T A C K I T E M -//######################################################################## +static bool tokStep(Token &tok, TokenExecutor &exec) +{ + return true; +} -/** - * - */ -StackItem::StackItem() +static bool tokNameTest(Token &tok, TokenExecutor &exec) { - ival = 0L; - dval = 0.0; + return true; } +static bool tokExpr(Token &tok, TokenExecutor &exec) +{ + return true; +} -/** - * - */ -StackItem::StackItem(const StackItem &other) +static bool tokUnion(Token &tok, TokenExecutor &exec) { - assign(other); + return true; } -/** - * - */ -StackItem::~StackItem() + + +//########################### +//# A X I S +//########################### + + +static bool tokAxisAncestorOrSelf(Token &tok, TokenExecutor &exec) { + return true; } -/** - * - */ -StackItem &StackItem::operator=(const StackItem &other) +static bool tokAxisAncestor(Token &tok, TokenExecutor &exec) { - assign(other); - return *this; + return true; } -/** - * - */ -void StackItem::assign(const StackItem &other) + +static bool tokAxisAttribute(Token &tok, TokenExecutor &exec) { - sval = other.sval; - ival = other.ival; - dval = other.dval; + return true; } -//######################################################################## -//# T O K E N L I S T -//######################################################################## +static bool tokAxisChild(Token &tok, TokenExecutor &exec) +{ + return true; +} -/** - * - */ -TokenList::TokenList() + +static bool tokAxisDescendantOrSelf(Token &tok, TokenExecutor &exec) { + return true; } -/** - * - */ -TokenList::TokenList(const TokenList &other) +static bool tokAxisDescendant(Token &tok, TokenExecutor &exec) { - assign(other); + return true; } -/** - * - */ -TokenList &TokenList::operator=(const TokenList &other) + +static bool tokAxisFollowingSibling(Token &tok, TokenExecutor &exec) { - assign(other); - return *this; + return true; } -/** - * - */ -void TokenList::assign(const TokenList &other) + +static bool tokAxisFollowing(Token &tok, TokenExecutor &exec) { - tokens = other.tokens; + return true; } -/** - * - */ -TokenList::~TokenList() + +static bool tokAxisNamespace(Token &tok, TokenExecutor &exec) { - clear(); + return true; } -/** - * - */ -void TokenList::clear() + +static bool tokAxisParent(Token &tok, TokenExecutor &exec) { - std::vector::iterator iter; - for (iter = tokens.begin() ; iter!= tokens.end() ; iter++) - { - delete (*iter); - } - tokens.clear(); + return true; } -/** - * - */ -void TokenList::add(Token *tok) + +static bool tokAxisPrecedingSibling(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokAxisPreceding(Token &tok, TokenExecutor &exec) { - tokens.push_back(tok); + return true; } +static bool tokAxisSelf(Token &tok, TokenExecutor &exec) +{ + return true; +} + + + +//########################### +//# F U N C T I O N S +//########################### + + +static bool tokFuncLast(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncPosition(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncCount(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncId(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncLocalName(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncNamespaceUri(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncName(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncString(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncConcat(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncStartsWith(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncContains(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncSubstringBefore(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncSubstringAfter(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncSubstring(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncStringLength(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncNormalizeSpace(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncTranslate(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncBoolean(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncNot(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncTrue(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncFalse(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncLang(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncNumber(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncSum(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncFloor(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncCeiling(Token &tok, TokenExecutor &exec) +{ + return true; +} + + +static bool tokFuncRound(Token &tok, TokenExecutor &exec) +{ + return true; +} + + + + + +typedef struct +{ + int ival; + char *sval; + TokenFunc tokenFunc; +} TokenTableEntry; + +static TokenTableEntry tokenTable[] = +{ + //### primitives + { + Token::TOK_NOP, + "nop", + NULL + }, + { + Token::TOK_STR, + "str", + tokStr + }, + { + Token::TOK_INT, + "int", + tokInt + }, + { + Token::TOK_FLOAT, + "float", + tokFloat + }, + + //### operators + { + Token::TOK_AND, + "and", + tokAnd + }, + { + Token::TOK_OR, + "or", + tokOr + }, + { + Token::TOK_MOD, + "mod", + tokMod + }, + { + Token::TOK_DIV, + "div", + tokDiv + }, + { + Token::TOK_MUL, + "multiply", + tokMul + }, + { + Token::TOK_DOUBLE_SLASH, + "double-slash", + NULL + }, + { + Token::TOK_SLASH, + "slash", + NULL + }, + { + Token::TOK_PIPE, + "pipe", + NULL + }, + { + Token::TOK_PLUS, + "plus", + tokPlus + }, + { + Token::TOK_MINUS, + "minus", + tokMinus + }, + { + Token::TOK_NEG, + "neg", + tokNeg + }, + { + Token::TOK_EQUALS, + "equals", + tokEquals + }, + { + Token::TOK_NOT_EQUALS, + "not-equals", + tokNotEquals + }, + { + Token::TOK_LESS_THAN_EQUALS, + "less-than-equals", + tokLessThanEquals + }, + { + Token::TOK_LESS_THAN, + "less-than", + tokLessThan + }, + { + Token::TOK_GREATER_THAN_EQUALS, + "greater-than-equals", + tokGreaterThanEquals + }, + { + Token::TOK_GREATER_THAN, + "greater-than", + tokGreaterThan + }, + + //### path types + { + Token::TOK_ABSOLUTE, + "absolute", + tokAbsolute + }, + { + Token::TOK_RELATIVE, + "relative", + tokRelative + }, + { + Token::TOK_STEP, + "step", + tokStep + }, + { + Token::TOK_NAME_TEST, + "name-test", + tokNameTest + }, + { + Token::TOK_EXPR, + "expr", + tokExpr + }, + { + Token::TOK_UNION, + "union", + tokUnion + }, + + //### axis types + { + Token::TOK_AXIS_ANCESTOR_OR_SELF, + "axis-ancestor-or-self", + tokAxisAncestorOrSelf + }, + { + Token::TOK_AXIS_ANCESTOR, + "axis-ancestor", + tokAxisAncestor + }, + { + Token::TOK_AXIS_ATTRIBUTE, + "axis-attribute", + tokAxisAttribute + }, + { + Token::TOK_AXIS_CHILD, + "axis-child", + tokAxisChild + }, + { + Token::TOK_AXIS_DESCENDANT_OR_SELF, + "axis-descendant-or-self", + tokAxisDescendantOrSelf + }, + { + Token::TOK_AXIS_DESCENDANT, + "axis-descendant", + tokAxisDescendant + }, + { + Token::TOK_AXIS_FOLLOWING_SIBLING, + "axis-following-sibling", + tokAxisFollowingSibling + }, + { + Token::TOK_AXIS_FOLLOWING, + "axis-following", + tokAxisFollowing + }, + { + Token::TOK_AXIS_NAMESPACE, + "axis-namespace", + tokAxisNamespace + }, + { + Token::TOK_AXIS_PARENT, + "axis-parent", + tokAxisParent + }, + { + Token::TOK_AXIS_PRECEDING_SIBLING, + "axis-preceding-sibling", + tokAxisPrecedingSibling + }, + { + Token::TOK_AXIS_PRECEDING, + "axis-preceding", + tokAxisPreceding + }, + { + Token::TOK_AXIS_SELF, + "axis-self", + tokAxisSelf + }, + + //### function types + { + Token::TOK_FUNC_LAST, + "func-last", + tokFuncLast + }, + { + Token::TOK_FUNC_POSITION, + "func-position", + tokFuncPosition + }, + { + Token::TOK_FUNC_COUNT, + "func-count", + tokFuncCount + }, + { + Token::TOK_FUNC_ID, + "func-id", + tokFuncId + }, + { + Token::TOK_FUNC_LOCAL_NAME, + "func-local-name", + tokFuncLocalName + }, + { + Token::TOK_FUNC_NAMESPACE_URI, + "func-namespace-uri", + tokFuncNamespaceUri + }, + { + Token::TOK_FUNC_NAME, + "func-name", + tokFuncName + }, + { + Token::TOK_FUNC_STRING, + "func-string", + tokFuncString + }, + { + Token::TOK_FUNC_CONCAT, + "func-concat", + tokFuncConcat + }, + { + Token::TOK_FUNC_STARTS_WITH, + "func-starts-with", + tokFuncStartsWith + }, + { + Token::TOK_FUNC_CONTAINS, + "func-contains", + tokFuncContains + }, + { + Token::TOK_FUNC_SUBSTRING_BEFORE, + "func-substring-before", + tokFuncSubstringBefore + }, + { + Token::TOK_FUNC_SUBSTRING_AFTER, + "func-substring-after", + tokFuncSubstringAfter + }, + { + Token::TOK_FUNC_SUBSTRING, + "func-substring", + tokFuncSubstring + }, + { + Token::TOK_FUNC_STRING_LENGTH, + "func-string-length", + tokFuncStringLength + }, + { + Token::TOK_FUNC_NORMALIZE_SPACE, + "func-normalize-space", + tokFuncNormalizeSpace + }, + { + Token::TOK_FUNC_TRANSLATE, + "func-translate", + tokFuncTranslate + }, + { + Token::TOK_FUNC_BOOLEAN, + "func-boolean", + tokFuncBoolean + }, + { + Token::TOK_FUNC_NOT, + "func-not", + tokFuncNot + }, + { + Token::TOK_FUNC_TRUE, + "func-true", + tokFuncTrue + }, + { + Token::TOK_FUNC_FALSE, + "func-false", + tokFuncFalse + }, + { + Token::TOK_FUNC_LANG, + "func-lang", + tokFuncLang + }, + { + Token::TOK_FUNC_NUMBER, + "func-number", + tokFuncNumber + }, + { + Token::TOK_FUNC_SUM, + "func-sum", + tokFuncSum + }, + { + Token::TOK_FUNC_FLOOR, + "func-floor", + tokFuncFloor + }, + { + Token::TOK_FUNC_CEILING, + "func-ceiling", + tokFuncCeiling + }, + { + Token::TOK_FUNC_ROUND, + "func-round", + tokFuncRound + }, + + { -1, + (char *)0, + NULL + } +}; + + /** - * + * Return the string TokenType of this token + * (in the .cpp file) */ -unsigned int TokenList::size() const +DOMString Token::getTypeString() { - return (unsigned int)tokens.size(); + DOMString ret = "unknown"; + for (TokenTableEntry *entry = tokenTable ; entry->sval ; entry++) + { + if (entry->ival == type) + { + ret = entry->sval; + break; + } + } + return ret; } /** - * + * Create a token of the given type, giving it + * the data and personalities it needs */ -void TokenList::dump() +Token Token::create(int type, long ival, + double dval, const DOMString &sval) { - std::vector::iterator iter; - printf("############# TOKENS\n"); - for (iter = tokens.begin() ; iter != tokens.end() ; iter++) + Token tok(type, ival, dval, sval); + for (TokenTableEntry *entry = tokenTable ; entry->sval ; entry++) { - Token *tok = *iter; - tok->dump(); + if (entry->ival == type) + { + tok.tokenFunc = entry->tokenFunc; + break; + } } + + return tok; } + + + + + + //######################################################################## //# X P A T H E X E C U T O R //######################################################################## @@ -426,11 +955,8 @@ TokenExecutor::~TokenExecutor() */ void TokenExecutor::assign(const TokenExecutor &other) { - axis = other.axis; - axisStack = other.axisStack; - stackSize = other.stackSize; - for (int i=0 ; i=STACK_SIZE) - { - return; - } - stack[stackSize++] = item; + stack.push_back(item); } /** @@ -486,12 +999,15 @@ void TokenExecutor::push(StackItem &item) */ StackItem TokenExecutor::pop() { - if (stackSize<1) + if (stack.size()<1) { StackItem item; return item; } - return stack[--stackSize]; + std::vector::iterator iter = stack.end()-1; + StackItem item = *iter; + stack.erase(iter); + return item; } diff --git a/src/dom/xpathtoken.h b/src/dom/xpathtoken.h index 6c44e639d..26aee60f8 100644 --- a/src/dom/xpathtoken.h +++ b/src/dom/xpathtoken.h @@ -48,70 +48,13 @@ namespace xpath typedef org::w3c::dom::DOMString DOMString; -class Axis -{ -public: - /** - * Constructor - */ - Axis(); - - /** - * Constructor - */ - Axis(int tokPos); - - /** - * Copy constructor - */ - Axis(const Axis &other); - - /** - * Destructor - */ - virtual ~Axis(); - - /** - * - */ - Axis &operator=(const Axis &other); - - /** - * - */ - void init(); - - /** - * - */ - void assign(const Axis &other); - - /** - * - */ - void setPosition(unsigned int val); - - /** - * - */ - unsigned int getPosition(); - - /** - * - */ - void setNode(const Node *node); - - /** - * - */ - Node *getNode(); -private: +class TokenExecutor; - int tokenPosition; - Node *node; -}; +//######################################################################## +//# S T A C K I T E M +//######################################################################## /** @@ -124,28 +67,26 @@ public: /** * Constructor */ - StackItem(); + StackItem() + { init(); } /** * Copy constructor */ - StackItem(const StackItem &other); + StackItem(const StackItem &other) + { assign(other); } /** * Destructor */ - virtual ~StackItem(); - - /** - * - */ - StackItem &operator=(const StackItem &other); + virtual ~StackItem() + {} /** * */ - void assign(const StackItem &other); - + StackItem &operator=(const StackItem &other) + { assign(other); return *this; } //treat the stack item like an union of string, integer, and double @@ -164,99 +105,41 @@ public: */ double dval; -}; - -class TokenList; - -//######################################################################## -//# T O K E N E X E C U T O R -//######################################################################## - -#define STACK_SIZE 1024 - -/** - * A token evaluator, with stack and axis context - */ -class TokenExecutor -{ -public: - - /** - * Constructor - */ - TokenExecutor(); - - /** - * Copy constructor - */ - TokenExecutor(const TokenExecutor &other); - - /** - * Destructor - */ - virtual ~TokenExecutor(); - - /** - * Assign our values to those of the other - */ - virtual void assign(const TokenExecutor &other); - - /** - * Reset the stack to its original settings - */ - virtual void reset(); - - /** - * Push a stack item onto the stack - */ - virtual void push(StackItem &item); - - /** - * Pop a stack item from the stack - */ - virtual StackItem pop(); - - /** - * Execute a token list on the stack - */ - NodeList execute(const TokenList &list, const Node *node); - - /** - * - */ - Axis axis; - - /** - * - */ - std::vector axisStack; private: - /** - * Contains the StackItem stack; - */ - StackItem stack[STACK_SIZE]; + void init() + { + sval = ""; + ival = 0; + dval = 0.0; + } - /** - * Marks the head of the stack, for push() and pop() - */ - int stackSize; + void assign(const StackItem &other) + { + sval = other.sval; + ival = other.ival; + dval = other.dval; + } - /** - * Current list of nodes found by the expression - */ - NodeList nodeList; +}; -}; +/** + * Contains the StackItem stack; + */ +typedef std::vector Stack; //######################################################################## //# X P A T H T O K E N //######################################################################## +class Token; +class TokenExecutor; + +typedef bool (*TokenFunc)(Token &tok, TokenExecutor &exec); /** @@ -287,7 +170,7 @@ public: TOK_OR, TOK_MOD, TOK_DIV, - TOK_MULTIPLY, + TOK_MUL, TOK_DOUBLE_SLASH, TOK_SLASH, TOK_PIPE, @@ -358,22 +241,38 @@ public: * Constructor with a NOP default type */ Token() - { - type = TOK_NOP; - ival = 0L; - dval = 0.0; + { init(); } + + /** + * Constructor with a NOP default type + */ + Token(int typeArg) + { init(); type = typeArg; } + + /** + * Constructor with a NOP default type + */ + Token(int typeArg, + long ivalArg, double dvalArg, const DOMString &svalArg) + { + init(); + type = typeArg, + ival = ivalArg; + dval = dvalArg; + sval = svalArg; } /** * Copy constructor */ Token(const Token &other) - { - type = other.type; - sval = other.sval; - ival = other.ival; - dval = other.dval; - } + { assign(other); } + + /** + * Assignment + */ + Token &operator=(const Token &other) + { assign(other); return *this; } /** * Destructor @@ -395,8 +294,12 @@ public: * Let this token execute itself on the given stack, * possibly adding Nodes to the node list. */ - virtual bool execute(TokenExecutor &stack) - { return true; } + virtual bool execute(TokenExecutor &exec) + { + if (tokenFunc) + return tokenFunc(*this, exec); + return false; + } /** * Print the contents of this token @@ -424,1007 +327,345 @@ public: */ double dval; -protected: + /** + * + */ + static Token create(int type, long ival, + double dval, const DOMString &sval); /** - * The enmerated token type + * */ - int type; + static Token create(int type) + { return create(type, 0, 0.0, ""); } + + /** + * + */ + static Token create(int type, long val) + { return create(type, val, 0.0, ""); } + /** + * + */ + static Token create(int type, double val) + { return create(type, 0, val, ""); } -private: + /** + * + */ + static Token create(int type, const DOMString &val) + { return create(type, 0, 0.0, val); } -}; +protected: -//######################################################################## -//# X P A T H T O K E N T Y P E S -//######################################################################## + /** + * The enmerated token type + */ + int type; + /** + * The function that defines the behaviour of this token + */ + TokenFunc tokenFunc; -//########################### -//# V A L U E S -//########################### +private: -class TokStr : public Token -{ -public: - TokStr(const DOMString &val) + void init() { - type = TOK_STR; - sval = val; + tokenFunc = NULL; + type = TOK_NOP; + ival = 0L; + dval = 0.0; } - virtual bool execute(TokenExecutor &exec) + + void assign(const Token &other) { - StackItem item; - item.sval = sval; - exec.push(item); - return true; + tokenFunc = other.tokenFunc; + type = other.type; + sval = other.sval; + ival = other.ival; + dval = other.dval; } + + }; -class TokFloat : public Token + +//######################################################################## +//# C O N T E X T +//######################################################################## + +/** + * + */ +class Context { public: - TokFloat(double val) - { - type = TOK_FLOAT; - dval = val; - } - virtual bool execute(TokenExecutor &exec) + + //# From 2.3, principal type of child axes + typedef enum { - StackItem item; - item.dval = dval; - exec.push(item); - return true; - } -}; + AXIS_ATTRIBUTE, + AXIS_NAMESPACE, + AXIS_ELEMENT + } PrincipalNodeType; -class TokInt : public Token -{ -public: - TokInt(long val) + /** + * Constructor + */ + Context() + { init(); } + + /** + * Constructor + */ + Context(int principalNodeTypeArg) + { init(); principalNodeType = principalNodeTypeArg; } + + /** + * Copy constructor + */ + Context(const Context &other) + { assign(other); } + + /** + * Destructor + */ + virtual ~Context() + {} + + /** + * + */ + Context &operator=(const Context &other) + { assign(other); return *this; } + + /** + * + */ + std::vector &getTokens() + { return tokens; } + + /** + * + */ + void setTokens(const std::vector &tokensArg) + { tokens = tokensArg; } + + /** + * + */ + void add(const Token &token) + { tokens.push_back(token); } + + /** + * + */ + virtual void dump() { - type = TOK_INT; - ival = val; + for (unsigned int i=0 ; i tokens; + }; -class TokOr : public Token -{ -public: - TokOr() - { - type = TOK_OR; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = item1.ival || item2.ival; - exec.push(item1); - return true; - } -}; - -class TokMod : public Token -{ -public: - TokMod() - { - type = TOK_MOD; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.dval = fmod(item1.dval, item2.dval); - exec.push(item1); - return true; - } -}; - -class TokDiv : public Token -{ -public: - TokDiv() - { - type = TOK_DIV; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.dval /= item2.dval; - exec.push(item1); - return true; - } -}; - -class TokMul : public Token -{ -public: - TokMul() - { - type = TOK_MULTIPLY; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.dval *= item2.dval; - exec.push(item1); - return true; - } -}; - -class TokPlus : public Token -{ -public: - TokPlus() - { - type = TOK_PLUS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.dval += item2.dval; - exec.push(item1); - return true; - } -}; - -class TokMinus : public Token -{ -public: - TokMinus() - { - type = TOK_MINUS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.dval -= item2.dval; - exec.push(item1); - return true; - } -}; - -class TokNeg : public Token -{ -public: - TokNeg() - { - type = TOK_NEG; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item = exec.pop(); - item.dval = -item.dval; - item.ival = -item.ival; - exec.push(item); - return true; - } -}; - -class TokEquals : public Token -{ -public: - TokEquals() - { - type = TOK_EQUALS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval == item2.dval); - exec.push(item1); - return true; - } -}; - -class TokNotEquals : public Token -{ -public: - TokNotEquals() - { - type = TOK_NOT_EQUALS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval != item2.dval); - exec.push(item1); - return true; - } -}; - -class TokLessThanEquals : public Token -{ -public: - TokLessThanEquals() - { - type = TOK_LESS_THAN_EQUALS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval <= item2.dval); - exec.push(item1); - return true; - } -}; - -class TokLessThan : public Token -{ -public: - TokLessThan() - { - type = TOK_LESS_THAN; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval < item2.dval); - exec.push(item1); - return true; - } -}; - -class TokGreaterThanEquals : public Token -{ -public: - TokGreaterThanEquals() - { - type = TOK_GREATER_THAN_EQUALS; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval >= item2.dval); - exec.push(item1); - return true; - } -}; - -class TokGreaterThan : public Token -{ -public: - TokGreaterThan() - { - type = TOK_GREATER_THAN; - } - virtual bool execute(TokenExecutor &exec) - { - StackItem item1 = exec.pop(); - StackItem item2 = exec.pop(); - item1.ival = (item1.dval > item2.dval); - exec.push(item1); - return true; - } -}; - - -//########################### -//# X P A T H I T E M S -//########################### - -class TokAbsolute : public Token -{ -public: - TokAbsolute() - { - type = TOK_ABSOLUTE; - } - virtual bool execute(TokenExecutor &exec) - { - Node *n = exec.axis.getNode(); - while (n->getParentNode()) - n = n->getParentNode(); - exec.axis.setNode(n); - return true; - } -}; - -class TokRelative : public Token -{ -public: - TokRelative() - { - type = TOK_RELATIVE; - } - virtual bool execute(TokenExecutor &exec) - { - ///exec.axis.currentNode = stack.rootNode; - return true; - } -}; - -class TokStep : public Token -{ -public: - TokStep() - { - type = TOK_STEP; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokNameTest : public Token -{ -public: - TokNameTest(const DOMString &name) - { - type = TOK_NAME_TEST; - sval = name; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokExpr : public Token -{ -public: - TokExpr() - { - type = TOK_EXPR; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokUnion : public Token -{ -public: - TokUnion() - { - type = TOK_UNION; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - - - - -//########################### -//# A X I S -//########################### - - -class TokAxisAncestorOrSelf : public Token -{ -public: - TokAxisAncestorOrSelf() - { - type = TOK_AXIS_ANCESTOR_OR_SELF; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisAncestor : public Token -{ -public: - TokAxisAncestor() - { - type = TOK_AXIS_ANCESTOR; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisAttribute : public Token -{ -public: - TokAxisAttribute() - { - type = TOK_AXIS_ATTRIBUTE; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisChild : public Token -{ -public: - TokAxisChild() - { - type = TOK_AXIS_CHILD; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisDescendantOrSelf : public Token -{ -public: - TokAxisDescendantOrSelf() - { - type = TOK_AXIS_DESCENDANT_OR_SELF; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisDescendant : public Token -{ -public: - TokAxisDescendant() - { - type = TOK_AXIS_DESCENDANT; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisFollowingSibling : public Token -{ -public: - TokAxisFollowingSibling() - { - type = TOK_AXIS_FOLLOWING_SIBLING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisFollowing : public Token -{ -public: - TokAxisFollowing() - { - type = TOK_AXIS_FOLLOWING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisNamespace : public Token -{ -public: - TokAxisNamespace() - { - type = TOK_AXIS_NAMESPACE; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisParent : public Token -{ -public: - TokAxisParent() - { - type = TOK_AXIS_PARENT; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisPrecedingSibling : public Token -{ -public: - TokAxisPrecedingSibling() - { - type = TOK_AXIS_PRECEDING_SIBLING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisPreceding : public Token -{ -public: - TokAxisPreceding() - { - type = TOK_AXIS_PRECEDING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokAxisSelf : public Token -{ -public: - TokAxisSelf() - { - type = TOK_AXIS_SELF; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - - - -//########################### -//# F U N C T I O N S -//########################### - -class TokFuncLast : public Token -{ -public: - TokFuncLast() - { - type = TOK_FUNC_LAST; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncPosition : public Token -{ -public: - TokFuncPosition() - { - type = TOK_FUNC_POSITION; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncCount : public Token -{ -public: - TokFuncCount() - { - type = TOK_FUNC_COUNT; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncId : public Token -{ -public: - TokFuncId() - { - type = TOK_FUNC_ID; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncLocalName : public Token -{ -public: - TokFuncLocalName() - { - type = TOK_FUNC_LOCAL_NAME; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncNamespaceUri : public Token -{ -public: - TokFuncNamespaceUri() - { - type = TOK_FUNC_NAMESPACE_URI; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncName : public Token -{ -public: - TokFuncName() - { - type = TOK_FUNC_NAME; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncString : public Token -{ -public: - TokFuncString() - { - type = TOK_FUNC_STRING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; - -class TokFuncConcat : public Token -{ -public: - TokFuncConcat() - { - type = TOK_FUNC_CONCAT; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; -class TokFuncStartsWith : public Token -{ -public: - TokFuncStartsWith() - { - type = TOK_FUNC_STARTS_WITH; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; +//######################################################################## +//# T O K E N L I S T +//######################################################################## -class TokFuncContains : public Token +/** + * + */ +class TokenList { public: - TokFuncContains() - { - type = TOK_FUNC_CONTAINS; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; -class TokFuncSubstringBefore : public Token -{ -public: - TokFuncSubstringBefore() - { - type = TOK_FUNC_SUBSTRING_BEFORE; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; + /** + * + */ + TokenList() + { init(); } -class TokFuncSubstringAfter : public Token -{ -public: - TokFuncSubstringAfter() - { - type = TOK_FUNC_SUBSTRING_AFTER; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; + /** + * + */ + TokenList(const TokenList &other) + { assign(other); } -class TokFuncSubstring : public Token -{ -public: - TokFuncSubstring() - { - type = TOK_FUNC_SUBSTRING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; + /** + * + */ + TokenList &operator=(const TokenList &other) + { assign(other); return *this; } -class TokFuncStringLength : public Token -{ -public: - TokFuncStringLength() - { - type = TOK_FUNC_STRING_LENGTH; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; + /** + * + */ + virtual ~TokenList() + { } -class TokFuncNormalizeSpace : public Token -{ -public: - TokFuncNormalizeSpace() - { - type = TOK_FUNC_NORMALIZE_SPACE; - } - virtual bool execute(TokenExecutor &exec) + /** + * + */ + virtual void add(const Context &contextArg) { - return true; + contexts.push_back(currentContext); + currentContext=contextArg; } -}; -class TokFuncTranslate : public Token -{ -public: - TokFuncTranslate() - { - type = TOK_FUNC_TRANSLATE; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; + /** + * + */ + virtual void add(const Token &token) + { currentContext.add(token); } -class TokFuncBoolean : public Token -{ -public: - TokFuncBoolean() - { - type = TOK_FUNC_BOOLEAN; - } - virtual bool execute(TokenExecutor &exec) + /** + * + */ + virtual void dump() { - return true; + for (unsigned int i=0 ; i contexts; -class TokFuncCeiling : public Token -{ -public: - TokFuncCeiling() - { - type = TOK_FUNC_CEILING; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } -}; -class TokFuncRound : public Token -{ -public: - TokFuncRound() - { - type = TOK_FUNC_ROUND; - } - virtual bool execute(TokenExecutor &exec) - { - return true; - } }; - - //######################################################################## -//# T O K E N L I S T +//# T O K E N E X E C U T O R //######################################################################## + /** - * + * A token evaluator, with stack and axis context */ -class TokenList +class TokenExecutor { public: /** - * + * Constructor */ - TokenList(); + TokenExecutor(); /** - * + * Copy constructor */ - TokenList(const TokenList &other); + TokenExecutor(const TokenExecutor &other); /** - * + * Destructor */ - TokenList &operator=(const TokenList &other); + virtual ~TokenExecutor(); /** - * + * Assign our values to those of the other */ - void assign(const TokenList &other); + virtual void assign(const TokenExecutor &other); /** - * + * Reset the stack to its original settings */ - virtual ~TokenList(); + virtual void reset(); /** - * + * Push a stack item onto the stack */ - virtual void clear(); + virtual void push(StackItem &item); /** - * + * Pop a stack item from the stack */ - virtual void add(Token *tok); + virtual StackItem pop(); /** - * + * Execute a token list on the stack */ - virtual unsigned int size() const; + NodeList execute(const TokenList &list, const Node *node); + +private: /** - * + * Contains the StackItem stack; */ - virtual void dump(); + Stack stack; -private: + /** + * + */ + TokenList tokenList; - std::vector tokens; + /** + * + */ + NodeList nodeList; }; @@ -1432,9 +673,6 @@ private: - - - } // namespace xpath } // namespace dom } // namespace w3c -- 2.30.2