MCPcopy Create free account
hub / github.com/KDE/kdevelop / initAndRunParser

Function initAndRunParser

kdevplatform/language/util/debuglanguageparserhelper.h:168–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166/// call this after setting up @p aboutData in your @c main() function.
167template <class ParserT>
168int initAndRunParser(KAboutData& aboutData, int argc, char* argv[])
169{
170 QCoreApplication app(argc, argv);
171
172 KAboutData::setApplicationData(aboutData);
173
174 QCommandLineParser parser;
175 aboutData.setupCommandLine(&parser);
176
177 parser.addPositionalArgument("files",
178 i18n(
179 "files or - to read from STDIN, the latter is the default if nothing is provided"),
180 "[FILE...]");
181
182 parser.addOption(QCommandLineOption{QStringList{"a", "print-ast"}, i18n("print generated AST tree")});
183 parser.addOption(QCommandLineOption{QStringList{"t", "print-tokens"}, i18n("print generated token stream")});
184 parser.addOption(QCommandLineOption{QStringList{"c", "code"}, i18n("code to parse"), "code"});
185 setupCustomArgs<ParserT>(&parser);
186
187 parser.process(app);
188 aboutData.processCommandLine(&parser);
189
190 QStringList files = parser.positionalArguments();
191 bool printAst = parser.isSet("print-ast");
192 bool printTokens = parser.isSet("print-tokens");
193
194 KDevelop::AutoTestShell::init();
195 KDevelop::TestCore::initialize(KDevelop::Core::NoUi);
196
197 KDevelop::DUChain::self()->disablePersistentStorage();
198 KDevelop::CodeRepresentation::setDiskChangesForbidden(true);
199
200 ParserT parserT(printAst, printTokens);
201 setCustomArgs(&parserT, &parser);
202
203 if (parser.isSet("code")) {
204 parserT.parseCode(parser.value("code"));
205 } else if (files.isEmpty()) {
206 files << "-";
207 }
208
209 for (const QString& fileName : std::as_const(files)) {
210 if (fileName == "-") {
211#ifndef Q_OS_WIN
212 if (isatty(STDIN_FILENO)) {
213 qerr << "no STDIN given" << Qt::endl;
214 return 255;
215 }
216#endif
217 parserT.parseCode(qin.readAll().toUtf8());
218 } else {
219 parserT.parseFile(QFileInfo(fileName).absoluteFilePath());
220 }
221 }
222
223 KDevelop::TestCore::shutdown();
224
225 return 0;

Callers

nothing calls this directly

Calls 11

initializeFunction · 0.85
setCustomArgsFunction · 0.85
initFunction · 0.50
QFileInfoClass · 0.50
processMethod · 0.45
isSetMethod · 0.45
parseCodeMethod · 0.45
valueMethod · 0.45
isEmptyMethod · 0.45
parseFileMethod · 0.45

Tested by

no test coverage detected