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



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

def dump_Application o
  ["application", o.name, do_dump(o.parameters), do_dump(o.body)]
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


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

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.



345
346
347
348
349
350
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 345

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



279
280
281
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 279

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

#dump_CaseExpression(o) ⇒ Object



365
366
367
368
369
370
371
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 365

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



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

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



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

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

#dump_FunctionDefinition(o) ⇒ Object



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

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)
  result = ["@(#{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



322
323
324
325
326
327
328
329
330
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 322

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



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

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



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

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



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

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)



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

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



312
313
314
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 312

def dump_ParenthesizedExpression o
  do_dump(o.expr)
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



318
319
320
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 318

def dump_Program(o)
  dump(o.body)
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



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

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

#dump_RenderExpression(o) ⇒ Object



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

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

#dump_RenderStringExpression(o) ⇒ Object



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

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

#dump_ReservedWord(o) ⇒ Object



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

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

#dump_ResourceBody(o) ⇒ Object



392
393
394
395
396
397
398
399
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 392

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



401
402
403
404
405
406
407
408
409
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 401

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



411
412
413
414
415
416
417
418
419
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 411

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



283
284
285
286
287
288
289
290
291
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 283

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



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

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

#dump_SelectorEntry(o) ⇒ Object



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

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

#dump_SelectorExpression(o) ⇒ Object



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

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

#dump_SiteDefinition(o) ⇒ Object



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

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

#dump_SubLocatedExpression(o) ⇒ Object



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

def dump_SubLocatedExpression o
  ["sublocated", do_dump(o.expr)]
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



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

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

#dump_TypeDefinition(o) ⇒ Object



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

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

#dump_TypeMapping(o) ⇒ Object



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

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



332
333
334
335
336
337
338
339
340
# File 'lib/puppet/pops/model/model_tree_dumper.rb', line 332

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)


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

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