tla-sbuilder 0.3.4 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -70
  3. data/VERSION +1 -1
  4. data/lib/sbuilder/constants.rb +4 -4
  5. data/lib/sbuilder/controller.rb +232 -76
  6. data/lib/sbuilder/default-sbuilder.yaml +66 -22
  7. data/lib/sbuilder/facade/api_loader_facade.rb +47 -11
  8. data/lib/sbuilder/facade/facade_constants.rb +26 -0
  9. data/lib/sbuilder/facade/loader_plugin_root.rb +4 -1
  10. data/lib/sbuilder/facade/param_set_root.rb +38 -1
  11. data/lib/sbuilder/facade/snippet_loader_facade.rb +90 -8
  12. data/lib/sbuilder/factory.rb +9 -4
  13. data/lib/sbuilder/model.rb +25 -3
  14. data/lib/sbuilder/param_set.rb +8 -7
  15. data/mustache/cfg/const_def.mustache +2 -0
  16. data/mustache/{setup → config}/assumptions_activate.mustache +0 -0
  17. data/mustache/{setup → config}/domains_run.mustache +0 -0
  18. data/mustache/config/module_footer.mustache +1 -0
  19. data/mustache/config/module_header.mustache +10 -0
  20. data/mustache/{setup → config}/operator_run.mustache +0 -0
  21. data/mustache/{setup → config}/operator_tick.mustache +0 -0
  22. data/mustache/config/steps_run.mustache +43 -0
  23. data/mustache/{setup → config}/steps_run_bind_rule.mustache +5 -2
  24. data/mustache/{setup → config}/steps_run_bind_set.mustache +11 -5
  25. data/mustache/{setup → config}/steps_run_parameterBind.mustache +10 -4
  26. data/mustache/{setup → config}/steps_run_parameterExact.mustache +11 -3
  27. data/mustache/inherit/inherit_config.mustache +29 -0
  28. data/mustache/interface_processes.mustache +6 -2
  29. data/mustache/interfaces/interface_mapper.mustache +12 -0
  30. data/mustache/possibility/module_extends.mustache +1 -1
  31. data/mustache/possibility/operator_set_step_input.mustache +8 -0
  32. data/mustache/possibility/possibility_definition.mustache +4 -4
  33. data/mustache/possibility/possility_setup.mustache +4 -3
  34. data/mustache/setup/module_header.mustache +3 -1
  35. data/mustache/setup/operator_set_step_input.mustache +8 -0
  36. data/mustache/state_type_invariant-infrastructure-service.mustache +2 -2
  37. data/mustache/tla/const_def.mustache +1 -0
  38. data/mustache/tla/macro_run.mustache +10 -2
  39. data/mustache/tla/plc_run_state.mustache +2 -0
  40. data/src/pet/infrastructure_id_get.tla +6 -2
  41. data/src/pet/service_pet_post.tla +2 -2
  42. data/src/pet/service_tag_post.tla +1 -1
  43. data/tla-sbuilder.gemspec +1 -1
  44. metadata +21 -13
  45. data/mustache/setup/steps_run.mustache +0 -23
@@ -190,13 +190,24 @@ generate:
190
190
  modelData: none
191
191
 
192
192
  # ----------------------------------------
193
- # Default setup.cfg
193
+ # interfaces.rb - reverse map interfaces
194
194
  #
195
- # Override template extension points
196
- # - extend_invariant.cfg
197
195
 
198
196
 
199
- - output: tla/setup.cfg
197
+ - output: tla/interfaces.yaml
198
+ inputs:
199
+ - desc: Model interfaces
200
+ template: interfaces/interface_mapper.mustache
201
+ modelData: interfaces
202
+
203
+
204
+ # ----------------------------------------
205
+ # Default config.cfg:
206
+ #
207
+ # Override template extension points
208
+ # - extend_invariant.cfg
209
+
210
+ - output: tla/config.cfg
200
211
  inputs:
201
212
 
202
213
  - desc: Configuration module header
@@ -245,32 +256,31 @@ generate:
245
256
 
246
257
 
247
258
  # ----------------------------------------
248
- # Default setup.tla
249
- #
250
- # Override template extension points
259
+ # config.tla: define setup configuration, extend model
260
+ #
251
261
 
252
262
 
253
- - output: tla/setup.tla
263
+ - output: tla/config.tla
254
264
  inputs:
255
265
 
256
266
  - desc: Start of module
257
- template: setup/module_header.mustache
267
+ template: config/module_header.mustache
258
268
  modelData: none
259
269
 
260
270
  - desc: Implemenation for environment execution operators
261
- template: setup/operator_run.mustache
271
+ template: config/operator_run.mustache
262
272
  modelData: none
263
273
 
264
274
  - desc: Implemenation for environment time tick operator
265
- template: setup/operator_tick.mustache
275
+ template: config/operator_tick.mustache
266
276
  modelData: none
267
-
277
+
268
278
  - desc: Setup domain values
269
- template: setup/domains_run.mustache
279
+ template: config/domains_run.mustache
270
280
  modelData: domains
271
281
 
272
282
  - desc: Activate assumptions on setup
273
- template: setup/assumptions_activate.mustache
283
+ template: config/assumptions_activate.mustache
274
284
  modelData: assumptions
275
285
 
276
286
 
@@ -279,14 +289,43 @@ generate:
279
289
  # modelData: interfaces
280
290
 
281
291
  - desc: Setup environment execution steps
282
- template: setup/steps_run.mustache
292
+ template: config/steps_run.mustache
283
293
  modelData: steps
284
294
 
285
295
  - desc: End of of module
286
- template: setup/module_footer.mustache
296
+ template: config/module_footer.mustache
287
297
  modelData: none
288
298
 
289
299
 
300
+ # ----------------------------------------
301
+ # setup.tla: model checking for Correctness
302
+ #
303
+
304
+ - output: tla/setup.tla
305
+ inputs:
306
+ - desc: Start of module
307
+ template: setup/module_header.mustache
308
+ modelData: none
309
+
310
+ - desc: Specification constans assignments
311
+ template: setup/operator_set_step_input.mustache
312
+ modelData: none
313
+
314
+ - desc: End of of module
315
+ template: setup/module_footer.mustache
316
+ modelData: none
317
+
318
+ # ----------------------------------------
319
+ # setup.cfg: include config.cfg (after generating it)
320
+ #
321
+
322
+ - output: tla/setup.cfg
323
+ inputs:
324
+
325
+ - desc: Include config.cfg
326
+ template: inherit/inherit_config.mustache
327
+ modelData: none
328
+
290
329
  # ----------------------------------------
291
330
  # Dump data-models for template generation
292
331
 
@@ -357,11 +396,15 @@ generate:
357
396
  - desc: Start of module
358
397
  template: possibility/module_header.mustache
359
398
  modelData: possibility
360
-
399
+
361
400
  - desc: Extension definition
362
401
  template: possibility/module_extends.mustache
363
402
  modelData: possibility
364
403
 
404
+ - desc: Specification constans assignments
405
+ template: possibility/operator_set_step_input.mustache
406
+ modelData: none
407
+
365
408
  - desc: Define possibility invariant operator
366
409
  template: possibility/possibility_definition.mustache
367
410
  modelData: possibility
@@ -376,11 +419,12 @@ generate:
376
419
  category: possibility
377
420
  inputs:
378
421
 
379
- - desc: Include setup.cfg
380
- template: possibility/possility_setup.mustache
381
- modelData: possibility
382
- templateParameters:
383
- include: tla/setup.cfg
422
+ - desc: Include config.cfg
423
+ template: inherit/inherit_config.mustache
424
+ modelData: none
425
+ # modelData: possibility
426
+ # templateParameters:
427
+ # include: tla/config.cfg
384
428
 
385
429
 
386
430
  - desc: Activate possibility directive
@@ -91,7 +91,8 @@ module Sbuilder
91
91
  end
92
92
 
93
93
  ##
94
- # Tag all interfaces created using this facadate with property 'infrastructureServices'
94
+ # Tag all interfaces loaded using this facede with property
95
+ # 'infrastructureServices'. See attriute {#infrastructureServices}
95
96
  #
96
97
  # @param [Boolean] infrastructureServices true/false set on all interfaces
97
98
  #
@@ -100,7 +101,8 @@ module Sbuilder
100
101
  end
101
102
 
102
103
  ##
103
- # Tag all interfaces created using this facadate with property 'interfaceService'
104
+ # Tag all interfaces loaded using this facadate with property
105
+ # 'interfaceService'. See attribute {interfaceServices}
104
106
  def configureInterfaceService( interfaceServices )
105
107
  @interfaceServices = interfaceServices
106
108
  end
@@ -235,6 +237,13 @@ module Sbuilder
235
237
  # Create new interface paramtereter set (and a response parameter
236
238
  # set)
237
239
  #
240
+ # @param optionReturn [Boolean, nil] true allow inteface to return
241
+ # response, nil uses facade {#infrastructureServices}
242
+ #
243
+ # @param optionInterface [Boolean, nil] true generates interface
244
+ # process for the service, nil uses facade default
245
+ # {#interfaceServices}
246
+ #
238
247
  # @param [String] path of restfull interface operation
239
248
  #
240
249
  # @param [String] op rest operation (get, put, post,...), defaults
@@ -242,13 +251,33 @@ module Sbuilder
242
251
  #
243
252
  # @return [Sbuilder::ParamSet_If] New interface param set createds
244
253
  # for request. Use #response to access response object.
245
- def newInterface( path, op )
246
- interfaceParamSet = newParamset( path, op )
254
+ def newInterface( path, op, optionReturn=nil, optionInterface=nil )
255
+ @logger.info "#{__method__}: path=#{path}, op=#{op}, optionReturn=#{optionReturn}, optionInterface=#{optionInterface}"
256
+
257
+ interfaceParamSet = newParamset( path, op, optionReturn, optionInterface )
247
258
  paramSetResponse = newParamset( path )
248
259
  interfaceParamSet.setResponse( paramSetResponse )
249
260
  return interfaceParamSet
250
261
  end
251
262
 
263
+
264
+ # Implementation delegates 'setSourceLink' to 'paramSet'
265
+ #
266
+ # @param paramSet [Sbuilder::ParamSet] parameset where to set the link to
267
+ #
268
+ # @param sourceModule [String] pointer to module defining
269
+ # parameter set
270
+ #
271
+ # @param sourceLine [int] sourceLine line number in {#sourceModule}
272
+ #
273
+ # @param sourceColumn [int] source column number {#sourceModule}
274
+
275
+ def setSourceLink(paramSet, sourceModule, sourceLine, sourceColumn=0)
276
+ @logger.info "#{__method__}: paramSet=#{paramSet}, sourceModule=#{sourceModule}, sourceLine=#{sourceLine}"
277
+ paramSet.setSourceLink(sourceModule, sourceLine, sourceColumn)
278
+ end
279
+
280
+
252
281
  # Cretate new pojo for a simple paramter
253
282
  # @param [String] name of the simple paramter to create
254
283
  # @param [Boolean] isArray true if array
@@ -392,15 +421,22 @@ module Sbuilder
392
421
 
393
422
  private
394
423
 
395
- # @return [Sbuilder::ParamSet_If] New interface param set created
396
- def newParamset( path, op ='response' )
424
+ # @param optionReturn [Boolean, nil] true generates
425
+ # response
426
+ #
427
+ # @param optionInterface [Boolean, nil] true generates interface
428
+ # process for the service
429
+ #
430
+ # @return [Sbuilder::ParamSet_If] New interface param set created
431
+ def newParamset( path, op ='response', optionReturn=nil, optionInterface=nil )
397
432
  interfaceParamSet = createParamSet( Sbuilder::Constants::INTERFACE_OPERATION )
398
433
  interfaceParamSet.setIdentity( path, op )
399
- # infrastructureService (capability to return response), and
400
- # infrastructureService (interface process) use values set using
401
- # configure* -methods
402
- interfaceParamSet.setInfrastructureService( infrastructureServices )
403
- interfaceParamSet.setInterfaceService( interfaceServices )
434
+
435
+ # infrastructureService (capability to return response)
436
+ interfaceParamSet.setInfrastructureService( optionReturn.nil? ? infrastructureServices : optionReturn )
437
+ # setInterfaceService (interface process)
438
+ interfaceParamSet.setInterfaceService( optionInterface.nil? ? interfaceServices : optionInterface )
439
+
404
440
  return interfaceParamSet
405
441
  end
406
442
 
@@ -14,10 +14,36 @@ module Sbuilder
14
14
  META_MODEL_FRAMEWORK_SVC="framework-svc"
15
15
  META_MODEL_INVARIANT='invariants'
16
16
 
17
+ # Create template string, which invokes lambda to returns domain
18
+ # of 'field' in parameter set 'definition'.
19
+ def self.snippetFacadeParamsetDomain( definition, field )
20
+ "{{#PARAM_SET_FIELD_DOMAIN}}#{definition}.#{field}{{/PARAM_SET_FIELD_DOMAIN}}"
21
+ end
22
+
23
+ # Create template string, which invokes lambda to return init
24
+ # value from domain for the 'field' in parameter set 'definition'.
25
+ def self.snippetFacadeParamsetDomainInit( definition, field )
26
+ "{{#PARAM_SET_FIELD_DOMAIN_INIT}}#{definition}.#{field}{{/PARAM_SET_FIELD_DOMAIN_INIT}}"
27
+ end
28
+
29
+ # Create template string, which invokes lambda to return init
30
+ # value from domain for the 'field' in RESPONSE parameter set
31
+ # 'definition' (of type interface)
32
+ def self.snippetFacadeResponseDomainInit( definition, field )
33
+ "{{#RESPONSE_SET_FIELD_DOMAIN_INIT}}#{definition}.#{field}{{/RESPONSE_SET_FIELD_DOMAIN_INIT}}"
34
+ end
35
+
36
+
37
+ # Non-existing value (initial value if domain.includeNil)
38
+ NIL = "Nil"
39
+ DOMAIN_BOOLEAN = "BOOLEAN"
40
+
17
41
  end
18
42
 
19
43
  class Facade
20
44
  include Sbuilder::FacadeConstants
45
+
46
+
21
47
  end
22
48
 
23
49
  end
@@ -40,7 +40,10 @@ module Sbuilder
40
40
  def self.validateProperties( hash, required_props, allowed_props )
41
41
  Sbuilder::Utils::Validate.validateProperties( hash, required_props, allowed_props )
42
42
  end
43
-
43
+
44
+ def self.baseMetatypes
45
+ Sbuilder::Controller.baseMetatypes
46
+ end
44
47
 
45
48
  def validateProperties( hash, required_props, allowed_props )
46
49
  self.class.validateProperties( hash, required_props, allowed_props )
@@ -9,6 +9,15 @@ module Sbuilder
9
9
 
10
10
  class ParamSetRoot
11
11
 
12
+ # @# @!attribute [String] sourceModule pointer to to source module
13
+ # where defined
14
+ attr_accessor :sourceModule
15
+
16
+ # @# @!attribute [int] sourceLine line number inf {#sourceModule}
17
+ attr_accessor :sourceLine
18
+
19
+ # @# @!attribute [int] sourceColumn
20
+ attr_accessor :sourceColumn
12
21
 
13
22
  attr_reader :parameters # array of parameters:Parameter
14
23
 
@@ -21,7 +30,25 @@ module Sbuilder
21
30
  @parameters = []
22
31
  end
23
32
 
24
- # @!endgroup
33
+ # @!endgroup
34
+
35
+ # ------------------------------------------------------------------
36
+ # @!group Static services
37
+
38
+ def self.id2name(id)
39
+ id.
40
+ gsub( /\//, "_" ). # / --> _
41
+ gsub( /\(/, "_" ). # ( --> _
42
+ gsub( /\{/, "_" ). # { --> _
43
+ gsub( /\}/, "_" ). # } --> _
44
+ gsub( /\./, "_" ). # . --> _
45
+ gsub( /\)/, "_" ) # ) --> _
46
+
47
+ end
48
+
49
+
50
+ # @!endgroup
51
+
25
52
 
26
53
  # ------------------------------------------------------------------
27
54
  # @!group Configure Model Object Relationships
@@ -34,6 +61,16 @@ module Sbuilder
34
61
  self
35
62
  end
36
63
 
64
+ # @param sourceModule [String] pointer to module defining
65
+ # parameter set
66
+ #
67
+ # @param sourceLine [int] sourceLine line number in {#sourceModule}
68
+ def setSourceLink(sourceModule, sourceLine, sourceColumn)
69
+ self.sourceModule = sourceModule
70
+ self.sourceLine = sourceLine
71
+ self.sourceColumn = sourceColumn
72
+ end
73
+
37
74
  # @param [String] name to look
38
75
  #
39
76
  # @return [Sbuilder::Parameter|nil] return parameter with name, nil if not found
@@ -235,9 +235,8 @@ module Sbuilder
235
235
  # enable mapping from 'metatype/appName' to 'specName'
236
236
  addSymbol( metatype, appName, entry['specName'] )
237
237
 
238
- # TLA code generated for interface defition need to entry point
239
- # to model implementation defined using
240
- # META_MODEL_SERVICE_IMPLEMENTATION -metatype
238
+ # Snippet entry defines behavior for an interface implementation
239
+ # or complelation?
241
240
  if ( metatype == Sbuilder::Constants::META_MODEL_SERVICE_IMPLEMENTATION ) then
242
241
  interfaceExtension( appName, entry['specName'], 'implementation' )
243
242
  elsif metatype == Sbuilder::Constants::META_MODEL_SERVICE_COMPLETION
@@ -289,7 +288,10 @@ module Sbuilder
289
288
 
290
289
  # snippet loader can process only one snippet at a time
291
290
  raise Sbuilder::FacadeException.new <<-EOS if snippets.length > 1
292
- Too many snippets defined in an entry
291
+ Too many snippets defined in an entry:
292
+
293
+ #{snippetCode}
294
+
293
295
  EOS
294
296
 
295
297
  # extract name && type of the snippet from the parsed result
@@ -329,13 +331,93 @@ module Sbuilder
329
331
  # @option snippetEntry [String] metatype
330
332
  # @option snippetEntry [String] appName
331
333
  # @option snippetEntry [String] specName
332
- private def initialReaderData( snippetEntry )
334
+ private def initialReaderData( mustache, snippetEntry )
335
+ snippetEntry
336
+
337
+ # Template function, which returns domain of 'field' from 'paramSet'
338
+ # Template cal
339
+ snippetEntry['PARAM_SET_FIELD_DOMAIN'] = lambda do |accesKey|
340
+
341
+ key = mustache.render( accesKey, snippetEntry )
342
+ keys = key.split( '.' )
343
+ begin
344
+ return key if ( keys.length == 1 ) # just a name
345
+ paramSet = controller.model.getParamset( keys[0] )
346
+ parameter = paramSet.locateParameter( keys[1] )
347
+ domain = parameter.getType
348
+ ret = domain
349
+ rescue Exception => ee
350
+ msg =<<-EOS
351
+ Error
352
+
353
+ #{ee}
354
+ when accessing model domain with key #{accesKey}
355
+
356
+ EOS
357
+ @logger.error( "#{__method__} #{msg}" )
358
+ raise ControllerException.new, msg, ee.backtrace
359
+ end
360
+ ret
361
+ end # PARAM_SET_FIELD_DOMAIN
362
+
363
+
364
+ # Template function, which returns init value for domain of
365
+ # 'field' from 'paramSet' Template cal
366
+ snippetEntry['PARAM_SET_FIELD_DOMAIN_INIT'] = lambda do |paramSet_paramName|
367
+ getDomainInitEntry( paramSet_paramName, false, snippetEntry, mustache )
368
+ end # PARAM_SET_FIELD_DOMAIN
369
+
370
+ snippetEntry['RESPONSE_SET_FIELD_DOMAIN_INIT'] = lambda do |paramSet_paramName|
371
+
372
+ getDomainInitEntry( paramSet_paramName, true, snippetEntry, mustache )
373
+
374
+ end # PARAM_SET_FIELD_DOMAIN
375
+
333
376
  snippetEntry
334
377
  end
335
378
 
336
379
 
337
-
338
- private def initRenderData
380
+ # @return [DomainEntry,NIL] initial value in domain of the
381
+ # (inResponse?) field pointed by 'mustache' rendering
382
+ # 'paramSet_paramName' in 'snippetEntry' data context.
383
+ #
384
+ private def getDomainInitEntry(paramSet_paramName, inResponse, snippetEntry, mustache )
385
+
386
+ key = mustache.render( paramSet_paramName, snippetEntry )
387
+ keys = key.split( '.' )
388
+ begin
389
+ raise "Expecting string 'paramset.parameter' in #{key} rendered for #{paramSet_paramName}" if ( keys.length != 2 ) # just a name
390
+ paramSet = controller.model.getParamset( keys[0] )
391
+
392
+ # dig deeper - for interfaces response parameter set
393
+ paramSet = paramSet.response if inResponse
394
+
395
+ # Access named parameter in 'paramSet'
396
+ parameter = paramSet.locateParameter( keys[1] )
397
+ raise "Implementation missing for reference paramSet_paramName=#{paramSet_paramName} paramter=#{parameter}" if parameter.isReference
398
+ domain = parameter.resolvedDomain
399
+ raise "Domain '#{parameter.domain}' was not resolved paramSet_paramName=#{paramSet_paramName} parameter=#{parameter}" if domain.nil?
400
+ # return Nil if Nil valid, 0 (or range min/smallest element)
401
+ @logger.debug "#{__method__}: domain=#{domain}, domain.includeNil=#{domain.includeNil}, domain.extension=#{domain.extension}" if @logger.debug?
402
+ if domain.includeNil
403
+ ret = FacadeConstants::NIL
404
+ else
405
+ ret = domain.domain_entry( 0 )
406
+ end
407
+ @logger.info "#{__method__}: domain=#{domain}, domain.includeNil=#{domain.includeNil}, domain init value==#{ret}"
408
+ rescue Exception => ee
409
+ msg =<<-EOS
410
+ Error
411
+
412
+ #{ee}
413
+ when accessing model domain with key #{paramSet_paramName}
414
+
415
+ EOS
416
+ @logger.error( "#{__method__} #{msg}" )
417
+ raise ControllerException.new, msg, ee.backtrace
418
+ end
419
+ ret
420
+
339
421
 
340
422
  end
341
423
 
@@ -495,7 +577,7 @@ module Sbuilder
495
577
  @logger.debug "#{__method__}: snippetEntry['snippetBody']=#{snippetEntry['snippetBody']}" if @logger.debug?
496
578
 
497
579
  # create initial hash
498
- renderData = initialReaderData( snippetEntry )
580
+ renderData = initialReaderData( mustache, snippetEntry )
499
581
 
500
582
  # add functions to renderData allowing access to symbol_table
501
583
  # (SPEC_NAME)