Class: Puppet::Pops::Model::ModelTreeDumper
Overview
Dumps a Pops::Model in reverse polish notation; i.e. LISP style The intention is to use this for debugging output TODO: BAD NAME - A DUMP is a Ruby Serialization
Instance Attribute Summary
Attributes inherited from TreeDumper
#indent_count
Instance Method Summary
collapse
Methods inherited from TreeDumper
#do_dump, #dump, #format, #format_r, #indent, #initialize
Instance Method Details
#dump_AccessExpression(o) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 47
def dump_AccessExpression o
if o.keys.size <= 1
["slice", do_dump(o.left_expr), do_dump(o.keys[0])]
else
["slice", do_dump(o.left_expr), do_dump(o.keys)]
end
end
|
#dump_AndExpression(o) ⇒ Object
99
100
101
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 99
def dump_AndExpression o
["&&", do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_ArithmeticExpression(o) ⇒ Object
42
43
44
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 42
def dump_ArithmeticExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_Array(o) ⇒ Object
8
9
10
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 8
def dump_Array o
o.collect { |e| do_dump(e) }
end
|
#dump_AssignmentExpression(o) ⇒ Object
111
112
113
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 111
def dump_AssignmentExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_AttributeOperation(o) ⇒ Object
Produces (name => expr) or (name +> expr)
116
117
118
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 116
def dump_AttributeOperation o
[o.attribute_name, o.operator, do_dump(o.value_expr)]
end
|
#dump_AttributesOperation(o) ⇒ Object
120
121
122
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 120
def dump_AttributesOperation o
['* =>', do_dump(o.expr)]
end
|
#dump_BlockExpression(o) ⇒ Object
201
202
203
204
205
206
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 201
def dump_BlockExpression o
result = ["block", :indent]
o.statements.each { |x| result << :break; result << do_dump(x) }
result << :dedent << :break
result
end
|
#dump_CallMethodExpression(o) ⇒ Object
def dump_CallNamedFunctionExpression o
result = [o.rval_required ? "call" : "invoke", do_dump(o.functor_expr)]
o.arguments.collect {|a| result << do_dump(a) }
result
end
357
358
359
360
361
362
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 357
def dump_CallMethodExpression o
result = [o.rval_required ? "call-method" : "invoke-method", do_dump(o.functor_expr)]
o.arguments.collect { |a| result << do_dump(a) }
result << do_dump(o.lambda) if o.lambda
result
end
|
#dump_CallNamedFunctionExpression(o) ⇒ Object
Produces (invoke name args…) when not required to produce an rvalue, and (call name args … ) otherwise.
344
345
346
347
348
349
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 344
def dump_CallNamedFunctionExpression o
result = [o.rval_required ? "call" : "invoke", do_dump(o.functor_expr)]
o.arguments.collect { |a| result << do_dump(a) }
result << do_dump(o.lambda) if o.lambda
result
end
|
#dump_CaseExpression(o) ⇒ Object
364
365
366
367
368
369
370
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 364
def dump_CaseExpression o
result = ["case", do_dump(o.test), :indent]
o.options.each do |s|
result << :break << do_dump(s)
end
result << :dedent
end
|
#dump_CaseOption(o) ⇒ Object
372
373
374
375
376
377
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 372
def dump_CaseOption o
result = ["when"]
result << o.values.collect { |x| do_dump(x) }
result << ["then", do_dump(o.then_expr)]
result
end
|
#dump_CollectExpression(o) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 59
def dump_CollectExpression o
result = ["collect", do_dump(o.type_expr), :indent, :break, do_dump(o.query), :indent]
o.operations do |ao|
result << :break << do_dump(ao)
end
result += [:dedent, :dedent]
result
end
|
#dump_ComparisonExpression(o) ⇒ Object
95
96
97
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 95
def dump_ComparisonExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_ConcatenatedString(o) ⇒ Object
Interpolated strings are shown as (cat seg0 seg1 … segN)
209
210
211
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 209
def dump_ConcatenatedString o
["cat"] + o.segments.collect { |x| do_dump(x) }
end
|
#dump_EppExpression(o) ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 68
def dump_EppExpression o
result = ["epp"]
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_ExportedQuery(o) ⇒ Object
79
80
81
82
83
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 79
def dump_ExportedQuery o
result = ["<<| |>>"]
result += dump_QueryExpression(o) unless is_nop?(o.expr)
result
end
|
#dump_Factory(o) ⇒ Object
37
38
39
40
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 37
def dump_Factory o
o['locator'] ||= Puppet::Pops::Parser::Locator.locator("<not from source>", nil)
do_dump(o.model)
end
|
#dump_FunctionDefinition(o) ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 264
def dump_FunctionDefinition o
result = ['function', o.name]
result << ['parameters'] + o.parameters.collect { |p| do_dump(p) } if o.parameters.size() > 0
result << ['return_type', do_dump(o.return_type)] unless o.return_type.nil?
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_HeredocExpression(o) ⇒ Object
213
214
215
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 213
def dump_HeredocExpression(o)
["@(#{o.syntax})", :indent, :break, do_dump(o.text_expr), :dedent, :break]
end
|
#dump_HostClassDefinition(o) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 217
def dump_HostClassDefinition o
result = ["class", o.name]
result << ["inherits", o.parent_class] if o.parent_class
result << ["parameters"] + o.parameters.collect { |p| do_dump(p) } if o.parameters.size() > 0
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_IfExpression(o) ⇒ Object
321
322
323
324
325
326
327
328
329
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 321
def dump_IfExpression o
result = ["if", do_dump(o.test), :indent, :break,
["then", :indent, do_dump(o.then_expr), :dedent]]
result +=
[:break,
["else", :indent, do_dump(o.else_expr), :dedent],
:dedent] unless is_nop? o.else_expr
result
end
|
#dump_InExpression(o) ⇒ Object
107
108
109
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 107
def dump_InExpression o
["in", do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_KeyedEntry(o) ⇒ Object
132
133
134
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 132
def dump_KeyedEntry o
[do_dump(o.key), do_dump(o.value)]
end
|
#dump_LambdaExpression(o) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 144
def dump_LambdaExpression o
result = ["lambda"]
result << ["parameters"] + o.parameters.collect { |p| do_dump(p) } if o.parameters.size() > 0
result << ['return_type', do_dump(o.return_type)] unless o.return_type.nil?
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_LiteralDefault(o) ⇒ Object
156
157
158
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 156
def dump_LiteralDefault o
":default"
end
|
#dump_LiteralFloat(o) ⇒ Object
12
13
14
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 12
def dump_LiteralFloat o
o.value.to_s
end
|
#dump_LiteralHash(o) ⇒ Object
128
129
130
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 128
def dump_LiteralHash o
["{}"] + o.entries.collect { |x| do_dump(x) }
end
|
#dump_LiteralInteger(o) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 16
def dump_LiteralInteger o
case o.radix
when 10
o.value.to_s
when 8
"0%o" % o.value
when 16
"0x%X" % o.value
else
"bad radix:" + o.value.to_s
end
end
|
#dump_LiteralList(o) ⇒ Object
124
125
126
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 124
def dump_LiteralList o
["[]"] + o.values.collect { |x| do_dump(x) }
end
|
#dump_LiteralRegularExpression(o) ⇒ Object
#dump_LiteralString(o) ⇒ Object
140
141
142
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 140
def dump_LiteralString o
"'#{o.value}'"
end
|
#dump_LiteralUndef(o) ⇒ Object
160
161
162
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 160
def dump_LiteralUndef o
":undef"
end
|
#dump_LiteralValue(o) ⇒ Object
29
30
31
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 29
def dump_LiteralValue o
o.value.to_s
end
|
#dump_MatchesExpression(o) ⇒ Object
55
56
57
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 55
def dump_MatchesExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_MatchExpression(o) ⇒ Object
136
137
138
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 136
def dump_MatchExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_NamedAccessExpression(o) ⇒ Object
172
173
174
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 172
def dump_NamedAccessExpression o
[".", do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_NamedDefinition(o) ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 252
def dump_NamedDefinition o
result = [nil, o.name]
result << ["parameters"] + o.parameters.collect { |p| do_dump(p) } if o.parameters.size() > 0
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_NilClass(o) ⇒ Object
176
177
178
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 176
def dump_NilClass o
"()"
end
|
#dump_NodeDefinition(o) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 240
def dump_NodeDefinition o
result = ["node"]
result << ["matches"] + o.host_matches.collect { |m| do_dump(m) }
result << ["parent", do_dump(o.parent)] if o.parent
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_Nop(o) ⇒ Object
168
169
170
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 168
def dump_Nop o
":nop"
end
|
#dump_NotExpression(o) ⇒ Object
180
181
182
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 180
def dump_NotExpression o
['!', dump(o.expr)]
end
|
#dump_Object(o) ⇒ Object
440
441
442
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 440
def dump_Object o
[o.class.to_s, o.to_s]
end
|
#dump_OrExpression(o) ⇒ Object
103
104
105
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 103
def dump_OrExpression o
["||", do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_Parameter(o) ⇒ Object
Produces parameters as name, or (= name value)
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 297
def dump_Parameter o
name_prefix = o.captures_rest ? '*' : ''
name_part = "#{name_prefix}#{o.name}"
if o.value && o.type_expr
["=t", do_dump(o.type_expr), name_part, do_dump(o.value)]
elsif o.value
["=", name_part, do_dump(o.value)]
elsif o.type_expr
["t", do_dump(o.type_expr), name_part]
else
name_part
end
end
|
#dump_ParenthesizedExpression(o) ⇒ Object
311
312
313
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 311
def dump_ParenthesizedExpression o
do_dump(o.expr)
end
|
#dump_PlanDefinition(o) ⇒ Object
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 229
def dump_PlanDefinition o
result = ["plan", o.name]
result << ["parameters"] + o.parameters.collect { |p| do_dump(p) } if o.parameters.size() > 0
if o.body
result << do_dump(o.body)
else
result << []
end
result
end
|
#dump_Program(o) ⇒ Object
Hides that Program exists in the output (only its body is shown), the definitions are just references to contained classes, resource types, and nodes
317
318
319
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 317
def dump_Program(o)
dump(o.body)
end
|
#dump_QualifiedReference(o) ⇒ Object
33
34
35
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 33
def dump_QualifiedReference o
o.cased_value.to_s
end
|
#dump_QueryExpression(o) ⇒ Object
91
92
93
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 91
def dump_QueryExpression o
[do_dump(o.expr)]
end
|
#dump_RelationshipExpression(o) ⇒ Object
379
380
381
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 379
def dump_RelationshipExpression o
[o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end
|
#dump_RenderExpression(o) ⇒ Object
387
388
389
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 387
def dump_RenderExpression o
["render", do_dump(o.expr)]
end
|
#dump_RenderStringExpression(o) ⇒ Object
383
384
385
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 383
def dump_RenderStringExpression o
["render-s", " '#{o.value}'"]
end
|
#dump_ReservedWord(o) ⇒ Object
292
293
294
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 292
def dump_ReservedWord o
['reserved', o.word]
end
|
#dump_ResourceBody(o) ⇒ Object
391
392
393
394
395
396
397
398
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 391
def dump_ResourceBody o
result = [do_dump(o.title), :indent]
o.operations.each do |p|
result << :break << do_dump(p)
end
result << :dedent
result
end
|
#dump_ResourceDefaultsExpression(o) ⇒ Object
400
401
402
403
404
405
406
407
408
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 400
def dump_ResourceDefaultsExpression o
form = o.form == 'regular' ? '' : o.form + '-'
result = [form + 'resource-defaults', do_dump(o.type_ref), :indent]
o.operations.each do |p|
result << :break << do_dump(p)
end
result << :dedent
result
end
|
#dump_ResourceExpression(o) ⇒ Object
410
411
412
413
414
415
416
417
418
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 410
def dump_ResourceExpression o
form = o.form == 'regular' ? '' : o.form + '-'
result = [form + 'resource', do_dump(o.type_name), :indent]
o.bodies.each do |b|
result << :break << do_dump(b)
end
result << :dedent
result
end
|
#dump_ResourceOverrideExpression(o) ⇒ Object
282
283
284
285
286
287
288
289
290
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 282
def dump_ResourceOverrideExpression o
form = o.form == 'regular' ? '' : o.form + '-'
result = [form + 'override', do_dump(o.resources), :indent]
o.operations.each do |p|
result << :break << do_dump(p)
end
result << :dedent
result
end
|
#dump_ResourceTypeDefinition(o) ⇒ Object
276
277
278
279
280
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 276
def dump_ResourceTypeDefinition o
result = dump_NamedDefinition(o)
result[0] = 'define'
result
end
|
#dump_SelectorEntry(o) ⇒ Object
424
425
426
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 424
def dump_SelectorEntry o
[do_dump(o.matching_expr), "=>", do_dump(o.value_expr)]
end
|
#dump_SelectorExpression(o) ⇒ Object
420
421
422
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 420
def dump_SelectorExpression o
["?", do_dump(o.left_expr)] + o.selectors.collect { |x| do_dump(x) }
end
|
#dump_TextExpression(o) ⇒ Object
Interpolation (to string) shown as (str expr)
189
190
191
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 189
def dump_TextExpression o
["str", do_dump(o.expr)]
end
|
#dump_TypeAlias(o) ⇒ Object
428
429
430
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 428
def dump_TypeAlias(o)
['type-alias', o.name, do_dump(o.type_expr)]
end
|
#dump_TypeDefinition(o) ⇒ Object
436
437
438
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 436
def dump_TypeDefinition(o)
['type-definition', o.name, o.parent, do_dump(o.body)]
end
|
#dump_TypeMapping(o) ⇒ Object
432
433
434
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 432
def dump_TypeMapping(o)
['type-mapping', do_dump(o.type_expr), do_dump(o.mapping_expr)]
end
|
#dump_UnaryMinusExpression(o) ⇒ Object
193
194
195
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 193
def dump_UnaryMinusExpression o
['-', do_dump(o.expr)]
end
|
#dump_UnfoldExpression(o) ⇒ Object
197
198
199
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 197
def dump_UnfoldExpression o
['unfold', do_dump(o.expr)]
end
|
#dump_UnlessExpression(o) ⇒ Object
331
332
333
334
335
336
337
338
339
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 331
def dump_UnlessExpression o
result = ["unless", do_dump(o.test), :indent, :break,
["then", :indent, do_dump(o.then_expr), :dedent]]
result +=
[:break,
["else", :indent, do_dump(o.else_expr), :dedent],
:dedent] unless is_nop? o.else_expr
result
end
|
#dump_VariableExpression(o) ⇒ Object
184
185
186
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 184
def dump_VariableExpression o
"$#{dump(o.expr)}"
end
|
#dump_VirtualQuery(o) ⇒ Object
85
86
87
88
89
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 85
def dump_VirtualQuery o
result = ["<| |>"]
result += dump_QueryExpression(o) unless is_nop?(o.expr)
result
end
|
#is_nop?(o) ⇒ Boolean
444
445
446
|
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 444
def is_nop? o
o.nil? || o.is_a?(Puppet::Pops::Model::Nop)
end
|