Class: Puppet::Pops::Model::ModelTreeDumper

Inherits:
TreeDumper show all
Defined in:
lib/puppet/pops/model/model_tree_dumper.rb

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

Constructor Details

This class inherits a constructor from Puppet::Pops::Model::TreeDumper

Instance Method Details

#dump_AccessExpression(o) ⇒ Object

x prints as (slice x y)


45
46
47
48
49
50
51
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 45

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


97
98
99
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 97

def dump_AndExpression o
  ["&&", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_ArithmeticExpression(o) ⇒ Object


40
41
42
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 40

def dump_ArithmeticExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_Array(o) ⇒ Object


6
7
8
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 6

def dump_Array o
  o.collect {|e| do_dump(e) }
end

#dump_AssignmentExpression(o) ⇒ Object


109
110
111
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 109

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)


114
115
116
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 114

def dump_AttributeOperation o
  [o.attribute_name, o.operator, do_dump(o.value_expr)]
end

#dump_AttributesOperation(o) ⇒ Object


118
119
120
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 118

def dump_AttributesOperation o
  ['* =>', do_dump(o.expr)]
end

#dump_BlockExpression(o) ⇒ Object


199
200
201
202
203
204
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 199

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

355
356
357
358
359
360
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 355

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.


342
343
344
345
346
347
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 342

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


362
363
364
365
366
367
368
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 362

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


370
371
372
373
374
375
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 370

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


57
58
59
60
61
62
63
64
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 57

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


93
94
95
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 93

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)


207
208
209
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 207

def dump_ConcatenatedString o
  ["cat"] + o.segments.collect {|x| do_dump(x)}
end

#dump_EppExpression(o) ⇒ Object


66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 66

def dump_EppExpression o
  result = ["epp"]
#    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_ExportedQuery(o) ⇒ Object


77
78
79
80
81
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 77

def dump_ExportedQuery o
  result = ["<<| |>>"]
  result += dump_QueryExpression(o) unless is_nop?(o.expr)
  result
end

#dump_Factory(o) ⇒ Object


35
36
37
38
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 35

def dump_Factory o
  o['locator'] ||= Puppet::Pops::Parser::Locator.locator("<not from source>", nil)
  do_dump(o.model)
end

#dump_FunctionDefinition(o) ⇒ Object


262
263
264
265
266
267
268
269
270
271
272
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 262

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


211
212
213
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 211

def dump_HeredocExpression(o)
  ["@(#{o.syntax})", :indent, :break, do_dump(o.text_expr), :dedent, :break]
end

#dump_HostClassDefinition(o) ⇒ Object


215
216
217
218
219
220
221
222
223
224
225
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 215

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


319
320
321
322
323
324
325
326
327
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 319

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


105
106
107
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 105

def dump_InExpression o
  ["in", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_KeyedEntry(o) ⇒ Object


130
131
132
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 130

def dump_KeyedEntry o
  [do_dump(o.key), do_dump(o.value)]
end

#dump_LambdaExpression(o) ⇒ Object


142
143
144
145
146
147
148
149
150
151
152
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 142

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


154
155
156
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 154

def dump_LiteralDefault o
  ":default"
end

#dump_LiteralFloat(o) ⇒ Object


10
11
12
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 10

def dump_LiteralFloat o
  o.value.to_s
end

#dump_LiteralHash(o) ⇒ Object


126
127
128
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 126

def dump_LiteralHash o
  ["{}"] + o.entries.collect {|x| do_dump(x)}
end

#dump_LiteralInteger(o) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 14

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


122
123
124
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 122

def dump_LiteralList o
  ["[]"] + o.values.collect {|x| do_dump(x)}
end

#dump_LiteralRegularExpression(o) ⇒ Object


162
163
164
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 162

def dump_LiteralRegularExpression o
  Puppet::Pops::Types::StringConverter.convert(o.value, '%p')
end

#dump_LiteralString(o) ⇒ Object


138
139
140
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 138

def dump_LiteralString o
  "'#{o.value}'"
end

#dump_LiteralUndef(o) ⇒ Object


158
159
160
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 158

def dump_LiteralUndef o
  ":undef"
end

#dump_LiteralValue(o) ⇒ Object


27
28
29
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 27

def dump_LiteralValue o
  o.value.to_s
end

#dump_MatchesExpression(o) ⇒ Object


53
54
55
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 53

def dump_MatchesExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_MatchExpression(o) ⇒ Object


134
135
136
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 134

def dump_MatchExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_NamedAccessExpression(o) ⇒ Object


170
171
172
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 170

def dump_NamedAccessExpression o
  [".", do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_NamedDefinition(o) ⇒ Object


250
251
252
253
254
255
256
257
258
259
260
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 250

def dump_NamedDefinition o
  # the nil must be replaced with a string
  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


174
175
176
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 174

def dump_NilClass o
  "()"
end

#dump_NodeDefinition(o) ⇒ Object


238
239
240
241
242
243
244
245
246
247
248
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 238

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


166
167
168
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 166

def dump_Nop o
  ":nop"
end

#dump_NotExpression(o) ⇒ Object


178
179
180
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 178

def dump_NotExpression o
  ['!', dump(o.expr)]
end

#dump_Object(o) ⇒ Object


438
439
440
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 438

def dump_Object o
  [o.class.to_s, o.to_s]
end

#dump_OrExpression(o) ⇒ Object


101
102
103
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 101

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)


295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 295

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


309
310
311
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 309

def dump_ParenthesizedExpression o
  do_dump(o.expr)
end

#dump_PlanDefinition(o) ⇒ Object


227
228
229
230
231
232
233
234
235
236
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 227

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


315
316
317
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 315

def dump_Program(o)
  dump(o.body)
end

#dump_QualifiedReference(o) ⇒ Object


31
32
33
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 31

def dump_QualifiedReference o
  o.cased_value.to_s
end

#dump_QueryExpression(o) ⇒ Object


89
90
91
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 89

def dump_QueryExpression o
  [do_dump(o.expr)]
end

#dump_RelationshipExpression(o) ⇒ Object


377
378
379
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 377

def dump_RelationshipExpression o
  [o.operator.to_s, do_dump(o.left_expr), do_dump(o.right_expr)]
end

#dump_RenderExpression(o) ⇒ Object


385
386
387
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 385

def dump_RenderExpression o
  ["render", do_dump(o.expr)]
end

#dump_RenderStringExpression(o) ⇒ Object


381
382
383
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 381

def dump_RenderStringExpression o
  ["render-s", " '#{o.value}'"]
end

#dump_ReservedWord(o) ⇒ Object


290
291
292
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 290

def dump_ReservedWord o
  [ 'reserved', o.word ]
end

#dump_ResourceBody(o) ⇒ Object


389
390
391
392
393
394
395
396
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 389

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


398
399
400
401
402
403
404
405
406
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 398

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


408
409
410
411
412
413
414
415
416
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 408

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


280
281
282
283
284
285
286
287
288
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 280

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


274
275
276
277
278
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 274

def dump_ResourceTypeDefinition o
  result = dump_NamedDefinition(o)
  result[0] = 'define'
  result
end

#dump_SelectorEntry(o) ⇒ Object


422
423
424
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 422

def dump_SelectorEntry o
  [do_dump(o.matching_expr), "=>", do_dump(o.value_expr)]
end

#dump_SelectorExpression(o) ⇒ Object


418
419
420
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 418

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)


187
188
189
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 187

def dump_TextExpression o
  ["str", do_dump(o.expr)]
end

#dump_TypeAlias(o) ⇒ Object


426
427
428
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 426

def dump_TypeAlias(o)
  ['type-alias', o.name, do_dump(o.type_expr)]
end

#dump_TypeDefinition(o) ⇒ Object


434
435
436
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 434

def dump_TypeDefinition(o)
  ['type-definition', o.name, o.parent, do_dump(o.body)]
end

#dump_TypeMapping(o) ⇒ Object


430
431
432
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 430

def dump_TypeMapping(o)
  ['type-mapping', do_dump(o.type_expr), do_dump(o.mapping_expr)]
end

#dump_UnaryMinusExpression(o) ⇒ Object


191
192
193
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 191

def dump_UnaryMinusExpression o
  ['-', do_dump(o.expr)]
end

#dump_UnfoldExpression(o) ⇒ Object


195
196
197
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 195

def dump_UnfoldExpression o
  ['unfold', do_dump(o.expr)]
end

#dump_UnlessExpression(o) ⇒ Object


329
330
331
332
333
334
335
336
337
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 329

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


182
183
184
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 182

def dump_VariableExpression o
  "$#{dump(o.expr)}"
end

#dump_VirtualQuery(o) ⇒ Object


83
84
85
86
87
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 83

def dump_VirtualQuery o
  result = ["<| |>"]
  result += dump_QueryExpression(o) unless is_nop?(o.expr)
  result
end

#is_nop?(o) ⇒ Boolean

Returns:

  • (Boolean)

442
443
444
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 442

def is_nop? o
  o.nil? || o.is_a?(Puppet::Pops::Model::Nop)
end