Rename moc -> generator

This commit is contained in:
Martchus 2017-10-25 17:41:19 +02:00
parent 3889031247
commit b725f59e78
22 changed files with 108 additions and 108 deletions

View File

@ -33,4 +33,4 @@ add_subdirectory(lib)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake/modules" "${CMAKE_MODULE_PATH}")
# add code generator
add_subdirectory(moc)
add_subdirectory(generator)

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# metadata
set(META_PROJECT_NAME reflective_rapidjson_moc)
set(META_PROJECT_NAME reflective_rapidjson_generator)
set(META_PROJECT_TYPE application)
set(LINK_TESTS_AGAINST_APP_TARGET ON)

View File

@ -1,105 +1,105 @@
#include "./codefactory.h"
#include "resources/config.h"
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/commandlineutils.h>
#include <c++utilities/application/failure.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/misc.h>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
using namespace ApplicationUtilities;
using namespace EscapeCodes;
using namespace IoUtilities;
using namespace ReflectiveRapidJSON;
int main(int argc, char *argv[])
{
SET_APPLICATION_INFO;
CMD_UTILS_CONVERT_ARGS_TO_UTF8;
// setup argument parser
ArgumentParser parser;
ConfigValueArgument inputFileArg("input-file", 'i', "specifies the input file", { "path" });
inputFileArg.setRequired(true);
ConfigValueArgument outputFileArg("output-file", 'o', "specifies the output file", { "path" });
Argument generatorsArg("generators", 'g', "specifies the generators (by default all generators are enabled)");
generatorsArg.setValueNames({ "json" });
generatorsArg.setPreDefinedCompletionValues("json");
generatorsArg.setRequiredValueCount(Argument::varValueCount);
generatorsArg.setCombinable(true);
ConfigValueArgument clangOptionsArg("clang-opt", 'c', "specifies an argument to be passed to Clang", { "option" });
HelpArgument helpArg(parser);
NoColorArgument noColorArg;
parser.setMainArguments({ &inputFileArg, &outputFileArg, &generatorsArg, &clangOptionsArg, &noColorArg, &helpArg });
// parse arguments
parser.parseArgsOrExit(argc, argv);
if (helpArg.isPresent()) {
return 0;
}
// setup output stream
ostream *os = nullptr;
try {
ofstream outputFile;
if (outputFileArg.isPresent()) {
outputFile.exceptions(ios_base::badbit | ios_base::failbit);
outputFile.open(outputFileArg.values(0).front(), ios_base::out | ios_base::trunc | ios_base::binary);
os = &outputFile;
} else {
os = &cout;
}
// configure code generator
vector<const char *> defaultClangOptions;
CodeFactory factory(
parser.executable(), inputFileArg.values(0), clangOptionsArg.isPresent() ? clangOptionsArg.values(0) : defaultClangOptions, *os);
// add only specified generators if the --generator argument is present
if (generatorsArg.isPresent()) {
// find and construct generators by name
for (const char *generatorName : generatorsArg.values(0)) {
if (!strcmp(generatorName, "json")) {
factory.addGenerator<JSONSerializationCodeGenerator>();
} else {
cerr << Phrases::Error << "The specified generator \"" << generatorName << "\" does not exist." << Phrases::EndFlush;
return -5;
}
}
} else {
// add default generators
factory.addGenerator<JSONSerializationCodeGenerator>();
}
// read AST elements from input files
if (!factory.readAST()) {
cerr << Phrases::Error << "Errors occured when parsing the input file." << Phrases::EndFlush;
return -2;
}
// run the code generator
if (!factory.generate()) {
cerr << Phrases::Error << "Errors occured when during code generation." << Phrases::EndFlush;
return -3;
}
} catch (...) {
catchIoFailure();
const char *errorMessage;
if (os) {
errorMessage = os->fail() || os->bad() ? "An IO error occured when writing to the output stream." : "An IO error occured.";
} else {
errorMessage = "An IO error when opening output stream.";
}
cerr << Phrases::Error << errorMessage << Phrases::EndFlush;
return -4;
}
return 0;
}
#include "./codefactory.h"
#include "resources/config.h"
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/commandlineutils.h>
#include <c++utilities/application/failure.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/misc.h>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
using namespace ApplicationUtilities;
using namespace EscapeCodes;
using namespace IoUtilities;
using namespace ReflectiveRapidJSON;
int main(int argc, char *argv[])
{
SET_APPLICATION_INFO;
CMD_UTILS_CONVERT_ARGS_TO_UTF8;
// setup argument parser
ArgumentParser parser;
ConfigValueArgument inputFileArg("input-file", 'i', "specifies the input file", { "path" });
inputFileArg.setRequired(true);
ConfigValueArgument outputFileArg("output-file", 'o', "specifies the output file", { "path" });
Argument generatorsArg("generators", 'g', "specifies the generators (by default all generators are enabled)");
generatorsArg.setValueNames({ "json" });
generatorsArg.setPreDefinedCompletionValues("json");
generatorsArg.setRequiredValueCount(Argument::varValueCount);
generatorsArg.setCombinable(true);
ConfigValueArgument clangOptionsArg("clang-opt", 'c', "specifies an argument to be passed to Clang", { "option" });
HelpArgument helpArg(parser);
NoColorArgument noColorArg;
parser.setMainArguments({ &inputFileArg, &outputFileArg, &generatorsArg, &clangOptionsArg, &noColorArg, &helpArg });
// parse arguments
parser.parseArgsOrExit(argc, argv);
if (helpArg.isPresent()) {
return 0;
}
// setup output stream
ostream *os = nullptr;
try {
ofstream outputFile;
if (outputFileArg.isPresent()) {
outputFile.exceptions(ios_base::badbit | ios_base::failbit);
outputFile.open(outputFileArg.values(0).front(), ios_base::out | ios_base::trunc | ios_base::binary);
os = &outputFile;
} else {
os = &cout;
}
// configure code generator
vector<const char *> defaultClangOptions;
CodeFactory factory(
parser.executable(), inputFileArg.values(0), clangOptionsArg.isPresent() ? clangOptionsArg.values(0) : defaultClangOptions, *os);
// add only specified generators if the --generator argument is present
if (generatorsArg.isPresent()) {
// find and construct generators by name
for (const char *generatorName : generatorsArg.values(0)) {
if (!strcmp(generatorName, "json")) {
factory.addGenerator<JSONSerializationCodeGenerator>();
} else {
cerr << Phrases::Error << "The specified generator \"" << generatorName << "\" does not exist." << Phrases::EndFlush;
return -5;
}
}
} else {
// add default generators
factory.addGenerator<JSONSerializationCodeGenerator>();
}
// read AST elements from input files
if (!factory.readAST()) {
cerr << Phrases::Error << "Errors occured when parsing the input file." << Phrases::EndFlush;
return -2;
}
// run the code generator
if (!factory.generate()) {
cerr << Phrases::Error << "Errors occured when during code generation." << Phrases::EndFlush;
return -3;
}
} catch (...) {
catchIoFailure();
const char *errorMessage;
if (os) {
errorMessage = os->fail() || os->bad() ? "An IO error occured when writing to the output stream." : "An IO error occured.";
} else {
errorMessage = "An IO error when opening output stream.";
}
cerr << Phrases::Error << errorMessage << Phrases::EndFlush;
return -4;
}
return 0;
}

View File

@ -7,7 +7,7 @@ endif()
set(REFLECTION_GENERATOR_MODULE_LOADED YES)
# find code generator
set(REFLECTION_GENERATOR_EXECUTABLE reflective_rapidjson_moc)
set(REFLECTION_GENERATOR_EXECUTABLE reflective_rapidjson_generator)
if(CMAKE_CROSSCOMPILING OR NOT TARGET "${REFLECTION_GENERATOR_EXECUTABLE}")
# find "reflective_rapidjson_moc" from path
find_program(REFLECTION_GENERATOR_EXECUTABLE "${REFLECTION_GENERATOR_EXECUTABLE}")