Allow rterm in indexer ops.

Refs #5870
This commit is contained in:
Gunnar Beutner 2014-03-30 10:00:11 +02:00
parent ec0fdd3fd2
commit 5179eebf09
7 changed files with 76 additions and 28 deletions

View File

@ -299,14 +299,16 @@ Value AExpression::OpDict(const AExpression *expr, const Dictionary::Ptr& locals
Value AExpression::OpSet(const AExpression *expr, const Dictionary::Ptr& locals) Value AExpression::OpSet(const AExpression *expr, const Dictionary::Ptr& locals)
{ {
Value index = expr->EvaluateOperand1(locals);
Value right = expr->EvaluateOperand2(locals); Value right = expr->EvaluateOperand2(locals);
locals->Set(expr->m_Operand1, right); locals->Set(index, right);
return right; return right;
} }
Value AExpression::OpSetPlus(const AExpression *expr, const Dictionary::Ptr& locals) Value AExpression::OpSetPlus(const AExpression *expr, const Dictionary::Ptr& locals)
{ {
Value left = locals->Get(expr->m_Operand1); Value index = expr->EvaluateOperand1(locals);
Value left = locals->Get(index);
AExpression::Ptr exp_right = expr->m_Operand2; AExpression::Ptr exp_right = expr->m_Operand2;
Dictionary::Ptr xlocals = locals; Dictionary::Ptr xlocals = locals;
@ -326,13 +328,14 @@ Value AExpression::OpSetPlus(const AExpression *expr, const Dictionary::Ptr& loc
dict->Remove("__parent"); dict->Remove("__parent");
} }
locals->Set(expr->m_Operand1, result); locals->Set(index, result);
return result; return result;
} }
Value AExpression::OpSetMinus(const AExpression *expr, const Dictionary::Ptr& locals) Value AExpression::OpSetMinus(const AExpression *expr, const Dictionary::Ptr& locals)
{ {
Value left = locals->Get(expr->m_Operand1); Value index = expr->EvaluateOperand1(locals);
Value left = locals->Get(index);
AExpression::Ptr exp_right = expr->m_Operand2; AExpression::Ptr exp_right = expr->m_Operand2;
Dictionary::Ptr xlocals = locals; Dictionary::Ptr xlocals = locals;
@ -352,13 +355,14 @@ Value AExpression::OpSetMinus(const AExpression *expr, const Dictionary::Ptr& lo
dict->Remove("__parent"); dict->Remove("__parent");
} }
locals->Set(expr->m_Operand1, result); locals->Set(index, result);
return result; return result;
} }
Value AExpression::OpSetMultiply(const AExpression *expr, const Dictionary::Ptr& locals) Value AExpression::OpSetMultiply(const AExpression *expr, const Dictionary::Ptr& locals)
{ {
Value left = locals->Get(expr->m_Operand1); Value index = expr->EvaluateOperand1(locals);
Value left = locals->Get(index);
AExpression::Ptr exp_right = expr->m_Operand2; AExpression::Ptr exp_right = expr->m_Operand2;
Dictionary::Ptr xlocals = locals; Dictionary::Ptr xlocals = locals;
@ -378,13 +382,14 @@ Value AExpression::OpSetMultiply(const AExpression *expr, const Dictionary::Ptr&
dict->Remove("__parent"); dict->Remove("__parent");
} }
locals->Set(expr->m_Operand1, result); locals->Set(index, result);
return result; return result;
} }
Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& locals) Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& locals)
{ {
Value left = locals->Get(expr->m_Operand1); Value index = expr->EvaluateOperand1(locals);
Value left = locals->Get(index);
AExpression::Ptr exp_right = expr->m_Operand2; AExpression::Ptr exp_right = expr->m_Operand2;
Dictionary::Ptr xlocals = locals; Dictionary::Ptr xlocals = locals;
@ -404,7 +409,7 @@ Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& l
dict->Remove("__parent"); dict->Remove("__parent");
} }
locals->Set(expr->m_Operand1, result); locals->Set(index, result);
return result; return result;
} }

View File

@ -524,36 +524,43 @@ lterm_items_inner: /* empty */
lterm: identifier lbinary_op rterm lterm: identifier lbinary_op rterm
{ {
AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3); AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
$$ = new Value(make_shared<AExpression>($2, $1, aexpr, DebugInfoRange(@1, @3)));
free($1); free($1);
AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3);
$$ = new Value(make_shared<AExpression>($2, aindex, aexpr, DebugInfoRange(@1, @3)));
delete $3; delete $3;
} }
| identifier '[' T_STRING ']' lbinary_op rterm | identifier '[' rterm ']' lbinary_op rterm
{ {
AExpression::Ptr subexpr = make_shared<AExpression>($5, $3, static_cast<AExpression::Ptr>(*$6), DebugInfoRange(@1, @6)); AExpression::Ptr subexpr = make_shared<AExpression>($5, static_cast<AExpression::Ptr>(*$3), static_cast<AExpression::Ptr>(*$6), DebugInfoRange(@1, @6));
free($3); delete $3;
delete $6; delete $6;
Array::Ptr subexprl = make_shared<Array>(); Array::Ptr subexprl = make_shared<Array>();
subexprl->Add(subexpr); subexprl->Add(subexpr);
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6)); AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6)));
free($1); free($1);
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindex, expr, DebugInfoRange(@1, @6)));
} }
| identifier '.' T_IDENTIFIER lbinary_op rterm | identifier '.' T_IDENTIFIER lbinary_op rterm
{ {
AExpression::Ptr subexpr = make_shared<AExpression>($4, $3, static_cast<AExpression::Ptr>(*$5), DebugInfoRange(@1, @5)); AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
AExpression::Ptr subexpr = make_shared<AExpression>($4, aindex, static_cast<AExpression::Ptr>(*$5), DebugInfoRange(@1, @5));
free($3); free($3);
delete $5; delete $5;
Array::Ptr subexprl = make_shared<Array>(); Array::Ptr subexprl = make_shared<Array>();
subexprl->Add(subexpr); subexprl->Add(subexpr);
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5)); AExpression::Ptr aindexl = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @5)));
free($1); free($1);
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5));
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindexl, expr, DebugInfoRange(@1, @5)));
} }
| T_IMPORT rterm | T_IMPORT rterm
{ {

View File

@ -88,7 +88,12 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
Array::Ptr exprs = make_shared<Array>(); Array::Ptr exprs = make_shared<Array>();
Array::Ptr templateArray = make_shared<Array>(); Array::Ptr templateArray = make_shared<Array>();
templateArray->Add(m_Name); templateArray->Add(m_Name);
exprs->Add(make_shared<AExpression>(&AExpression::OpSetPlus, "templates", make_shared<AExpression>(&AExpression::OpLiteral, templateArray, m_DebugInfo), m_DebugInfo));
exprs->Add(make_shared<AExpression>(&AExpression::OpSetPlus,
make_shared<AExpression>(&AExpression::OpLiteral, "templates", m_DebugInfo),
make_shared<AExpression>(&AExpression::OpLiteral, templateArray, m_DebugInfo),
m_DebugInfo));
exprs->Add(make_shared<AExpression>(&AExpression::OpDict, m_Expressions, true, m_DebugInfo)); exprs->Add(make_shared<AExpression>(&AExpression::OpDict, m_Expressions, true, m_DebugInfo));
AExpression::Ptr exprl = make_shared<AExpression>(&AExpression::OpDict, exprs, true, m_DebugInfo); AExpression::Ptr exprl = make_shared<AExpression>(&AExpression::OpDict, exprs, true, m_DebugInfo);

View File

@ -67,8 +67,15 @@ void Dependency::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
builder->SetName(name); builder->SetName(name);
builder->SetScope(rule.GetScope()); builder->SetScope(rule.GetScope());
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "child_host", make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "child_service", make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di), di)); make_shared<AExpression>(&AExpression::OpLiteral, "child_host", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(),
di), di));
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "child_service", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di), di));
builder->AddExpression(rule.GetExpression()); builder->AddExpression(rule.GetExpression());
ConfigItem::Ptr serviceItem = builder->Compile(); ConfigItem::Ptr serviceItem = builder->Compile();

View File

@ -67,8 +67,16 @@ void Notification::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
builder->SetName(name); builder->SetName(name);
builder->SetScope(rule.GetScope()); builder->SetScope(rule.GetScope());
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "host", make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "service", make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di), di)); make_shared<AExpression>(&AExpression::OpLiteral, "host", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(), di),
di));
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "service", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di),
di));
builder->AddExpression(rule.GetExpression()); builder->AddExpression(rule.GetExpression());
ConfigItem::Ptr serviceItem = builder->Compile(); ConfigItem::Ptr serviceItem = builder->Compile();

View File

@ -67,8 +67,16 @@ void ScheduledDowntime::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
builder->SetName(name); builder->SetName(name);
builder->SetScope(rule.GetScope()); builder->SetScope(rule.GetScope());
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "host", make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "service", make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di), di)); make_shared<AExpression>(&AExpression::OpLiteral, "host", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetHost()->GetName(), di),
di));
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "service", di),
make_shared<AExpression>(&AExpression::OpLiteral, service->GetShortName(), di),
di));
builder->AddExpression(rule.GetExpression()); builder->AddExpression(rule.GetExpression());
ConfigItem::Ptr serviceItem = builder->Compile(); ConfigItem::Ptr serviceItem = builder->Compile();

View File

@ -66,8 +66,16 @@ void Service::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
builder->SetName(name); builder->SetName(name);
builder->SetScope(rule.GetScope()); builder->SetScope(rule.GetScope());
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "host", make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(), di), di)); builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet, "short_name", make_shared<AExpression>(&AExpression::OpLiteral, rule.GetName(), di), di)); make_shared<AExpression>(&AExpression::OpLiteral, "host", di),
make_shared<AExpression>(&AExpression::OpLiteral, host->GetName(), di),
di));
builder->AddExpression(make_shared<AExpression>(&AExpression::OpSet,
make_shared<AExpression>(&AExpression::OpLiteral, "short_name", di),
make_shared<AExpression>(&AExpression::OpLiteral, rule.GetName(), di),
di));
builder->AddExpression(rule.GetExpression()); builder->AddExpression(rule.GetExpression());
ConfigItem::Ptr serviceItem = builder->Compile(); ConfigItem::Ptr serviceItem = builder->Compile();