bool CodeExecuter::start(QIODevice *device, const QString &filename) { if(!Executer::start(device, filename)) return false; QString code = QString::fromUtf8(device->readAll()); device->close(); mScriptAgent->setContext(LibExecuter::ScriptAgent::ActionInit); LibExecuter::CodeInitializer::initialize(mScriptEngine, mScriptAgent, actionFactory(), filename); Code::CodeTools::addClassToScriptEngine<LibExecuter::CodeStdio>(QStringLiteral("Console"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::print, QStringLiteral("print"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::println, QStringLiteral("println"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::printWarning, QStringLiteral("printWarning"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::printlnWarning, QStringLiteral("printlnWarning"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::printError, QStringLiteral("printError"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::printlnError, QStringLiteral("printlnError"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Console"), &LibExecuter::CodeStdio::clear, QStringLiteral("clear"), mScriptEngine); Code::CodeTools::addClassToScriptEngine<LibExecuter::CodeActiona>(QStringLiteral("Actiona"), mScriptEngine); LibExecuter::CodeActiona::setActExec(true); LibExecuter::CodeActiona::setActionaVersion(Global::ACTIONA_VERSION); LibExecuter::CodeActiona::setScriptVersion(Global::SCRIPT_VERSION); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Actiona"), &LibExecuter::CodeActiona::version, QStringLiteral("version"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Actiona"), &LibExecuter::CodeActiona::scriptVersion, QStringLiteral("scriptVersion"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Actiona"), &LibExecuter::CodeActiona::isActExec, QStringLiteral("isActExec"), mScriptEngine); Code::CodeTools::addClassGlobalFunctionToScriptEngine(QStringLiteral("Actiona"), &LibExecuter::CodeActiona::isActiona, QStringLiteral("isActiona"), mScriptEngine); QString locale = Tools::Languages::locale(); for(int actionPackIndex = 0; actionPackIndex < actionFactory()->actionPackCount(); ++actionPackIndex) { ActionTools::ActionPack *actionPack = actionFactory()->actionPack(actionPackIndex); Tools::Languages::installTranslator(QStringLiteral("actionpack%1").arg(actionPack->id()), locale); } mScriptAgent->setContext(LibExecuter::ScriptAgent::Parameters); QScriptValue result = mScriptEngine->evaluate(code, filename); if(result.isError()) { QTextStream stream(stdout); stream << QObject::tr("Uncaught exception: ") << result.toString() << "\n"; stream << tr("Backtrace: ") << mScriptEngine->uncaughtExceptionBacktrace().join(QStringLiteral("\n")) << "\n"; stream.flush(); } QTimer::singleShot(0, qApp, SLOT(quit())); return true; }
ScriptExecuter::ScriptExecuter(QObject *parent) : Executer(parent), mScript(new ActionTools::Script(actionFactory(), this)), mExecuter(new LibExecuter::Executer(this)) { connect(mExecuter, SIGNAL(executionStopped()), this, SLOT(executionStopped())); connect(mExecuter, SIGNAL(scriptError(int,QString,QString)), this, SLOT(scriptError(int,QString,QString))); }
void runTranslationUnitHandlerOnFile(TranslationUnitHandlerPtr handler, std::string filename) { ClangToolArgsBuilder args; args.setSourceFilename(filename); auto argc = args.getArgc(); auto argv = args.getArgv(); clang::tooling::CommonOptionsParser parser(argc, argv); clang::tooling::ClangTool tool(parser.GetCompilations(), { filename }); // clang bug: parser.GetSourcePathList() uses statics and "adds up" source file names FrontendActionWithTranslationUnitHandlerFactory actionFactory(handler); tool.run(&actionFactory); }
bool ScriptExecuter::start(QIODevice *device, const QString &filename) { if(!Executer::start(device, filename)) return false; ActionTools::Script::ReadResult result = mScript->read(device, Global::SCRIPT_VERSION); switch(result) { case ActionTools::Script::ReadInternal: { QTextStream stream(stdout); stream << QObject::tr("Reading script file failed due to an internal error") << "\n"; stream.flush(); } return false; case ActionTools::Script::ReadInvalidSchema: { QTextStream stream(stdout); stream << QObject::tr("Input script file has an invalid script schema") << "\n"; stream.flush(); } return false; case ActionTools::Script::ReadInvalidScriptVersion: { QTextStream stream(stdout); stream << QObject::tr("Input script file is too recent") << "\n"; stream.flush(); } return false; default: break; } device->close(); mExecuter->setup(mScript, actionFactory(), false, 0, 0, false, 0, 0, mScript->pauseBefore(), mScript->pauseAfter(), Global::ACTIONA_VERSION, Global::SCRIPT_VERSION, true, 0); if(!mExecuter->startExecution(false)) { QTextStream stream(stdout); stream << QObject::tr("Start execution failed") << "\n"; stream.flush(); return false; } return true; }