mirror of
https://github.com/jezhiggins/arabica
synced 2024-12-28 22:23:21 +01:00
Bit more work on variable resolution
This commit is contained in:
commit
7abcba0420
3 changed files with 39 additions and 4 deletions
|
@ -112,6 +112,37 @@ private:
|
||||||
}; // class ExecutionContext
|
}; // 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
|
class VariableClosure : public Variable_instance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -119,6 +150,9 @@ public:
|
||||||
const DOM::Node<std::string>& node,
|
const DOM::Node<std::string>& node,
|
||||||
ExecutionContext& context)
|
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));
|
return Variable_instance_ptr(new VariableClosure(var, node, context));
|
||||||
} // create
|
} // create
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,6 @@ public:
|
||||||
return;
|
return;
|
||||||
} // if ...
|
} // if ...
|
||||||
|
|
||||||
if(var->precedence() == Precedence::FrozenPrecedence()) // we're running, so resolve immediately
|
|
||||||
var->value();
|
|
||||||
|
|
||||||
stack[name] = var;
|
stack[name] = var;
|
||||||
} // declareVariable
|
} // declareVariable
|
||||||
|
|
||||||
|
|
|
@ -29,4 +29,8 @@ Performance
|
||||||
params - avoid creating closure for xsl:param if the param has been passed - DONE
|
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
|
- 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
|
- 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.
|
Loading…
Reference in a new issue