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)


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

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


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

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

#dump_Application(o) ⇒ Object


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

def dump_Application o
  ["application", o.name, do_dump(o.parameters), do_dump(o.body)]
end

#dump_ArithmeticExpression(o) ⇒ Object


44
45
46
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 44

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


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

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)


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

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

#dump_AttributesOperation(o) ⇒ Object


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

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

#dump_BlockExpression(o) ⇒ Object


203
204
205
206
207
208
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 203

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

373
374
375
376
377
378
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 373

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.


360
361
362
363
364
365
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 360

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_CapabilityMapping(o) ⇒ Object


294
295
296
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 294

def dump_CapabilityMapping o
  [o.kind, do_dump(o.component), o.capability, do_dump(o.mappings)]
end

#dump_CaseExpression(o) ⇒ Object


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

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


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

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


61
62
63
64
65
66
67
68
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 61

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


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

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)


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

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

#dump_EppExpression(o) ⇒ Object


70
71
72
73
74
75
76
77
78
79
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 70

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


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

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


276
277
278
279
280
281
282
283
284
285
286
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 276

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


215
216
217
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 215

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

#dump_HostClassDefinition(o) ⇒ Object


219
220
221
222
223
224
225
226
227
228
229
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 219

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


337
338
339
340
341
342
343
344
345
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 337

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


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

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

#dump_KeyedEntry(o) ⇒ Object


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

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

#dump_LambdaExpression(o) ⇒ Object


146
147
148
149
150
151
152
153
154
155
156
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 146

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


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

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


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

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


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

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

#dump_LiteralRegularExpression(o) ⇒ Object


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

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

#dump_LiteralString(o) ⇒ Object


142
143
144
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 142

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

#dump_LiteralUndef(o) ⇒ Object


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

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


57
58
59
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 57

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

#dump_MatchExpression(o) ⇒ Object


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

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

#dump_NamedAccessExpression(o) ⇒ Object


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

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

#dump_NamedDefinition(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_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


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

def dump_NilClass o
  "()"
end

#dump_NodeDefinition(o) ⇒ Object


242
243
244
245
246
247
248
249
250
251
252
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 242

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


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

def dump_Nop o
  ":nop"
end

#dump_NotExpression(o) ⇒ Object


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

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

#dump_Object(o) ⇒ Object


460
461
462
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 460

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

#dump_OrExpression(o) ⇒ Object


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

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)


313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 313

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


327
328
329
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 327

def dump_ParenthesizedExpression o
  do_dump(o.expr)
end

#dump_PlanDefinition(o) ⇒ Object


231
232
233
234
235
236
237
238
239
240
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 231

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


333
334
335
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 333

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


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

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

#dump_RelationshipExpression(o) ⇒ Object


395
396
397
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 395

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

#dump_RenderExpression(o) ⇒ Object


403
404
405
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 403

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

#dump_RenderStringExpression(o) ⇒ Object


399
400
401
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 399

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

#dump_ReservedWord(o) ⇒ Object


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

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

#dump_ResourceBody(o) ⇒ Object


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

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


416
417
418
419
420
421
422
423
424
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 416

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


426
427
428
429
430
431
432
433
434
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 426

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


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

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


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

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

#dump_SelectorEntry(o) ⇒ Object


440
441
442
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 440

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

#dump_SelectorExpression(o) ⇒ Object


436
437
438
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 436

def dump_SelectorExpression o
  ["?", do_dump(o.left_expr)] + o.selectors.collect {|x| do_dump(x) }
end

#dump_SiteDefinition(o) ⇒ Object


254
255
256
257
258
259
260
261
262
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 254

def dump_SiteDefinition o
  result = ["site"]
  if o.body
    result << do_dump(o.body)
  else
    result << []
  end
  result
end

#dump_SubLocatedExpression(o) ⇒ Object


444
445
446
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 444

def dump_SubLocatedExpression o
  ["sublocated", do_dump(o.expr)]
end

#dump_TextExpression(o) ⇒ Object

Interpolation (to string) shown as (str expr)


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

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

#dump_TypeAlias(o) ⇒ Object


448
449
450
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 448

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

#dump_TypeDefinition(o) ⇒ Object


456
457
458
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 456

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

#dump_TypeMapping(o) ⇒ Object


452
453
454
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 452

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

#dump_UnaryMinusExpression(o) ⇒ Object


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

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

#dump_UnfoldExpression(o) ⇒ Object


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

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

#dump_UnlessExpression(o) ⇒ Object


347
348
349
350
351
352
353
354
355
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 347

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


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

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

#dump_VirtualQuery(o) ⇒ Object


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

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

#is_nop?(o) ⇒ Boolean


464
465
466
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 464

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