Skip to content

Commit fe5ad5f

Browse files
author
Dale Wilson
committed
Add comments to generated files to identify them as generated by mFAST
1 parent ac294f3 commit fe5ad5f

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
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/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)