adsl 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # base
4
+ # indentation added to prevent these dependencies when building the gem
5
+ gem "rake"
6
+ gem "test-unit"
7
+ gem "i18n"
8
+
9
+ # lexer/parser
10
+ gem "rex"
11
+ gem "racc"
12
+
13
+ # used all over the place
14
+ gem "active_support"
15
+
16
+ # terminal color output
17
+ gem "colorize"
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ ADSL - Abstract Data Store Language Parser and Translator
2
+ =========================================================
3
+
4
+ This package contains adsl, a Ruby gem for verifying ADSL specifications.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Usage
10
+ -----
11
+
12
+ adsl-verify <specification-file>
13
+
14
+ For options and other modes of operation, run
15
+
16
+ adsl-verify --help
17
+
18
+ Development
19
+ -----------
20
+
21
+ ### Source Repository
22
+
23
+ The ADSL gem is currently hosted at github. The github web page is
24
+ http://github.com/Bocete/adsl. The public git clone URL is
25
+
26
+ git://github.com/Bocete/adsl.git
27
+
28
+ ### Issues and Bug Reports
29
+
30
+ Feature requests and bug reports can be made here
31
+
32
+ https://github.com/Bocete/adsl/issues
33
+
34
+ License
35
+ -------
36
+
37
+ Rake is available under a [Lesser GPL (LGPL) license](LICENSE).
38
+
39
+ Warranty
40
+ --------
41
+
42
+ This software is provided "as is" and without any express or
43
+ implied warranties, including, without limitation, the implied
44
+ warranties of merchantibility and fitness for a particular
45
+ purpose.
data/bin/adsl-verify ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'optparse'
4
+ require 'ostruct'
5
+
6
+ options = OpenStruct.new
7
+ options.path = :stdin
8
+ options.language = 'spass'
9
+ options.halt_on_error = false
10
+ options.check_satisfiability = true
11
+ options.timeout = 30
12
+ options.csv_output = false
13
+ options.actions = nil
14
+ options.invariants = nil
15
+
16
+ OptionParser.new do |opts|
17
+ opts.banner = "Usage: verify-adsl [options] [input_file]"
18
+ opts.separator ""
19
+ opts.separator "Specific options:"
20
+
21
+ opts.on("-l", "--language LANGUAGE",
22
+ "Specify the method for verifying the specification",
23
+ " Only 'spass' is supported so far",
24
+ " Default: #{options.language}") do |lang|
25
+ options.language = lang
26
+ end
27
+
28
+ opts.on("-h", "--[no-]halt-on-error",
29
+ "Halt verification on the first error encountered. Default: #{options.halt_on_error}") do |halt|
30
+ options.halt_on_error = halt
31
+ end
32
+
33
+ opts.on("-c", "--[no-]check-satisfiability",
34
+ "Before verifying actions individually, check that the data store has a valid state.",
35
+ " Default: #{options.check_satisfiability}") do |check|
36
+ options.check_satisfiability = check
37
+ end
38
+
39
+ opts.on("-s", "--stats-csv",
40
+ "Output the results of the verification with stats in CSV form.",
41
+ " Default: #{options.csv_output}") do
42
+ options.csv_output = true
43
+ end
44
+
45
+ opts.on("-t", "--timeout TIMEOUT", Integer,
46
+ "Timeout for verifying each individual conjecture, in seconds.",
47
+ " Use -1 to allow infinite time for each conjecture. Default: #{options.timeout} sec") do |timeout|
48
+ raise OptionParser::InvalidArgument, "Timeout has to be a non-negative integer, or -1" if timeout < -1
49
+ options.timeout = timeout
50
+ end
51
+
52
+ opts.on("-a", "--actions ACTIONS",
53
+ "A colon separated list of actions to be verified.",
54
+ " Only actions whose name contains any of the arguments will be vefified",
55
+ " All actions are verified by default") do |actions|
56
+ options.actions = actions.split(':').map(&:strip)
57
+ end
58
+
59
+ opts.on("-i", "--invariants INVARIANTS",
60
+ "A colon separated list of invariants to be verified.",
61
+ " Only invariants whose name contains any of the arguments will be vefified",
62
+ " All invariants are verified by default") do |actions|
63
+ options.invariants = actions.split(':').map(&:strip)
64
+ end
65
+
66
+ opts.on_tail("--help", "Show this message") do
67
+ puts opts
68
+ exit
69
+ end
70
+ end.parse!
71
+
72
+ input = ""
73
+ unless ARGV.empty?
74
+ raise OptionParser::ParseError "Invalid usage. Run verify-adsl --help for instructions" if ARGV.length != 1
75
+ options.path = ARGV.first
76
+ raise OptionParser::InvalidArgument, "File not found: #{File.expand_path options.path}" unless File.exists? options.path
77
+
78
+ file = File.new options.path
79
+ input = file.read
80
+ else
81
+ input = STDIN.read
82
+ end
83
+
84
+ GEM_BIN_PATH = Pathname.new(File.expand_path(__FILE__)).parent
85
+ GEM_LIB_PATH = GEM_BIN_PATH.parent + "lib"
86
+ $LOAD_PATH.unshift GEM_LIB_PATH unless $LOAD_PATH.include? GEM_LIB_PATH
87
+
88
+ case options.language
89
+ when 'spass'
90
+ require 'spass/bin'
91
+ include Spass::Bin
92
+ begin
93
+ verify(input,
94
+ :halt_on_error => options.halt_on_error,
95
+ :check_satisfiability => options.check_satisfiability,
96
+ :timeout => options.timeout,
97
+ :csv_output => options.csv_output,
98
+ :actions => options.actions,
99
+ :invariants => options.invariants)
100
+ rescue Exception => e
101
+ $stderr.puts "Error thrown"
102
+ $stderr.puts e.message unless e.message.nil? or e.message.strip.length == 0
103
+ $stderr.puts e.backtrace
104
+ exit -1
105
+ end
106
+ else
107
+ $stderr.puts "Unknown translation language #{options.language}"
108
+ exit -1
109
+ end
110
+
111
+ exit 0
@@ -0,0 +1,292 @@
1
+ require 'util/util'
2
+
3
+ module DS
4
+ class DSNode
5
+ def list_entity_classes_written_to
6
+ recursively_gather :entity_class_writes
7
+ end
8
+
9
+ def list_entity_classes_read
10
+ recursively_gather :entity_class_reads
11
+ end
12
+
13
+ def replace(what, with)
14
+ to_inspect = [self]
15
+ inspected = Set[]
16
+ replaced = false
17
+ while not to_inspect.empty?
18
+ elem = to_inspect.pop
19
+ if elem.kind_of? Array
20
+ elem.length.times do |i|
21
+ if elem[i] == what
22
+ elem[i] = with
23
+ replaced = true
24
+ else
25
+ to_inspect << elem[i] unless inspected.include? elem[i]
26
+ end
27
+ inspected << elem[i]
28
+ end
29
+ elsif elem.class.methods.include? 'container_for_fields'
30
+ elem.class.container_for_fields.each do |field_name|
31
+ field_val = elem.send field_name
32
+ if field_val == what
33
+ elem.send "#{field_name}=", with
34
+ replaced = true
35
+ elsif field_val.kind_of?(Array) or field_val.class.methods.include?('container_for_fields')
36
+ to_inspect << field_val unless inspected.include? field_val
37
+ end
38
+ inspected << field_val
39
+ end
40
+ end
41
+ end
42
+ replaced
43
+ end
44
+ end
45
+
46
+ class DSSpec < DSNode
47
+ container_for :classes, :actions, :invariants
48
+ end
49
+
50
+ class DSClass < DSNode
51
+ container_for :name, :parent, :relations, :inverse_relations do
52
+ @relations = [] if @relations.nil?
53
+ @inverse_relations = [] if @inverse_relations.nil?
54
+ end
55
+
56
+ def to_s
57
+ @name
58
+ end
59
+
60
+ def superclass_of?(other_class)
61
+ until other_class.nil?
62
+ return true if other_class == self
63
+ other_class = other_class.parent
64
+ end
65
+ return false
66
+ end
67
+ end
68
+
69
+ class DSRelation < DSNode
70
+ container_for :cardinality, :from_class, :to_class, :name, :inverse_of
71
+
72
+ def to_s
73
+ "#{from}.#{name}"
74
+ end
75
+ end
76
+
77
+ class DSAction < DSNode
78
+ container_for :name, :args, :cardinalities, :block
79
+
80
+ def statements
81
+ @block.statements
82
+ end
83
+ end
84
+
85
+ class DSBlock < DSNode
86
+ container_for :statements
87
+ end
88
+
89
+ class DSAssignment < DSNode
90
+ container_for :var, :objset
91
+ end
92
+
93
+ class DSCreateObj < DSNode
94
+ container_for :klass
95
+
96
+ def entity_class_writes
97
+ Set[@klass]
98
+ end
99
+ end
100
+
101
+ class DSCreateObjset < DSNode
102
+ container_for :createobj
103
+ end
104
+
105
+ class DSCreateTup < DSNode
106
+ container_for :objset1, :relation, :objset2
107
+ end
108
+
109
+ class DSDeleteObj < DSNode
110
+ container_for :objset
111
+
112
+ def entity_class_writes
113
+ Set[@objset.type]
114
+ end
115
+ end
116
+
117
+ class DSDeleteTup < DSNode
118
+ container_for :objset1, :relation, :objset2
119
+ end
120
+
121
+ class DSEither < DSNode
122
+ container_for :blocks, :lambdas
123
+ end
124
+
125
+ class DSEitherLambdaObjset < DSNode
126
+ container_for :either, :vars
127
+ end
128
+
129
+ class DSForEachCommon < DSNode
130
+ container_for :objset, :block
131
+ end
132
+
133
+ class DSForEach < DSForEachCommon
134
+ end
135
+
136
+ class DSFlatForEach < DSForEachCommon
137
+ end
138
+
139
+ class DSForEachIteratorObjset < DSNode
140
+ container_for :for_each
141
+
142
+ def typecheck_and_resolve(context)
143
+ self
144
+ end
145
+
146
+ def type
147
+ @for_each.objset.type
148
+ end
149
+ end
150
+
151
+ class DSForEachPreLambdaObjset < DSNode
152
+ container_for :for_each, :before_var, :inside_var
153
+ end
154
+
155
+ class DSForEachPostLambdaObjset < DSNode
156
+ container_for :for_each, :before_var, :inside_var
157
+ end
158
+
159
+ class DSVariable < DSNode
160
+ container_for :name, :type
161
+ end
162
+
163
+ class DSAllOf < DSNode
164
+ container_for :klass
165
+
166
+ def type
167
+ @klass
168
+ end
169
+
170
+ def entity_class_reads
171
+ @klass
172
+ end
173
+ end
174
+
175
+ class DSSubset < DSNode
176
+ container_for :objset
177
+
178
+ def type
179
+ @objset.type
180
+ end
181
+ end
182
+
183
+ class DSOneOf < DSNode
184
+ container_for :objset
185
+ def type
186
+ @objset.type
187
+ end
188
+ end
189
+
190
+ class DSDereference < DSNode
191
+ container_for :objset, :relation
192
+
193
+ def type
194
+ @relation.to_class
195
+ end
196
+ end
197
+
198
+ class DSInvariant < DSNode
199
+ container_for :name, :formula
200
+ end
201
+
202
+ class DSBoolean < DSNode
203
+ container_for :bool_value
204
+
205
+ TRUE = DSBoolean.new :bool_value => true
206
+ FALSE = DSBoolean.new :bool_value => false
207
+
208
+ def type
209
+ :formula
210
+ end
211
+ end
212
+
213
+ class DSForAll < DSNode
214
+ container_for :vars, :objsets, :subformula
215
+
216
+ def type
217
+ :formula
218
+ end
219
+ end
220
+
221
+ class DSExists < DSNode
222
+ container_for :vars, :objsets, :subformula
223
+
224
+ def type
225
+ :formula
226
+ end
227
+ end
228
+
229
+ class DSIn < DSNode
230
+ container_for :objset1, :objset2
231
+
232
+ def type
233
+ :formula
234
+ end
235
+ end
236
+
237
+ class DSEmpty < DSNode
238
+ container_for :objset
239
+
240
+ def type
241
+ :formula
242
+ end
243
+ end
244
+
245
+ class DSNot < DSNode
246
+ container_for :subformula
247
+
248
+ def type
249
+ :formula
250
+ end
251
+ end
252
+
253
+ class DSAnd < DSNode
254
+ container_for :subformulae
255
+
256
+ def type
257
+ :formula
258
+ end
259
+ end
260
+
261
+ class DSOr < DSNode
262
+ container_for :subformulae
263
+
264
+ def type
265
+ :formula
266
+ end
267
+ end
268
+
269
+ class DSImplies < DSNode
270
+ container_for :subformula1, :subformula2
271
+
272
+ def type
273
+ :formula
274
+ end
275
+ end
276
+
277
+ class DSEquiv < DSNode
278
+ container_for :subformulae
279
+
280
+ def type
281
+ :formula
282
+ end
283
+ end
284
+
285
+ class DSEqual < DSNode
286
+ container_for :objsets
287
+
288
+ def type
289
+ :formula
290
+ end
291
+ end
292
+ end