Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/kconfig_compiler.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | 43 | | |||
44 | #include "../../kconfig_version.h" | 44 | #include "../../kconfig_version.h" | ||
45 | #include "KConfigParameters.h" | 45 | #include "KConfigParameters.h" | ||
46 | #include "KConfigCommonStructs.h" | 46 | #include "KConfigCommonStructs.h" | ||
47 | #include "KConfigHeaderGenerator.h" | 47 | #include "KConfigHeaderGenerator.h" | ||
48 | #include "KConfigSourceGenerator.h" | 48 | #include "KConfigSourceGenerator.h" | ||
49 | #include "KConfigXmlParser.h" | 49 | #include "KConfigXmlParser.h" | ||
50 | 50 | | |||
51 | namespace | | |||
52 | { | | |||
53 | QTextStream cout(stdout); | | |||
54 | QTextStream cerr(stderr); | | |||
55 | } | | |||
56 | | ||||
57 | QString varName(const QString &n, const KConfigParameters &cfg) | 51 | QString varName(const QString &n, const KConfigParameters &cfg) | ||
58 | { | 52 | { | ||
59 | QString result; | 53 | QString result; | ||
60 | if (!cfg.dpointer) { | 54 | if (!cfg.dpointer) { | ||
61 | result = QChar::fromLatin1('m') + n; | 55 | result = QChar::fromLatin1('m') + n; | ||
62 | result[1] = result[1].toUpper(); | 56 | result[1] = result[1].toUpper(); | ||
63 | } else { | 57 | } else { | ||
64 | result = n; | 58 | result = n; | ||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Line(s) | 254 | } else if (type == QLatin1String("pathlist")) { | |||
261 | return QStringLiteral("const QStringList &"); | 255 | return QStringLiteral("const QStringList &"); | ||
262 | } else if (type == QLatin1String("password")) { | 256 | } else if (type == QLatin1String("password")) { | ||
263 | return QStringLiteral("const QString &"); | 257 | return QStringLiteral("const QString &"); | ||
264 | } else if (type == QLatin1String("url")) { | 258 | } else if (type == QLatin1String("url")) { | ||
265 | return QStringLiteral("const QUrl &"); | 259 | return QStringLiteral("const QUrl &"); | ||
266 | } else if (type == QLatin1String("urllist")) { | 260 | } else if (type == QLatin1String("urllist")) { | ||
267 | return QStringLiteral("const QList<QUrl> &"); | 261 | return QStringLiteral("const QList<QUrl> &"); | ||
268 | } else { | 262 | } else { | ||
269 | cerr << "kconfig_compiler_kf5 does not support type \"" << type << "\"" << endl; | 263 | std::cerr << "kconfig_compiler_kf5 does not support type \"" << qPrintable(type) << "\"" << std::endl; | ||
270 | return QStringLiteral("QString"); //For now, but an assert would be better | 264 | return QStringLiteral("QString"); //For now, but an assert would be better | ||
271 | } | 265 | } | ||
272 | } | 266 | } | ||
273 | 267 | | |||
274 | /** | 268 | /** | ||
275 | Actual C++ storage type for given type. | 269 | Actual C++ storage type for given type. | ||
276 | */ | 270 | */ | ||
277 | QString cppType(const QString &t) | 271 | QString cppType(const QString &t) | ||
Show All 37 Lines | 308 | } else if (type == QLatin1String("pathlist")) { | |||
315 | return QStringLiteral("QStringList"); | 309 | return QStringLiteral("QStringList"); | ||
316 | } else if (type == QLatin1String("password")) { | 310 | } else if (type == QLatin1String("password")) { | ||
317 | return QStringLiteral("QString"); | 311 | return QStringLiteral("QString"); | ||
318 | } else if (type == QLatin1String("url")) { | 312 | } else if (type == QLatin1String("url")) { | ||
319 | return QStringLiteral("QUrl"); | 313 | return QStringLiteral("QUrl"); | ||
320 | } else if (type == QLatin1String("urllist")) { | 314 | } else if (type == QLatin1String("urllist")) { | ||
321 | return QStringLiteral("QList<QUrl>"); | 315 | return QStringLiteral("QList<QUrl>"); | ||
322 | } else { | 316 | } else { | ||
323 | cerr << "kconfig_compiler_kf5 does not support type \"" << type << "\"" << endl; | 317 | std::cerr << "kconfig_compiler_kf5 does not support type \"" << qPrintable(type) << "\"" << std::endl; | ||
324 | return QStringLiteral("QString"); //For now, but an assert would be better | 318 | return QStringLiteral("QString"); //For now, but an assert would be better | ||
325 | } | 319 | } | ||
326 | } | 320 | } | ||
327 | 321 | | |||
328 | QString defaultValue(const QString &t) | 322 | QString defaultValue(const QString &t) | ||
329 | { | 323 | { | ||
330 | const QString type = t.toLower(); | 324 | const QString type = t.toLower(); | ||
331 | if (type == QLatin1String("string")) { | 325 | if (type == QLatin1String("string")) { | ||
Show All 34 Lines | 359 | } else if (type == QLatin1String("pathlist")) { | |||
366 | return QStringLiteral("QStringList()"); | 360 | return QStringLiteral("QStringList()"); | ||
367 | } else if (type == QLatin1String("password")) { | 361 | } else if (type == QLatin1String("password")) { | ||
368 | return QStringLiteral("\"\""); // Use empty string, not null string! | 362 | return QStringLiteral("\"\""); // Use empty string, not null string! | ||
369 | } else if (type == QLatin1String("url")) { | 363 | } else if (type == QLatin1String("url")) { | ||
370 | return QStringLiteral("QUrl()"); | 364 | return QStringLiteral("QUrl()"); | ||
371 | } else if (type == QLatin1String("urllist")) { | 365 | } else if (type == QLatin1String("urllist")) { | ||
372 | return QStringLiteral("QList<QUrl>()"); | 366 | return QStringLiteral("QList<QUrl>()"); | ||
373 | } else { | 367 | } else { | ||
374 | cerr << "Error, kconfig_compiler_kf5 does not support the \"" << type << "\" type!" << endl; | 368 | std::cerr << "Error, kconfig_compiler_kf5 does not support the \"" << qPrintable(type) << "\" type!" << std::endl; | ||
375 | return QStringLiteral("QString"); //For now, but an assert would be better | 369 | return QStringLiteral("QString"); //For now, but an assert would be better | ||
376 | } | 370 | } | ||
377 | } | 371 | } | ||
378 | 372 | | |||
379 | QString itemType(const QString &type) | 373 | QString itemType(const QString &type) | ||
380 | { | 374 | { | ||
381 | QString t; | 375 | QString t; | ||
382 | 376 | | |||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Line(s) | |||||
589 | 583 | | |||
590 | // returns the member get default implementation | 584 | // returns the member get default implementation | ||
591 | // which should go in the h file if inline | 585 | // which should go in the h file if inline | ||
592 | // or the cpp file if not inline | 586 | // or the cpp file if not inline | ||
593 | QString memberGetDefaultBody(const CfgEntry *e) | 587 | QString memberGetDefaultBody(const CfgEntry *e) | ||
594 | { | 588 | { | ||
595 | QString result = e->code; | 589 | QString result = e->code; | ||
596 | QTextStream out(&result, QIODevice::WriteOnly); | 590 | QTextStream out(&result, QIODevice::WriteOnly); | ||
597 | out << endl; | 591 | out << '\n'; | ||
598 | 592 | | |||
599 | if (!e->param.isEmpty()) { | 593 | if (!e->param.isEmpty()) { | ||
600 | out << " switch (i) {" << endl; | 594 | out << " switch (i) {\n"; | ||
601 | for (int i = 0; i <= e->paramMax; ++i) { | 595 | for (int i = 0; i <= e->paramMax; ++i) { | ||
602 | if (!e->paramDefaultValues[i].isEmpty()) { | 596 | if (!e->paramDefaultValues[i].isEmpty()) { | ||
603 | out << " case " << i << ": return " << e->paramDefaultValues[i] << ';' << endl; | 597 | out << " case " << i << ": return " << e->paramDefaultValues[i] << ";\n"; | ||
604 | } | 598 | } | ||
605 | } | 599 | } | ||
606 | QString defaultValue = e->defaultValue; | 600 | QString defaultValue = e->defaultValue; | ||
607 | 601 | | |||
608 | out << " default:" << endl; | 602 | out << " default:\n"; | ||
609 | out << " return " << defaultValue.replace("$(" + e->param + ')', QLatin1String("i")) << ';' << endl; | 603 | out << " return " << defaultValue.replace("$(" + e->param + ')', QLatin1String("i")) << ";\n"; | ||
610 | out << " }" << endl; | 604 | out << " }\n"; | ||
611 | } else { | 605 | } else { | ||
612 | out << " return " << e->defaultValue << ';'; | 606 | out << " return " << e->defaultValue << ';'; | ||
613 | } | 607 | } | ||
614 | 608 | | |||
615 | return result; | 609 | return result; | ||
616 | } | 610 | } | ||
617 | 611 | | |||
618 | // returns the item accesor implementation | 612 | // returns the item accesor implementation | ||
619 | // which should go in the h file if inline | 613 | // which should go in the h file if inline | ||
620 | // or the cpp file if not inline | 614 | // or the cpp file if not inline | ||
621 | QString itemAccessorBody(const CfgEntry *e, const KConfigParameters &cfg) | 615 | QString itemAccessorBody(const CfgEntry *e, const KConfigParameters &cfg) | ||
622 | { | 616 | { | ||
623 | QString result; | 617 | QString result; | ||
624 | QTextStream out(&result, QIODevice::WriteOnly); | 618 | QTextStream out(&result, QIODevice::WriteOnly); | ||
625 | 619 | | |||
626 | out << "return " << itemPath(e, cfg); | 620 | out << "return " << itemPath(e, cfg); | ||
627 | if (!e->param.isEmpty()) { | 621 | if (!e->param.isEmpty()) { | ||
628 | out << "[i]"; | 622 | out << "[i]"; | ||
629 | } | 623 | } | ||
630 | out << ";" << endl; | 624 | out << ";\n"; | ||
631 | 625 | | |||
632 | return result; | 626 | return result; | ||
633 | } | 627 | } | ||
634 | 628 | | |||
635 | //indents text adding X spaces per line | 629 | //indents text adding X spaces per line | ||
636 | QString indent(QString text, int spaces) | 630 | QString indent(QString text, int spaces) | ||
637 | { | 631 | { | ||
638 | QString result; | 632 | QString result; | ||
639 | QTextStream out(&result, QIODevice::WriteOnly); | 633 | QTextStream out(&result, QIODevice::WriteOnly); | ||
640 | QTextStream in(&text, QIODevice::ReadOnly); | 634 | QTextStream in(&text, QIODevice::ReadOnly); | ||
641 | QString currLine; | 635 | QString currLine; | ||
642 | while (!in.atEnd()) { | 636 | while (!in.atEnd()) { | ||
643 | currLine = in.readLine(); | 637 | currLine = in.readLine(); | ||
644 | if (!currLine.isEmpty()) | 638 | if (!currLine.isEmpty()) | ||
645 | for (int i = 0; i < spaces; i++) { | 639 | for (int i = 0; i < spaces; i++) { | ||
646 | out << " "; | 640 | out << " "; | ||
647 | } | 641 | } | ||
648 | out << currLine << endl; | 642 | out << currLine << '\n'; | ||
649 | } | 643 | } | ||
650 | return result; | 644 | return result; | ||
651 | } | 645 | } | ||
652 | 646 | | |||
653 | bool hasErrors(KConfigXmlParser &parser, const ParseResult& parseResult, const KConfigParameters &cfg) | 647 | bool hasErrors(KConfigXmlParser &parser, const ParseResult& parseResult, const KConfigParameters &cfg) | ||
654 | { | 648 | { | ||
655 | if (cfg.className.isEmpty()) { | 649 | if (cfg.className.isEmpty()) { | ||
656 | cerr << "Class name missing" << endl; | 650 | std::cerr << "Class name missing" << std::endl; | ||
657 | return true; | 651 | return true; | ||
658 | } | 652 | } | ||
659 | 653 | | |||
660 | if (cfg.singleton && !parseResult.parameters.isEmpty()) { | 654 | if (cfg.singleton && !parseResult.parameters.isEmpty()) { | ||
661 | cerr << "Singleton class can not have parameters" << endl; | 655 | std::cerr << "Singleton class can not have parameters" << std::endl; | ||
662 | return true; | 656 | return true; | ||
663 | } | 657 | } | ||
664 | 658 | | |||
665 | if (!parseResult.cfgFileName.isEmpty() && parseResult.cfgFileNameArg) { | 659 | if (!parseResult.cfgFileName.isEmpty() && parseResult.cfgFileNameArg) { | ||
666 | cerr << "Having both a fixed filename and a filename as argument is not possible." << endl; | 660 | std::cerr << "Having both a fixed filename and a filename as argument is not possible." << std::endl; | ||
667 | return true; | 661 | return true; | ||
668 | } | 662 | } | ||
669 | 663 | | |||
670 | /* TODO: For some reason some configuration files prefer to have *no* entries | 664 | /* TODO: For some reason some configuration files prefer to have *no* entries | ||
671 | * at all in it, and the generated code is mostly bogus as KConfigXT will not | 665 | * at all in it, and the generated code is mostly bogus as KConfigXT will not | ||
672 | * handle save / load / properties, etc, nothing. | 666 | * handle save / load / properties, etc, nothing. | ||
673 | * | 667 | * | ||
674 | * The first of those files that I came across are qmakebuilderconfig.kcfg from the KDevelop | 668 | * The first of those files that I came across are qmakebuilderconfig.kcfg from the KDevelop | ||
675 | * project. | 669 | * project. | ||
676 | * I think we should remove the possibility of creating configuration classes from configuration | 670 | * I think we should remove the possibility of creating configuration classes from configuration | ||
677 | * files that don't really have configuration in it. but I'm changing this right now to allow | 671 | * files that don't really have configuration in it. but I'm changing this right now to allow | ||
678 | * kdevelop files to pass. | 672 | * kdevelop files to pass. | ||
679 | * | 673 | * | ||
680 | * Remove for KDE 6 | 674 | * Remove for KDE 6 | ||
681 | * (to make things more interesting, it failed in a code that's never used within KDevelop... ) | 675 | * (to make things more interesting, it failed in a code that's never used within KDevelop... ) | ||
682 | */ | 676 | */ | ||
683 | if (parseResult.entries.isEmpty()) { | 677 | if (parseResult.entries.isEmpty()) { | ||
684 | cerr << "No entries." << endl; | 678 | std::cerr << "No entries." << std::endl; | ||
685 | return false; | 679 | return false; | ||
686 | } | 680 | } | ||
687 | 681 | | |||
688 | return false; | 682 | return false; | ||
689 | } | 683 | } | ||
690 | 684 | | |||
691 | int main(int argc, char **argv) | 685 | int main(int argc, char **argv) | ||
692 | { | 686 | { | ||
Show All 19 Lines | |||||
712 | parser.addOption(targetDirectoryOption); | 706 | parser.addOption(targetDirectoryOption); | ||
713 | parser.addOption (licenseOption); | 707 | parser.addOption (licenseOption); | ||
714 | 708 | | |||
715 | parser.addVersionOption(); | 709 | parser.addVersionOption(); | ||
716 | parser.addHelpOption(); | 710 | parser.addHelpOption(); | ||
717 | parser.process(app); | 711 | parser.process(app); | ||
718 | 712 | | |||
719 | if (parser.isSet(licenseOption)) { | 713 | if (parser.isSet(licenseOption)) { | ||
720 | cout << "Copyright 2003 Cornelius Schumacher, Waldo Bastian, Zack Rusin," << endl; | 714 | std::cout << "Copyright 2003 Cornelius Schumacher, Waldo Bastian, Zack Rusin," << std::endl; | ||
721 | cout << " Reinhold Kainhofer, Duncan Mac-Vicar P., Harald Fernengel" << endl; | 715 | std::cout << " Reinhold Kainhofer, Duncan Mac-Vicar P., Harald Fernengel" << std::endl; | ||
722 | cout << "This program comes with ABSOLUTELY NO WARRANTY." << endl; | 716 | std::cout << "This program comes with ABSOLUTELY NO WARRANTY." << std::endl; | ||
723 | cout << "You may redistribute copies of this program" << endl; | 717 | std::cout << "You may redistribute copies of this program" << std::endl; | ||
724 | cout << "under the terms of the GNU Library Public License." << endl; | 718 | std::cout << "under the terms of the GNU Library Public License." << std::endl; | ||
725 | cout << "For more information about these matters, see the file named COPYING." << endl; | 719 | std::cout << "For more information about these matters, see the file named COPYING." << std::endl; | ||
726 | return 0; | 720 | return 0; | ||
727 | } | 721 | } | ||
728 | 722 | | |||
729 | const QStringList args = parser.positionalArguments(); | 723 | const QStringList args = parser.positionalArguments(); | ||
730 | if (args.count() < 2) { | 724 | if (args.count() < 2) { | ||
731 | cerr << "Too few arguments." << endl; | 725 | std::cerr << "Too few arguments." << std::endl; | ||
732 | return 1; | 726 | return 1; | ||
733 | } | 727 | } | ||
734 | 728 | | |||
735 | if (args.count() > 2) { | 729 | if (args.count() > 2) { | ||
736 | cerr << "Too many arguments." << endl; | 730 | std::cerr << "Too many arguments." << std::endl; | ||
737 | return 1; | 731 | return 1; | ||
738 | } | 732 | } | ||
739 | inputFilename = args.at(0); | 733 | inputFilename = args.at(0); | ||
740 | codegenFilename = args.at(1); | 734 | codegenFilename = args.at(1); | ||
741 | 735 | | |||
742 | // TODO: Transform baseDir into a helper. | 736 | // TODO: Transform baseDir into a helper. | ||
743 | QString baseDir = parser.value(targetDirectoryOption); | 737 | QString baseDir = parser.value(targetDirectoryOption); | ||
744 | 738 | | |||
Show All 38 Lines |