MCPcopy Create free account
hub / github.com/Genivia/RE-flex / export_code

Method export_code

lib/pattern.cpp:3753–3855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3751}
3752
3753void Pattern::export_code() const
3754{
3755#ifndef WITH_NO_CODEGEN
3756 if (nop_ == 0)
3757 return;
3758 for (std::vector<std::string>::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it)
3759 {
3760 const std::string& filename = *it;
3761 size_t len = filename.length();
3762 if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0)
3763 || (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
3764 || (len > 4 && filename.compare(len - 4, 4, ".hpp") == 0)
3765 || (len > 4 && filename.compare(len - 4, 4, ".hxx") == 0)
3766 || (len > 3 && filename.compare(len - 3, 3, ".cc" ) == 0)
3767 || (len > 4 && filename.compare(len - 4, 4, ".cpp") == 0)
3768 || (len > 4 && filename.compare(len - 4, 4, ".cxx") == 0))
3769 {
3770 FILE *file = NULL;
3771 int err = 0;
3772 if (filename.compare(0, 7, "stdout.") == 0)
3773 file = stdout;
3774 else if (filename.at(0) == '+')
3775 err = reflex::fopen_s(&file, filename.c_str() + 1, "a");
3776 else
3777 err = reflex::fopen_s(&file, filename.c_str(), "w");
3778 if (!err && file)
3779 {
3780 ::fprintf(file, "#ifndef REFLEX_CODE_DECL\n#include <reflex/pattern.h>\n#define REFLEX_CODE_DECL const reflex::Pattern::Opcode\n#endif\n\n");
3781 write_namespace_open(file);
3782 ::fprintf(file, "REFLEX_CODE_DECL reflex_code_%s[%u] =\n{\n", opt_.n.empty() ? "FSM" : opt_.n.c_str(), nop_);
3783 for (Index i = 0; i < nop_; ++i)
3784 {
3785 Opcode opcode = opc_[i];
3786 Char lo = lo_of(opcode);
3787 Char hi = hi_of(opcode);
3788 ::fprintf(file, " 0x%08X, // %u: ", opcode, i);
3789 if (is_opcode_redo(opcode))
3790 {
3791 ::fprintf(file, "REDO\n");
3792 }
3793 else if (is_opcode_take(opcode))
3794 {
3795 ::fprintf(file, "TAKE %u\n", long_index_of(opcode));
3796 }
3797 else if (is_opcode_tail(opcode))
3798 {
3799 ::fprintf(file, "TAIL %u\n", long_index_of(opcode));
3800 }
3801 else if (is_opcode_head(opcode))
3802 {
3803 ::fprintf(file, "HEAD %u\n", long_index_of(opcode));
3804 }
3805 else if (is_opcode_halt(opcode))
3806 {
3807 ::fprintf(file, "HALT\n");
3808 }
3809 else
3810 {

Callers

nothing calls this directly

Calls 6

print_charFunction · 0.85
atMethod · 0.80
fopen_sFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected