[prev in list] [next in list] [prev in thread] [next in thread]
List: quanta-devel
Subject: [quanta-devel] branches/work/kdom/xpath/functions
From: Frans Englich <frans.englich () telia ! com>
Date: 2005-08-25 20:34:10
Message-ID: 1125002050.215228.26173.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 453309 by englich:
Change how functions which defaults to the context item are handled. Instead of \
having each function manually override typeCheck and do the test, it is declared in \
its FunctionSignature and the test implemented in FunctionCall. Saved a bit code even \
now, and will do more as more functions are implemented.
One interesting thing is that this information is now available in declared form, as \
with the other info in FunctionSignature -- number of arguments, the type of \
arguments, and so forth. One have to be able to do something interesting with that, \
an interactive API browser or something..
CCMAIL: quanta-devel@kde.org
M +0 -6 AccessorFNs.cpp
M +0 -3 AccessorFNs.h
M +7 -2 FunctionCall.cpp
M +3 -12 FunctionCall.h
M +11 -4 FunctionSignature.cpp
M +29 -2 FunctionSignature.h
M +0 -6 NumberFN.cpp
M +0 -4 NumberFN.h
M +6 -4 SystemFunctionFactory.cpp
--- branches/work/kdom/xpath/functions/AccessorFNs.cpp #453308:453309
@@ -53,10 +53,4 @@
return String::CreateFromNative(item->stringValue());
}
-Expression *StringFN::typeCheck(StaticContext *context)
-{
- useContextItemAsDefault();
- return FunctionCall::typeCheck(context);
-}
-
// vim:ts=4:noet
--- branches/work/kdom/xpath/functions/AccessorFNs.h #453308:453309
@@ -28,7 +28,6 @@
{
class DynamicContext;
class Item;
- class StaticContext;
/**
* @author Frans Englich <frans.englich@telia.com>
@@ -46,8 +45,6 @@
{
public:
virtual Item *evaluateSingleton(DynamicContext *context);
-
- virtual Expression *typeCheck(StaticContext *context);
};
};
--- branches/work/kdom/xpath/functions/FunctionCall.cpp #453308:453309
@@ -55,10 +55,15 @@
return result;
}
-void FunctionCall::useContextItemAsDefault()
+Expression *FunctionCall::typeCheck(StaticContext *context)
{
- if(m_operands.isEmpty())
+ Q_ASSERT(m_signature);
+
+ if(m_operands.isEmpty() && m_signature->properties() & \
FunctionSignature::UseContextItem + == FunctionSignature::UseContextItem)
m_operands.append(new ContextItem());
+
+ return InfiniteExpression::typeCheck(context);
}
void FunctionCall::setSignature(FunctionSignature *sign)
--- branches/work/kdom/xpath/functions/FunctionCall.h #453308:453309
@@ -29,6 +29,7 @@
class DynamicContext;
class FunctionSignature;
class SequenceIterator;
+ class StaticContext;
class Value;
/**
@@ -40,24 +41,14 @@
FunctionCall();
virtual ~FunctionCall();
- /**
- * Modifies the function's arguments to have the first argument refer
- * to the context item, if the existing amount of arguments is zero. This is
- * in other words a helper function for sub-classes handling functions with
- * a signature of name($arg as item()?) and whose single argument defaults
- * to the context item. One such function is fn:number().
- *
- * @see <a href="http://www.w3.org/TR/xpath-functions/#func-signatures">XQuery 1.0 \
and
- * XPath 2.0 Functions and Operators1.3 Function Signatures and Descriptions</a>
- */
- virtual void useContextItemAsDefault();
-
virtual SequenceType::List expectedOperandTypes() const;
virtual SequenceType *staticType() const;
virtual void setSignature(FunctionSignature *sign);
virtual FunctionSignature *signature() const;
+ virtual Expression *typeCheck(StaticContext *context);
+
private:
FunctionSignature *m_signature;
};
--- branches/work/kdom/xpath/functions/FunctionSignature.cpp #453308:453309
@@ -28,10 +28,12 @@
using namespace KXPATH;
-FunctionSignature::FunctionSignature(KDOM::SharedQName *name, short minArgs, short \
maxArgs,
- SequenceType *returnType) : m_name(name), m_minArgs(minArgs),
- m_maxArgs(maxArgs), m_returnType(returnType),
- m_arguments()
+FunctionSignature::FunctionSignature(KDOM::SharedQName *name, const short minArgs,
+ const short maxArgs,SequenceType *returnType,
+ const Properties props)
+ : m_name(name), m_minArgs(minArgs),
+ m_maxArgs(maxArgs), m_returnType(returnType),
+ m_arguments(), m_props(props)
{
Q_ASSERT(minArgs <= maxArgs || maxArgs == -1);
Q_ASSERT(m_maxArgs >= -1);
@@ -126,4 +128,9 @@
return m_returnType;
}
+FunctionSignature::Properties FunctionSignature::properties() const
+{
+ return m_props;
+}
+
// vim:ts=4:noet
--- branches/work/kdom/xpath/functions/FunctionSignature.h #453308:453309
@@ -48,10 +48,34 @@
{
public:
+ /**
+ * Values which describes characteristics of the function.
+ */
+ enum Properties
+ {
+ None,
+
+ /**
+ * The function uses the context item, ".", when it is passed
+ * zero arguments.
+ *
+ * In effect, it result in a modification of the function's arguments to have
+ * the first argument refer to the context item, if the existing amount of
+ * arguments is zero.
+ *
+ * One function which has this property is fn:number().
+ *
+ * @see <a href="http://www.w3.org/TR/xpath-functions/#func-signatures">XQuery \
1.0 and + * XPath 2.0 Functions and Operators, 1.3 Function Signatures and \
Descriptions</a> + */
+ UseContextItem
+ };
+
typedef KDOM::SharedDict<FunctionSignature> Dict;
- FunctionSignature(KDOM::SharedQName *name,
- short minArgs, short maxArgs, SequenceType *returnType);
+ FunctionSignature(KDOM::SharedQName *name, const short minArgs,
+ const short maxArgs, SequenceType *returnType,
+ const Properties chars = None);
virtual ~FunctionSignature();
virtual void setArguments(const FunctionArgument::List &args);
@@ -76,6 +100,8 @@
virtual SequenceType *returnType() const;
+ virtual Properties properties() const;
+
/**
* Builds a string representation for this function signature. The syntax
* used is the one specified in "XQuery 1.0 and XPath 2.0 Functions and \
Operators", whose @@ -97,6 +123,7 @@
short m_maxArgs;
SequenceType *m_returnType;
mutable FunctionArgument::List m_arguments;
+ Properties m_props;
};
};
#endif
--- branches/work/kdom/xpath/functions/NumberFN.cpp #453308:453309
@@ -54,10 +54,4 @@
return val;
}
-Expression *NumberFN::typeCheck(StaticContext *context)
-{
- useContextItemAsDefault();
- return FunctionCall::typeCheck(context);
-}
-
// vim:ts=4:noet
--- branches/work/kdom/xpath/functions/NumberFN.h #453308:453309
@@ -28,7 +28,6 @@
{
class DynamicContext;
class Item;
- class StaticContext;
/**
*
@@ -41,9 +40,6 @@
virtual ~NumberFN();
virtual Item *evaluateSingleton(DynamicContext *context);
-
- virtual Expression *typeCheck(StaticContext *context);
-
};
};
--- branches/work/kdom/xpath/functions/SystemFunctionFactory.cpp #453308:453309
@@ -63,11 +63,13 @@
using namespace KXPATH;
-#define addFunction(lname, min, max, seqType) \
+#define addPropFunction(lname, min, max, seqType, prop) \
s = new FunctionSignature(new KDOM::SharedQName(KDOM::NS_XFN, lname, \
KDOM::DOMString()), \
- min, max, seqType); \
+ min, max, seqType, FunctionSignature::prop); \
m_signatures.insert((KDOM::DOMString("{") + KDOM::NS_XFN + "}" + lname).string(), \
s)
+#define addFunction(lname, min, max, seqType) addPropFunction(lname, min, max, \
seqType, None) +
SystemFunctionFactory::SystemFunctionFactory() : m_signatures(59)
{
FunctionSignature *s = 0;
@@ -172,13 +174,13 @@
s->appendArgument("position", CommonSequenceTypes::ExactlyOneInteger);
s->appendArgument("insert", CommonSequenceTypes::ZeroOrMoreItems);
- addFunction("string", 0, 1, CommonSequenceTypes::ExactlyOneString);
+ addPropFunction("string", 0, 1, CommonSequenceTypes::ExactlyOneString, \
UseContextItem); s->appendArgument("arg", CommonSequenceTypes::ZeroOrOneItem);
addFunction("nilled", 1, 1, CommonSequenceTypes::ZeroOrOneBoolean);
s->appendArgument("arg", CommonSequenceTypes::ZeroOrOneNode);
- addFunction("number", 0, 1, CommonSequenceTypes::ExactlyOneDouble);
+ addPropFunction("number", 0, 1, CommonSequenceTypes::ExactlyOneDouble, \
UseContextItem); s->appendArgument("arg", \
CommonSequenceTypes::ZeroOrOneAnyAtomicType);
addFunction("concat", 2, -1, CommonSequenceTypes::ExactlyOneString);
_______________________________________________
quanta-devel mailing list
quanta-devel@kde.org
https://mail.kde.org/mailman/listinfo/quanta-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic