<commit_before>#include <SCV/SCV.h>
#include "CodeGenerator.h"
#include "Application.h"

#include <cstring>

CodeGenerator::CodeGenerator(void) {
   _scvFrame = NULL;
}

CodeGenerator::~CodeGenerator(void) {
}

std::string CodeGenerator::addChildren(scv::Component *child, std::string dad) {
   std::string code;
   int x, y;
   int type = child->getType();

   if(type == 1) { // Panel
      if(child == static_cast<Application*>(scv::Kernel::getInstance())->_mainPanel)
         return "";
      int count_n = count[child->getType()];
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::Panel *panel" + scv::toString(count_n) + " = new scv::Panel(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "));\n";
      code += "      panel" + scv::toString(count_n) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      if(!child->_children.empty()) {
         for(auto c = child->_children.begin(); c != child->_children.end(); c++) {
            scv::Component *a = *c;
            code += addChildren(a, "panel" + scv::toString(count_n));
         }
      }
      code += "\n";
   } else if(type == 2) { // ColorPicker
      code += "      scv::ColorPicker *colorPicker" + scv::toString(count[child->getType()]) + " = new scv::ColorPicker(scv::Point(" + scv::toString(child->getRelativePosition()) + "));\n";
      code += "      colorPicker" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 3) { // ProgressBar
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::ProgressBar *progressBar" + scv::toString(count[child->getType()]) + " = new scv::ProgressBar(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), " + "0);\n";
      code += "      progressBar" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 4) { // Scroll

   } else if(type == 5) { // Slider
      code += "      scv::Slider *slider" + scv::toString(count[child->getType()]) + " = new scv::Slider(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", 0.f, 100.f, 50.f, 1.f);\n";
      code += "      slider" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 6) { // Spinner
      code += "      scv::Spinner *spinner" + scv::toString(count[child->getType()]) + " = new scv::Spinner(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", 0.f, 100.f, 50.f, 1.f);\n";
      code += "      spineer" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 7) { // Button
      scv::Button *button = (scv::Button*)(child);
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::Button *button" + scv::toString(count[child->getType()]) + " = new scv::Button(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), \"" + scv::toString(button->getString()) + "\");\n";
      code += "      button" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 8) { // CheckBox
      scv::CheckBox *checkBox = (scv::CheckBox*)(child);
      code += "      scv::CheckBox *checkBox" + scv::toString(count[child->getType()]) + " = new scv::CheckBox(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(checkBox->getState()) + ", \"" + scv::toString(checkBox->getString()) + "\");\n";
      code += "      checkBox" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 9) { // RadioButton
      scv::RadioButton *radioButton = (scv::RadioButton*)(child);
      code += "      scv::RadioButton *radioButton" + scv::toString(count[child->getType()]) + " = new scv::RadioButton(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(radioButton->getState()) + ", \"" + scv::toString(radioButton->getString()) + "\");\n";
      code += "      radioButton" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 10) {// ToggleButton
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      scv::ToggleButton *toggleButton = (scv::ToggleButton*)(child);
      code += "      scv::ToggleButton *toggleButton" + scv::toString(count[child->getType()]) + " = new scv::ToggleButton(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), " + scv::toString(toggleButton->getState()) + ", \"" + scv::toString(toggleButton->getString()) + "\");\n";
      code += "      toggleButton" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      code += "\n";
   } else if(type == 11) {// TextField
      scv::TextField *textField = (scv::TextField*)(child);
      code += "      scv::TextField *textField" + scv::toString(count[child->getType()]) + " = new scv::TextField(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", \"" + textField->getString() + "\");\n";
      code += "      textField" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 12) {// TextBox
      scv::TextBox *textBox = (scv::TextBox*)(child);
      x = child->getRelativePosition().x + child->getHeight();
      y = child->getRelativePosition().y + child->getWidth();
      code += "      scv::TextBox *textBox" + scv::toString(count[child->getType()]) + " = new scv::TextBox(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(textBox->getInternalSize()) + "), \"" + textBox->getString() + "\");\n";
      code += "      textBox" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 13) {// Separator
      scv::Separator *separator = (scv::Separator*)(child);
      if(separator->getAlign() == 0)
         code += "      scv::Separator *separator" + scv::toString(count[child->getType()]) + " = new scv::Separator(scv::Point(" + scv::toString(child->getRelativePosition()) + "), (scv::Separator::Orientation)" + scv::toString(separator->getAlign()) + ", " + scv::toString(separator->getWidth()) + ");\n";
      if(separator->getAlign() == 1)
         code += "      scv::Separator *separator" + scv::toString(count[child->getType()]) + " = new scv::Separator(scv::Point(" + scv::toString(child->getRelativePosition()) + "), (scv::Separator::Orientation)" + scv::toString(separator->getAlign()) + ", " + scv::toString(separator->getHeight()) + ");\n";
      code += "      separator" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 14) {// Window
      scv::InternalFrame *internalFrame = (scv::InternalFrame*)(child);
      int count_n = count[child->getType()];
      code += "   scv::InternalFrame *internalFrame" + scv::toString(count[child->getType()]) + " = new scv::InternalFrame(" + scv::toString(child->getWidth()) + ", " + scv::toString(child->getHeight()) + ", \"" + scv::toString(internalFrame->getTitle()) + "\");\n";
      code += "   addComponent(internalFrame" + scv::toString(count[child->getType()]) + ");\n";
      count[child->getType()] += 1;
       if(!child->_children.empty()) {
         auto c = child->_children.begin();
         scv::Component *a = *c;
         count[a->getType()] += 1;
         if(!a->_children.empty()) {
            for(auto f = a->_children.begin(); f != a->_children.end();f++) {
               scv::Component *x = *f;
               code += addChildren(x, "internalFrame"+scv::toString(count_n)+"->getPanel()");<commit_msg>fixed the InternalFrame code generated on the recursive function.<commit_after>#include <SCV/SCV.h>
#include "CodeGenerator.h"
#include "Application.h"

#include <cstring>

CodeGenerator::CodeGenerator(void) {
   _scvFrame = NULL;
}

CodeGenerator::~CodeGenerator(void) {
}

std::string CodeGenerator::addChildren(scv::Component *child, std::string dad) {
   std::string code;
   int x, y;
   int type = child->getType();

   if(type == 1) { // Panel
      if(child == static_cast<Application*>(scv::Kernel::getInstance())->_mainPanel)
         return "";
      int count_n = count[child->getType()];
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::Panel *panel" + scv::toString(count_n) + " = new scv::Panel(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "));\n";
      code += "      panel" + scv::toString(count_n) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      if(!child->_children.empty()) {
         for(auto c = child->_children.begin(); c != child->_children.end(); c++) {
            scv::Component *a = *c;
            code += addChildren(a, "panel" + scv::toString(count_n));
         }
      }
      code += "\n";
   } else if(type == 2) { // ColorPicker
      code += "      scv::ColorPicker *colorPicker" + scv::toString(count[child->getType()]) + " = new scv::ColorPicker(scv::Point(" + scv::toString(child->getRelativePosition()) + "));\n";
      code += "      colorPicker" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 3) { // ProgressBar
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::ProgressBar *progressBar" + scv::toString(count[child->getType()]) + " = new scv::ProgressBar(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), " + "0);\n";
      code += "      progressBar" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 4) { // Scroll

   } else if(type == 5) { // Slider
      code += "      scv::Slider *slider" + scv::toString(count[child->getType()]) + " = new scv::Slider(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", 0.f, 100.f, 50.f, 1.f);\n";
      code += "      slider" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 6) { // Spinner
      code += "      scv::Spinner *spinner" + scv::toString(count[child->getType()]) + " = new scv::Spinner(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", 0.f, 100.f, 50.f, 1.f);\n";
      code += "      spineer" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 7) { // Button
      scv::Button *button = (scv::Button*)(child);
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      code += "      scv::Button *button" + scv::toString(count[child->getType()]) + " = new scv::Button(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), \"" + scv::toString(button->getString()) + "\");\n";
      code += "      button" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 8) { // CheckBox
      scv::CheckBox *checkBox = (scv::CheckBox*)(child);
      code += "      scv::CheckBox *checkBox" + scv::toString(count[child->getType()]) + " = new scv::CheckBox(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(checkBox->getState()) + ", \"" + scv::toString(checkBox->getString()) + "\");\n";
      code += "      checkBox" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 9) { // RadioButton
      scv::RadioButton *radioButton = (scv::RadioButton*)(child);
      code += "      scv::RadioButton *radioButton" + scv::toString(count[child->getType()]) + " = new scv::RadioButton(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(radioButton->getState()) + ", \"" + scv::toString(radioButton->getString()) + "\");\n";
      code += "      radioButton" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 10) {// ToggleButton
      x = child->getRelativePosition().x + child->getWidth();
      y = child->getRelativePosition().y + child->getHeight();
      scv::ToggleButton *toggleButton = (scv::ToggleButton*)(child);
      code += "      scv::ToggleButton *toggleButton" + scv::toString(count[child->getType()]) + " = new scv::ToggleButton(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(x) + ", " + scv::toString(y) + "), " + scv::toString(toggleButton->getState()) + ", \"" + scv::toString(toggleButton->getString()) + "\");\n";
      code += "      toggleButton" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      code += "\n";
   } else if(type == 11) {// TextField
      scv::TextField *textField = (scv::TextField*)(child);
      code += "      scv::TextField *textField" + scv::toString(count[child->getType()]) + " = new scv::TextField(scv::Point(" + scv::toString(child->getRelativePosition()) + "), " + scv::toString(child->getWidth()) + ", \"" + textField->getString() + "\");\n";
      code += "      textField" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 12) {// TextBox
      scv::TextBox *textBox = (scv::TextBox*)(child);
      x = child->getRelativePosition().x + child->getHeight();
      y = child->getRelativePosition().y + child->getWidth();
      code += "      scv::TextBox *textBox" + scv::toString(count[child->getType()]) + " = new scv::TextBox(scv::Point(" + scv::toString(child->getRelativePosition()) + "), scv::Point(" + scv::toString(textBox->getInternalSize()) + "), \"" + textBox->getString() + "\");\n";
      code += "      textBox" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 13) {// Separator
      scv::Separator *separator = (scv::Separator*)(child);
      if(separator->getAlign() == 0)
         code += "      scv::Separator *separator" + scv::toString(count[child->getType()]) + " = new scv::Separator(scv::Point(" + scv::toString(child->getRelativePosition()) + "), (scv::Separator::Orientation)" + scv::toString(separator->getAlign()) + ", " + scv::toString(separator->getWidth()) + ");\n";
      if(separator->getAlign() == 1)
         code += "      scv::Separator *separator" + scv::toString(count[child->getType()]) + " = new scv::Separator(scv::Point(" + scv::toString(child->getRelativePosition()) + "), (scv::Separator::Orientation)" + scv::toString(separator->getAlign()) + ", " + scv::toString(separator->getHeight()) + ");\n";
      code += "      separator" + scv::toString(count[child->getType()]) + "->setParent(" + dad + ");\n";
      count[child->getType()] += 1;
      code += "\n";
   } else if(type == 14) {// Window
      scv::InternalFrame *internalFrame = (scv::InternalFrame*)(child);
      int count_n = count[child->getType()];
      code += "   scv::InternalFrame *internalFrame" + scv::toString(count[child->getType()]) + " = new scv::InternalFrame(" + scv::toString(internalFrame->getInternalSize()) + ", \"" + scv::toString(internalFrame->getTitle()) + "\");\n";
      code += "   addComponent(internalFrame" + scv::toString(count[child->getType()]) + ");\n";
      count[child->getType()] += 1;
       if(!child->_children.empty()) {
         auto c = child->_children.begin();
         scv::Component *a = *c;
         count[a->getType()] += 1;
         if(!a->_children.empty()) {
            for(auto f = a->_children.begin(); f != a->_children.end();f++) {
               scv::Component *x = *f;
               code += addChildren(x, "internalFrame"+scv::toString(count_n)+"->getPanel()");
{'fraction_non_alphanumeric': 0.24268404206675812, 'fraction_numerical': 0.005601280292638317, 'mean_word_length': 3.5972149238045192, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 244, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5443003', 'n_tokens_mistral': 5811, 'n_tokens_neox': 5809, 'n_words': 922}