]> granicus.if.org Git - icinga2/commitdiff
Clean up the +=, -=, *= and /= operators.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 24 Mar 2014 08:06:16 +0000 (09:06 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 24 Mar 2014 08:06:16 +0000 (09:06 +0100)
Refs #5846

doc/4.1-configuration-syntax.md
lib/config/aexpression.cpp
lib/config/config_parser.yy

index c644edb9e5661bc245fd9e8666affe7b63befacd..cbdf913c771c4c9dd15df165802769d188c0e11a 100644 (file)
@@ -223,65 +223,67 @@ In this example a has the value 7 after both instructions are executed.
 
 #### <a id="operator-additive-assignment"></a> Operator +=
 
-Modifies a dictionary or array by adding new elements to it.
-
-Example:
+The += operator is a shortcut. The following expression:
 
     {
       a = [ "hello" ],
       a += [ "world" ]
     }
 
-In this example a contains both `"hello"` and `"world"`. This currently
-only works for dictionaries and arrays.
+is equivalent to:
 
-<!--
+    {
+      a = [ "hello" ],
+      a = a + [ "world" ]
+    }
 
 #### <a id="operator-substractive-assignment"></a> Operator -=
 
-Removes elements from a dictionary.
-
-Example:
+The -= operator is a shortcut. The following expression:
 
     {
-      a = { "hello", "world" },
-      a -= [ "world" ]
+      a = 10,
+      a -= 5
     }
 
-In this example a contains `"hello"`. Trying to remove an item that does
-not exist is not an error. Not implemented yet.
+is equivalent to:
+
+    {
+      a = 10,
+      a = a - 5
+    }
 
 #### <a id="operator-multiply-assignment"></a> Operator \*=
 
-Multiplies an existing dictionary element with the specified number. If
-the dictionary element does not already exist 0 is used as its value.
-
-Example:
+The *= operator is a shortcut. The following expression:
 
     {
       a = 60,
       a *= 5
     }
 
-In this example a is 300. This only works for numbers. Not implemented
-yet.
+is equivalent to:
+
+    {
+      a = 60,
+      a = a * 5
+    }
 
 #### <a id="operator-dividing-assignment"></a> Operator /=
 
-Divides an existing dictionary element by the specified number. If the
-dictionary element does not already exist 0 is used as its value.
-
-Example:
+The /= operator is a shortcut. The following expression:
 
     {
       a = 300,
       a /= 5
     }
 
-In this example a is 60. This only works for numbers. Not implemented
-yet.
+is equivalent to:
 
--->
+    {
+      a = 300,
+      a = a / 5
+    }
 
 ### <a id="indexer"></a> Indexer
 
index 133c4ab94e8e7284aff2ce7f5b3525799f0b7a27..5e8add22c2e91e87005a39e2c4d3386c3298d3f4 100644 (file)
@@ -397,5 +397,9 @@ Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& l
 Value AExpression::OpIndexer(const AExpression *expr, const Dictionary::Ptr& locals)
 {
        Dictionary::Ptr dict = locals->Get(expr->m_Operand1);
+       
+       if (!dict)
+               BOOST_THROW_EXCEPTION(ConfigError("Script variable '" + expr->m_Operand1 + "' not set in this scope."));
+       
        return dict->Get(expr->m_Operand2);
 }
index c3e88d1254ce02e3e099071f2ed26ca308a9cfe3..68bc238bd130012dab2015841b351b43d8c66b4e 100644 (file)
@@ -547,9 +547,6 @@ lterm_items_inner: /* empty */
 lterm: identifier lbinary_op rterm
        {
                AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3);
-               if ($2 == &AExpression::OpSetPlus || $2 == &AExpression::OpSetMinus || $2 == &AExpression::OpSetMultiply || $2 == &AExpression::OpSetDivide)
-                       aexpr->MakeInline();
-
                $$ = new Value(make_shared<AExpression>($2, $1, aexpr, DebugInfoRange(@1, @3)));
                free($1);
                delete $3;
@@ -564,9 +561,6 @@ lterm: identifier lbinary_op rterm
                subexprl->Add(subexpr);
                
                AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
-               if ($5 == &AExpression::OpSetPlus || $5 == &AExpression::OpSetMinus || $5 == &AExpression::OpSetMultiply || $5 == &AExpression::OpSetDivide)
-                       expr->MakeInline();
-
                $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6)));
                free($1);
        }