src
output.h
Go to the documentation of this file.
1 #ifndef _RE2C_CODEGEN_OUTPUT_
2 #define _RE2C_CODEGEN_OUTPUT_
3 
4 #include "src/util/c99_stdint.h"
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <fstream>
8 #include <set>
9 #include <sstream>
10 #include <string>
11 #include <vector>
12 
13 #include "src/codegen/label.h"
14 #include "src/util/counter.h"
15 #include "src/util/forbid_copy.h"
16 
17 namespace re2c
18 {
19 
20 class rule_rank_t;
21 
23 {
24  enum type_t
25  { CODE
26 // , CONFIG
33  };
34 
36  std::ostringstream stream;
37  uint32_t indent;
38 
39  OutputFragment (type_t t, uint32_t i);
40  uint32_t count_lines ();
41 };
42 
44 {
45  std::vector<OutputFragment *> fragments;
48  std::string user_start_label;
49  uint32_t line;
50 
51  OutputBlock ();
52  ~OutputBlock ();
53 };
54 
55 struct OutputFile
56 {
57 public:
58  const char * file_name;
59 
60 private:
61  FILE * file;
62  std::vector<OutputBlock *> blocks;
63 
64 public:
67 
68 private:
69  std::ostream & stream ();
70  void insert_code ();
71 
72 public:
73  OutputFile (const char * fn);
74  ~OutputFile ();
75 
76  bool open ();
77 
78  void new_block ();
79 
80  // immediate output
81  OutputFile & wraw (const char * s, size_t n);
82  OutputFile & wc (char c);
83  OutputFile & wc_hex (uint32_t n);
84  OutputFile & wu32 (uint32_t n);
85  OutputFile & wu32_hex (uint32_t n);
86  OutputFile & wu32_width (uint32_t n, int w);
87  OutputFile & wu64 (uint64_t n);
88  OutputFile & wstring (const std::string & s);
89  OutputFile & ws (const char * s);
92  OutputFile & wrange (uint32_t u, uint32_t l);
93  OutputFile & wline_info (uint32_t l, const char * fn);
96  OutputFile & wind (uint32_t ind);
97 
98  // delayed output
100  OutputFile & wdelay_state_goto (uint32_t ind);
103  OutputFile & wdelay_yyaccept_init (uint32_t ind);
105 
106  void set_used_yyaccept ();
107  bool get_used_yyaccept () const;
108  void set_force_start_label (bool force);
109  void set_user_start_label (const std::string & label);
110  bool get_force_start_label () const;
111  void set_block_line (uint32_t l);
112  uint32_t get_block_line () const;
113 
114  void emit (const std::vector<std::string> & types, size_t max_fill);
115 
117 };
118 
120 {
121  HeaderFile (const char * fn);
122  ~HeaderFile ();
123  bool open ();
124  void emit (const std::vector<std::string> & types);
125 
126 private:
127  std::ostringstream stream;
128  const char * file_name;
129  FILE * file;
130 
131  FORBID_COPY (HeaderFile);
132 };
133 
134 struct Output
135 {
138  std::vector<std::string> types;
139  std::set<std::string> skeletons;
140  size_t max_fill;
141 
142  Output (const char * source_name, const char * header_name);
143  ~Output ();
144 };
145 
146 void output_line_info (std::ostream &, uint32_t, const char *);
147 void output_state_goto (std::ostream &, uint32_t, uint32_t);
148 void output_types (std::ostream &, uint32_t, const std::vector<std::string> &);
149 void output_version_time (std::ostream &);
150 void output_yyaccept_init (std::ostream &, uint32_t, bool);
151 void output_yymaxfill (std::ostream &, size_t);
152 
153 // helpers
154 std::string output_get_state ();
155 
156 } // namespace re2c
157 
158 #endif // _RE2C_CODEGEN_OUTPUT_
OutputFile & wdelay_warn_condition_order()
Definition: output.cc:228
HeaderFile(const char *fn)
Definition: output.cc:338
void output_line_info(std::ostream &o, uint32_t line_number, const char *file_name)
Definition: output.cc:424
size_t max_fill
Definition: output.h:140
OutputFragment(type_t t, uint32_t i)
Definition: output.cc:16
FORBID_COPY(OutputFile)
bool get_used_yyaccept() const
Definition: output.cc:254
void new_block()
Definition: output.cc:284
uint32_t indent
Definition: output.h:37
OutputFile & wuser_start_label()
Definition: output.cc:139
std::vector< std::string > types
Definition: output.h:138
std::ostringstream stream
Definition: output.h:36
OutputFile & wversion_time()
Definition: output.cc:133
OutputFile & ws(const char *s)
Definition: output.cc:173
OutputFile & wu32(uint32_t n)
Definition: output.cc:155
void set_used_yyaccept()
Definition: output.cc:249
OutputFile & wdelay_state_goto(uint32_t ind)
Definition: output.cc:209
OutputFile & wdelay_yymaxfill()
Definition: output.cc:242
OutputFile & wind(uint32_t ind)
Definition: output.cc:191
OutputFile & wlabel(label_t l)
Definition: output.cc:179
OutputFile source
Definition: output.h:136
void output_state_goto(std::ostream &o, uint32_t ind, uint32_t start_label)
Definition: output.cc:388
OutputFile & wdelay_types()
Definition: output.cc:220
OutputFile & wc(char c)
Definition: output.cc:149
HeaderFile header
Definition: output.h:137
OutputFile & wc_hex(uint32_t n)
Definition: output.cc:108
bool force_start_label
Definition: output.h:47
OutputFile & wrange(uint32_t u, uint32_t l)
Definition: output.cc:114
std::string user_start_label
Definition: output.h:48
OutputFile & wdelay_line_info()
Definition: output.cc:202
void output_types(std::ostream &o, uint32_t ind, const std::vector< std::string > &types)
Definition: output.cc:432
OutputFile & wu64(uint64_t n)
Definition: output.cc:161
void emit(const std::vector< std::string > &types, size_t max_fill)
Definition: output.cc:291
OutputFile(const char *fn)
Definition: output.cc:55
std::string output_get_state()
Definition: output.cc:458
Output(const char *source_name, const char *header_name)
Definition: output.cc:371
void emit(const std::vector< std::string > &types)
Definition: output.cc:353
bool warn_condition_order
Definition: output.h:66
bool open()
Definition: output.cc:65
void set_block_line(uint32_t l)
Definition: output.cc:274
OutputFile & wdelay_yyaccept_init(uint32_t ind)
Definition: output.cc:235
const char * file_name
Definition: output.h:58
uint32_t count_lines()
Definition: output.cc:22
bool used_yyaccept
Definition: output.h:46
void output_version_time(std::ostream &o)
Definition: output.cc:442
OutputFile & wu32_hex(uint32_t n)
Definition: output.cc:102
bool get_force_start_label() const
Definition: output.cc:269
OutputFile & wraw(const char *s, size_t n)
Definition: output.cc:96
std::vector< OutputFragment * > fragments
Definition: output.h:45
void output_yymaxfill(std::ostream &o, size_t max_fill)
Definition: output.cc:419
uint32_t get_block_line() const
Definition: output.cc:279
OutputFile & wrank(rule_rank_t l)
Definition: output.cc:185
OutputFile & wu32_width(uint32_t n, int w)
Definition: output.cc:120
void set_user_start_label(const std::string &label)
Definition: output.cc:264
counter_t< label_t > label_counter
Definition: output.h:65
Definition: bitmap.cc:10
void output_yyaccept_init(std::ostream &o, uint32_t ind, bool used_yyaccept)
Definition: output.cc:411
uint32_t line
Definition: output.h:49
OutputFile & wline_info(uint32_t l, const char *fn)
Definition: output.cc:127
std::set< std::string > skeletons
Definition: output.h:139
OutputFile & wstring(const std::string &s)
Definition: output.cc:167
void set_force_start_label(bool force)
Definition: output.cc:259