Integrating latest 47acbe8
This commit is contained in:
@@ -10,19 +10,29 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "Translation.h"
|
||||
|
||||
#include <AzCore/Script/ScriptAsset.h>
|
||||
#include <AzCore/Script/ScriptContext.h>
|
||||
#include <AzCore/Script/lua/lua.h>
|
||||
#include <AzCore/std/string/conversions.h>
|
||||
|
||||
#include <AzFramework/IO/LocalFileIO.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
|
||||
#include <ScriptCanvas/Grammar/PrimitivesDeclarations.h>
|
||||
#include <ScriptCanvas/Grammar/AbstractCodeModel.h>
|
||||
#include <ScriptCanvas/Translation/GraphToCPlusPlus.h>
|
||||
#include <ScriptCanvas/Translation/GraphToLua.h>
|
||||
#include <ScriptCanvas/Core/Graph.h>
|
||||
|
||||
namespace TranslationCPP
|
||||
{
|
||||
using namespace ScriptCanvas;
|
||||
using namespace ScriptCanvas::Translation;
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ToCPlusPlus(const Grammar::AbstractCodeModel& model)
|
||||
/*
|
||||
AZ::Outcome<AZStd::pair<AZStd::string, AZStd::string>, AZStd::pair<AZStd::string, AZStd::string>> ToCPlusPlus(const Grammar::AbstractCodeModel& model, bool rawSave = false)
|
||||
{
|
||||
AZStd::string dotH, dotCPP;
|
||||
|
||||
@@ -35,22 +45,33 @@ namespace TranslationCPP
|
||||
AZ_TracePrintf("ScriptCanvas", "\n\n *** .cpp file *\n\n");
|
||||
AZ_TracePrintf("ScriptCanvas", dotCPP.data());
|
||||
AZ_TracePrintf("ScriptCanvas", "\n\n");
|
||||
#endif
|
||||
outcome = SaveDotH(model.GetSource(), dotH);
|
||||
if (outcome.IsSuccess())
|
||||
#endif
|
||||
if (rawSave)
|
||||
{
|
||||
outcome = SaveDotCPP(model.GetSource(), dotCPP);
|
||||
auto saveOutcome = SaveDotH(model.GetSource(), dotH);
|
||||
if (saveOutcome.IsSuccess())
|
||||
{
|
||||
saveOutcome = SaveDotCPP(model.GetSource(), dotCPP);
|
||||
}
|
||||
|
||||
if (!saveOutcome.IsSuccess())
|
||||
{
|
||||
AZ_TracePrintf("Save failed %s", saveOutcome.GetError().data());
|
||||
}
|
||||
}
|
||||
|
||||
return AZ::Success(AZStd::make_pair(AZStd::move(dotH), AZStd::move(dotCPP)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Failure(outcome.TakeError());
|
||||
}
|
||||
|
||||
return outcome;
|
||||
}
|
||||
*/
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ToLua(const Grammar::AbstractCodeModel& model)
|
||||
AZ::Outcome<TargetResult, ErrorList> ToLua(const Grammar::AbstractCodeModel& model, bool rawSave = false)
|
||||
{
|
||||
AZStd::string lua;
|
||||
|
||||
auto outcome = GraphToLua::Translate(model, lua);
|
||||
auto outcome = GraphToLua::Translate(model);
|
||||
if (outcome.IsSuccess())
|
||||
{
|
||||
#if defined(SCRIPT_CANVAS_PRINT_FILES_CONSOLE)
|
||||
@@ -58,78 +79,111 @@ namespace TranslationCPP
|
||||
AZ_TracePrintf("ScriptCanvas", lua.data());
|
||||
AZ_TracePrintf("ScriptCanvas", "\n\n");
|
||||
#endif
|
||||
outcome = SaveDotLua(model.GetSource(), lua);
|
||||
if (rawSave)
|
||||
{
|
||||
auto saveOutcome = SaveDotLua(model.GetSource(), outcome.GetValue().m_text);
|
||||
if (!saveOutcome.IsSuccess())
|
||||
{
|
||||
AZ_TracePrintf("Save failed %s", saveOutcome.GetError().data());
|
||||
}
|
||||
}
|
||||
|
||||
return AZ::Success(outcome.TakeValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Failure(outcome.TakeError());
|
||||
}
|
||||
|
||||
return outcome;
|
||||
}
|
||||
} // namespace TranslationCPP
|
||||
|
||||
}
|
||||
|
||||
namespace ScriptCanvas
|
||||
{
|
||||
namespace Translation
|
||||
{
|
||||
AZ::Outcome<void, AZStd::string> ToCPlusPlusAndLua(const Graph& graph, const AZStd::string& name, const AZStd::string& path)
|
||||
Result ParseGraph(const Grammar::Request& request)
|
||||
{
|
||||
AZ::Outcome<Grammar::Source, AZStd::string> sourceOutcome = Grammar::Source::Construct(graph, name, path);
|
||||
AZ::Outcome<Grammar::Source, AZStd::string> sourceOutcome = Grammar::Source::Construct(request);
|
||||
|
||||
if (!sourceOutcome.IsSuccess())
|
||||
{
|
||||
return AZ::Failure(sourceOutcome.GetError());
|
||||
return Result(sourceOutcome.TakeError());
|
||||
}
|
||||
|
||||
const Grammar::AbstractCodeModel model(sourceOutcome.GetValue());
|
||||
|
||||
auto outcome = model.GetOutcome();
|
||||
if (outcome.IsSuccess())
|
||||
Grammar::AbstractCodeModelConstPtr model = Grammar::AbstractCodeModel::Parse(sourceOutcome.TakeValue());
|
||||
Translations translations;
|
||||
Errors errors;
|
||||
|
||||
if (model->IsErrorFree())
|
||||
{
|
||||
outcome = TranslationCPP::ToCPlusPlus(model);
|
||||
if (outcome.IsSuccess())
|
||||
if (request.translationTargetFlags & TargetFlags::Lua)
|
||||
{
|
||||
outcome = TranslationCPP::ToLua(model);
|
||||
auto outcomeLua = TranslationCPP::ToLua(*model.get(), request.rawSaveDebugOutput);
|
||||
if (outcomeLua.IsSuccess())
|
||||
{
|
||||
translations.emplace(TargetFlags::Lua, outcomeLua.TakeValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
errors.emplace(TargetFlags::Lua, outcomeLua.TakeError());
|
||||
}
|
||||
}
|
||||
|
||||
// if (targetFlags & (TargetFlags::Cpp | TargetFlags::Hpp))
|
||||
// {
|
||||
// auto outcomeCPP = TranslationCPP::ToCPlusPlus(*model.get(), rawSave);
|
||||
// if (outcomeCPP.IsSuccess())
|
||||
// {
|
||||
// auto hppAndCpp = outcomeCPP.TakeValue();
|
||||
//
|
||||
// TargetResult cppResult;
|
||||
// cppResult.m_text = AZStd::move(hppAndCpp.first);
|
||||
// translations.emplace(TargetFlags::Hpp, AZStd::move(cppResult));
|
||||
// TargetResult hppResult;
|
||||
// hppResult.m_text = AZStd::move(hppAndCpp.second);
|
||||
// translations.emplace(TargetFlags::Cpp, AZStd::move(hppResult));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// auto hppAndCpp = outcomeCPP.TakeError();
|
||||
// errors.emplace(TargetFlags::Hpp, AZStd::move(hppAndCpp.first));
|
||||
// errors.emplace(TargetFlags::Cpp, AZStd::move(hppAndCpp.second));
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResults results;
|
||||
for (auto& test : model->GetValidationEvents())
|
||||
{
|
||||
results.AddValidationEvent(test.get());
|
||||
}
|
||||
}
|
||||
|
||||
return outcome;
|
||||
}
|
||||
return Result(model, AZStd::move(translations), AZStd::move(errors));
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ToCPlusPlus(const Graph& graph, const AZStd::string& name, const AZStd::string& path)
|
||||
Result ToCPlusPlusAndLua(const Grammar::Request& request)
|
||||
{
|
||||
AZ::Outcome<Grammar::Source, AZStd::string> sourceOutcome = Grammar::Source::Construct(graph, name, path);
|
||||
if (!sourceOutcome.IsSuccess())
|
||||
{
|
||||
return AZ::Failure(sourceOutcome.GetError());
|
||||
}
|
||||
|
||||
const Grammar::AbstractCodeModel model(sourceOutcome.GetValue());
|
||||
|
||||
auto outcome = model.GetOutcome();
|
||||
if (outcome.IsSuccess())
|
||||
{
|
||||
outcome = TranslationCPP::ToCPlusPlus(model);
|
||||
}
|
||||
|
||||
return outcome;
|
||||
Grammar::Request toBoth = request;
|
||||
toBoth.translationTargetFlags = TargetFlags::Lua | TargetFlags::Cpp;
|
||||
return ParseGraph(toBoth);
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ToLua(const Graph& graph, const AZStd::string& name, const AZStd::string& path)
|
||||
Result ToCPlusPlus(const Grammar::Request& request)
|
||||
{
|
||||
AZ::Outcome<Grammar::Source, AZStd::string> sourceOutcome = Grammar::Source::Construct(graph, name, path);
|
||||
if (!sourceOutcome.IsSuccess())
|
||||
{
|
||||
return AZ::Failure(sourceOutcome.GetError());
|
||||
}
|
||||
|
||||
const Grammar::AbstractCodeModel model(sourceOutcome.GetValue());
|
||||
|
||||
auto outcome = model.GetOutcome();
|
||||
if (outcome.IsSuccess())
|
||||
{
|
||||
outcome = TranslationCPP::ToLua(model);
|
||||
}
|
||||
|
||||
return outcome;
|
||||
Grammar::Request toCpp = request;
|
||||
toCpp.translationTargetFlags = TargetFlags::Cpp;
|
||||
return ParseGraph(toCpp);
|
||||
}
|
||||
|
||||
} // namespace Translation
|
||||
} // namespace ScriptCanvas
|
||||
Result ToLua(const Grammar::Request& request)
|
||||
{
|
||||
Grammar::Request toLua = request;
|
||||
toLua.translationTargetFlags = TargetFlags::Lua;
|
||||
return ParseGraph(toLua);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user