CXErrorCode Index::ParseSourceFile(const std::string& file, const std::vector<std::string>& arguments, unsigned options, TranslationUnit& translationUnit) const { std::vector<const char*> args; args.reserve(arguments.size()); for (auto& argument : arguments) { args.push_back(argument.c_str()); } CXTranslationUnit tu; auto result = clang_parseTranslationUnit2( index_, file.c_str(), &args[0], (int)args.size(), nullptr, // unsavedFiles 0, // unsavedFilesCount options, &tu ); translationUnit = TranslationUnit(tu); return result; }
/* @ 名称: emit() @ 作用: 生成汇编代码 @ 返回: */ void Compiler::emit(char *output) { // SetUpASMfile(output); BufferSize = 0; TranslationUnit(); }
bool Parser::read() { // Augmented Rule for Grammar _message.print(DBUG, "PARSER: In AugmentedRule()\n"); _lookAhead = getToken(); TranslationUnit(); match(TOK_EOF); return (_message.getErrorCount() == 0); }
void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileContainer) { TranslationUnit::FileExistsCheck checkIfFileExists = fileContainer.hasUnsavedFileContent() ? TranslationUnit::DoNotCheckIfFileExists : TranslationUnit::CheckIfFileExists; auto findIterator = findTranslationUnit(fileContainer); if (findIterator == translationUnits_.end()) translationUnits_.push_back(TranslationUnit(fileContainer.filePath(), unsavedFiles, projects.project(fileContainer.projectPartId()), checkIfFileExists)); }
TEST_F( TranslationUnitTest, ExceptionThrownOnParseFailure ) { fs::path test_file = fs::temp_directory_path() / fs::unique_path(); std::string junk = "#&9112(^(^#>@(^@!@(&#@a}}}}{nthoeu\n&&^^&^&!#%%@@!aeu"; WriteUtf8File( test_file, junk ); std::vector< std::string > flags; flags.push_back( junk ); EXPECT_THROW( TranslationUnit( test_file.string(), std::vector< UnsavedFile >(), flags, NULL ), ClangParseError ); }
TEST_F( TranslationUnitTest, ExceptionThrownOnParseFailure ) { // Create a translation unit for a C++ file that is not saved on disk. std::string filename = PathToTestFile( "unsaved_file.cpp" ).string(); UnsavedFile unsaved_file; unsaved_file.filename_ = filename; try { // libclang requires a valid index to parse a file. TranslationUnit( filename, std::vector< UnsavedFile >{ unsaved_file }, std::vector< std::string >(), nullptr ); FAIL() << "Expected ClangParseError exception."; } catch ( const ClangParseError &error ) { EXPECT_STREQ( error.what(), "Invalid arguments supplied " "when parsing the translation unit." ); } catch ( ... ) { FAIL() << "Expected ClangParseError exception."; } }