Bit more work on variable resolution

This commit is contained in:
jez 2009-10-05 23:27:57 +01:00
commit 7abcba0420
3 changed files with 39 additions and 4 deletions

View file

@ -112,6 +112,37 @@ private:
}; // class ExecutionContext
///////////////////////////
class ResolvedVariable : public Variable_instance
{
public:
ResolvedVariable(const Variable_declaration& var,
const DOM::Node<std::string>& node,
ExecutionContext& context) :
var_(var)
{
DOMSink sink;
value_ = var_.value(node, context, sink);
} // ResolvedVariable
virtual const std::string& name() const { return var_.name(); }
virtual const Precedence& precedence() const { return var_.precedence(); }
virtual Arabica::XPath::XPathValue<std::string> value() const { return value_; }
virtual void injectGlobalScope(const Scope& scope) const
{
;
} // globalScope
private:
const Variable_declaration& var_;
mutable Arabica::XPath::XPathValue<std::string> value_;
ResolvedVariable();
ResolvedVariable(const ResolvedVariable&);
ResolvedVariable& operator=(const ResolvedVariable&);
const ResolvedVariable& operator==(const ResolvedVariable&) const;
}; // class ResolvedVariable
class VariableClosure : public Variable_instance
{
public:
@ -119,6 +150,9 @@ public:
const DOM::Node<std::string>& node,
ExecutionContext& context)
{
if(var.precedence() == Precedence::FrozenPrecedence()) // we're running, so resolve immediately
return Variable_instance_ptr(new ResolvedVariable(var, node, context));
return Variable_instance_ptr(new VariableClosure(var, node, context));
} // create

View file

@ -120,9 +120,6 @@ public:
return;
} // if ...
if(var->precedence() == Precedence::FrozenPrecedence()) // we're running, so resolve immediately
var->value();
stack[name] = var;
} // declareVariable

View file

@ -29,4 +29,8 @@ Performance
params - avoid creating closure for xsl:param if the param has been passed - DONE
- if running, resolve variable immediately, don't bother to create closure
- when declaring variable, don't create closure/resolve if higher-precedence variable already exists
- bin variable_instance_pointer, think I can pass by value
- bin variable_instance_pointer, think I can pass by value
- actually, I think we avoid the whole closure creation business by getting the variables to pass in themselves,
or a simple wrapper around themselves. Top-level variables can hang on to a pointer to the toplevel injected context.
Top level variables are the only ones that need to worry about precedence. Immediate variable can just look up by name,
then get on with it.