]> granicus.if.org Git - icinga2/commitdiff
Implement support for marking functions as deprecated
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 10 Aug 2016 13:40:02 +0000 (15:40 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 10 Aug 2016 13:48:05 +0000 (15:48 +0200)
fixes #12393

23 files changed:
lib/base/CMakeLists.txt
lib/base/array-script.cpp
lib/base/boolean-script.cpp
lib/base/configobject-script.cpp
lib/base/datetime-script.cpp
lib/base/dictionary-script.cpp
lib/base/function-script.cpp
lib/base/function.cpp
lib/base/function.hpp
lib/base/function.ti [new file with mode: 0644]
lib/base/json-script.cpp
lib/base/math-script.cpp
lib/base/number-script.cpp
lib/base/object-script.cpp
lib/base/string-script.cpp
lib/base/typetype-script.cpp
lib/config/config_parser.yy
lib/config/expression.cpp
lib/config/expression.hpp
lib/config/vmops.hpp
lib/icinga/checkable-script.cpp
lib/icinga/macroprocessor.cpp
tools/mkclass/classcompiler.cpp

index a040371d49108a379620a34b2af421b57ff9b12c..ea0bb807fffa44d73508492404f960d991bbafc9 100644 (file)
@@ -19,6 +19,7 @@ mkclass_target(application.ti application.tcpp application.thpp)
 mkclass_target(configobject.ti configobject.tcpp configobject.thpp)
 mkclass_target(datetime.ti datetime.tcpp datetime.thpp)
 mkclass_target(filelogger.ti filelogger.tcpp filelogger.thpp)
+mkclass_target(function.ti function.tcpp function.thpp)
 mkclass_target(logger.ti logger.tcpp logger.thpp)
 mkclass_target(streamlogger.ti streamlogger.tcpp streamlogger.thpp)
 mkclass_target(sysloglogger.ti sysloglogger.tcpp sysloglogger.thpp)
@@ -32,7 +33,7 @@ set(base_SOURCES
   json-script.cpp loader.cpp logger.cpp logger.thpp math-script.cpp
   netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp
   object-script.cpp objecttype.cpp primitivetype.cpp process.cpp ringbuffer.cpp scriptframe.cpp
-  function.cpp function-script.cpp functionwrapper.cpp scriptglobal.cpp
+  function.cpp function.thpp function-script.cpp functionwrapper.cpp scriptglobal.cpp
   scriptutils.cpp serializer.cpp socket.cpp socketevents.cpp socketevents-epoll.cpp socketevents-poll.cpp stacktrace.cpp
   statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp string-script.cpp
   sysloglogger.cpp sysloglogger.thpp tcpsocket.cpp threadpool.cpp timer.cpp
index a56cb45679a8651470efe0c6a222f86acd4c5181..e7f57a34956d6dede6b4aa89519a8572e1ed0953 100644 (file)
@@ -229,22 +229,22 @@ Object::Ptr Array::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("len", new Function(WrapFunction(ArrayLen), true));
-               prototype->Set("set", new Function(WrapFunction(ArraySet)));
-               prototype->Set("get", new Function(WrapFunction(ArrayGet)));
-               prototype->Set("add", new Function(WrapFunction(ArrayAdd)));
-               prototype->Set("remove", new Function(WrapFunction(ArrayRemove)));
-               prototype->Set("contains", new Function(WrapFunction(ArrayContains), true));
-               prototype->Set("clear", new Function(WrapFunction(ArrayClear)));
-               prototype->Set("sort", new Function(WrapFunction(ArraySort), true));
-               prototype->Set("shallow_clone", new Function(WrapFunction(ArrayShallowClone), true));
-               prototype->Set("join", new Function(WrapFunction(ArrayJoin), true));
-               prototype->Set("reverse", new Function(WrapFunction(ArrayReverse), true));
-               prototype->Set("map", new Function(WrapFunction(ArrayMap), true));
-               prototype->Set("reduce", new Function(WrapFunction(ArrayReduce), true));
-               prototype->Set("filter", new Function(WrapFunction(ArrayFilter), true));
-               prototype->Set("unique", new Function(WrapFunction(ArrayUnique), true));
+               prototype->Set("len", new Function("Array#len", WrapFunction(ArrayLen), true));
+               prototype->Set("set", new Function("Array#set", WrapFunction(ArraySet)));
+               prototype->Set("get", new Function("Array#get", WrapFunction(ArrayGet)));
+               prototype->Set("add", new Function("Array#add", WrapFunction(ArrayAdd)));
+               prototype->Set("remove", new Function("Array#remove", WrapFunction(ArrayRemove)));
+               prototype->Set("contains", new Function("Array#contains", WrapFunction(ArrayContains), true));
+               prototype->Set("clear", new Function("Array#clear", WrapFunction(ArrayClear)));
+               prototype->Set("sort", new Function("Array#sort", WrapFunction(ArraySort), true));
+               prototype->Set("shallow_clone", new Function("Array#shallow_clone", WrapFunction(ArrayShallowClone), true));
+               prototype->Set("join", new Function("Array#join", WrapFunction(ArrayJoin), true));
+               prototype->Set("reverse", new Function("Array#reverse", WrapFunction(ArrayReverse), true));
+               prototype->Set("map", new Function("Array#map", WrapFunction(ArrayMap), true));
+               prototype->Set("reduce", new Function("Array#reduce", WrapFunction(ArrayReduce), true));
+               prototype->Set("filter", new Function("Array#filter", WrapFunction(ArrayFilter), true));
+               prototype->Set("unique", new Function("Array#unique", WrapFunction(ArrayUnique), true));
        }
 
        return prototype;
-}
\ No newline at end of file
+}
index d262ed5c6dc9d72f0f147fdbde0c036e0b94cc79..c454864b9b3c56040910f664b73acf79b0d9bd6a 100644 (file)
@@ -38,7 +38,7 @@ Object::Ptr Boolean::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("to_string", new Function(WrapFunction(BooleanToString), true));
+               prototype->Set("to_string", new Function("Boolean#to_string", WrapFunction(BooleanToString), true));
        }
 
        return prototype;
index 34d234325c2194e0416c5979b99f3c4442eb211c..23d968295e25e4f05dd2727ee000a0cebe2625d4 100644 (file)
@@ -45,8 +45,8 @@ Object::Ptr ConfigObject::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("modify_attribute", new Function(WrapFunction(ConfigObjectModifyAttribute), false));
-               prototype->Set("restore_attribute", new Function(WrapFunction(ConfigObjectRestoreAttribute), false));
+               prototype->Set("modify_attribute", new Function("ConfigObject#modify_attribute", WrapFunction(ConfigObjectModifyAttribute), false));
+               prototype->Set("restore_attribute", new Function("ConfigObject#restore_attribute", WrapFunction(ConfigObjectRestoreAttribute), false));
        }
 
        return prototype;
index e0210a9b6d495e6a3a8417c0bd1ddd0d01edfd6a..dda68b88c92f0ae8d3c95bbbcd5274d9c373f019 100644 (file)
@@ -39,7 +39,7 @@ Object::Ptr DateTime::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("format", new Function(WrapFunction(DateTimeFormat)));
+               prototype->Set("format", new Function("DateTime#format", WrapFunction(DateTimeFormat)));
        }
 
        return prototype;
index 9128eb9364a1cb399f1ba6a09b0d97b22064e3ff..01196d52cdeb5303af73a2984d1f1a90e5064130 100644 (file)
@@ -86,13 +86,13 @@ Object::Ptr Dictionary::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("len", new Function(WrapFunction(DictionaryLen), true));
-               prototype->Set("set", new Function(WrapFunction(DictionarySet)));
-               prototype->Set("get", new Function(WrapFunction(DictionaryGet)));
-               prototype->Set("remove", new Function(WrapFunction(DictionaryRemove)));
-               prototype->Set("contains", new Function(WrapFunction(DictionaryContains), true));
-               prototype->Set("shallow_clone", new Function(WrapFunction(DictionaryShallowClone), true));
-               prototype->Set("keys", new Function(WrapFunction(DictionaryKeys), true));
+               prototype->Set("len", new Function("Dictionary#len", WrapFunction(DictionaryLen), true));
+               prototype->Set("set", new Function("Dictionary#set", WrapFunction(DictionarySet)));
+               prototype->Set("get", new Function("Dictionary#get", WrapFunction(DictionaryGet)));
+               prototype->Set("remove", new Function("Dictionary#remove", WrapFunction(DictionaryRemove)));
+               prototype->Set("contains", new Function("Dictionary#contains", WrapFunction(DictionaryContains), true));
+               prototype->Set("shallow_clone", new Function("Dictionary#shallow_clone", WrapFunction(DictionaryShallowClone), true));
+               prototype->Set("keys", new Function("Dictionary#keys", WrapFunction(DictionaryKeys), true));
        }
 
        return prototype;
index f0bd611180ea54f9b578be2a7a823b7022fc5a3f..54b82cb2f19ed1996b6d6ebe122f3e4d32f1e574 100644 (file)
@@ -59,8 +59,8 @@ Object::Ptr Function::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("call", new Function(WrapFunction(FunctionCall)));
-               prototype->Set("callv", new Function(WrapFunction(FunctionCallV)));
+               prototype->Set("call", new Function("Function#call", WrapFunction(FunctionCall)));
+               prototype->Set("callv", new Function("Function#callv", WrapFunction(FunctionCallV)));
        }
 
        return prototype;
index d7ef94270537fec54cd38a1e68c364e55ec422d4..529e95dccaf7bf8143febc6f5d76c89a5ba03ff8 100644 (file)
  ******************************************************************************/
 
 #include "base/function.hpp"
-#include "base/primitivetype.hpp"
-#include "base/dictionary.hpp"
+#include "base/function.tcpp"
 #include "base/scriptframe.hpp"
 
 using namespace icinga;
 
-REGISTER_PRIMITIVE_TYPE_NOINST(Function, Object, Function::GetPrototype());
+REGISTER_TYPE_WITH_PROTOTYPE(Function, Function::GetPrototype());
 
-Function::Function(const Callback& function, bool side_effect_free)
-       : m_Callback(function), m_SideEffectFree(side_effect_free)
-{ }
+Function::Function(const String& name, const Callback& function, bool side_effect_free, bool deprecated)
+       : m_Callback(function)
+{
+       SetName(name, true);
+       SetSideEffectFree(side_effect_free, true);
+       SetDeprecated(deprecated, true);
+}
 
 Value Function::Invoke(const std::vector<Value>& arguments)
 {
@@ -43,11 +46,6 @@ Value Function::Invoke(const Value& otherThis, const std::vector<Value>& argumen
        return m_Callback(arguments);
 }
 
-bool Function::IsSideEffectFree(void) const
-{
-       return m_SideEffectFree;
-}
-
 Object::Ptr Function::Clone(void) const
 {
        return const_cast<Function *>(this);
index 6dba72582d42ea46f9c8b3b46489bd2cb358d4c5..223a94d2ebd9a4c6dfcc8dc5faa49d29b94e742e 100644 (file)
@@ -21,6 +21,7 @@
 #define SCRIPTFUNCTION_H
 
 #include "base/i2-base.hpp"
+#include "base/function.thpp"
 #include "base/value.hpp"
 #include "base/functionwrapper.hpp"
 #include "base/scriptglobal.hpp"
@@ -35,18 +36,27 @@ namespace icinga
  *
  * @ingroup base
  */
-class I2_BASE_API Function : public Object
+class I2_BASE_API Function : public ObjectImpl<Function>
 {
 public:
        DECLARE_OBJECT(Function);
 
        typedef boost::function<Value (const std::vector<Value>& arguments)> Callback;
 
-       Function(const Callback& function, bool side_effect_free = false);
+       Function(const String& name, const Callback& function, bool side_effect_free = false, bool deprecated = false);
 
        Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
        Value Invoke(const Value& otherThis, const std::vector<Value>& arguments = std::vector<Value>());
-       bool IsSideEffectFree(void) const;
+
+       inline bool IsSideEffectFree(void) const
+       {
+               return GetSideEffectFree();
+       }
+
+       inline bool IsDeprecated(void) const
+       {
+               return GetDeprecated();
+       }
 
        static Object::Ptr GetPrototype(void);
 
@@ -54,13 +64,12 @@ public:
 
 private:
        Callback m_Callback;
-       bool m_SideEffectFree;
 };
 
 #define REGISTER_SCRIPTFUNCTION(name, callback) \
        namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \
                void RegisterFunction(void) { \
-                       Function::Ptr sf = new icinga::Function(WrapFunction(callback)); \
+                       Function::Ptr sf = new icinga::Function(#name, WrapFunction(callback)); \
                        ScriptGlobal::Set(#name, sf); \
                } \
                INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
@@ -69,8 +78,10 @@ private:
 #define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
        namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
                void RegisterFunction(void) { \
-                       Function::Ptr sf = new icinga::Function(WrapFunction(callback)); \
+                       Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \
                        ScriptGlobal::Set(#ns "." #name, sf); \
+                       Function::Ptr dsf = new icinga::Function(#name " (deprecated)", WrapFunction(callback), false, true); \
+                       ScriptGlobal::Set(#name, dsf); \
                } \
                INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
        } } }
@@ -78,7 +89,7 @@ private:
 #define REGISTER_SAFE_SCRIPTFUNCTION(name, callback) \
        namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \
                void RegisterFunction(void) { \
-                       Function::Ptr sf = new icinga::Function(WrapFunction(callback), true); \
+                       Function::Ptr sf = new icinga::Function(#name, WrapFunction(callback), true); \
                        ScriptGlobal::Set(#name, sf); \
                } \
                INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
@@ -87,8 +98,10 @@ private:
 #define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
        namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
                void RegisterFunction(void) { \
-                       Function::Ptr sf = new icinga::Function(WrapFunction(callback), true); \
+                       Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \
                        ScriptGlobal::Set(#ns "." #name, sf); \
+                       Function::Ptr dsf = new icinga::Function(#name " (deprecated)", WrapFunction(callback), true, true); \
+                       ScriptGlobal::Set(#name, dsf); \
                } \
                INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
        } } }
diff --git a/lib/base/function.ti b/lib/base/function.ti
new file mode 100644 (file)
index 0000000..b9b9f9c
--- /dev/null
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)  *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#include "base/configobject.hpp"
+
+library base;
+
+namespace icinga
+{
+
+abstract class Function
+{
+       String "name";
+       bool side_effect_free;
+       bool deprecated;
+};
+
+}
index 5e754ec842bc2a1e4d9ead29d8851f8025e84005..9cf68b35b912e9e9121d70289610c1a53a444bf4 100644 (file)
@@ -36,8 +36,8 @@ static void InitializeJsonObj(void)
        Dictionary::Ptr jsonObj = new Dictionary();
 
        /* Methods */
-       jsonObj->Set("encode", new Function(WrapFunction(JsonEncodeShim), true));
-       jsonObj->Set("decode", new Function(WrapFunction(JsonDecode), true));
+       jsonObj->Set("encode", new Function("Json#encode", WrapFunction(JsonEncodeShim), true));
+       jsonObj->Set("decode", new Function("Json#decode", WrapFunction(JsonDecode), true));
 
        ScriptGlobal::Set("Json", jsonObj);
 }
index 9b23224093e95a0668347c9573a089aa7dbd94ea..ff24d8bc622feb1924a701a8336f699e9317badb 100644 (file)
@@ -174,27 +174,27 @@ static void InitializeMathObj(void)
        mathObj->Set("SQRT2", 1.41421356237309504880);
 
        /* Methods */
-       mathObj->Set("abs", new Function(WrapFunction(MathAbs), true));
-       mathObj->Set("acos", new Function(WrapFunction(MathAcos), true));
-       mathObj->Set("asin", new Function(WrapFunction(MathAsin), true));
-       mathObj->Set("atan", new Function(WrapFunction(MathAtan), true));
-       mathObj->Set("atan2", new Function(WrapFunction(MathAtan2), true));
-       mathObj->Set("ceil", new Function(WrapFunction(MathCeil), true));
-       mathObj->Set("cos", new Function(WrapFunction(MathCos), true));
-       mathObj->Set("exp", new Function(WrapFunction(MathExp), true));
-       mathObj->Set("floor", new Function(WrapFunction(MathFloor), true));
-       mathObj->Set("log", new Function(WrapFunction(MathLog), true));
-       mathObj->Set("max", new Function(WrapFunction(MathMax), true));
-       mathObj->Set("min", new Function(WrapFunction(MathMin), true));
-       mathObj->Set("pow", new Function(WrapFunction(MathPow), true));
-       mathObj->Set("random", new Function(WrapFunction(MathRandom), true));
-       mathObj->Set("round", new Function(WrapFunction(MathRound), true));
-       mathObj->Set("sin", new Function(WrapFunction(MathSin), true));
-       mathObj->Set("sqrt", new Function(WrapFunction(MathSqrt), true));
-       mathObj->Set("tan", new Function(WrapFunction(MathTan), true));
-       mathObj->Set("isnan", new Function(WrapFunction(MathIsnan), true));
-       mathObj->Set("isinf", new Function(WrapFunction(MathIsinf), true));
-       mathObj->Set("sign", new Function(WrapFunction(MathSign), true));
+       mathObj->Set("abs", new Function("Math#abs", WrapFunction(MathAbs), true));
+       mathObj->Set("acos", new Function("Math#acos", WrapFunction(MathAcos), true));
+       mathObj->Set("asin", new Function("Math#asin", WrapFunction(MathAsin), true));
+       mathObj->Set("atan", new Function("Math#atan", WrapFunction(MathAtan), true));
+       mathObj->Set("atan2", new Function("Math#atan2", WrapFunction(MathAtan2), true));
+       mathObj->Set("ceil", new Function("Math#ceil", WrapFunction(MathCeil), true));
+       mathObj->Set("cos", new Function("Math#cos", WrapFunction(MathCos), true));
+       mathObj->Set("exp", new Function("Math#exp", WrapFunction(MathExp), true));
+       mathObj->Set("floor", new Function("Math#floor", WrapFunction(MathFloor), true));
+       mathObj->Set("log", new Function("Math#log", WrapFunction(MathLog), true));
+       mathObj->Set("max", new Function("Math#max", WrapFunction(MathMax), true));
+       mathObj->Set("min", new Function("Math#min", WrapFunction(MathMin), true));
+       mathObj->Set("pow", new Function("Math#pow", WrapFunction(MathPow), true));
+       mathObj->Set("random", new Function("Math#random", WrapFunction(MathRandom), true));
+       mathObj->Set("round", new Function("Math#round", WrapFunction(MathRound), true));
+       mathObj->Set("sin", new Function("Math#sin", WrapFunction(MathSin), true));
+       mathObj->Set("sqrt", new Function("Math#sqrt", WrapFunction(MathSqrt), true));
+       mathObj->Set("tan", new Function("Math#tan", WrapFunction(MathTan), true));
+       mathObj->Set("isnan", new Function("Math#isnan", WrapFunction(MathIsnan), true));
+       mathObj->Set("isinf", new Function("Math#isinf", WrapFunction(MathIsinf), true));
+       mathObj->Set("sign", new Function("Math#sign", WrapFunction(MathSign), true));
 
        ScriptGlobal::Set("Math", mathObj);
 }
index 30d2e43b75f5590389cbca4417ac4ca2951b5f5e..b6ccf0c37ac1182114dcb10f331bdf0dde63b335 100644 (file)
@@ -37,7 +37,7 @@ Object::Ptr Number::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("to_string", new Function(WrapFunction(NumberToString), true));
+               prototype->Set("to_string", new Function("Number#to_string", WrapFunction(NumberToString), true));
        }
 
        return prototype;
index edef300775624f68ef9efcfca8adf08badcc1f7a..903c93987bab228a6a300c2d923d3594c60ef2a4 100644 (file)
@@ -52,9 +52,9 @@ Object::Ptr Object::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("to_string", new Function(WrapFunction(ObjectToString), true));
-               prototype->Set("notify_attribute", new Function(WrapFunction(ObjectNotifyAttribute), false));
-               prototype->Set("clone", new Function(WrapFunction(ObjectClone), true));
+               prototype->Set("to_string", new Function("Object#to_string", WrapFunction(ObjectToString), true));
+               prototype->Set("notify_attribute", new Function("Object#notify_attribute", WrapFunction(ObjectNotifyAttribute), false));
+               prototype->Set("clone", new Function("Object#clone", WrapFunction(ObjectClone), true));
        }
 
        return prototype;
index 7ea1c91ab6980216b3ffdbdb950b1cd1af2a197c..531918e8e1b526a13f4ba61964239e98d72e807e 100644 (file)
@@ -146,17 +146,17 @@ Object::Ptr String::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("len", new Function(WrapFunction(StringLen), true));
-               prototype->Set("to_string", new Function(WrapFunction(StringToString), true));
-               prototype->Set("substr", new Function(WrapFunction(StringSubstr), true));
-               prototype->Set("upper", new Function(WrapFunction(StringUpper), true));
-               prototype->Set("lower", new Function(WrapFunction(StringLower), true));
-               prototype->Set("split", new Function(WrapFunction(StringSplit), true));
-               prototype->Set("find", new Function(WrapFunction(StringFind), true));
-               prototype->Set("contains", new Function(WrapFunction(StringContains), true));
-               prototype->Set("replace", new Function(WrapFunction(StringReplace), true));
-               prototype->Set("reverse", new Function(WrapFunction(StringReverse), true));
-               prototype->Set("trim", new Function(WrapFunction(StringTrim), true));
+               prototype->Set("len", new Function("String#len", WrapFunction(StringLen), true));
+               prototype->Set("to_string", new Function("String#to_string", WrapFunction(StringToString), true));
+               prototype->Set("substr", new Function("String#substr", WrapFunction(StringSubstr), true));
+               prototype->Set("upper", new Function("String#upper", WrapFunction(StringUpper), true));
+               prototype->Set("lower", new Function("String#lower", WrapFunction(StringLower), true));
+               prototype->Set("split", new Function("String#split", WrapFunction(StringSplit), true));
+               prototype->Set("find", new Function("String#find", WrapFunction(StringFind), true));
+               prototype->Set("contains", new Function("String#contains", WrapFunction(StringContains), true));
+               prototype->Set("replace", new Function("String#replace", WrapFunction(StringReplace), true));
+               prototype->Set("reverse", new Function("String#reverse", WrapFunction(StringReverse), true));
+               prototype->Set("trim", new Function("String#trim", WrapFunction(StringTrim), true));
        }
 
        return prototype;
index 01a9950cfaee87865181a4ee5436c156ac916246..54b3ccf2b5fc0481cff06775401be728587fbdbd 100644 (file)
@@ -48,7 +48,7 @@ Object::Ptr TypeType::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("register_attribute_handler", new Function(WrapFunction(TypeRegisterAttributeHandler), false));
+               prototype->Set("register_attribute_handler", new Function("Type#register_attribute_handler", WrapFunction(TypeRegisterAttributeHandler), false));
        }
 
        return prototype;
index 6a0e4df69888973342102a1f59c50290dbe23da0..baf9b241fa84959208dfbe559f3dd38654172ad9 100644 (file)
@@ -629,7 +629,7 @@ lterm: T_LIBRARY rterm
        {
                EndFlowControlBlock(context);
 
-               FunctionExpression *fexpr = new FunctionExpression(*$4, $6, $8, @$);
+               FunctionExpression *fexpr = new FunctionExpression(*$2, *$4, $6, $8, @$);
                delete $4;
 
                $$ = new SetExpression(MakeIndexer(ScopeThis, *$2), OpSetLiteral, fexpr, @$);
@@ -920,7 +920,7 @@ rterm_no_side_effect_no_dict: T_STRING
                args.push_back(*$1);
                delete $1;
 
-               $$ = new FunctionExpression(args, new std::map<String, Expression *>(), $4, @$);
+               $$ = new FunctionExpression("<anonymous>", args, new std::map<String, Expression *>(), $4, @$);
        }
        | identifier T_FOLLOWS rterm %dprec 1
        {
@@ -930,7 +930,7 @@ rterm_no_side_effect_no_dict: T_STRING
                args.push_back(*$1);
                delete $1;
 
-               $$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, @$);
+               $$ = new FunctionExpression("<anonymous>", args, new std::map<String, Expression *>(), $3, @$);
        }
        | '(' identifier_items ')' T_FOLLOWS
        {
@@ -940,14 +940,14 @@ rterm_no_side_effect_no_dict: T_STRING
        {
                EndFlowControlBlock(context);
 
-               $$ = new FunctionExpression(*$2, new std::map<String, Expression *>(), $6, @$);
+               $$ = new FunctionExpression("<anonymous>", *$2, new std::map<String, Expression *>(), $6, @$);
                delete $2;
        }
        | '(' identifier_items ')' T_FOLLOWS rterm %dprec 1
        {
                ASSERT(!dynamic_cast<DictExpression *>($5));
 
-               $$ = new FunctionExpression(*$2, new std::map<String, Expression *>(), $5, @$);
+               $$ = new FunctionExpression("<anonymous>", *$2, new std::map<String, Expression *>(), $5, @$);
                delete $2;
        }
        | rterm_array
@@ -988,7 +988,7 @@ rterm_no_side_effect_no_dict: T_STRING
        {
                EndFlowControlBlock(context);
 
-               $$ = new FunctionExpression(*$3, $5, $7, @$);
+               $$ = new FunctionExpression("<anonymous>", *$3, $5, $7, @$);
                delete $3;
        }
        | T_NULLARY_LAMBDA_BEGIN
@@ -1012,7 +1012,7 @@ rterm_no_side_effect_no_dict: T_STRING
                DictExpression *aexpr = new DictExpression(dlist, @$);
                aexpr->MakeInline();
 
-               $$ = new FunctionExpression(std::vector<String>(), NULL, aexpr, @$);
+               $$ = new FunctionExpression("<anonymous>", std::vector<String>(), NULL, aexpr, @$);
        }
        ;
 
index bd87767e32e6d33ccf7c0635840f9b4a9af23f44..2e52425fd3e6efa84eb78c1459f1d9ac0a60e610 100644 (file)
@@ -755,7 +755,7 @@ ExpressionResult ImportExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
 
 ExpressionResult FunctionExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
 {
-       return VMOps::NewFunction(frame, m_Args, m_ClosedVars, m_Expression);
+       return VMOps::NewFunction(frame, m_Name, m_Args, m_ClosedVars, m_Expression);
 }
 
 ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
index 8e0e9cdadcfd77d702925a136f18730cd6c49358..7db4b11a28ef3b204594be5211778fdb28f21266 100644 (file)
@@ -790,7 +790,7 @@ private:
 class I2_CONFIG_API FunctionExpression : public DebuggableExpression
 {
 public:
-       FunctionExpression(const std::vector<String>& args,
+       FunctionExpression(const String& name, const std::vector<String>& args,
            std::map<String, Expression *> *closedVars, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
                : DebuggableExpression(debugInfo), m_Args(args), m_ClosedVars(closedVars), m_Expression(expression)
        { }
@@ -799,6 +799,7 @@ protected:
        virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
 
 private:
+       String m_Name;
        std::vector<String> m_Args;
        std::map<String, Expression *> *m_ClosedVars;
        boost::shared_ptr<Expression> m_Expression;
index 1dc5b2b948337ec271f193fdf3181834accf1258..a23687217e67c29c135ad41b4140e296df5de17b 100644 (file)
@@ -95,10 +95,10 @@ public:
 
        }
 
-       static inline Value NewFunction(ScriptFrame& frame, const std::vector<String>& args,
+       static inline Value NewFunction(ScriptFrame& frame, const String& name, const std::vector<String>& args,
            std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression)
        {
-               return new Function(boost::bind(&FunctionWrapper, _1, args,
+               return new Function(name, boost::bind(&FunctionWrapper, _1, args,
                    EvaluateClosedVars(frame, closedVars), expression));
        }
 
index ce02e66050a3a59857a64c65d3bf7fcb5e1532bb..1e301ff7b8e17bf5ae54fdf5f37ad1fb6095767d 100644 (file)
@@ -39,7 +39,7 @@ Object::Ptr Checkable::GetPrototype(void)
 
        if (!prototype) {
                prototype = new Dictionary();
-               prototype->Set("process_check_result", new Function(WrapFunction(CheckableProcessCheckResult), false));
+               prototype->Set("process_check_result", new Function("Checkable#process_check_result", WrapFunction(CheckableProcessCheckResult), false));
        }
 
        return prototype;
index a985fa933332c049efaafecb12e969e414078687..de90b055d0b25052f3f13f6f93db7bbf69507c9c 100644 (file)
@@ -216,10 +216,10 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver
                resolvers_this->Set(resolver.first, resolver.second);
        }
 
-       resolvers_this->Set("macro", new Function(boost::bind(&MacroProcessor::InternalResolveMacrosShim,
+       resolvers_this->Set("macro", new Function("macro (temporary)", boost::bind(&MacroProcessor::InternalResolveMacrosShim,
            _1, boost::cref(resolvers), cr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros,
            recursionLevel + 1)));
-       resolvers_this->Set("resolve_arguments", new Function(boost::bind(&MacroProcessor::InternalResolveArgumentsShim,
+       resolvers_this->Set("resolve_arguments", new Function("resolve_arguments (temporary)", boost::bind(&MacroProcessor::InternalResolveArgumentsShim,
            _1, boost::cref(resolvers), cr, resolvedMacros, useResolvedMacros,
            recursionLevel + 1)));
 
index 80c0b107d15f8016365d0d6936de6bc18e1cfdc7..8277826be72465bd3a1a81bc1d7defdb6c84d305 100644 (file)
@@ -522,6 +522,12 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
                } else
                        m_Impl << "\t" << "Value avalue = value;" << std::endl;
 
+               m_Impl << "\t" << "if (avalue.IsObjectType<Function>()) {" << std::endl
+                      << "\t\t" << "Function::Ptr func = avalue;" << std::endl
+                      << "\t\t" << "if (func->IsDeprecated())" << std::endl
+                      << "\t\t\t" << "Log(LogWarning, \"" << klass.Name << "\") << \"Field '" << field.Name << "' for object '\" << dynamic_cast<ConfigObject *>(this)->GetName() << \"' of type '\" << dynamic_cast<ConfigObject *>(this)->GetType()->GetName() << \"' is set to a deprecated function: \" << func->GetName();" << std::endl
+                      << "\t" << "}" << std::endl << std::endl;
+
                std::string ftype = FieldTypeToIcingaName(field, true);
 
                if (field.Type.IsName) {
@@ -1379,6 +1385,9 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream& input,
              << "#include \"base/utility.hpp\"" << std::endl
              << "#include \"base/convert.hpp\"" << std::endl
              << "#include \"base/dependencygraph.hpp\"" << std::endl
+             << "#include \"base/logger.hpp\"" << std::endl
+             << "#include \"base/function.hpp\"" << std::endl
+             << "#include \"base/configtype.hpp\"" << std::endl
              << "#include <boost/foreach.hpp>" << std::endl
              << "#include <boost/assign/list_of.hpp>" << std::endl
              << "#ifdef _MSC_VER" << std::endl