Make apply rules zone-aware

refs #6919
This commit is contained in:
Alexander A. Klimov 2019-07-04 18:25:23 +02:00
parent a65f2d6b41
commit 74618c6598
6 changed files with 20 additions and 12 deletions

View File

@ -11,9 +11,9 @@ ApplyRule::RuleMap ApplyRule::m_Rules;
ApplyRule::TypeMap ApplyRule::m_Types; ApplyRule::TypeMap ApplyRule::m_Types;
ApplyRule::ApplyRule(String name, Expression::Ptr expression, ApplyRule::ApplyRule(String name, Expression::Ptr expression,
Expression::Ptr filter, String package, String fkvar, String fvvar, Expression::Ptr fterm, Expression::Ptr filter, String zone, String package, String fkvar, String fvvar, Expression::Ptr fterm,
bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope) bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope)
: m_Name(std::move(name)), m_Expression(std::move(expression)), m_Filter(std::move(filter)), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), : m_Name(std::move(name)), m_Expression(std::move(expression)), m_Filter(std::move(filter)), m_Zone(std::move(zone)), m_Package(std::move(package)), m_FKVar(std::move(fkvar)),
m_FVVar(std::move(fvvar)), m_FTerm(std::move(fterm)), m_IgnoreOnError(ignoreOnError), m_DebugInfo(std::move(di)), m_Scope(std::move(scope)), m_HasMatches(false) m_FVVar(std::move(fvvar)), m_FTerm(std::move(fterm)), m_IgnoreOnError(ignoreOnError), m_DebugInfo(std::move(di)), m_Scope(std::move(scope)), m_HasMatches(false)
{ } { }
@ -32,6 +32,11 @@ Expression::Ptr ApplyRule::GetFilter() const
return m_Filter; return m_Filter;
} }
String ApplyRule::GetZone() const
{
return m_Zone;
}
String ApplyRule::GetPackage() const String ApplyRule::GetPackage() const
{ {
return m_Package; return m_Package;
@ -58,7 +63,7 @@ Dictionary::Ptr ApplyRule::GetScope() const
} }
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name, void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
const Expression::Ptr& expression, const Expression::Ptr& filter, const String& package, const String& fkvar, const Expression::Ptr& expression, const Expression::Ptr& filter, const String& zone, const String& package, const String& fkvar,
const String& fvvar, const Expression::Ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope) const String& fvvar, const Expression::Ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope)
{ {
auto actualTargetType (&targetType); auto actualTargetType (&targetType);
@ -71,7 +76,7 @@ void ApplyRule::AddRule(const String& sourceType, const String& targetType, cons
} }
} }
ApplyRule::Ptr rule = new ApplyRule(name, expression, filter, package, fkvar, fvvar, fterm, ignoreOnError, di, scope); ApplyRule::Ptr rule = new ApplyRule(name, expression, filter, zone, package, fkvar, fvvar, fterm, ignoreOnError, di, scope);
auto& rules (m_Rules[Type::GetByName(sourceType).get()]); auto& rules (m_Rules[Type::GetByName(sourceType).get()]);
if (!AddTargetedRule(rule, *actualTargetType, rules)) { if (!AddTargetedRule(rule, *actualTargetType, rules)) {

View File

@ -55,6 +55,7 @@ public:
String GetName() const; String GetName() const;
Expression::Ptr GetExpression() const; Expression::Ptr GetExpression() const;
Expression::Ptr GetFilter() const; Expression::Ptr GetFilter() const;
String GetZone() const;
String GetPackage() const; String GetPackage() const;
inline const String& GetFKVar() const noexcept inline const String& GetFKVar() const noexcept
@ -77,7 +78,7 @@ public:
bool EvaluateFilter(ScriptFrame& frame) const; bool EvaluateFilter(ScriptFrame& frame) const;
static void AddRule(const String& sourceType, const String& targetType, const String& name, const Expression::Ptr& expression, static void AddRule(const String& sourceType, const String& targetType, const String& name, const Expression::Ptr& expression,
const Expression::Ptr& filter, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm, const Expression::Ptr& filter, const String& zone, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm,
bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope); bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
static const std::vector<ApplyRule::Ptr>& GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType); static const std::vector<ApplyRule::Ptr>& GetRules(const Type::Ptr& sourceType, const Type::Ptr& targetType);
static const std::set<ApplyRule::Ptr>& GetTargetedHostRules(const Type::Ptr& sourceType, const String& host); static const std::set<ApplyRule::Ptr>& GetTargetedHostRules(const Type::Ptr& sourceType, const String& host);
@ -97,6 +98,7 @@ private:
String m_Name; String m_Name;
Expression::Ptr m_Expression; Expression::Ptr m_Expression;
Expression::Ptr m_Filter; Expression::Ptr m_Filter;
String m_Zone;
String m_Package; String m_Package;
String m_FKVar; String m_FKVar;
String m_FVVar; String m_FVVar;
@ -117,7 +119,7 @@ private:
static const Value * GetConst(Expression* exp, const Dictionary::Ptr& constants); static const Value * GetConst(Expression* exp, const Dictionary::Ptr& constants);
ApplyRule(String name, Expression::Ptr expression, ApplyRule(String name, Expression::Ptr expression,
Expression::Ptr filter, String package, String fkvar, String fvvar, Expression::Ptr fterm, Expression::Ptr filter, String zone, String package, String fkvar, String fvvar, Expression::Ptr fterm,
bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope); bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope);
}; };

View File

@ -1221,7 +1221,7 @@ apply:
std::unique_ptr<Expression> fterm{context->m_FTerm.top()}; std::unique_ptr<Expression> fterm{context->m_FTerm.top()};
context->m_FTerm.pop(); context->m_FTerm.pop();
$$ = new ApplyExpression(std::move(type), std::move(target), std::unique_ptr<Expression>($4), std::move(filter), context->GetPackage(), std::move(fkvar), std::move(fvvar), std::move(fterm), std::move(*$7), $8, std::unique_ptr<Expression>($10), DebugInfoRange(@2, @8)); $$ = new ApplyExpression(std::move(type), std::move(target), std::unique_ptr<Expression>($4), std::move(filter), context->GetZone(), context->GetPackage(), std::move(fkvar), std::move(fvvar), std::move(fterm), std::move(*$7), $8, std::unique_ptr<Expression>($10), DebugInfoRange(@2, @8));
delete $7; delete $7;
} }
; ;

View File

@ -915,7 +915,7 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhin
ExpressionResult nameres = m_Name->Evaluate(frame); ExpressionResult nameres = m_Name->Evaluate(frame);
CHECK_RESULT(nameres); CHECK_RESULT(nameres);
return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter, return VMOps::NewApply(frame, m_Type, m_Target, nameres.GetValue(), m_Filter, m_Zone,
m_Package, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_IgnoreOnError, m_Expression, m_DebugInfo); m_Package, m_FKVar, m_FVVar, m_FTerm, m_ClosedVars, m_IgnoreOnError, m_Expression, m_DebugInfo);
} }

View File

@ -830,11 +830,11 @@ class ApplyExpression final : public DebuggableExpression
{ {
public: public:
ApplyExpression(String type, String target, std::unique_ptr<Expression> name, ApplyExpression(String type, String target, std::unique_ptr<Expression> name,
std::unique_ptr<Expression> filter, String package, String fkvar, String fvvar, std::unique_ptr<Expression> filter, String zone, String package, String fkvar, String fvvar,
std::unique_ptr<Expression> fterm, std::map<String, std::unique_ptr<Expression> >&& closedVars, bool ignoreOnError, std::unique_ptr<Expression> fterm, std::map<String, std::unique_ptr<Expression> >&& closedVars, bool ignoreOnError,
std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo()) std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Type(std::move(type)), m_Target(std::move(target)), : DebuggableExpression(debugInfo), m_Type(std::move(type)), m_Target(std::move(target)),
m_Name(std::move(name)), m_Filter(filter.release()), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)), m_Name(std::move(name)), m_Filter(filter.release()), m_Zone(std::move(zone)), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)),
m_FTerm(fterm.release()), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)), m_FTerm(fterm.release()), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)),
m_Expression(expression.release()) m_Expression(expression.release())
{ } { }
@ -847,6 +847,7 @@ private:
String m_Target; String m_Target;
std::unique_ptr<Expression> m_Name; std::unique_ptr<Expression> m_Name;
Expression::Ptr m_Filter; Expression::Ptr m_Filter;
String m_Zone;
String m_Package; String m_Package;
String m_FKVar; String m_FKVar;
String m_FVVar; String m_FVVar;

View File

@ -115,11 +115,11 @@ public:
return new Function(name, wrapper, argNames); return new Function(name, wrapper, argNames);
} }
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const Expression::Ptr& filter, static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const Expression::Ptr& filter, const String& zone,
const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm, const std::map<String, std::unique_ptr<Expression> >& closedVars, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm, const std::map<String, std::unique_ptr<Expression> >& closedVars,
bool ignoreOnError, const Expression::Ptr& expression, const DebugInfo& debugInfo = DebugInfo()) bool ignoreOnError, const Expression::Ptr& expression, const DebugInfo& debugInfo = DebugInfo())
{ {
ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar, ApplyRule::AddRule(type, target, name, expression, filter, zone, package, fkvar,
fvvar, fterm, ignoreOnError, debugInfo, EvaluateClosedVars(frame, closedVars)); fvvar, fterm, ignoreOnError, debugInfo, EvaluateClosedVars(frame, closedVars));
return Empty; return Empty;