@@ -51,11 +51,73 @@ static languaget* get_language(
51
51
52
52
std::vector<pretty_printer_factoryt> registered_pretty_printers;
53
53
54
+ /* ******************************************************************\
55
+
56
+ Function: register_global_pretty_printer
57
+
58
+ Inputs: `new_printer`: factory method returning
59
+ `unique_ptr<pretty_printert>`
60
+
61
+ Outputs:
62
+
63
+ Purpose: This registers a custom pretty-printer for use printing
64
+ expressions with `from_expr` and `from_type` also defined
65
+ in language_util.h. The function given should allocate
66
+ an instance of the printer and return a unique_ptr that
67
+ disposes of it appropriately (so if allocated with `new`,
68
+ ordinary `std::unique_ptr` will do the trick).
69
+ `from_expr` and `from_type` will always build a stack of
70
+ printer classes of the form:
71
+ L -> C1 -> C2 ... Cn -> X
72
+
73
+ L is the language frontend pretty-printer associated
74
+ with an expression, C1 ... Cn are instances of the registered
75
+ custom printers in order of registration, and X is the fallback
76
+ irep-to-lisp printer `norep_pretty_printert`. The -> arrows
77
+ represent `next_pretty_printer` fields used to defer printing
78
+ of expressions a particular printer can't handle; all printers
79
+ in the stack also get `top_pretty_printer` set to point at L,
80
+ which they should use when printing subexpressions to give
81
+ the whole stack a chance to provide a representation.
82
+
83
+ Note at present language custom printers such as `expr2javat`
84
+ are subclasses of `expr2ct` rather than using this deferral
85
+ mechanism; thus even when a Java expression is being printed
86
+ there is still only one L in the stack, rather than
87
+ expr2javat -> expr2ct -> C1 ... Cn -> X
88
+ as one might expect. The language printers (in particular
89
+ expr2ct) always assume they are at the top of the stack
90
+ (so top_pretty_printer == this), and will need adapting if
91
+ we want to e.g. place a custom printer *above* expr2ct
92
+ in the future.
93
+
94
+ \*******************************************************************/
95
+
54
96
void register_global_pretty_printer (pretty_printer_factoryt new_printer)
55
97
{
56
98
registered_pretty_printers.push_back (new_printer);
57
99
}
58
100
101
+ /* ******************************************************************\
102
+
103
+ Function: get_pretty_printer_stack
104
+
105
+ Inputs: `ns`: namespace
106
+ `language_printer`: pointer to instance of a pretty-printer
107
+ that should be placed at the head of the printer stack.
108
+
109
+ Outputs:
110
+
111
+ Purpose: (See `register_global_pretty_printer` above for context)
112
+ Takes a reference to language-specific pretty-printer L,
113
+ instantiates custom printers C1 .. Cn if any have been
114
+ registered, creates the fallback norep pretty-printer X,
115
+ and sets their next_ and top_pretty_printer pointers.
116
+ A vector of unique pointers is returned whose back member
117
+ is the head of the stack (L, in the notation used above).
118
+
119
+ \*******************************************************************/
120
+
59
121
static std::vector<std::unique_ptr<pretty_printert>> get_pretty_printer_stack (
60
122
const namespacet &ns,
61
123
std::unique_ptr<pretty_printert> language_printer)
@@ -84,11 +146,17 @@ static std::vector<std::unique_ptr<pretty_printert>> get_pretty_printer_stack(
84
146
85
147
Function: from_expr
86
148
87
- Inputs:
149
+ Inputs: `ns`: global namespace
150
+ `identifier`: symbol-table identifier associated with `expr`
151
+ or the empty string if none
152
+ `expr`: expression to print
88
153
89
- Outputs:
154
+ Outputs: Returns pretty-printed string equivalent of `expr`.
90
155
91
- Purpose:
156
+ Purpose: Pretty-prints an expression. If custom pretty-printers have
157
+ been registered they will be instantiated and may take part
158
+ in printing `expr`; see `register_global_pretty_printer` for
159
+ details.
92
160
93
161
\*******************************************************************/
94
162
@@ -106,11 +174,17 @@ std::string from_expr(
106
174
107
175
Function: from_type
108
176
109
- Inputs:
177
+ Inputs: `ns`: global namespace
178
+ `identifier`: symbol-table identifier associated with `type`
179
+ or the empty string if none
180
+ `type`: type to print
110
181
111
- Outputs:
182
+ Outputs: Returns pretty-printed string equivalent of `type`.
112
183
113
- Purpose:
184
+ Purpose: Pretty-prints an type. If custom pretty-printers have
185
+ been registered they will be instantiated and may take part
186
+ in printing `type`; see `register_global_pretty_printer` for
187
+ details.
114
188
115
189
\*******************************************************************/
116
190
0 commit comments