Skip to content

Commit 94f42de

Browse files
Merge pull request #64 from objectcomputing/fast_type_gen_changes
Fast type gen changes
2 parents ac294f3 + 1f992b4 commit 94f42de

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

src/fast_type_gen/codegen_base.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#include <utility>
1111

1212
codegen_base::codegen_base(const char *filebase, const char *fileext)
13-
: filebase_(filebase), cpp_ns_(filebase),
14-
out_((filebase_ + fileext).c_str(), std::ofstream::trunc) {
13+
: filebase_(filebase), ext_(fileext),cpp_ns_(filebase),
14+
out_((filebase_ + fileext).c_str(), std::ofstream::trunc) ,
15+
use_standard_comment_(true) {
1516
if (!out_.is_open()) {
1617
filebase_ += fileext;
1718
throw file_open_error(filebase_);
@@ -24,6 +25,15 @@ codegen_base::dont_generate(const mfast::field_instruction * /*inst*/) const {
2425
return false;
2526
}
2627

28+
void codegen_base::generate_comment(){
29+
if(use_standard_comment_){
30+
out_ << "// " << filebase_ << ext_ << " generated by mFAST from FAST Template. \n"
31+
<< "// Do not modify this file directly. Any modifications \n"
32+
<< "// will be lost the next time this file is generated.\n\n";
33+
}
34+
}
35+
36+
2737
void codegen_base::set_outer_ns(const char *outer_ns) {
2838
outer_ns_.clear();
2939
while (outer_ns) {
@@ -41,6 +51,10 @@ void codegen_base::set_outer_ns(const char *outer_ns) {
4151
}
4252
}
4353

54+
void codegen_base::set_generate_comment(bool generateComment){
55+
use_standard_comment_ = generateComment;
56+
}
57+
4458
void codegen_base::traverse(mfast::dynamic_templates_description &desc) {
4559
for (auto inst : desc.defined_type_instructions()) {
4660
// we use the second parameter to identify whether the instruction is nested.

src/fast_type_gen/codegen_base.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ class file_open_error : public virtual boost::exception,
2525
class codegen_base : public mfast::field_instruction_visitor {
2626
protected:
2727
std::string filebase_;
28+
std::string ext_;
2829
std::vector<std::string> outer_ns_;
2930
std::string cpp_ns_;
3031
std::ofstream out_;
3132
std::stringstream cref_scope_;
33+
bool use_standard_comment_;
3234

3335
public:
3436
codegen_base(const char* filebase, const char* fileext);
3537
void set_outer_ns(const char *outer_ns);
38+
void set_generate_comment(bool generateComment);
39+
3640
static std::string cpp_name(const mfast::field_instruction* inst);
3741
static std::string cpp_name(boost::string_ref n);
3842
static const mfast::field_instruction* get_element_instruction(const mfast::sequence_field_instruction* inst);
3943
protected:
44+
void generate_comment();
4045
void traverse(mfast::dynamic_templates_description &desc);
4146
virtual void traverse(const mfast::group_field_instruction *inst,
4247
const char *name_suffix = "");

src/fast_type_gen/cpp_gen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ void cpp_gen::visit(const mfast::templateref_instruction *inst, void *pIndex) {
534534
}
535535

536536
void cpp_gen::generate(mfast::dynamic_templates_description &desc) {
537+
538+
generate_comment();
539+
537540
out_ << "#include \"" << filebase_ << hpp_fileext_ << "\"\n"
538541
<< "\n"
539542
<< "using namespace mfast;\n\n";

src/fast_type_gen/fast_type_gen.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ int main(int argc, const char **argv) {
7373
bool show_usage = false;
7474
bool bad_arguments = false;
7575

76-
while ((i < argc) && (std::strlen(argv[i]) > 1) && (argv[i][0] == '-') && (std::strcmp(argv[i], "--") != 0) && !bad_arguments) {
76+
// handle all options:
77+
// valid option formats:
78+
// -h or -help
79+
// -Xparam where X is a single character option
80+
// -X param where X is a single character option
81+
// -OPT=param where OPT is long option
82+
// -OPT param where OPT is long option
83+
// -- Stops the scan for options.
84+
while (i < argc && argv[i][0] == '-' && std::strcmp(argv[i], "--") != 0 && !bad_arguments) {
7785
const char *flag = &argv[i][1];
7886
if (*flag == '-') {
7987
++flag;
@@ -106,11 +114,21 @@ int main(int argc, const char **argv) {
106114
}
107115
++i;
108116
}
109-
if ((i < argc) && (std::strcmp(argv[i], "--") == 0))
117+
118+
// If a "--" stopped the scan, skip it.
119+
if(i < argc && std::strcmp(argv[i], "--") == 0){
110120
++i;
111-
if (show_usage || bad_arguments || (i >= argc)) {
121+
}
122+
123+
if(i >= argc){
124+
std::cerr << "No template file(s) on command line." << std::endl;
125+
bad_arguments = true;
126+
}
127+
128+
// Handle errors and help requests then exit
129+
if (show_usage || bad_arguments) {
112130
std::ostream &output = show_usage ? std::cout : std::cerr;
113-
output << "usage: " << command_name << " [-E symbol] [-H extension] [-I extension] [-C extension] file ...\n"
131+
output << "usage: " << command_name << " [-E symbol] [-H extension] [-I extension] [-C extension] template_file ...\n"
114132
" generate C++ bindings for FAST types\n";
115133
if (show_usage) {
116134
output << "\n"
@@ -121,18 +139,16 @@ int main(int argc, const char **argv) {
121139
" -C, --source-extension=EXT source filename extension (default .cpp)\n"
122140
" -H, --header-extension=EXT header filename extension (default .h)\n"
123141
" -I, --inline-extension=EXT inline function filename extension (default .inl)\n"
124-
" file ... XML FAST message template inputs\n";
142+
" template_file ... One or more XML FAST message template inputs\n";
125143
}
126-
return (bad_arguments || (!show_usage && (i >= argc))) ? -1 : 0;
144+
return bad_arguments ? -1 : 0;
127145
}
128146

129-
std::vector<mfast::dynamic_templates_description> descriptions;
130-
147+
// remaining arguments must be template file names
131148
std::vector<std::string> filebases;
132149

133-
mfast::simple_template_repo_t repo;
134-
135-
for (int j = 0; i < argc; ++i, ++j) {
150+
std::vector<mfast::dynamic_templates_description> descriptions;
151+
for (; i < argc; ++i) {
136152

137153
std::ifstream ifs(argv[i]);
138154

@@ -144,8 +160,6 @@ int main(int argc, const char **argv) {
144160
std::string xml((std::istreambuf_iterator<char>(ifs)),
145161
std::istreambuf_iterator<char>());
146162

147-
//path f(path(argv[i]).stem());
148-
149163
#ifdef _WINDOWS
150164
char filebase_buf[_MAX_FNAME];
151165
_splitpath(argv[i], NULL, NULL, filebase_buf, NULL);
@@ -157,9 +171,10 @@ int main(int argc, const char **argv) {
157171
#endif
158172
filebases.push_back(codegen_base::cpp_name(filebase));
159173

160-
descriptions.emplace_back(xml.c_str(), filebases[j].c_str(), &registry);
174+
descriptions.emplace_back(xml.c_str(), filebases.back().c_str(), &registry);
161175
}
162176

177+
mfast::simple_template_repo_t repo;
163178
repo.build(descriptions.begin(), descriptions.end());
164179

165180
for (std::size_t j = 0; j < filebases.size(); ++j) {

src/fast_type_gen/hpp_gen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ void hpp_gen::generate(mfast::dynamic_templates_description &desc) {
517517

518518
std::string filebase_upper = boost::to_upper_copy(filebase_);
519519

520+
generate_comment();
521+
520522
out_ << "#pragma once\n"
521523
<< "\n"
522524
<< "#include <mfast.h>\n";

src/fast_type_gen/inl_gen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ void inl_gen::visit(const mfast::templateref_instruction *, void *pIndex) {
942942
}
943943

944944
void inl_gen::generate(mfast::dynamic_templates_description &desc) {
945+
946+
generate_comment();
947+
945948
codegen_base::traverse(desc);
946949
for (auto &&info : desc.view_infos()) {
947950
this->generate(info);

0 commit comments

Comments
 (0)