Add parameter names to predefined functions 30/169430/3
authorPaweł Stawicki <p.stawicki@samsung.com>
Thu, 8 Feb 2018 10:59:24 +0000 (11:59 +0100)
committerPaweł Stawicki <p.stawicki@samsung.com>
Thu, 8 Feb 2018 11:55:07 +0000 (12:55 +0100)
Change-Id: I27a0c223e308756ea8f8e34cc25a7213c602c58c

src/batch/BatchRunner.cpp

index 668acb3..0c8cfbf 100644 (file)
@@ -451,66 +451,69 @@ void BatchExecutor::insertMethods()
                return  EvaluationContext::getCurrentEvaluationContext().topBatchPath();
        };
 
-       variables["import"] = [&](std::string filename) -> EvaluationValue {
+       variables["import"] =  EvaluationValueFunction{ [&](std::string filename) -> EvaluationValue {
 
-               StatPtr result;
-               auto currentRdlFile = EvaluationContext::getCurrentEvaluationContext().topBatchPath();
-               auto filenameFullPath = getPathRelativeToFile(filename, currentRdlFile);
-               auto it = imports.insert({ filenameFullPath, {} });
-               if (!it.second)
-               {
-                       result = it.first->second;
-                       if (!result) {
-                               throw EvaluationFailure{} << "nested import found in " << filenameFullPath;
+                       StatPtr result;
+                       auto currentRdlFile = EvaluationContext::getCurrentEvaluationContext().topBatchPath();
+                       auto filenameFullPath = getPathRelativeToFile(filename, currentRdlFile);
+                       auto it = imports.insert({ filenameFullPath, {} });
+                       if (!it.second)
+                       {
+                               result = it.first->second;
+                               if (!result) {
+                                       throw EvaluationFailure{} << "nested import found in " << filenameFullPath;
+                               }
+                               result->evaluate();
+                               return {};
                        }
-                       result->evaluate();
-                       return {};
-               }
 
-               auto content = getFileContent(filenameFullPath);
-               std::string error;
-               auto tokens = lexTest(error, filenameFullPath, content);
+                       auto content = getFileContent(filenameFullPath);
+                       std::string error;
+                       auto tokens = lexTest(error, filenameFullPath, content);
 
-               if (!error.empty())
-                       throw EvaluationFailure{} << "Lexing failed\n" << error;
+                       if (!error.empty())
+                               throw EvaluationFailure{} << "Lexing failed\n" << error;
 
-               std::vector<std::string> errors;
-               result = parseTokens(errors, tokens);
+                       std::vector<std::string> errors;
+                       result = parseTokens(errors, tokens);
 
-               if (!errors.empty())
-               {
-                       auto error = EvaluationFailure{};
-                       error << "Parsing failed\n";
-                       for (auto &e : errors) {
-                               error << e << "\n";
+                       if (!errors.empty())
+                       {
+                               auto error = EvaluationFailure{};
+                               error << "Parsing failed\n";
+                               for (auto &e : errors) {
+                                       error << e << "\n";
+                               }
+                               throw std::move(error);
                        }
-                       throw std::move(error);
-               }
-               ASSERT(result);
-               result->evaluate();
-               it.first->second = std::move(result);
-               return {};
-       };
+                       ASSERT(result);
+                       result->evaluate();
+                       it.first->second = std::move(result);
+                       return {};
+               }, { {"filename"} } };
 
-       variables["sleep"] = [&](double tm) -> EvaluationValue {
-               if (tm > 0)
-               {
-                       auto sleepTime = std::chrono::milliseconds{ static_cast<int>(std::floor(1000.0 * tm + 0.5)) };
-                       std::this_thread::sleep_for(sleepTime);
-               }
-               return {};
-       };
-       variables["print"] = [&](std::string txt) -> EvaluationValue {
-               output << txt << "\n";
-               return {};
-       };
-       variables["get_at_point"] = [&](Point pt) -> EvaluationValue {
-               return convertToUIElement(pt);
-       };
-       variables["assert"] = [&](bool condition) -> EvaluationValue {
-               if (!condition) throw EvaluationFailure{} << "assertion failed";
-               return {};
-       };
+       variables["sleep"] =  EvaluationValueFunction{ [&](double seconds) -> EvaluationValue {
+                       if (seconds > 0)
+                       {
+                               auto sleepTime = std::chrono::milliseconds{ static_cast<int>(std::floor(1000.0 * seconds + 0.5)) };
+                               std::this_thread::sleep_for(sleepTime);
+                       }
+                       return {};
+               },  { {"seconds"} } };
+
+       variables["print"] = EvaluationValueFunction{ [&](std::string text) -> EvaluationValue {
+                       output << text << "\n";
+                       return {};
+               },  { {"text"} } };
+
+       variables["get_at_point"] = EvaluationValueFunction{ [&](Point point) -> EvaluationValue {
+                       return convertToUIElement(point);
+               }, { {"point"} } };
+
+       variables["assert"] = EvaluationValueFunction{ [&](bool condition) -> EvaluationValue {
+                       if (!condition) throw EvaluationFailure{} << "assertion failed";
+                       return {};
+               }, { {"condition"} } };
        variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name, std::vector<int> roles, std::vector<int> states) -> EvaluationValue {
                        auto root = getVisibleRoot();
                        if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";