Exemplo n.º 1
0
bool InstructionSelectorDialog::MatchSearchCriteria(gd::String search, const gd::InstructionMetadata & instrMetadata)
{
    if (search.empty()) return true;

    return instrMetadata.GetGroup().FindCaseInsensitive(search) != string::npos ||
        instrMetadata.GetFullName().FindCaseInsensitive(search) != string::npos;
}
Exemplo n.º 2
0
gd::String EventsCodeGenerator::GenerateBehaviorAction(
    const gd::String& objectName,
    const gd::String& behaviorName,
    const gd::BehaviorMetadata& autoInfo,
    const std::vector<gd::String>& arguments,
    const gd::InstructionMetadata& instrInfos,
    gd::EventsCodeGenerationContext& context) {
  gd::String actionCode;

  // Prepare call
  // Add a static_cast if necessary
  gd::String objectPart =
      (!instrInfos.parameters[1].supplementaryInformation.empty())
          ? "static_cast<" + autoInfo.className + "*>(" +
                ManObjListName(objectName) + "[i]->GetBehaviorRawPointer(" +
                GenerateGetBehaviorNameCode(behaviorName) + "))->"
          : ManObjListName(objectName) + "[i]->GetBehaviorRawPointer(" +
                GenerateGetBehaviorNameCode(behaviorName) + ")->";

  // Create call
  gd::String call;
  if ((instrInfos.codeExtraInformation.type == "number" ||
       instrInfos.codeExtraInformation.type == "string")) {
    if (instrInfos.codeExtraInformation.accessType ==
        gd::InstructionMetadata::ExtraInformation::MutatorAndOrAccessor)
      call = GenerateOperatorCall(
          instrInfos,
          arguments,
          objectPart + instrInfos.codeExtraInformation.functionCallName,
          objectPart +
              instrInfos.codeExtraInformation.optionalAssociatedInstruction,
          2);
    else if (instrInfos.codeExtraInformation.accessType ==
             gd::InstructionMetadata::ExtraInformation::Mutators)
      call = GenerateMutatorCall(
          instrInfos,
          arguments,
          objectPart + instrInfos.codeExtraInformation.functionCallName,
          2);
    else
      call = GenerateCompoundOperatorCall(
          instrInfos,
          arguments,
          objectPart + instrInfos.codeExtraInformation.functionCallName,
          2);
  } else {
    call = objectPart + instrInfos.codeExtraInformation.functionCallName + "(" +
           GenerateArgumentsList(arguments, 2) + ")";
  }

  // Verify that object has behavior.
  vector<gd::String> behaviors = gd::GetBehaviorsOfObject(
      GetGlobalObjectsAndGroups(), GetObjectsAndGroups(), objectName);
  if (find(behaviors.begin(), behaviors.end(), behaviorName) ==
      behaviors.end()) {
    cout << "Error: bad behavior \"" << behaviorName
         << "\" requested for object \'" << objectName
         << "\" (action: " << instrInfos.GetFullName() << ")." << endl;
  } else {
    actionCode += "for(std::size_t i = 0;i < " + ManObjListName(objectName) +
                  ".size();++i)\n";
    actionCode += "{\n";
    actionCode += "    " + call + ";\n";
    actionCode += "}\n";
  }

  return actionCode;
}
Exemplo n.º 3
0
gd::String EventsCodeGenerator::GenerateBehaviorCondition(
    const gd::String& objectName,
    const gd::String& behaviorName,
    const gd::BehaviorMetadata& autoInfo,
    const std::vector<gd::String>& arguments,
    const gd::InstructionMetadata& instrInfos,
    const gd::String& returnBoolean,
    bool conditionInverted,
    gd::EventsCodeGenerationContext& context) {
  gd::String conditionCode;

  // Prepare call
  // Add a static_cast if necessary
  gd::String objectFunctionCallNamePart =
      (!instrInfos.parameters[1].supplementaryInformation.empty())
          ? "static_cast<" + autoInfo.className + "*>(" +
                ManObjListName(objectName) + "[i]->GetBehaviorRawPointer(" +
                GenerateGetBehaviorNameCode(behaviorName) + "))->" +
                instrInfos.codeExtraInformation.functionCallName
          : ManObjListName(objectName) + "[i]->GetBehaviorRawPointer(" +
                GenerateGetBehaviorNameCode(behaviorName) + ")->" +
                instrInfos.codeExtraInformation.functionCallName;

  // Create call
  gd::String predicat;
  if ((instrInfos.codeExtraInformation.type == "number" ||
       instrInfos.codeExtraInformation.type == "string")) {
    predicat = GenerateRelationalOperatorCall(
        instrInfos, arguments, objectFunctionCallNamePart, 2);
  } else {
    predicat = objectFunctionCallNamePart + "(" +
               GenerateArgumentsList(arguments, 2) + ")";
  }
  if (conditionInverted) predicat = GenerateNegatedPredicat(predicat);

  // Verify that object has behavior.
  vector<gd::String> behaviors = gd::GetBehaviorsOfObject(
      GetGlobalObjectsAndGroups(), GetObjectsAndGroups(), objectName);
  if (find(behaviors.begin(), behaviors.end(), behaviorName) ==
      behaviors.end()) {
    cout << "Error: bad behavior \"" << behaviorName
         << "\" requested for object \'" << objectName
         << "\" (condition: " << instrInfos.GetFullName() << ")." << endl;
  } else {
    conditionCode += "for(std::size_t i = 0;i < " + ManObjListName(objectName) +
                     ".size();)\n";
    conditionCode += "{\n";
    conditionCode += "    if ( " + predicat + " )\n";
    conditionCode += "    {\n";
    conditionCode += "        " + returnBoolean + " = true;\n";
    conditionCode += "        ++i;\n";
    conditionCode += "    }\n";
    conditionCode += "    else\n";
    conditionCode += "    {\n";
    conditionCode += "        " + ManObjListName(objectName) + ".erase(" +
                     ManObjListName(objectName) + ".begin()+i);\n";
    conditionCode += "    }\n";
    conditionCode += "}";
  }

  return conditionCode;
}