int main(int argc, char *arg[]) { int port = atoi(arg[1]); std::string fileSystemPrefix = std::string(arg[2]); Logger logger("Application"); std::shared_ptr< ClientsMap<int, ClientManager *> > clients = std::make_shared< ClientsMap<int, ClientManager *> >("Clients"); FileManager fileManager(fileSystemPrefix); PlaylistManager playlistManager(fileSystemPrefix); Dispatcher *dispatcher = new Dispatcher(fileManager, playlistManager, clients); std::thread dispatcherThread = std::thread(&Dispatcher::start, dispatcher); logger.log("Dispatcher has been created"); ConnectionManager connectionManager(dispatcher, port, clients); std::thread connectionManagerThread = std::thread(&ConnectionManager::start, &connectionManager); logger.log("ConnectionManager has been created"); SoundProcessor soundProcessor(fileManager, playlistManager, clients); std::thread soundProcessorThread = std::thread(&SoundProcessor::stream, &soundProcessor); logger.log("SoundProcessor has been created"); connectionManagerThread.join(); dispatcherThread.join(); soundProcessorThread.join(); delete dispatcher; logger.log("Has been closed"); return 0; }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), &diagnosticOptions, true); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; //clang::DiagnosticIDs diagIDs; clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, &diagnosticOptions, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); std::shared_ptr<clang::TargetOptions> targetOptions = std::make_shared<clang::TargetOptions>(); // clang::TargetOptions targetOptions; targetOptions->Triple = llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, targetOptions); llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> hso; clang::HeaderSearch headerSearch(hso, sourceManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); clang::CompilerInstance compInst; llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> pOpts; clang::Preprocessor preprocessor( pOpts, *pDiagnosticsEngine, languageOptions, sourceManager, headerSearch, compInst ); return 0; }
HomeWidget::HomeWidget(Device *device, QWidget *parent) : StandardWidget(device, parent), ui(new Ui::HomeWidget) { ui->setupUi(this); performStandardSetup(UiStandards::homeString()); connect(ui->programs, SIGNAL(clicked()), SLOT(programs())); connect(ui->fileManager, SIGNAL(clicked()), SLOT(fileManager())); connect(ui->motorsSensors, SIGNAL(clicked()), SLOT(motorsSensors())); connect(ui->settings, SIGNAL(clicked()), SLOT(settings())); // QAction *lock = menuBar()->addAction(UiStandards::lockString()); // connect(lock, SIGNAL(triggered()), SLOT(lock())); QAction *about = menuBar()->addAction(tr("About")); connect(about, SIGNAL(triggered()), SLOT(about())); }
/* * Arguments : void * Return Type : double */ static double g_fprintf(void) { int nbytesint; FILE * b_NULL; boolean_T autoflush; FILE * filestar; static const char cfmt[9] = { '\x0a', '\x0a', 'd', 'o', 'n', 'e', '!', '\x0a', '\x00' }; nbytesint = 0; b_NULL = NULL; fileManager(&filestar, &autoflush); if (filestar == b_NULL) { } else { nbytesint = fprintf(filestar, cfmt); fflush(filestar); } return nbytesint; }
int compressFile(const std::string& inputPath, const std::string& outputPath) { char currentChar; char lastChar; unsigned char frequency = 1; bool first = true; std::ifstream file; BitFileManager fileManager(BitFileManager::Mode::Write, outputPath); file.open(inputPath, std::ios_base::binary); addHeader(fileManager.getOStream()); file.get(lastChar); auto writeData = [&]() { fileManager.write(bool(frequency > 1)); if (frequency > 1) fileManager.write(frequency); fileManager.write(static_cast<unsigned char>(lastChar)); }; while (file.get(currentChar)) { if (lastChar != currentChar || frequency >= 255) { writeData(); lastChar = currentChar; frequency = 1; } else frequency++; } writeData(); file.close(); return EXIT_SUCCESS; }
/* * Arguments : void * Return Type : double */ static double c_fprintf(void) { int nbytesint; FILE * b_NULL; boolean_T autoflush; FILE * filestar; static const char cfmt[24] = { '-', 'I', 'n', 'i', 't', 'i', 'a', 'l', 'i', 'z', 'i', 'n', 'g', ' ', 'm', 'o', 'd', 'e', 'l', '.', '.', '.', '\x0a', '\x00' }; nbytesint = 0; b_NULL = NULL; fileManager(&filestar, &autoflush); if (filestar == b_NULL) { } else { nbytesint = fprintf(filestar, cfmt); fflush(filestar); } return nbytesint; }
int decompressFile(const std::string& inputPath, const std::string& outputPath) { std::ofstream os; char currentChar; unsigned char frequency; BitFileManager fileManager(BitFileManager::Mode::Read, inputPath); if (!checkHeader(fileManager.getIStream())) return EXIT_FAILURE; os.open(outputPath, std::ios_base::binary); bool moreData = true; while (moreData) { bool hasFrecv = false; if (fileManager.read(hasFrecv) != EXIT_SUCCESS) { moreData = false; continue; } if (hasFrecv == true) fileManager.read(frequency); else frequency = 1; if (fileManager.read(reinterpret_cast<unsigned char&>(currentChar)) == EXIT_SUCCESS) { for (unsigned char j = 0; j < frequency; ++j) os.write((char*)¤tChar, sizeof(char)); } } os.close(); return EXIT_SUCCESS; }
/* * Arguments : double varargin_1 * double varargin_2 * Return Type : double */ static double e_fprintf(double varargin_1, double varargin_2) { int nbytesint; FILE * b_NULL; boolean_T autoflush; FILE * filestar; static const char cfmt[48] = { 'S', 'c', 'h', 'l', 'e', 'i', 'f', 'e', ' ', '%', '1', '.', '0', 'f', ' ', 'b', 'e', 'r', 'e', 'c', 'h', 'n', 'e', 't', '.', ' ', '%', '1', '.', '0', 'f', ' ', '%', '%', ' ', 'g', 'e', 's', 'c', 'h', 'a', 'f', 'f', 't', '.', ' ', '\x0d', '\x00' }; nbytesint = 0; b_NULL = NULL; fileManager(&filestar, &autoflush); if (filestar == b_NULL) { } else { nbytesint = fprintf(filestar, cfmt, varargin_1, varargin_2); fflush(filestar); } return nbytesint; }
std::vector<std::string> getLocalizedStringFromFile(std::string filename, std::string triple, std::vector<std::string> includepaths) { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), &diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, &diagnosticOptions, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); const std::shared_ptr<clang::TargetOptions> targetOptions = std::make_shared<clang::TargetOptions>(); targetOptions->Triple = triple;//"arm-apple-darwin11";//llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, targetOptions ); llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> headerSearchOptions(new clang::HeaderSearchOptions()); for(unsigned long i = 0 ; i < includepaths.size(); i++) { headerSearchOptions->AddPath(includepaths.at(i), clang::frontend::Angled, false, false); } clang::HeaderSearch headerSearch(headerSearchOptions, sourceManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); /* headerSearchOptions->AddPath("/usr/share/iPhoneOS5.0.sdk/usr/include/c++/4.2.1/tr1/", clang::frontend::Angled, false, false, false); headerSearchOptions->AddPath("/usr/share/iPhoneOS5.0.sdk/usr/include/c++/4.2.1", clang::frontend::Angled, false, false, false); */ clang::CompilerInstance compInst; llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> pOpts (new clang::PreprocessorOptions()); clang::Preprocessor preprocessor( pOpts, *pDiagnosticsEngine, languageOptions, sourceManager, headerSearch, compInst); preprocessor.Initialize(*pTargetInfo); clang::FrontendOptions frontendOptions; clang::RawPCHContainerReader Reader; clang::InitializePreprocessor( preprocessor, *pOpts, Reader, frontendOptions); clang::ApplyHeaderSearchOptions( headerSearch,//preprocessor.getHeaderSearchInfo(), *headerSearchOptions,//compInst.getHeaderSearchOpts(), preprocessor.getLangOpts(), preprocessor.getTargetInfo().getTriple()); const clang::FileEntry *pFile = fileManager.getFile(filename); //sourceManager.setMainFileID( sourceManager.createFileID( pFile, clang::SourceLocation(), clang::SrcMgr::C_System)); sourceManager.setMainFileID( sourceManager.createFileID( pFile, clang::SourceLocation(), clang::SrcMgr::C_User)); //sourceManager.createMainFileID(pFile); preprocessor.EnterMainSourceFile(); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); /* * identifier 'localizedStringForKey' * colon ':' * l_paren '(' * unknown '@' * string_literal '"UIAlertView"' * r_paren ')' * */ int found = 0; std::string trans_str; std::vector<std::string> trans_list; clang::Token token; do { preprocessor.Lex(token); if( pDiagnosticsEngine->hasErrorOccurred()) { break; } // if we meet localizedStringForKey, that means we need record it params. if(token.is(clang::tok::identifier) && token.isNot(clang::tok::raw_identifier)) { const clang::IdentifierInfo *II = token.getIdentifierInfo(); if ( II && (strcmp(II->getName().data(), "localizedStringForKey") == 0)) found = 1; } // only string literal we should handle. if(found == 1 && token.is(clang::tok::string_literal)) { std::string got = preprocessor.getSpelling(token); //here, we got a string with "" got = got.substr(1,got.length()-2); //remove "" trans_str += got; // string may split to multiline, we save them all. } // when match ), that means we got what we need. // push it to vector and wait next found == 1; if(found == 1 && token.is(clang::tok::r_paren) && token.isNot(clang::tok::raw_identifier)) { trans_list.push_back(trans_str); trans_str.clear(); found = 0; } } while( token.isNot(clang::tok::eof)); pTextDiagnosticPrinter->EndSourceFile(); /*for(int i = 0; i < trans_list.size(); i++) std::cout<<trans_list[i]<<std::endl; */ return trans_list; }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); clang::HeaderSearchOptions headerSearchOptions; // <Warning!!> -- Platform Specific Code lives here // This depends on A) that you're running linux and // B) that you have the same GCC LIBs installed that // I do. // Search through Clang itself for something like this, // go on, you won't find it. The reason why is Clang // has its own versions of std* which are installed under // /usr/local/lib/clang/<version>/include/ // See somewhere around Driver.cpp:77 to see Clang adding // its version of the headers to its include path. headerSearchOptions.AddPath("/usr/include/linux", clang::frontend::Angled, false, false, false); headerSearchOptions.AddPath("/usr/include/c++/4.4/tr1", clang::frontend::Angled, false, false, false); headerSearchOptions.AddPath("/usr/include/c++/4.4", clang::frontend::Angled, false, false, false); // </Warning!!> -- End of Platform Specific Code clang::TargetOptions targetOptions; targetOptions.Triple = llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, targetOptions); clang::HeaderSearch headerSearch(fileManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); clang::CompilerInstance compInst; clang::Preprocessor preprocessor( *pDiagnosticsEngine, languageOptions, pTargetInfo, sourceManager, headerSearch, compInst); clang::PreprocessorOptions preprocessorOptions; clang::FrontendOptions frontendOptions; clang::InitializePreprocessor( preprocessor, preprocessorOptions, headerSearchOptions, frontendOptions); const clang::FileEntry *pFile = fileManager.getFile( "input04.c"); sourceManager.createMainFileID(pFile); const clang::TargetInfo &targetInfo = *pTargetInfo; clang::IdentifierTable identifierTable(languageOptions); clang::SelectorTable selectorTable; clang::Builtin::Context builtinContext; builtinContext.InitializeTarget(targetInfo); clang::ASTContext astContext( languageOptions, sourceManager, pTargetInfo, identifierTable, selectorTable, builtinContext, 0 /* size_reserve*/); MyASTConsumer astConsumer; clang::Sema sema( preprocessor, astContext, astConsumer); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); clang::ParseAST(preprocessor, &astConsumer, astContext); pTextDiagnosticPrinter->EndSourceFile(); return 0; }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; // THis cannot be right clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); clang::TargetOptions targetOptions; targetOptions.Triple = llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, targetOptions); clang::HeaderSearch headerSearch(fileManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); clang::CompilerInstance compInst; clang::Preprocessor preprocessor( *pDiagnosticsEngine, languageOptions, pTargetInfo, sourceManager, headerSearch, compInst); const clang::FileEntry *pFile = fileManager.getFile("test.c"); sourceManager.createMainFileID(pFile); preprocessor.EnterMainSourceFile(); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); clang::Token token; do { preprocessor.Lex(token); if( pDiagnosticsEngine->hasErrorOccurred()) { break; } preprocessor.DumpToken(token); std::cerr << std::endl; } while( token.isNot(clang::tok::eof)); pTextDiagnosticPrinter->EndSourceFile(); return 0; }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), &diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, &diagnosticOptions, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); clang::TargetOptions targetOptions; targetOptions.Triple = llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, &targetOptions); llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> hso(new clang::HeaderSearchOptions()); clang::HeaderSearch headerSearch(hso, fileManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); clang::CompilerInstance compInst; llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> pOpts; clang::Preprocessor preprocessor( pOpts, *pDiagnosticsEngine, languageOptions, pTargetInfo, sourceManager, headerSearch, compInst); clang::PreprocessorOptions preprocessorOptions; clang::FrontendOptions frontendOptions; clang::InitializePreprocessor( preprocessor, preprocessorOptions, *hso, frontendOptions); // Note: Changed the file from tutorial2. const clang::FileEntry *pFile = fileManager.getFile("../Resources/testInclude.c"); sourceManager.createMainFileID(pFile); preprocessor.EnterMainSourceFile(); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); clang::Token token; do { preprocessor.Lex(token); if( pDiagnosticsEngine->hasErrorOccurred()) { break; } preprocessor.DumpToken(token); std::cerr << std::endl; } while( token.isNot(clang::tok::eof)); pTextDiagnosticPrinter->EndSourceFile(); return 0; }
ConvolutionalNeuralNetwork::ConvolutionalNeuralNetwork(string folderPath, string _programPath) { FileManager fileManager(folderPath + "\\"); programPath = _programPath; vector<string>* files = fileManager.getFiles(); initialized = true; // Gets required files and initializes corresponding layers int requiredFileCount = 0; for (vector<string>::iterator file = files->begin(); file != files->end(); ++file) { if (file->find("Wconv1.txt") != string::npos) { cout << "Reading Wconv1.txt..." << endl; requiredFileCount++; initConvTensor(*file, Wconv1, 5, 5, 1, 32); } else if (file->find("bconv1.txt") != string::npos) { cout << "Reading bconv1.txt..." << endl; requiredFileCount++; initBTensor(*file, bconv1); } else if (file->find("Wconv2.txt") != string::npos) { cout << "Reading Wconv2.txt..." << endl; requiredFileCount++; initConvTensor(*file, Wconv2, 5, 5, 32, 64); } else if (file->find("bconv2.txt") != string::npos) { cout << "Reading bconv2.txt..." << endl; requiredFileCount++; initBTensor(*file, bconv2); } else if (file->find("Wfc1.txt") != string::npos) { cout << "Reading Wfc1.txt..." << endl; requiredFileCount++; initWTensor(*file, Wfc1, 7 * 7 * 64, 1024); } else if (file->find("bfc1.txt") != string::npos) { cout << "Reading bfc1.txt..." << endl; requiredFileCount++; initBTensor(*file, bfc1); } else if (file->find("Wfc2.txt") != string::npos) { cout << "Reading Wfc2.txt..." << endl; requiredFileCount++; initWTensor(*file, Wfc2, 1024, 62); } else if (file->find("bfc2.txt") != string::npos) { cout << "Reading bfc2.txt..." << endl; requiredFileCount++; initBTensor(*file, bfc2); } } // Checks number of files present if (requiredFileCount != 8) { cout << "Required files not present" << endl; initialized = false; return; } else { cout << "Files read and imported" << endl; } }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; clang::Diagnostic diagnostic(pDiagIDs, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( diagnostic, fileManager); clang::HeaderSearch headerSearch(fileManager); clang::HeaderSearchOptions headerSearchOptions; clang::TargetOptions targetOptions; targetOptions.Triple = llvm::sys::getHostTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( diagnostic, targetOptions); clang::ApplyHeaderSearchOptions( headerSearch, headerSearchOptions, languageOptions, pTargetInfo->getTriple()); clang::Preprocessor preprocessor( diagnostic, languageOptions, *pTargetInfo, sourceManager, headerSearch); clang::PreprocessorOptions preprocessorOptions; // disable predefined Macros so that you only see the tokens from your // source file. preprocessorOptions.UsePredefines = false; clang::FrontendOptions frontendOptions; clang::InitializePreprocessor( preprocessor, preprocessorOptions, headerSearchOptions, frontendOptions); const clang::FileEntry *pFile = fileManager.getFile( "test.c"); sourceManager.createMainFileID(pFile); preprocessor.EnterMainSourceFile(); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); clang::Token token; do { preprocessor.Lex(token); if( diagnostic.hasErrorOccurred()) { break; } preprocessor.DumpToken(token); std::cerr << std::endl; } while( token.isNot(clang::tok::eof)); pTextDiagnosticPrinter->EndSourceFile(); return 0; }
int main(int argc, const char **argv, char * const *envp) { // Path void *MainAddr = (void*) (intptr_t) GetExecutablePath; llvm::sys::Path Path = GetExecutablePath(argv[0]); // DiagnosticOptions DiagnosticOptions diagnosticOptions; // DiagnosticClient TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::outs(), diagnosticOptions); // Diagnostic llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); Diagnostic diagnostic(DiagID, DiagClient); //DiagnosticOptions DiagOpts; //llvm::IntrusiveRefCntPtr<Diagnostic> diagnostic = CompilerInstance::createDiagnostics(DiagOpts, argc, argv); // LangOptions LangOptions langOptions; langOptions.CPlusPlus = 1; langOptions.CPlusPlus0x = 1; langOptions.Microsoft = 1; langOptions.Bool = 1; langOptions.Exceptions = 1; langOptions.CXXExceptions = 1; langOptions.EmitAllDecls = 1; // FileManager FileSystemOptions fileSystemOptions; FileManager fileManager(fileSystemOptions); // SourceManager SourceManager sourceManager(diagnostic, fileManager); // HeadderSearch HeaderSearch headerSearch(fileManager); // TargetOptions TargetOptions targetOptions; targetOptions.Triple = llvm::sys::getHostTriple(); // TargetInfo TargetInfo *pTargetInfo = TargetInfo::CreateTargetInfo( diagnostic, targetOptions); // HeaderSearchOptions HeaderSearchOptions headerSearchOptions; ApplyHeaderSearchOptions( headerSearch, headerSearchOptions, langOptions, pTargetInfo->getTriple()); // Preprocessor Preprocessor preprocessor( diagnostic, langOptions, *pTargetInfo, sourceManager, headerSearch); // PreprocessorOptions PreprocessorOptions preprocessorOptions; preprocessorOptions.DetailedRecord = true; preprocessor.createPreprocessingRecord(); // FrontendOptions FrontendOptions frontendOptions; // InitializePreprocessor InitializePreprocessor( preprocessor, preprocessorOptions, headerSearchOptions, frontendOptions); //preprocessor.SetCommentRetentionState(true, true); // Tutorial const FileEntry *pFile = fileManager.getFile( "test.cpp", true); sourceManager.createMainFileID(pFile); /*preprocessor.EnterMainSourceFile(); Token Tok; do { preprocessor.Lex(Tok); // read one token //if (context.diags.hasErrorOccurred()) // stop lexing/pp on error // break; preprocessor.DumpToken(Tok); // outputs to cerr std::cerr << std::endl; } while (Tok.isNot(tok::eof));*/ const TargetInfo &targetInfo = *pTargetInfo; IdentifierTable identifierTable(langOptions); SelectorTable selectorTable; Builtin::Context builtinContext(targetInfo); ASTContext astContext( langOptions, sourceManager, targetInfo, identifierTable, selectorTable, builtinContext, 0 /* size_reserve*/); // ASTConsumer astConsumer; MyASTConsumer astConsumer; astConsumer.sourceManager = &sourceManager; astConsumer.html = new ClangDocHTML; astConsumer.html->astConsumer = &astConsumer; preprocessor.addPPCallbacks(astConsumer.html); preprocessor.AddCommentHandler(astConsumer.html); Sema sema( preprocessor, astContext, astConsumer); sema.Initialize(); //MySemanticAnalisys mySema( preprocessor, astContext, astConsumer); //Parser parser( preprocessor, sema); //parser.ParseTranslationUnit(); astConsumer.preprocessor = &sema.PP; ParseAST(preprocessor, &astConsumer, astContext); return 0; }
int main() { clang::DiagnosticOptions diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter( llvm::outs(), &diagnosticOptions); llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; clang::DiagnosticsEngine *pDiagnosticsEngine = new clang::DiagnosticsEngine(pDiagIDs, &diagnosticOptions, pTextDiagnosticPrinter); clang::LangOptions languageOptions; clang::FileSystemOptions fileSystemOptions; clang::FileManager fileManager(fileSystemOptions); clang::SourceManager sourceManager( *pDiagnosticsEngine, fileManager); const std::shared_ptr<clang::TargetOptions> targetOptions = std::make_shared<clang::TargetOptions>(); targetOptions->Triple = llvm::sys::getDefaultTargetTriple(); clang::TargetInfo *pTargetInfo = clang::TargetInfo::CreateTargetInfo( *pDiagnosticsEngine, targetOptions); llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> hso(new clang::HeaderSearchOptions()); clang::HeaderSearch headerSearch(hso, sourceManager, *pDiagnosticsEngine, languageOptions, pTargetInfo); clang::CompilerInstance compInst; llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> pOpts(new clang::PreprocessorOptions); clang::Preprocessor preprocessor( pOpts, *pDiagnosticsEngine, languageOptions, sourceManager, headerSearch, compInst); preprocessor.Initialize(*pTargetInfo); // disable predefined Macros so that you only see the tokens from your // source file. Note, this has some nasty side-effects like also undefning // your archictecture and things like that. //preprocessorOptions.UsePredefines = false; clang::FrontendOptions frontendOptions; clang::InitializePreprocessor( preprocessor, *pOpts, frontendOptions); clang::ApplyHeaderSearchOptions( preprocessor.getHeaderSearchInfo(), compInst.getHeaderSearchOpts(), preprocessor.getLangOpts(), preprocessor.getTargetInfo().getTriple()); // Note: Changed the file from tutorial2. const clang::FileEntry *pFile = fileManager.getFile("testInclude.c"); sourceManager.setMainFileID( sourceManager.createFileID( pFile, clang::SourceLocation(), clang::SrcMgr::C_User)); preprocessor.EnterMainSourceFile(); pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor); clang::Token token; do { preprocessor.Lex(token); if( pDiagnosticsEngine->hasErrorOccurred()) { break; } preprocessor.DumpToken(token); std::cerr << std::endl; } while( token.isNot(clang::tok::eof)); pTextDiagnosticPrinter->EndSourceFile(); return 0; }