MCPcopy Create free account
hub / github.com/Icinga/icinga2 / WarnOnImplicitlySetGlobalVar

Function WarnOnImplicitlySetGlobalVar

lib/config/expression.cpp:561–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

559}
560
561static inline
562void WarnOnImplicitlySetGlobalVar(const std::unique_ptr<Expression>& setLhs, const Value& setLhsParent, CombinedSetOp setOp, const DebugInfo& debug)
563{
564 auto var (dynamic_cast<VariableExpression*>(setLhs.get()));
565
566 if (var && setLhsParent.IsObject()) {
567 auto ns (dynamic_pointer_cast<Namespace>(setLhsParent.Get<Object::Ptr>()));
568
569 if (ns && ns == ScriptGlobal::GetGlobals() && debug.Path.GetLength()) {
570 const char *opStr = nullptr;
571
572 switch (setOp) {
573 case OpSetLiteral:
574 opStr = "=";
575 break;
576 case OpSetAdd:
577 opStr = "+=";
578 break;
579 case OpSetSubtract:
580 opStr = "-=";
581 break;
582 case OpSetMultiply:
583 opStr = "*=";
584 break;
585 case OpSetDivide:
586 opStr = "/=";
587 break;
588 case OpSetModulo:
589 opStr = "%=";
590 break;
591 case OpSetXor:
592 opStr = "^=";
593 break;
594 case OpSetBinaryAnd:
595 opStr = "&=";
596 break;
597 case OpSetBinaryOr:
598 opStr = "|=";
599 break;
600 default:
601 VERIFY(!"Invalid opcode.");
602 }
603
604 auto varName (var->GetVariable());
605
606 Log(LogWarning, "config")
607 << "Global variable '" << varName << "' has been set implicitly via '" << varName << ' ' << opStr << " ...' " << debug << "."
608 " Please set it explicitly via 'globals." << varName << ' ' << opStr << " ...' instead.";
609 }
610 }
611}
612
613ExpressionResult SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
614{

Callers 1

DoEvaluateMethod · 0.85

Calls 5

LogClass · 0.85
IsObjectMethod · 0.80
GetVariableMethod · 0.80
getMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected