]> granicus.if.org Git - icinga2/commitdiff
Remove the C++ code generator
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 22 Nov 2014 18:23:42 +0000 (19:23 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 22 Nov 2014 18:24:13 +0000 (19:24 +0100)
refs #7699

lib/cli/CMakeLists.txt
lib/cli/codegencommand.cpp [deleted file]
lib/cli/codegencommand.hpp [deleted file]
lib/config/CMakeLists.txt
lib/config/expression-codegen.cpp [deleted file]
lib/config/expression.hpp

index 8590d36072fdc070f65bc418c43e2c4e84f44629..121effb76d2186e99d72c4e7034120e8ba3c3b05 100644 (file)
@@ -16,7 +16,6 @@
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 set(cli_SOURCES
-  codegencommand.cpp
   nodeaddcommand.cpp nodeblackandwhitelistcommand.cpp nodelistcommand.cpp noderemovecommand.cpp
   nodesetcommand.cpp nodesetupcommand.cpp nodeupdateconfigcommand.cpp nodewizardcommand.cpp nodeutility.cpp
   clicommand.cpp
diff --git a/lib/cli/codegencommand.cpp b/lib/cli/codegencommand.cpp
deleted file mode 100644 (file)
index 57c3587..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2014 Icinga Development Team (http://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 "cli/codegencommand.hpp"
-#include "config/expression.hpp"
-#include "config/configcompiler.hpp"
-#include "config/configcompilercontext.hpp"
-#include "base/logger.hpp"
-
-using namespace icinga;
-
-REGISTER_CLICOMMAND("codegen", CodeGenCommand);
-
-String CodeGenCommand::GetDescription(void) const
-{
-       return "Generates native code for an Icinga 2 config file.";
-}
-
-String CodeGenCommand::GetShortDescription(void) const
-{
-       return "compiles an Icinga 2 config file";
-}
-
-void CodeGenCommand::InitParameters(boost::program_options::options_description& visibleDesc,
-       boost::program_options::options_description& hiddenDesc) const
-{
-}
-
-bool CodeGenCommand::IsHidden(void) const
-{
-       return true;
-}
-
-/**
- * The entry point for the "codegen" CLI command.
- *
- * @returns An exit status.
- */
-int CodeGenCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
-{
-       Logger::SetConsoleLogSeverity(LogWarning);
-
-       Expression *expr = ConfigCompiler::CompileStream("<stdin>", &std::cin);
-
-       int errors = 0;
-
-       BOOST_FOREACH(const ConfigCompilerMessage& message, ConfigCompilerContext::GetInstance()->GetMessages()) {
-               String logmsg = String("Config ") + (message.Error ? "error" : "warning") + ": " + message.Text;
-
-               if (message.Error) {
-                       Log(LogCritical, "config", logmsg);
-                       errors++;
-               } else {
-                       Log(LogWarning, "config", logmsg);
-               }
-       }
-
-       if (errors > 0)
-               return 1;
-
-       std::cout << "#include \"config/expression.hpp\"" << "\n"
-                 << "#include \"config/vmops.hpp\"" << "\n"
-                 << "#include \"base/json.hpp\"" << "\n"
-                 << "#include \"base/initialize.hpp\"" << "\n"
-                 << "#include <boost/smart_ptr/make_shared.hpp>" << "\n"
-                 << "\n"
-                 << "using namespace icinga;" << "\n"
-                 << "\n";
-
-       std::map<String, String> definitions;
-
-       String name = CodeGenExpression(definitions, expr);
-
-       BOOST_FOREACH(const DefinitionMap::value_type& kv, definitions) {
-               std::cout << "static Value " << kv.first << "(const Object::Ptr& context);" << "\n";
-       }
-
-       std::cout << "\n"
-                 << "static Dictionary::Ptr l_ModuleScope = new Dictionary();" << "\n"
-                 << "\n"
-                 << "static void RunCode(void)" << "\n"
-                 << "{" << "\n"
-                 << "  " << name << "(l_ModuleScope);" << "\n"
-                 << "}" << "\n"
-                 << "\n"
-                 << "INITIALIZE_ONCE(RunCode);" << "\n"
-                 << "\n"
-                 << "int main(int argc, char **argv)" << "\n"
-                 << "{" << "\n"
-                 << "  RunCode();" << "\n"
-                 << "  if (l_ModuleScope->Contains(\"__result\"))" << "\n"
-                 << "    std::cout << \"Result: \" << JsonEncode(l_ModuleScope->Get(\"__result\")) << \"\\n\";" << "\n"
-                 << "  else" << "\n"
-                 << "    std::cout << \"No result.\" << \"\\n\";" << "\n"
-                 << "}" << "\n"
-                 << "\n";
-
-       BOOST_FOREACH(const DefinitionMap::value_type& kv, definitions) {
-               std::cout << kv.second << "\n";
-       }
-
-       delete expr;
-
-       return 0;
-}
diff --git a/lib/cli/codegencommand.hpp b/lib/cli/codegencommand.hpp
deleted file mode 100644 (file)
index 813c393..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2014 Icinga Development Team (http://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.             *
- ******************************************************************************/
-
-#ifndef CODEGENCOMMAND_H
-#define CODEGENCOMMAND_H
-
-#include "base/dictionary.hpp"
-#include "base/array.hpp"
-#include "cli/clicommand.hpp"
-#include <ostream>
-
-namespace icinga
-{
-
-/**
- * The "variable get" command.
- *
- * @ingroup cli
- */
-class CodeGenCommand : public CLICommand
-{
-public:
-       DECLARE_PTR_TYPEDEFS(CodeGenCommand);
-
-       virtual String GetDescription(void) const;
-       virtual String GetShortDescription(void) const;
-       virtual bool IsHidden(void) const;
-       void InitParameters(boost::program_options::options_description& visibleDesc,
-           boost::program_options::options_description& hiddenDesc) const;
-       virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const;
-};
-
-}
-
-#endif /* CODEGENCOMMAND_H */
index b09aaf848714592b59b687e166db21ba83dc1796..596c70ccc10529c2fa3c94b0198547b3c46f3dc2 100644 (file)
@@ -34,7 +34,7 @@ set(config_SOURCES
   applyrule.cpp base-type.conf base-type.cpp
   configcompilercontext.cpp configcompiler.cpp configitembuilder.cpp
   configitem.cpp ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS}
-  configtype.cpp expression.cpp expression-codegen.cpp objectrule.cpp typerule.cpp typerulelist.cpp
+  configtype.cpp expression.cpp objectrule.cpp typerule.cpp typerulelist.cpp
 )
 
 if(ICINGA2_UNITY_BUILD)
diff --git a/lib/config/expression-codegen.cpp b/lib/config/expression-codegen.cpp
deleted file mode 100644 (file)
index d21d5be..0000000
+++ /dev/null
@@ -1,563 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2014 Icinga Development Team (http://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 "config/expression.hpp"
-#include "config/vmops.hpp"
-#include "base/object.hpp"
-#include <boost/foreach.hpp>
-
-using namespace icinga;
-
-void LiteralExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       if (m_Value.IsString())
-               fp << "String(\"" << m_Value << "\")";
-       else if (m_Value.IsNumber())
-               fp << m_Value;
-       else if (m_Value.IsEmpty())
-               fp << "Value()";
-       else
-               throw std::invalid_argument("Literal expression has invalid type: " + m_Value.GetTypeName());
-}
-
-void VariableExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "VMOps::Variable(context, \"" << m_Variable << "\")";
-}
-
-void NegateExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "~(long)(";
-       m_Operand->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void LogicalNegateExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "!(";
-       m_Operand->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void AddExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") + (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void SubtractExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") - (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void MultiplyExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") * (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void DivideExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") / (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void BinaryAndExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") & (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void BinaryOrExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") | (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void ShiftLeftExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") << (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void ShiftRightExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") >> (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void EqualExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") == (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void NotEqualExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") != (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void LessThanExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") < (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void GreaterThanExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") > (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void LessThanOrEqualExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") <= (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void GreaterThanOrEqualExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ") >= (";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void InExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "!static_cast<Array::Ptr>(";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")->Contains(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void NotInExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "!static_cast<Array::Ptr>(";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ")->Contains(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void LogicalAndExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "Value(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ").ToBool() && Value(";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ").ToBool()";
-}
-
-void LogicalOrExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "Value(";
-       m_Operand1->GenerateCode(definitions, fp);
-       fp << ").ToBool() || Value(";
-       m_Operand2->GenerateCode(definitions, fp);
-       fp << ").ToBool()";
-}
-
-void FunctionCallExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_fcall_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  Value funcName = (";
-       m_FName->GenerateCode(definitions, df);
-       df << ");" << "\n"
-          << "  std::vector<Value> args;" << "\n";
-
-       BOOST_FOREACH(Expression *expr, m_Args) {
-               df << "  args.push_back(";
-               expr->GenerateCode(definitions, df);
-               df << ");" << "\n";
-       }
-
-       df << "  return VMOps::FunctionCall(context, funcName, args);" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void ArrayExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_array_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  Array::Ptr result = new Array();" << "\n";
-
-       BOOST_FOREACH(Expression *aexpr, m_Expressions) {
-               df << "  result->Add(";
-               aexpr->GenerateCode(definitions, df);
-               df << ");" << "\n";
-       }
-
-       df << "  return result;" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void DictExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_dict_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& ucontext)" << "\n"
-          << "{" << "\n";
-
-       if (!m_Inline) {
-               df << "  Dictionary::Ptr result = new Dictionary();" << "\n"
-                  << "  result->Set(\"__parent\", ucontext);" << "\n"
-                  << "  Object::Ptr context = result;" << "\n";
-       } else
-               df << "  Object::Ptr context = ucontext;" << "\n";
-
-       df << "  do {" << "\n";
-
-       BOOST_FOREACH(Expression *expression, m_Expressions) {
-               df << "    ";
-               expression->GenerateCode(definitions, df);
-               df << ";" << "\n"
-                  << "    if (VMOps::HasField(context, \"__result\"))" << "\n"
-                  << "      break;" << "\n";
-       }
-
-       df << "  } while (0);" << "\n"
-          << "\n";
-
-       if (!m_Inline) {
-               df << "  Dictionary::Ptr xresult = result->ShallowClone();" << "\n"
-                  << "  xresult->Remove(\"__parent\");" << "\n"
-                  << "  return xresult;" << "\n";
-       } else
-               df << "  return Empty;" << "\n";
-
-       df << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void SetExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_set_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  Value parent, object;" << "\n"
-          << "  String tempindex, index;" << "\n";
-
-       for (Array::SizeType i = 0; i < m_Indexer.size(); i++) {
-               Expression *indexExpr = m_Indexer[i];
-               df << "  tempindex = (";
-               indexExpr->GenerateCode(definitions, df);
-               df << ");" << "\n";
-
-               if (i == 0)
-                       df << "  parent = context;" << "\n";
-               else
-                       df << "  parent = object;" << "\n";
-
-               if (i == m_Indexer.size() - 1) {
-                       df << "  index = tempindex" << ";" << "\n";
-
-                       /* No need to look up the last indexer's value if this is a direct set */
-                       if (m_Op == OpSetLiteral)
-                               break;
-               }
-
-               df << "  object = VMOps::Indexer(context, parent, tempindex);" << "\n";
-
-               if (i != m_Indexer.size() - 1) {
-                       df << "  if (object.IsEmpty()) {" << "\n"
-                          << "    object = new Dictionary();" << "\n"
-                          << "    VMOps::SetField(parent, tempindex, object);" << "\n"
-                          << "  }" << "\n";
-               }
-       }
-
-       df << "  Value right = (";
-       m_Operand2->GenerateCode(definitions, df);
-       df << ");" << "\n";
-
-       if (m_Op != OpSetLiteral) {
-               String opcode;
-
-               switch (m_Op) {
-                       case OpSetAdd:
-                               opcode = "+";
-                               break;
-                       case OpSetSubtract:
-                               opcode = "-";
-                               break;
-                       case OpSetMultiply:
-                               opcode = "*";
-                               break;
-                       case OpSetDivide:
-                               opcode = "/";
-                               break;
-                       default:
-                               VERIFY(!"Invalid opcode.");
-               }
-
-               df << "  right = object " << opcode << " right;" << "\n";
-       }
-
-       df << "  VMOps::SetField(parent, index, right);" << "\n"
-          << "  return right;" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void IndexerExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_indexer_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  return VMOps::Indexer(context, (";
-       m_Operand1->GenerateCode(definitions, df);
-       df << "), (";
-       m_Operand2->GenerateCode(definitions, df);
-       df << "));" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void ImportExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_import_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  String name = (";
-       m_Name->GenerateCode(definitions, df);
-       df << ");" << "\n"
-          << "  String type = VMOps::GetField(context, \"type\");" << "\n"
-          << "\n"
-          << "  ConfigItem::Ptr item = ConfigItem::GetObject(type, name);" << "\n"
-          << "\n"
-          << "  if (!item)" << "\n"
-          << "    BOOST_THROW_EXCEPTION(ConfigError(\"Import references unknown template: '\" + name + \"' of type '\" + type + \"'\"));" << "\n"
-          << "\n"
-          << "  item->GetExpression()->Evaluate(context);" << "\n"
-          << "\n"
-          << "  return Empty;" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void FunctionExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_function_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  std::vector<String> args;" << "\n";
-
-       BOOST_FOREACH(const String& arg, m_Args)
-               df << "  args.push_back(\"" << arg << "\");" << "\n";
-
-       df << "  return VMOps::NewFunction(context, \"" << m_Name << "\", args, boost::make_shared<NativeExpression>("
-          << CodeGenExpression(definitions, m_Expression.get()) << "));" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void SlotExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       fp << "VMOps::NewSlot(context, \"" << m_Signal << "\", ";
-       m_Slot->GenerateCode(definitions, fp);
-       fp << ")";
-}
-
-void ApplyExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_apply_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  boost::shared_ptr<Expression> fterm;" << "\n";
-
-       if (m_FTerm)
-               df << "  fterm = boost::make_shared<NativeExpression>(" << CodeGenExpression(definitions, m_FTerm.get()) << ");" << "\n";
-
-       df << "  boost::shared_ptr<Expression> filter = boost::make_shared<NativeExpression>(" << CodeGenExpression(definitions, m_Filter.get()) << ");" << "\n"
-          << "  boost::shared_ptr<Expression> expression = boost::make_shared<NativeExpression>(" << CodeGenExpression(definitions, m_Expression.get()) << ");" << "\n"
-          << "  return VMOps::NewApply(context, \"" << m_Type << "\", \"" << m_Target << "\", (";
-       m_Name->GenerateCode(definitions, df);
-       df << "), filter, "
-          << "\"" << m_FKVar << "\", \"" << m_FVVar << "\", fterm, expression);" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void ObjectExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_object_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  String name;" << "\n";
-
-       if (m_Name) {
-               df << "  name = (";
-               m_Name->GenerateCode(definitions, df);
-               df << ");" << "\n";
-       }
-
-       df << "  boost::shared_ptr<Expression> filter;" << "\n";
-
-       if (m_Filter)
-               df << "  filter = boost::make_shared<NativeExpression>("
-                  << CodeGenExpression(definitions, m_Filter.get()) << ");" << "\n";
-
-       df << "  boost::shared_ptr<Expression> expression = boost::make_shared<NativeExpression>("
-          << CodeGenExpression(definitions, m_Expression.get()) << ");" << "\n"
-          << "  return VMOps::NewObject(context, " << m_Abstract << ", \"" << m_Type << "\", name, filter, \"" << m_Zone << "\", expression);" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-void ForExpression::GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-{
-       std::ostringstream namebuf, df;
-
-       namebuf << "native_for_" << reinterpret_cast<uintptr_t>(this);
-
-       df << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-          << "{" << "\n"
-          << "  static NativeExpression expression("
-          << CodeGenExpression(definitions, m_Expression) << ");" << "\n"
-          << "  return VMOps::For(context, \"" << m_FKVar << "\", \"" << m_FVVar << "\", (";
-       m_Value->GenerateCode(definitions, df);
-       df << "), &expression);" << "\n"
-          << "}" << "\n";
-
-       definitions[namebuf.str()] = df.str();
-
-       fp << namebuf.str() << "(context)";
-}
-
-String icinga::CodeGenExpression(DefinitionMap& definitions, Expression *expression)
-{
-       std::ostringstream namebuf, definitionbuf;
-
-       namebuf << "native_expression_" << reinterpret_cast<uintptr_t>(expression);
-
-       definitionbuf << "static Value " << namebuf.str() << "(const Object::Ptr& context)" << "\n"
-                     << "{" << "\n"
-                     << "  return (";
-
-       expression->GenerateCode(definitions, definitionbuf);
-
-       definitionbuf << ");" << "\n"
-                     << "}" << "\n";
-
-       definitions[namebuf.str()] = definitionbuf.str();
-
-       return namebuf.str();
-}
index 4c67fb82b1e699ee07236875c34e08da0be63d3a..23ac200ff75f26144a7684731cad4fc253b26b55 100644 (file)
@@ -114,7 +114,6 @@ public:
        Value Evaluate(VMFrame& frame, DebugHint *dhint = NULL) const;
 
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const = 0;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fp) const = 0;
        virtual const DebugInfo& GetDebugInfo(void) const;
 };
 
@@ -133,11 +132,6 @@ protected:
                return m_Expression->DoEvaluate(frame, dhint);
        }
 
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-       {
-               return m_Expression->GenerateCode(definitions, fp);
-       }
-
        virtual const DebugInfo& GetDebugInfo(void) const
        {
                return m_Expression->GetDebugInfo();
@@ -147,30 +141,6 @@ private:
        boost::shared_ptr<Expression> m_Expression;
 };
 
-class I2_CONFIG_API NativeExpression : public Expression
-{
-public:
-       typedef Value (*Callback)(VMFrame& frame);
-
-       NativeExpression(Callback callback)
-               : m_Callback(callback)
-       { }
-
-protected:
-       virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const
-       {
-               return m_Callback(frame);
-       }
-
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fp) const
-       {
-               throw std::runtime_error("Native expression does not support codegen.");
-       }
-
-private:
-       Callback m_Callback;
-};
-
 class I2_CONFIG_API LiteralExpression : public Expression
 {
 public:
@@ -178,7 +148,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fp) const;
 
 private:
        Value m_Value;
@@ -246,7 +215,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        String m_Variable;
@@ -261,7 +229,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API LogicalNegateExpression : public UnaryExpression
@@ -273,7 +240,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
 
 class I2_CONFIG_API AddExpression : public BinaryExpression
@@ -285,7 +251,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API SubtractExpression : public BinaryExpression
@@ -297,7 +262,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API MultiplyExpression : public BinaryExpression
@@ -309,7 +273,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API DivideExpression : public BinaryExpression
@@ -321,7 +284,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API BinaryAndExpression : public BinaryExpression
@@ -333,7 +295,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API BinaryOrExpression : public BinaryExpression
@@ -345,7 +306,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API ShiftLeftExpression : public BinaryExpression
@@ -357,7 +317,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API ShiftRightExpression : public BinaryExpression
@@ -369,7 +328,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API EqualExpression : public BinaryExpression
@@ -381,7 +339,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API NotEqualExpression : public BinaryExpression
@@ -393,7 +350,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API LessThanExpression : public BinaryExpression
@@ -405,7 +361,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API GreaterThanExpression : public BinaryExpression
@@ -417,7 +372,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API LessThanOrEqualExpression : public BinaryExpression
@@ -429,7 +383,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API GreaterThanOrEqualExpression : public BinaryExpression
@@ -441,7 +394,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API InExpression : public BinaryExpression
@@ -453,7 +405,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API NotInExpression : public BinaryExpression
@@ -465,7 +416,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API LogicalAndExpression : public BinaryExpression
@@ -477,7 +427,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API LogicalOrExpression : public BinaryExpression
@@ -489,7 +438,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
        
 class I2_CONFIG_API FunctionCallExpression : public DebuggableExpression
@@ -509,7 +457,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 public:
        Expression *m_FName;
@@ -531,7 +478,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        std::vector<Expression *> m_Expressions;
@@ -554,7 +500,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        std::vector<Expression *> m_Expressions;
@@ -578,7 +523,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        CombinedSetOp m_Op;
@@ -597,7 +541,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 };
 
 class I2_CONFIG_API ImportExpression : public DebuggableExpression
@@ -614,14 +557,11 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        Expression *m_Name;
 };
 
-I2_CONFIG_API String CodeGenExpression(DefinitionMap& definitions, Expression *expression);
-
 class I2_CONFIG_API FunctionExpression : public DebuggableExpression
 {
 public:
@@ -632,7 +572,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        String m_Name;
@@ -650,7 +589,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        String m_Signal;
@@ -676,7 +614,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        String m_Type;
@@ -707,7 +644,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        bool m_Abstract;
@@ -734,7 +670,6 @@ public:
 
 protected:
        virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
-       virtual void GenerateCode(DefinitionMap& definitions, std::ostream& fpg) const;
 
 private:
        String m_FKVar;