本文整理汇总了C++中Lexer::files方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexer::files方法的具体用法?C++ Lexer::files怎么用?C++ Lexer::files使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer::files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
/*QSettings test("test.ini", QSettings::IniFormat);
test.beginGroup("compiler");
test.setValue("test-value", "asd");
test.setValue("other-value", "val");
test.endGroup();
test.beginGroup("opt");
test.setValue("test-value2", "asd2");
test.setValue("other-value2", "val2");
test.endGroup();
test.sync();
return 0;*/
QTime bigTimer;
bigTimer.start();
QStringList params = a.arguments();
if (params.size() != 2) {
qCritical() << "Expecting file to compile";
return 0;
}
ErrorHandler errHandler;
Settings settings;
bool success = false;
success = settings.loadDefaults();
if (!success) {
errHandler.error(ErrorCodes::ecSettingsLoadingFailed, errHandler.tr("Loading the default settings \"%1\" failed").arg(settings.loadPath()), CodePoint());
return ErrorCodes::ecSettingsLoadingFailed;
}
Lexer lexer;
QObject::connect(&lexer, &Lexer::error, &errHandler, &ErrorHandler::error);
QObject::connect(&lexer, &Lexer::warning, &errHandler, &ErrorHandler::warning);
QTime timer;
timer.start();
if (lexer.tokenizeFile(params[1], settings) == Lexer::Success) {
qDebug() << "Lexical analysing took " << timer.elapsed() << "ms";
#ifdef DEBUG_OUTPUT
lexer.writeTokensToFile("tokens.txt");
#endif
}
else {
errHandler.error(ErrorCodes::ecLexicalAnalysingFailed, errHandler.tr("Lexical analysing failed"), CodePoint(lexer.files().first().first));
return ErrorCodes::ecLexicalAnalysingFailed;
}
Parser parser;
QObject::connect(&parser, &Parser::error, &errHandler, &ErrorHandler::error);
QObject::connect(&parser, &Parser::warning, &errHandler, &ErrorHandler::warning);
timer.start();
ast::Program *program = parser.parse(lexer.tokens(), settings);
qDebug() << "Parsing took " << timer.elapsed() << "ms";
if (!parser.success()) {
errHandler.error(ErrorCodes::ecParsingFailed, errHandler.tr("Parsing failed \"%1\"").arg(params[1]), CodePoint());
return ErrorCodes::ecParsingFailed;
}
#ifdef DEBUG_OUTPUT
if (program) {
QFile file("ast.txt");
if (file.open(QFile::WriteOnly)) {
QTextStream stream(&file);
program->write(stream);
file.close();
}
}
#endif
CodeGenerator codeGenerator;
//QObject::connect(&codeGenerator, &CodeGenerator::error, &errHandler, &ErrorHandler::error);
//QObject::connect(&codeGenerator, &CodeGenerator::warning, &errHandler, &ErrorHandler::warning);
QObject::connect(&codeGenerator, &CodeGenerator::error, &errHandler, &ErrorHandler::error);
QObject::connect(&codeGenerator, &CodeGenerator::warning, &errHandler, &ErrorHandler::warning);
timer.start();
if (!codeGenerator.initialize(settings)) {
return ErrorCodes::ecCodeGeneratorInitializationFailed;
}
qDebug() << "Code generator initialization took " << timer.elapsed() << "ms";
timer.start();
if (!codeGenerator.generate(program)) {
errHandler.error(ErrorCodes::ecCodeGenerationFailed, errHandler.tr("Code generation failed"), CodePoint());
return ErrorCodes::ecCodeGenerationFailed;
}
qDebug() << "Code generation took" << timer.elapsed() << "ms";
qDebug() << "LLVM-IR generated";
timer.start();
//.........这里部分代码省略.........