Rewrite of XPath Lexer and Parser. Also implement the remaining XPath features (Unary minus and processing-insruction(Literal)). Bug 75102.

Lexer changes by Pike, parser and expressionclasses changes by me.
r=peterv Pike(on my code) me(on pikes code), sr=jst
This commit is contained in:
sicking%bigfoot.com 2001-06-30 13:54:38 +00:00
Родитель d134c1e1ee
Коммит ee6851b4ce
22 изменённых файлов: 1238 добавлений и 2026 удалений

Просмотреть файл

@ -78,12 +78,13 @@ LOBJS =../source/base/ArrayList.o \
../source/xpath/BooleanResult.o \
../source/xpath/ElementExpr.o \
../source/xpath/ErrorFunctionCall.o \
../source/xpath/Expr.o \
../source/xpath/ExprLexer.o \
../source/xpath/ExprLexerChars.o \
../source/xpath/ExprParser.o \
../source/xpath/ExtensionFunctionCall.o \
../source/xpath/FilterExpr.o \
../source/xpath/FunctionCall.o \
../source/xpath/IdentityExpr.o \
../source/xpath/LocationStep.o \
../source/xpath/MultiplicativeExpr.o \
../source/xpath/NodeSet.o \
@ -92,7 +93,6 @@ LOBJS =../source/base/ArrayList.o \
../source/xpath/NumberExpr.o \
../source/xpath/NumberFunctionCall.o \
../source/xpath/NumberResult.o \
../source/xpath/ParentExpr.o \
../source/xpath/PathExpr.o \
../source/xpath/PredicateList.o \
../source/xpath/RelationalExpr.o \
@ -102,6 +102,7 @@ LOBJS =../source/base/ArrayList.o \
../source/xpath/StringResult.o \
../source/xpath/TextExpr.o \
../source/xpath/UnionExpr.o \
../source/xpath/UnaryExpr.o \
../source/xpath/VariableRefExpr.o \
../source/xpath/XPathNames.o \
../source/xpath/XPathProcessor.o \

Просмотреть файл

@ -73,12 +73,13 @@ CPP_OBJS= \
..\source\xpath\$(OBJDIR)\BooleanResult.obj \
..\source\xpath\$(OBJDIR)\ElementExpr.obj \
..\source\xpath\$(OBJDIR)\ErrorFunctionCall.obj \
..\source\xpath\$(OBJDIR)\Expr.obj \
..\source\xpath\$(OBJDIR)\ExprLexer.obj \
..\source\xpath\$(OBJDIR)\ExprLexerChars.obj \
..\source\xpath\$(OBJDIR)\ExprParser.obj \
..\source\xpath\$(OBJDIR)\ExtensionFunctionCall.obj \
..\source\xpath\$(OBJDIR)\FilterExpr.obj \
..\source\xpath\$(OBJDIR)\FunctionCall.obj \
..\source\xpath\$(OBJDIR)\IdentityExpr.obj \
..\source\xpath\$(OBJDIR)\LocationStep.obj \
..\source\xpath\$(OBJDIR)\MultiplicativeExpr.obj \
..\source\xpath\$(OBJDIR)\NodeSet.obj \
@ -87,7 +88,6 @@ CPP_OBJS= \
..\source\xpath\$(OBJDIR)\NumberExpr.obj \
..\source\xpath\$(OBJDIR)\NumberFunctionCall.obj \
..\source\xpath\$(OBJDIR)\NumberResult.obj \
..\source\xpath\$(OBJDIR)\ParentExpr.obj \
..\source\xpath\$(OBJDIR)\PathExpr.obj \
..\source\xpath\$(OBJDIR)\PredicateList.obj \
..\source\xpath\$(OBJDIR)\RelationalExpr.obj \
@ -97,6 +97,7 @@ CPP_OBJS= \
..\source\xpath\$(OBJDIR)\StringResult.obj \
..\source\xpath\$(OBJDIR)\TextExpr.obj \
..\source\xpath\$(OBJDIR)\UnionExpr.obj \
..\source\xpath\$(OBJDIR)\UnaryExpr.obj \
..\source\xpath\$(OBJDIR)\VariableRefExpr.obj \
..\source\xpath\$(OBJDIR)\XPathNames.obj \
..\source\xpath\$(OBJDIR)\XPathProcessor.obj \

Просмотреть файл

@ -70,12 +70,13 @@ OBJS =../base/ArrayList.o \
../xpath/BooleanResult.o \
../xpath/ElementExpr.o \
../xpath/ErrorFunctionCall.o \
../xpath/Expr.o \
../xpath/ExprLexer.o \
../xpath/ExprLexerChars.o \
../xpath/ExprParser.o \
../xpath/ExtensionFunctionCall.o \
../xpath/FilterExpr.o \
../xpath/FunctionCall.o \
../xpath/IdentityExpr.o \
../xpath/LocationStep.o \
../xpath/MultiplicativeExpr.o \
../xpath/NodeSet.o \
@ -83,7 +84,6 @@ OBJS =../base/ArrayList.o \
../xpath/NumberExpr.o \
../xpath/NumberFunctionCall.o \
../xpath/NumberResult.o \
../xpath/ParentExpr.o \
../xpath/PathExpr.o \
../xpath/PredicateList.o \
../xpath/RelationalExpr.o \
@ -93,6 +93,7 @@ OBJS =../base/ArrayList.o \
../xpath/StringResult.o \
../xpath/TextExpr.o \
../xpath/UnionExpr.o \
../xpath/UnaryExpr.o \
../xpath/VariableRefExpr.o \
../xpath/XPathNames.o \
../xml/XMLUtils.o \

Просмотреть файл

@ -68,12 +68,13 @@ CPP_OBJS= \
../xpath/$(OBJDIR)/BooleanResult.obj \
../xpath/$(OBJDIR)/ElementExpr.obj \
../xpath/$(OBJDIR)/ErrorFunctionCall.obj \
../xpath/$(OBJDIR)/Expr.obj \
../xpath/$(OBJDIR)/ExprLexer.obj \
../xpath/$(OBJDIR)/ExprLexerChars.obj \
../xpath/$(OBJDIR)/ExprParser.obj \
../xpath/$(OBJDIR)/ExtensionFunctionCall.obj \
../xpath/$(OBJDIR)/FilterExpr.obj \
../xpath/$(OBJDIR)/FunctionCall.obj \
../xpath/$(OBJDIR)/IdentityExpr.obj \
../xpath/$(OBJDIR)/LocationStep.obj \
../xpath/$(OBJDIR)/MultiplicativeExpr.obj \
../xpath/$(OBJDIR)/NodeSet.obj \
@ -81,7 +82,6 @@ CPP_OBJS= \
../xpath/$(OBJDIR)/NumberExpr.obj \
../xpath/$(OBJDIR)/NumberFunctionCall.obj \
../xpath/$(OBJDIR)/NumberResult.obj \
../xpath/$(OBJDIR)/ParentExpr.obj \
../xpath/$(OBJDIR)/PathExpr.obj \
../xpath/$(OBJDIR)/PredicateList.obj \
../xpath/$(OBJDIR)/RelationalExpr.obj \
@ -91,6 +91,7 @@ CPP_OBJS= \
../xpath/$(OBJDIR)/StringResult.obj \
../xpath/$(OBJDIR)/TextExpr.obj \
../xpath/$(OBJDIR)/UnionExpr.obj \
../xpath/$(OBJDIR)/UnaryExpr.obj \
../xpath/$(OBJDIR)/VariableRefExpr.obj \
../xpath/$(OBJDIR)/XPathNames.obj \
../xml/$(OBJDIR)/XMLUtils.obj \

Просмотреть файл

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: BasicNodeExpr.cpp,v 1.4 2001-05-14 14:22:46 axel%pike.org Exp $
* $Id: BasicNodeExpr.cpp,v 1.5 2001-06-30 13:54:26 sicking%bigfoot.com Exp $
*/
#include "Expr.h"
/**
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.4 $ $Date: 2001-05-14 14:22:46 $
* @version $Revision: 1.5 $ $Date: 2001-06-30 13:54:26 $
**/
//- Constructors -/
@ -38,6 +38,7 @@
**/
BasicNodeExpr::BasicNodeExpr() {
this->type = NodeExpr::NODE_EXPR;
nodeNameSet = MB_FALSE;
} //-- BasicNodeExpr
/**
@ -45,6 +46,7 @@ BasicNodeExpr::BasicNodeExpr() {
**/
BasicNodeExpr::BasicNodeExpr(NodeExpr::NodeExprType nodeExprType) {
this->type = nodeExprType;
nodeNameSet = MB_FALSE;
} //-- BasicNodeExpr
/**
@ -56,6 +58,15 @@ BasicNodeExpr::~BasicNodeExpr() {};
//- Public Methods -/
//------------------/
void BasicNodeExpr::setNodeName(const String& name) {
this->nodeName = name;
nodeNameSet = MB_TRUE;
}
//-----------------------------/
//- Methods from NodeExpr.cpp -/
//-----------------------------/
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
@ -65,7 +76,8 @@ BasicNodeExpr::~BasicNodeExpr() {};
**/
ExprResult* BasicNodeExpr::evaluate(Node* context, ContextState* cs) {
NodeSet* nodeSet = new NodeSet();
if ( !context ) return nodeSet;
if (!context)
return nodeSet;
Node* node = context->getFirstChild();
while (node) {
if (matches(node, context, cs))
@ -75,17 +87,14 @@ ExprResult* BasicNodeExpr::evaluate(Node* context, ContextState* cs) {
return nodeSet;
} //-- evaluate
//-----------------------------/
//- Methods from NodeExpr.cpp -/
//-----------------------------/
/**
* Returns the default priority of this Pattern based on the given Node,
* Returns the default priority of this Expr based on the given Node,
* context Node, and ContextState.
* If this pattern does not match the given Node under the current context Node and
* ContextState then Negative Infinity is returned.
**/
double BasicNodeExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
double BasicNodeExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs) {
if (nodeNameSet)
return 0;
return -0.5;
} //-- getDefaultPriority
@ -102,20 +111,21 @@ short BasicNodeExpr::getType() {
* the given context
**/
MBool BasicNodeExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( !node ) return MB_FALSE;
switch ( type ) {
if (!node)
return MB_FALSE;
switch (type) {
case NodeExpr::COMMENT_EXPR:
return (MBool) (node->getNodeType() == Node::COMMENT_NODE);
return (MBool)(node->getNodeType() == Node::COMMENT_NODE);
case NodeExpr::PI_EXPR :
return (MBool) (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE);
return (MBool)(node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE &&
!nodeNameSet || nodeName.isEqual(node->getNodeName()));
default: //-- node()
if(node->getNodeType() == Node::TEXT_NODE)
if (node->getNodeType() == Node::TEXT_NODE)
return !cs->isStripSpaceAllowed(node);
return MB_TRUE;
break;
}
return MB_TRUE;
} //-- matches
@ -128,12 +138,18 @@ MBool BasicNodeExpr::matches(Node* node, Node* context, ContextState* cs) {
* @return the String representation of this NodeExpr.
**/
void BasicNodeExpr::toString(String& dest) {
switch ( type ) {
switch (type) {
case NodeExpr::COMMENT_EXPR:
dest.append("comment()");
break;
case NodeExpr::PI_EXPR :
dest.append("processing-instruction()");
dest.append("processing-instruction(");
if (nodeNameSet) {
dest.append('\'');
dest.append(nodeName);
dest.append('\'');
}
dest.append(')');
break;
default: //-- node()
dest.append("node()");

Просмотреть файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,4 +1,4 @@
/*
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -25,7 +25,6 @@
* -- changed constant short declarations in Token and ExprLexer to
* enumerations, commented with //--LF
*
* $Id: ExprLexer.h,v 1.8 2001-06-26 14:07:54 peterv%netscape.com Exp $
*/
@ -41,7 +40,6 @@
* This class was ported from XSL:P, an open source Java based
* XSLT processor, written by yours truly.
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.8 $ $Date: 2001-06-26 14:07:54 $
**/
class Token {
@ -60,48 +58,59 @@ public:
LITERAL,
NUMBER,
CNAME,
L_PAREN,
R_PAREN,
L_BRACKET,
R_BRACKET,
COMMA,
FUNCTION_NAME,
AT_SIGN,
VAR_REFERENCE,
PARENT_NODE,
SELF_NODE,
R_PAREN,
R_BRACKET, // 10
/**
* start of tokens for 3.7, bullet 1
* ExprLexer::nextIsOperatorToken bails if the tokens aren't
* consecutive.
**/
COMMA,
AT_SIGN,
L_PAREN,
L_BRACKET,
AXIS_IDENTIFIER,
//-------------/
//- operators -/
//-------------/
//-- boolean ops
AND_OP,
AND_OP, // 16
OR_OP,
//-- relational
EQUAL_OP,
EQUAL_OP, // 18
NOT_EQUAL_OP,
LESS_THAN_OP,
GREATER_THAN_OP,
LESS_OR_EQUAL_OP,
GREATER_OR_EQUAL_OP,
//-- additive operators
ADDITION_OP,
ADDITION_OP, // 24
SUBTRACTION_OP,
//-- multiplicative
DIVIDE_OP ,
DIVIDE_OP , // 26
MULTIPLY_OP,
MODULUS_OP,
//-- path operators
PARENT_OP,
PARENT_OP, // 29
ANCESTOR_OP,
UNION_OP,
/**
* end of tokens for 3.7, bullet 1 -/
**/
//-- node type tokens
COMMENT,
COMMENT, // 32
NODE,
PROC_INST,
TEXT
TEXT,
//-- Special endtoken
END // 36
};
@ -166,6 +175,17 @@ public:
TX_LF = '\r'
};
enum _error_consts {
ERROR_UNRESOLVED_VAR_REFERENCE = 0,
ERROR_OP_EXPECTED,
ERROR_UNCLOSED_LITERAL,
ERROR_COLON,
ERROR_BANG,
ERROR_UNKNOWN_CHAR
};
static const String error_message[];
PRInt32 errorPos;
short errorCode;
/*
* Complex Tokens
@ -198,30 +218,14 @@ public:
~ExprLexer();
/**
* Counts the total number of tokens in this Lexer, even if the token
* has already been seen
* @return the total number of tokens in this Lexer
**/
int countAllTokens();
/**
* Counts the remaining number of tokens in this Lexer
* @return the number of remaining tokens in this Lexer
**/
int countRemainingTokens();
/**
* Returns the type of token that was last return by a call to nextToken
* Functions for iterating over the TokenList
**/
Token* lookAhead(int offset);
Token* nextToken();
Token* peek();
void pushBack();
MBool hasMoreTokens();
MBool isOperatorToken(Token* token);
private:
struct TokenListItem {
@ -237,50 +241,36 @@ private:
int tokenCount;
Token* prevToken;
Token endToken;
void addToken(Token* token);
/**
* Returns true if the following Token should be an operator.
* This is a helper for the first bullet of [XPath 3.7]
* Lexical Structure
**/
MBool nextIsOperatorToken(Token* token);
/**
* Returns true if the given character represents an Alpha letter
* Implemented in ExprLexerChars.cpp
**/
static MBool isAlphaChar(PRInt32 ch);
static MBool isLetter(UNICODE_CHAR ch);
/**
* Returns true if the given character represents a numeric letter (digit)
* Implemented in ExprLexerChars.cpp
**/
static MBool isDigit(PRInt32 ch);
/**
* Returns true if the given character is an allowable QName character
**/
static MBool isQNameChar(PRInt32 ch);
static MBool isDigit(UNICODE_CHAR ch);
/**
* Returns true if the given character is an allowable NCName character
* Implemented in ExprLexerChars.cpp
**/
static MBool isNCNameChar(PRInt32 ch);
/**
* Returns true if the given String is a valid XML QName
**/
static MBool isValidQName(String& name);
MBool matchDelimiter(UNICODE_CHAR ch);
/**
* Returns true if the value of the given String matches
* an OperatorName
**/
MBool matchesOperator(String& buffer);
/**
* Matches the given String to the appropriate Token
* @param buffer the current StringBuffer representing the value of the Token
* @param ch, the current delimiter token
**/
void matchToken(String& buffer, UNICODE_CHAR ch);
static MBool isNCNameChar(UNICODE_CHAR ch);
String subStr;
void parse(const String& pattern);
}; //-- ExprLexer

Просмотреть файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,4 +1,4 @@
/*
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ExprParser.h,v 1.4 2001-04-08 14:38:23 peterv%netscape.com Exp $
* $Id: ExprParser.h,v 1.5 2001-06-30 13:54:30 sicking%bigfoot.com Exp $
*/
/**
* ExprParser
* This class is used to parse XSL Expressions
* @author <A href="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.4 $ $Date: 2001-04-08 14:38:23 $
* @version $Revision: 1.5 $ $Date: 2001-06-30 13:54:30 $
* @see ExprLexer
**/
@ -44,9 +44,6 @@ class ExprParser {
public:
static const String R_CURLY_BRACE;
static const String L_CURLY_BRACE;
/**
* Creates a new ExprParser
**/
@ -58,7 +55,7 @@ public:
~ExprParser();
Expr* createExpr (const String& pattern);
PatternExpr* createPatternExpr (const String& pattern);
Expr* createPatternExpr (const String& pattern);
LocationStep* createLocationStep(const String& path);
/**
@ -72,13 +69,12 @@ private:
Expr* createBinaryExpr (Expr* left, Expr* right, Token* op);
Expr* createExpr (ExprLexer& lexer);
FilterExpr* createFilterExpr (ExprLexer& lexer);
Expr* createFilterExpr (ExprLexer& lexer);
FunctionCall* createFunctionCall (ExprLexer& lexer);
LocationStep* createLocationStep (ExprLexer& lexer);
NodeExpr* createNodeExpr (ExprLexer& lexer);
PathExpr* createPathExpr (ExprLexer& lexer);
PatternExpr* createPatternExpr (ExprLexer& lexer);
UnionExpr* createUnionExpr (ExprLexer& lexer);
Expr* createPathExpr (ExprLexer& lexer);
Expr* createUnionExpr (ExprLexer& lexer);
MBool isFilterExprToken (Token* tok);
MBool isLocationStepToken (Token* tok);
@ -94,8 +90,8 @@ private:
* @param lexer the ExprLexer to use for parsing tokens
* @return 0 if successful, or a String pointer to the error message
**/
String* parsePredicates(PredicateList* predicateList, ExprLexer& lexer);
String* parseParameters(List* list, ExprLexer& lexer);
MBool parsePredicates(PredicateList* predicateList, ExprLexer& lexer);
MBool parseParameters(FunctionCall* fnCall, ExprLexer& lexer);
}; //-- ExprParser

Просмотреть файл

@ -1,4 +1,4 @@
/*
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: FunctionCall.cpp,v 1.2 2000-04-19 10:36:17 kvisco%ziplink.net Exp $
* $Id: FunctionCall.cpp,v 1.3 2001-06-30 13:54:31 sicking%bigfoot.com Exp $
*/
#include "Expr.h"
@ -29,7 +29,7 @@
/**
* This class represents a FunctionCall as defined by the XSL Working Draft
* @author <A HREF="mailto:kvisco@ziplink">Keith Visco</A>
* @version $Revision: 1.2 $ $Date: 2000-04-19 10:36:17 $
* @version $Revision: 1.3 $ $Date: 2001-06-30 13:54:31 $
**/
const String FunctionCall::INVALID_PARAM_COUNT =
@ -49,7 +49,8 @@ FunctionCall::FunctionCall() {
* Note: The object references in parameters will be deleted when this
* FunctionCall gets destroyed.
**/
FunctionCall::FunctionCall(const String& name) {
FunctionCall::FunctionCall(const String& name)
{
//-- copy name
this->name = name;
} //-- FunctionCall
@ -59,13 +60,14 @@ FunctionCall::FunctionCall(const String& name) {
* Note: The object references in parameters will be deleted when this
* FunctionCall gets destroyed.
**/
FunctionCall::FunctionCall(const String& name, List* parameters) {
FunctionCall::FunctionCall(const String& name, List* parameters)
{
//-- copy name
this->name = name;
if (parameters) {
ListIterator* pIter = parameters->iterator();
while ( pIter->hasNext() ) {
while (pIter->hasNext()) {
params.add(pIter->next());
}
delete pIter;
@ -77,10 +79,10 @@ FunctionCall::FunctionCall(const String& name, List* parameters) {
/**
* Destructor
**/
FunctionCall::~FunctionCall() {
FunctionCall::~FunctionCall()
{
ListIterator* iter = params.iterator();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
iter->next();
Expr* expr = (Expr*) iter->remove();
delete expr;
@ -96,18 +98,48 @@ FunctionCall::~FunctionCall() {
* Adds the given parameter to this FunctionCall's parameter list
* @param expr the Expr to add to this FunctionCall's parameter list
**/
void FunctionCall::addParam(Expr* expr) {
if ( expr ) params.add(expr);
void FunctionCall::addParam(Expr* expr)
{
if (expr)
params.add(expr);
} //-- addParam
/**
* Returns the default priority of this Expr based on the given Node,
* context Node, and ContextState.
**/
double FunctionCall::getDefaultPriority(Node* node,
Node* context,
ContextState* cs)
{
return 0.5;
} //-- getDefaultPriority
/**
* Determines whether this Expr matches the given node within
* the given context
**/
MBool FunctionCall::matches(Node* node, Node* context, ContextState* cs)
{
MBool result = MB_FALSE;
ExprResult* exprResult = evaluate(node, cs);
if (exprResult->getResultType() == ExprResult::NODESET) {
NodeSet* nodes = (NodeSet*)exprResult;
result = (nodes->contains(node));
}
delete exprResult;
return result;
} //-- matches
/**
* Evaluates the given Expression and converts it's result to a String.
* The value is appended to the given destination String
**/
void FunctionCall::evaluateToString
(Expr* expr, Node* context, ContextState* cs, String& dest)
void FunctionCall::evaluateToString(Expr* expr, Node* context,
ContextState* cs, String& dest)
{
if (!expr) return;
if (!expr)
return;
ExprResult* exprResult = expr->evaluate(context, cs);
exprResult->stringValue(dest);
delete exprResult;
@ -116,11 +148,12 @@ void FunctionCall::evaluateToString
/**
* Evaluates the given Expression and converts it's result to a number.
**/
double FunctionCall::evaluateToNumber
(Expr* expr, Node* context, ContextState* cs)
double FunctionCall::evaluateToNumber(Expr* expr, Node* context,
ContextState* cs)
{
double result = Double::NaN;
if (!expr) return result;
if (!expr)
return result;
ExprResult* exprResult = expr->evaluate(context, cs);
result = exprResult->numberValue();
delete exprResult;
@ -131,19 +164,20 @@ double FunctionCall::evaluateToNumber
* Returns the name of this FunctionCall
* @return the name of this FunctionCall
**/
const String& FunctionCall::getName() {
return (const String&) this->name;
const String& FunctionCall::getName()
{
return (const String&)this->name;
} //-- getName
/**
* Called to check number of parameters
**/
MBool FunctionCall::requireParams
(int paramCountMin, int paramCountMax, ContextState* cs)
MBool FunctionCall::requireParams (int paramCountMin,
int paramCountMax,
ContextState* cs)
{
int argc = params.getLength();
if (( argc < paramCountMin) || (argc > paramCountMax)) {
if ((argc < paramCountMin) || (argc > paramCountMax)) {
String err(INVALID_PARAM_COUNT);
toString(err);
cs->recieveError(err);
@ -155,7 +189,8 @@ MBool FunctionCall::requireParams
/**
* Called to check number of parameters
**/
MBool FunctionCall::requireParams(int paramCountMin, ContextState* cs) {
MBool FunctionCall::requireParams(int paramCountMin, ContextState* cs)
{
int argc = params.getLength();
if (argc < paramCountMin) {
String err(INVALID_PARAM_COUNT);
@ -170,7 +205,8 @@ MBool FunctionCall::requireParams(int paramCountMin, ContextState* cs) {
* Sets the function name of this FunctionCall
* @param name the name of this Function
**/
void FunctionCall::setName(const String& name) {
void FunctionCall::setName(const String& name)
{
this->name.clear();
this->name.append(name);
} //-- setName
@ -183,18 +219,19 @@ void FunctionCall::setName(const String& name) {
* other #toString() methods for Expressions.
* @return the String representation of this NodeExpr.
**/
void FunctionCall::toString(String& dest) {
void FunctionCall::toString(String& dest)
{
dest.append(this->name);
dest.append('(');
//-- add parameters
ListIterator* iterator = params.iterator();
int argc = 0;
while ( iterator->hasNext() ) {
if ( argc > 0 ) dest.append(',');
while (iterator->hasNext()) {
if (argc > 0)
dest.append(',');
Expr* expr = (Expr*)iterator->next();
expr->toString(dest);
++argc;
}
delete iterator;
dest.append(')');

Просмотреть файл

@ -1,59 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: IdentityExpr.cpp,v 1.1 2000-04-06 07:45:31 kvisco%ziplink.net Exp $
*/
/**
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.1 $ $Date: 2000-04-06 07:45:31 $
**/
#include "Expr.h"
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param ps the ContextState containing the stack information needed
* for evaluation
* @return the result of the evaluation
**/
ExprResult* IdentityExpr::evaluate(Node* context, ContextState* cs) {
NodeSet* nodeSet = new NodeSet();
if ( context ) {
nodeSet->add(context);
}
return nodeSet;
} //-- evaluate
/**
* Returns the String representation of this NodeExpr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this NodeExpr.
**/
void IdentityExpr::toString(String& dest) {
dest.append('.');
} //-- toString

Просмотреть файл

@ -40,12 +40,13 @@ CPPSRCS = AdditiveExpr.cpp \
BooleanResult.cpp \
ElementExpr.cpp \
ErrorFunctionCall.cpp \
Expr.cpp \
ExprLexer.cpp \
ExprLexerChars.cpp \
ExprParser.cpp \
ExtensionFunctionCall.cpp \
FilterExpr.cpp \
FunctionCall.cpp \
IdentityExpr.cpp \
LocationStep.cpp \
MultiplicativeExpr.cpp \
NodeSet.cpp \
@ -53,7 +54,6 @@ CPPSRCS = AdditiveExpr.cpp \
NumberExpr.cpp \
NumberFunctionCall.cpp \
NumberResult.cpp \
ParentExpr.cpp \
PathExpr.cpp \
PredicateList.cpp \
RelationalExpr.cpp \
@ -63,6 +63,7 @@ CPPSRCS = AdditiveExpr.cpp \
StringResult.cpp \
TextExpr.cpp \
UnionExpr.cpp \
UnaryExpr.cpp \
VariableRefExpr.cpp \
XPathNames.cpp
ifndef TX_EXE

Просмотреть файл

@ -1,59 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ParentExpr.cpp,v 1.1 2000-04-06 07:45:35 kvisco%ziplink.net Exp $
*/
/**
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.1 $ $Date: 2000-04-06 07:45:35 $
**/
#include "Expr.h"
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param ps the ContextState containing the stack information needed
* for evaluation
* @return the result of the evaluation
**/
ExprResult* ParentExpr::evaluate(Node* context, ContextState* cs) {
NodeSet* nodeSet = new NodeSet();
if ( !context ) return nodeSet;
Node* node = context->getParentNode();
if (node) nodeSet->add(node);
return nodeSet;
} //-- evaluate
/**
* Returns the String representation of this NodeExpr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this NodeExpr.
**/
void ParentExpr::toString(String& dest) {
dest.append("..");
} //-- toString

Просмотреть файл

@ -1,4 +1,4 @@
/*
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -29,7 +29,7 @@
* - foo//bar would not match properly if there was more than
* one node in the NodeSet (nodes) on the final iteration
*
* $Id: PathExpr.cpp,v 1.6 2001-04-14 17:24:59 axel%pike.org Exp $
* $Id: PathExpr.cpp,v 1.7 2001-06-30 13:54:33 sicking%bigfoot.com Exp $
*/
#include "Expr.h"
@ -43,53 +43,58 @@
/**
* Creates a new PathExpr
**/
PathExpr::PathExpr() {
PathExpr::PathExpr()
{
//-- do nothing
}
/**
* Destructor, will delete all Pattern Expressions
* Destructor, will delete all Expressions
**/
PathExpr::~PathExpr() {
PathExpr::~PathExpr()
{
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
iter->next();
PathExprItem* pxi = (PathExprItem*)iter->remove();
delete pxi->pExpr;
delete pxi->expr;
delete pxi;
}
delete iter;
} //-- ~PathExpr
/**
* Adds the PatternExpr to this PathExpr
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
* @param index the index at which to add the given Expr
**/
void PathExpr::addPatternExpr(int index, PatternExpr* expr, short ancestryOp) {
void PathExpr::addExpr(int index, Expr* expr, short ancestryOp)
{
if (expr) {
PathExprItem* pxi = new PathExprItem;
pxi->pExpr = expr;
pxi->expr = expr;
pxi->ancestryOp = ancestryOp;
expressions.insert(index, pxi);
}
} //-- addPattenExpr
/**
* Adds the PatternExpr to this PathExpr
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void PathExpr::addPatternExpr(PatternExpr* expr, short ancestryOp) {
void PathExpr::addExpr(Expr* expr, short ancestryOp)
{
if (expr) {
PathExprItem* pxi = new PathExprItem;
pxi->pExpr = expr;
pxi->expr = expr;
pxi->ancestryOp = ancestryOp;
expressions.add(pxi);
}
} //-- addPattenExpr
MBool PathExpr::isAbsolute() {
if ( expressions.getLength() > 0 ) {
MBool PathExpr::isAbsolute()
{
if (expressions.getLength() > 0) {
ListIterator* iter = expressions.iterator();
PathExprItem* pxi = (PathExprItem*)iter->next();
delete iter;
@ -98,9 +103,9 @@ MBool PathExpr::isAbsolute() {
return MB_FALSE;
} //-- isAbsolute
//------------------------------------/
//- Virtual methods from PatternExpr -/
//------------------------------------/
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/
/**
* Evaluates this Expr based on the given context node and processor state
@ -109,24 +114,23 @@ MBool PathExpr::isAbsolute() {
* for evaluation
* @return the result of the evaluation
**/
ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
ExprResult* PathExpr::evaluate(Node* context, ContextState* cs)
{
//-- add selectExpr functionality here
if ( (!context) || (expressions.getLength() == 0))
if (!context || (expressions.getLength() == 0))
return new NodeSet(0);
NodeSet* nodes = new NodeSet();
if ((isAbsolute()) && (context->getNodeType() != Node::DOCUMENT_NODE))
if (isAbsolute() && (context->getNodeType() != Node::DOCUMENT_NODE))
nodes->add(context->getOwnerDocument());
else
nodes->add(context);
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
PathExprItem* pxi = (PathExprItem*)iter->next();
NodeSet* tmpNodes = 0;
cs->getNodeSetStack()->push(nodes);
@ -134,22 +138,21 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
Node* node = nodes->get(i);
NodeSet* resNodes;
if ( pxi->ancestryOp == ANCESTOR_OP) {
if (pxi->ancestryOp == ANCESTOR_OP) {
resNodes = new NodeSet;
evalDescendants(pxi->pExpr, node, cs, resNodes);
evalDescendants(pxi->expr, node, cs, resNodes);
}
else {
ExprResult *res = pxi->pExpr->evaluate(node, cs);
if (!res || res->getResultType() != ExprResult::NODESET) {
ExprResult *res = pxi->expr->evaluate(node, cs);
if (!res || (res->getResultType() != ExprResult::NODESET)) {
//XXX ErrorReport: report nonnodeset error
delete res;
res = new NodeSet;
}
resNodes = (NodeSet*)res;
}
if ( tmpNodes ) {
if (tmpNodes) {
resNodes->copyInto(*tmpNodes);
delete resNodes;
}
@ -159,7 +162,7 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
}
delete (NodeSet*) cs->getNodeSetStack()->pop();
nodes = tmpNodes;
if ( !nodes || nodes->size() == 0 ) break;
if (!nodes || (nodes->size() == 0)) break;
}
delete iter;
@ -168,14 +171,14 @@ ExprResult* PathExpr::evaluate(Node* context, ContextState* cs) {
/**
* Selects from the descendants of the context node
* all nodes that match the PatternExpr
* all nodes that match the Expr
* -- this will be moving to a Utility class
**/
void PathExpr::evalDescendants
(PatternExpr* pExpr, Node* context, ContextState* cs, NodeSet* resNodes)
void PathExpr::evalDescendants (Expr* expr, Node* context,
ContextState* cs, NodeSet* resNodes)
{
ExprResult *res = pExpr->evaluate(context, cs);
if (!res || res->getResultType() != ExprResult::NODESET) {
ExprResult *res = expr->evaluate(context, cs);
if (!res || (res->getResultType() != ExprResult::NODESET)) {
//XXX ErrorReport: report nonnodeset error
}
else
@ -185,10 +188,10 @@ void PathExpr::evalDescendants
MBool filterWS = cs->isStripSpaceAllowed(context);
Node* child = context->getFirstChild();
while(child) {
if(!(filterWS && child->getNodeType() == Node::TEXT_NODE &&
while (child) {
if (!(filterWS && (child->getNodeType() == Node::TEXT_NODE) &&
XMLUtils::shouldStripTextnode(child->getNodeValue())))
evalDescendants(pExpr, child, cs, resNodes);
evalDescendants(expr, child, cs, resNodes);
child = child->getNextSibling();
}
} //-- evalDescendants
@ -199,31 +202,30 @@ void PathExpr::evalDescendants
* If this pattern does not match the given Node under the current context Node and
* ContextState then Negative Infinity is returned.
**/
double PathExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
if ( matches(node, context, cs) ) {
double PathExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs)
{
if (matches(node, context, cs)) {
int size = expressions.getLength();
if ( size == 1) {
if (size == 1) {
ListIterator* iter = expressions.iterator();
PathExprItem* pxi = (PathExprItem*)iter->next();
delete iter;
return pxi->pExpr->getDefaultPriority(node, context, cs);
return pxi->expr->getDefaultPriority(node, context, cs);
}
else if ( size > 1 ) {
else if (size > 1)
return 0.5;
}
}
return Double::NEGATIVE_INFINITY;
} //-- getDefaultPriority
/**
* Determines whether this PatternExpr matches the given node within
* Determines whether this Expr matches the given node within
* the given context
**/
MBool PathExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( (!node) || (expressions.getLength() == 0))
MBool PathExpr::matches(Node* node, Node* context, ContextState* cs)
{
if (!node || (expressions.getLength() == 0))
return MB_FALSE;
//-- for performance reasons, I've duplicated some code
@ -241,7 +243,7 @@ MBool PathExpr::matches(Node* node, Node* context, ContextState* cs) {
{
Node* ancestor = node;
while (ancestor = cs->getParentNode(ancestor)) {
if (pxi->pExpr->matches(node, ancestor, cs))
if (pxi->expr->matches(node, ancestor, cs))
return MB_TRUE;
}
break;
@ -252,45 +254,40 @@ MBool PathExpr::matches(Node* node, Node* context, ContextState* cs) {
if (parent) {
//-- make sure node is Document node
if (parent->getNodeType() == Node::DOCUMENT_NODE)
return pxi->pExpr->matches(node, parent, cs);
return pxi->expr->matches(node, parent, cs);
}
break;
}
default:
return pxi->pExpr->matches(node, context, cs);
return pxi->expr->matches(node, context, cs);
}
return MB_FALSE;
}
//-- if we reach here we have subpaths...
NodeSet nodes(3);
NodeSet tmpNodes(3);
nodes.add(node);
ListIterator* iter = expressions.iterator();
iter->reverse();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
PathExprItem* pxi = (PathExprItem*)iter->next();
for (int i = 0; i < nodes.size(); i++) {
Node* tnode = nodes.get(i);
//-- select node's parent or ancestors
//-- select node's parent or ancestors
switch (pxi->ancestryOp) {
case ANCESTOR_OP:
{
Node* parent = tnode;
while (parent = cs->getParentNode(parent)) {
if (pxi->pExpr->matches(tnode, parent, cs))
if (pxi->expr->matches(tnode, parent, cs))
tmpNodes.add(parent);
}
break;
@ -299,29 +296,27 @@ MBool PathExpr::matches(Node* node, Node* context, ContextState* cs) {
{
Node* parent = cs->getParentNode(tnode);
if (parent) {
//-- make sure we have a document node if necessary
if ( !iter->hasNext() )
if (parent->getNodeType() != Node::DOCUMENT_NODE) break;
if (pxi->pExpr->matches(tnode, parent, cs))
if (!iter->hasNext())
if (parent->getNodeType() != Node::DOCUMENT_NODE)
break;
if (pxi->expr->matches(tnode, parent, cs))
tmpNodes.add(parent);
}
break;
}
default:
if ( !iter->hasNext() ) {
if (!iter->hasNext()) {
/*
// PREVIOUS // result = pxi->pExpr->matches(tnode, context, cs);
// PREVIOUS // result = pxi->expr->matches(tnode, context, cs);
// result was being overwritten if there was more than one
// node in nodes during the final iteration (Marina)
result = result || pxi->pExpr->matches(tnode, context, cs)
result = result || pxi->expr->matches(tnode, context, cs)
*/
//-- Just return true if we match here
if (pxi->pExpr->matches(tnode, context, cs)) {
if (pxi->expr->matches(tnode, context, cs)) {
delete iter;
return MB_TRUE;
}
@ -353,28 +348,29 @@ MBool PathExpr::matches(Node* node, Node* context, ContextState* cs) {
doc = node;
else
doc = node->getOwnerDocument();
return (MBool) nodes.contains(doc);
return (MBool)nodes.contains(doc);
}
return (MBool) (nodes.size() > 0);
return (MBool)(nodes.size() > 0);
} //-- matches
/**
* Returns the String representation of this PatternExpr.
* Returns the String representation of this Expr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this PatternExpr.
* @return the String representation of this Expr.
**/
void PathExpr::toString(String& dest) {
void PathExpr::toString(String& dest)
{
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
//-- set operator
PathExprItem* pxi = (PathExprItem*)iter->next();
switch ( pxi->ancestryOp ) {
switch (pxi->ancestryOp) {
case ANCESTOR_OP:
dest.append("//");
break;
@ -384,7 +380,7 @@ void PathExpr::toString(String& dest) {
default:
break;
}
pxi->pExpr->toString(dest);
pxi->expr->toString(dest);
}
delete iter;
} //-- toString

Просмотреть файл

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: StringExpr.cpp,v 1.2 2001-05-12 09:54:16 nisheeth%netscape.com Exp $
* $Id: StringExpr.cpp,v 1.3 2001-06-30 13:54:34 sicking%bigfoot.com Exp $
*/
#include "Expr.h"
@ -29,7 +29,7 @@
/**
* StringExpr
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.2 $ $Date: 2001-05-12 09:54:16 $
* @version $Revision: 1.3 $ $Date: 2001-06-30 13:54:34 $
**/
/**
@ -77,8 +77,11 @@ ExprResult* StringExpr::evaluate(Node* context, ContextState* cs) {
* @return the String representation of this Expr.
**/
void StringExpr::toString(String& str) {
str.append('\'');
UNICODE_CHAR ch = '\'';
if (value.indexOf(ch) != NOT_FOUND)
ch = '\"';
str.append(ch);
str.append(value);
str.append('\'');
str.append(ch);
} //-- toString

Просмотреть файл

@ -0,0 +1,73 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developer of the Original Code is Jonas Sicking.
* Portions created by Jonas Sicking are Copyright (C) 2001, Jonas Sicking.
* All rights reserved.
*
* Contributor(s):
* Jonas Sicking, sicking@bigfoot.com
* -- original author.
*/
#include "Expr.h"
UnaryExpr::UnaryExpr()
{
expr = 0;
}
UnaryExpr::UnaryExpr(Expr* expr)
{
this->expr = expr;
}
UnaryExpr::~UnaryExpr()
{
delete expr;
}
void UnaryExpr::setExpr(Expr* expr)
{
delete this->expr;
this->expr = expr;
}
/*
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param ps the ContextState containing the stack information needed
* for evaluation.
* @return the result of the evaluation.
*/
ExprResult* UnaryExpr::evaluate(Node* context, ContextState* cs)
{
ExprResult* exprRes = expr->evaluate(context, cs);
double value = exprRes->numberValue();
delete exprRes;
return new NumberResult(-value);
}
/*
* Returns the String representation of this Expr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this Expr.
*/
void UnaryExpr::toString(String& str)
{
if (!expr)
return;
str.append('-');
expr->toString(str);
}

Просмотреть файл

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: UnionExpr.cpp,v 1.1 2000-04-06 07:45:52 kvisco%ziplink.net Exp $
* $Id: UnionExpr.cpp,v 1.2 2001-06-30 13:54:35 sicking%bigfoot.com Exp $
*/
#include "Expr.h"
@ -43,31 +43,33 @@ UnionExpr::UnionExpr() {
**/
UnionExpr::~UnionExpr() {
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
while (iter->hasNext()) {
iter->next();
delete (PathExpr*)iter->remove();
delete (Expr*)iter->remove();
}
delete iter;
} //-- ~UnionExpr
/**
* Adds the PathExpr to this UnionExpr
* @param pathExpr the PathExpr to add to this UnionExpr
* Adds the Expr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void UnionExpr::addPathExpr(PathExpr* pathExpr) {
if (pathExpr) expressions.add(pathExpr);
} //-- addPathExpr
void UnionExpr::addExpr(Expr* expr) {
if (expr)
expressions.add(expr);
} //-- addExpr
/**
* Adds the PathExpr to this UnionExpr
* @param pathExpr the PathExpr to add to this UnionExpr
* Adds the Expr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void UnionExpr::addPathExpr(int index, PathExpr* pathExpr) {
if (pathExpr) expressions.insert(index, pathExpr);
} //-- addPathExpr
void UnionExpr::addExpr(int index, Expr* expr) {
if (expr)
expressions.insert(index, expr);
} //-- addExpr
//------------------------------------/
//- Virtual methods from PatternExpr -/
//- Virtual methods from Expr -/
//------------------------------------/
/**
@ -79,21 +81,19 @@ void UnionExpr::addPathExpr(int index, PathExpr* pathExpr) {
**/
ExprResult* UnionExpr::evaluate(Node* context, ContextState* cs) {
if ( (!context) || (expressions.getLength() == 0))
if (!context || (expressions.getLength() == 0))
return new NodeSet(0);
NodeSet* nodes = new NodeSet();
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
PathExpr* pExpr = (PathExpr*)iter->next();
NodeSet* tmpNodes = (NodeSet*)pExpr->evaluate(context, cs);
for (int j = 0; j < tmpNodes->size(); j++) {
nodes->add(tmpNodes->get(j));
while (iter->hasNext()) {
Expr* expr = (Expr*)iter->next();
ExprResult* exprResult = expr->evaluate(context, cs);
if (exprResult->getResultType() == ExprResult::NODESET) {
((NodeSet*)exprResult)->copyInto(*nodes);
}
delete tmpNodes;
}
delete iter;
@ -106,21 +106,20 @@ ExprResult* UnionExpr::evaluate(Node* context, ContextState* cs) {
* If this pattern does not match the given Node under the current context Node and
* ContextState then Negative Infinity is returned.
**/
double UnionExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
double UnionExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs) {
//-- find highest priority
double priority = Double::NEGATIVE_INFINITY;
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
PathExpr* pExpr = (PathExpr*)iter->next();
if ( pExpr->matches(node, context, cs) ) {
double tmpPriority = pExpr->getDefaultPriority(node, context, cs);
while (iter->hasNext()) {
Expr* expr = (Expr*)iter->next();
if (expr->matches(node, context, cs)) {
double tmpPriority = expr->getDefaultPriority(node, context, cs);
priority = (tmpPriority > priority) ? tmpPriority : priority;
}
}
delete iter;
return priority;
} //-- getDefaultPriority
/**
@ -131,9 +130,9 @@ MBool UnionExpr::matches(Node* node, Node* context, ContextState* cs) {
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
PathExpr* pExpr = (PathExpr*)iter->next();
if ( pExpr->matches(node, context, cs) ) {
while (iter->hasNext()) {
Expr* expr = (Expr*)iter->next();
if (expr->matches(node, context, cs)) {
delete iter;
return MB_TRUE;
}
@ -144,21 +143,22 @@ MBool UnionExpr::matches(Node* node, Node* context, ContextState* cs) {
/**
* Returns the String representation of this PatternExpr.
* Returns the String representation of this Expr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this PatternExpr.
* @return the String representation of this Expr.
**/
void UnionExpr::toString(String& dest) {
ListIterator* iter = expressions.iterator();
short count = 0;
while ( iter->hasNext() ) {
while (iter->hasNext()) {
//-- set operator
if (count > 0) dest.append(" | ");
((PathExpr*)iter->next())->toString(dest);
if (count > 0)
dest.append(" | ");
((Expr*)iter->next())->toString(dest);
++count;
}
delete iter;

Просмотреть файл

@ -36,12 +36,13 @@ CPPSRCS= \
BooleanResult.cpp \
ElementExpr.cpp \
ErrorFunctionCall.cpp \
Expr.cpp \
ExprLexer.cpp \
ExprLexerChars.cpp \
ExprParser.cpp \
ExtensionFunctionCall.cpp \
FilterExpr.cpp \
FunctionCall.cpp \
IdentityExpr.cpp \
LocationStep.cpp \
MultiplicativeExpr.cpp \
NodeSet.cpp \
@ -49,7 +50,6 @@ CPPSRCS= \
NumberExpr.cpp \
NumberFunctionCall.cpp \
NumberResult.cpp \
ParentExpr.cpp \
PathExpr.cpp \
PredicateList.cpp \
RelationalExpr.cpp \
@ -59,6 +59,7 @@ CPPSRCS= \
StringResult.cpp \
TextExpr.cpp \
UnionExpr.cpp \
UnaryExpr.cpp \
VariableRefExpr.cpp \
XPathNames.cpp \
!if !defined(TX_EXE)
@ -77,12 +78,13 @@ CPP_OBJS= \
.\$(OBJDIR)\BooleanResult.obj \
.\$(OBJDIR)\ElementExpr.obj \
.\$(OBJDIR)\ErrorFunctionCall.obj \
.\$(OBJDIR)\Expr.obj \
.\$(OBJDIR)\ExprLexer.obj \
.\$(OBJDIR)\ExprLexerChars.obj \
.\$(OBJDIR)\ExprParser.obj \
.\$(OBJDIR)\ExtensionFunctionCall.obj \
.\$(OBJDIR)\FilterExpr.obj \
.\$(OBJDIR)\FunctionCall.obj \
.\$(OBJDIR)\IdentityExpr.obj \
.\$(OBJDIR)\LocationStep.obj \
.\$(OBJDIR)\MultiplicativeExpr.obj \
.\$(OBJDIR)\NodeSet.obj \
@ -90,7 +92,6 @@ CPP_OBJS= \
.\$(OBJDIR)\NumberExpr.obj \
.\$(OBJDIR)\NumberFunctionCall.obj \
.\$(OBJDIR)\NumberResult.obj \
.\$(OBJDIR)\ParentExpr.obj \
.\$(OBJDIR)\PathExpr.obj \
.\$(OBJDIR)\PredicateList.obj \
.\$(OBJDIR)\RelationalExpr.obj \
@ -100,6 +101,7 @@ CPP_OBJS= \
.\$(OBJDIR)\StringResult.obj \
.\$(OBJDIR)\TextExpr.obj \
.\$(OBJDIR)\UnionExpr.obj \
.\$(OBJDIR)\UnaryExpr.obj \
.\$(OBJDIR)\VariableRefExpr.obj \
.\$(OBJDIR)\XPathNames.obj \
!if !defined(TX_EXE)

Просмотреть файл

@ -30,7 +30,7 @@
/**
* Implementation of ProcessorState
* Much of this code was ported from XSL:P
* @version $Revision: 1.33 $ $Date: 2001-06-26 14:09:18 $
* @version $Revision: 1.34 $ $Date: 2001-06-30 13:54:38 $
**/
#include "ProcessorState.h"
@ -195,8 +195,10 @@ void ProcessorState::addTemplate(Element* xslTemplate) {
namedTemplates.put(name,mObj);
if ( oldObj ) delete oldObj;
}
patternExprHash.put(match, exprParser.createPatternExpr(match));
templates.add(xslTemplate);
if (match.length() > 0) {
patternExprHash.put(match, exprParser.createPatternExpr(match));
templates.add(xslTemplate);
}
} //-- addTempalte
/**