-/* Generated by re2c 1.0.3 on Sat Apr 14 00:20:54 2018 */
+/* Generated by re2c 1.0.3 on Sat Apr 14 21:01:06 2018 */
#line 1 "../src/ast/lex.re"
#include "src/util/c99_stdint.h"
#include <stddef.h>
#line 115 "../src/ast/lex.re"
{
out.wraw(tok, ptr);
- out.wdelay_line_info();
+ out.wdelay_line_info_output();
out.wdelay_types();
- out.wline_info(cline, get_fname().c_str());
+ out.wdelay_line_info_input(cline, get_fname());
lex_end_of_comment(out);
goto echo;
}
{
if (ignored > 0) {
cline += ignored;
- out.wline_info(cline, get_fname().c_str());
+ out.wdelay_line_info_input(cline, get_fname());
}
tok = pos = cur;
return;
"/*!types:re2c" {
out.wraw(tok, ptr);
- out.wdelay_line_info();
+ out.wdelay_line_info_output();
out.wdelay_types();
- out.wline_info(cline, get_fname().c_str());
+ out.wdelay_line_info_input(cline, get_fname());
lex_end_of_comment(out);
goto echo;
}
eoc {
if (ignored > 0) {
cline += ignored;
- out.wline_info(cline, get_fname().c_str());
+ out.wdelay_line_info_input(cline, get_fname());
}
tok = pos = cur;
return;
if (!dfa.setup.empty()) {
o.wind(ind).wstring(dfa.setup).ws("\n");
}
- o.wline_info(code->fline, code->fname.c_str())
+ o.wdelay_line_info_input(code->fline, code->fname)
.wind(ind).wstring(code->text).ws("\n")
- .wdelay_line_info();
+ .wdelay_line_info_output();
} else if (!cond.empty()) {
strrreplace(s = opts->condGoto, opts->condGotoParam, opts->condPrefix + cond);
o.wind(ind).wstring(s).ws("\n");
// Generate prolog
if (bProlog)
{
- o.ws("\n").wdelay_line_info ();
+ o.ws("\n").wdelay_line_info_output ();
if ((!opts->fFlag && ob.used_yyaccept)
|| (!opts->fFlag && opts->bEmitYYCh)
|| (opts->bFlag && !opts->cFlag && !bitmaps.empty())
OutputFragment::~OutputFragment()
{
- if (type == STAGS || type == MTAGS) delete tags;
+ if (type == STAGS || type == MTAGS) {
+ delete tags;
+ } else if (type == LINE_INFO_INPUT) {
+ delete line_info;
+ }
}
uint32_t OutputFragment::count_lines () const
OutputBlock::OutputBlock ()
: fragments ()
, used_yyaccept (false)
+ , have_user_code (false)
, line (0)
, types ()
, stags ()
OutputFile &OutputFile::wraw(const char *s, const char *e)
{
- if (block().opts->target == TARGET_CODE) {
+ if (s != e && block().opts->target == TARGET_CODE) {
insert_code();
+ // scan for non-whitespace characters
+ bool &code = block().have_user_code;
+ for (const char *p = s; !code && p < e; ++p) {
+ code = !isspace(*p);
+ }
+
// convert CR LF to LF
std::ostream &o = stream();
for (const char *p = s;; ++p) {
return *this;
}
-OutputFile & OutputFile::wline_info (uint32_t l, const char * fn)
-{
- insert_code();
- output_line_info (stream (), l, fn, block().opts->iFlag);
- return *this;
-}
-
OutputFile & OutputFile::wversion_time ()
{
insert_code();
return *this;
}
-OutputFile & OutputFile::wdelay_line_info ()
+OutputFile & OutputFile::wdelay_line_info_input (uint32_t l, const std::string &fn)
+{
+ OutputFragment *frag = new OutputFragment(OutputFragment::LINE_INFO_INPUT, 0);
+ frag->line_info = new LineInfo(l, fn);
+ blocks.back()->fragments.push_back(frag);
+ return *this;
+}
+
+OutputFile & OutputFile::wdelay_line_info_output ()
{
- block().fragments.push_back (new OutputFragment (OutputFragment::LINE_INFO, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::LINE_INFO_OUTPUT, 0));
return *this;
}
opts.reset_startlabel();
}
+void OutputFile::fix_first_block_opts()
+{
+ // If the initial block contains only whitespace and no user code,
+ // then re2c options specified in the first re2c block are also
+ // applied to the initial block.
+ if (blocks.size() >= 2) {
+ OutputBlock
+ *fst = blocks[0],
+ *snd = blocks[1];
+ if (!fst->have_user_code) {
+ *const_cast<opt_t *>(fst->opts) = *snd->opts;
+ }
+ }
+}
+
void OutputFile::global_lists(uniq_vector_t<std::string> &types,
std::set<std::string> &stags, std::set<std::string> &mtags) const
{
}
}
+ fix_first_block_opts();
+
unsigned int line_count = 1;
for (unsigned int j = 0; j < blocks.size(); ++j) {
OutputBlock & b = * blocks[j];
switch (f.type) {
case OutputFragment::EMPTY:
case OutputFragment::CODE: break;
- case OutputFragment::LINE_INFO:
+ case OutputFragment::LINE_INFO_INPUT:
+ output_line_info(o, f.line_info->line, f.line_info->filename, bopt->iFlag);
+ break;
+ case OutputFragment::LINE_INFO_OUTPUT:
output_line_info(o, line_count + 1, filename, bopt->iFlag);
break;
case OutputFragment::COND_GOTO:
: format(f), separator(s) {}
};
+struct LineInfo
+{
+ uint32_t line;
+ std::string filename;
+
+ LineInfo(uint32_t l, const std::string &fn)
+ : line(l), filename(fn) {}
+};
+
struct OutputFragment
{
enum type_t
// , CONFIG
, COND_GOTO
, COND_TABLE
- , LINE_INFO
+ , LINE_INFO_INPUT
+ , LINE_INFO_OUTPUT
, STATE_GOTO
, STAGS
, MTAGS
uint32_t indent;
union
{
- const ConfTags* tags;
+ const ConfTags *tags;
+ const LineInfo *line_info;
};
OutputFragment (type_t t, uint32_t i);
{
std::vector<OutputFragment *> fragments;
bool used_yyaccept;
+ bool have_user_code;
uint32_t line;
std::vector<std::string> types;
std::set<std::string> stags;
OutputFile & ws (const char * s);
OutputFile & wlabel (label_t l);
OutputFile & wrange (uint32_t u, uint32_t l);
- OutputFile & wline_info (uint32_t l, const char * fn);
OutputFile & wversion_time ();
OutputFile & wuser_start_label ();
OutputFile & wind (uint32_t ind);
// delayed output
OutputFile & wdelay_tags(const ConfTags *cf, bool mtags);
- OutputFile & wdelay_line_info ();
+ OutputFile & wdelay_line_info_input (uint32_t l, const std::string &fn);
+ OutputFile & wdelay_line_info_output ();
OutputFile & wdelay_cond_goto(uint32_t ind);
OutputFile & wdelay_cond_table(uint32_t ind);
OutputFile & wdelay_state_goto (uint32_t ind);
OutputFile& wdelay_peek(uint32_t ind, bool peek);
OutputFile& wdelay_backup(uint32_t ind, bool backup);
+ void fix_first_block_opts();
void global_lists(uniq_vector_t<std::string> &types,
std::set<std::string> &stags, std::set<std::string> &mtags) const;
typedef std::vector<smart_ptr<DFA> > dfas_t;
o.new_block(opts);
- o.wversion_time().wline_info(input.get_cline(), input.get_fname().c_str());
+ o.wversion_time();
+ o.wdelay_line_info_input(input.get_cline(), input.get_fname());
if (globopts->target == TARGET_SKELETON) {
emit_prolog(o);
}
- for (Scanner::ParseMode mode; (mode = input.echo(o)) != Scanner::Stop;) {
-
+ for (;;) {
+ // parse everything up to the next re2c block
+ Scanner::ParseMode mode = input.echo(o);
+ if (mode == Scanner::Stop) break;
validate_mode(mode, globopts->rFlag, ropts, input);
- // parse next re2c block
+ // parse the next re2c block
specs_t specs;
if (mode == Scanner::Reuse) {
specs = rspecs;
}
}
- o.wline_info (input.get_cline (), input.get_fname ().c_str ());
+ o.wdelay_line_info_input(input.get_cline(), input.get_fname());
}
if (globopts->target == TARGET_SKELETON) {
# undef MUTOPT1
# undef MUTOPT
{}
- FORBID_COPY(opt_t);
};
// see note [constant and mutable options]
/* Generated by re2c */
-#line 1 "config/flags.re"