cauldron 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (409) hide show
  1. data/.gitignore +51 -0
  2. data/Gemfile +6 -3
  3. data/Gemfile.lock +16 -3
  4. data/Rakefile +94 -92
  5. data/VERSION +1 -1
  6. data/bin/cauldron +2 -2
  7. data/cauldron.gemspec +15 -451
  8. data/features/cauldron_new_approach.feature +46 -0
  9. data/features/step_definitions/cauldron_steps.rb +11 -0
  10. data/features/step_definitions/terminal_steps.rb +0 -2
  11. data/features/support/env.rb +11 -1
  12. data/features/support/hooks.rb +5 -0
  13. data/lib/cauldron.rb +13 -7
  14. data/lib/cauldron/array_reverse_operator.rb +39 -0
  15. data/lib/cauldron/concat_operator.rb +34 -0
  16. data/lib/cauldron/if_relationship.rb +37 -0
  17. data/lib/cauldron/numeric_operator.rb +45 -0
  18. data/lib/cauldron/pot.rb +54 -162
  19. data/lib/cauldron/relationship.rb +5 -0
  20. data/lib/cauldron/terminal.rb +4 -60
  21. data/lib/cauldron/version.rb +3 -0
  22. data/lib/core/string.rb +21 -0
  23. data/sandbox.rb +27 -6
  24. data/spec/cauldron/array_reverse_operator_spec.rb +59 -0
  25. data/spec/cauldron/concat_operator_spec.rb +89 -0
  26. data/spec/cauldron/if_relationship_spec.rb +25 -0
  27. data/spec/cauldron/numeric_operator_spec.rb +70 -0
  28. data/spec/cauldron/pot_spec.rb +81 -151
  29. data/spec/cauldron/terminal_spec.rb +1 -39
  30. data/spec/examples/adding_if_statement.yml +13 -0
  31. data/spec/examples/simple_head_theory.txt +13 -0
  32. data/spec/spec_helper.rb +1 -14
  33. data/tasks/theory_tasks.rake +207 -207
  34. metadata +92 -532
  35. data/cauldron/.autotest +0 -23
  36. data/cauldron/History.txt +0 -6
  37. data/cauldron/Manifest.txt +0 -8
  38. data/cauldron/README.txt +0 -57
  39. data/cauldron/Rakefile +0 -27
  40. data/cauldron/bin/cauldron +0 -3
  41. data/cauldron/lib/cauldron.rb +0 -3
  42. data/cauldron/test/test_cauldron.rb +0 -8
  43. data/features/cauldron_example_cases.feature +0 -13
  44. data/features/cauldron_generates_runtime_method.feature +0 -16
  45. data/features/cauldron_generates_single_paramter_methods.feature +0 -25
  46. data/features/cauldron_interactive_start_terminal.feature +0 -17
  47. data/features/cauldron_quit_terminal.feature +0 -9
  48. data/features/cauldron_start_terminal.feature +0 -12
  49. data/features/support/method_1.example +0 -3
  50. data/features/support/method_2.example +0 -6
  51. data/lib/Chain.rb +0 -771
  52. data/lib/ChainMapping.rb +0 -172
  53. data/lib/CodeHandler.rb +0 -513
  54. data/lib/Mapping.rb +0 -27
  55. data/lib/MappingValues.rb +0 -24
  56. data/lib/PartialChain.rb +0 -253
  57. data/lib/Theory.rb +0 -295
  58. data/lib/UnifiedChain.rb +0 -351
  59. data/lib/cauldron/conversion.rb +0 -15
  60. data/lib/cauldron/demos.rb +0 -280
  61. data/lib/cauldron/env.rb +0 -1
  62. data/lib/cauldron/sexp2cauldron.rb +0 -139
  63. data/lib/cauldron/theory_factory.rb +0 -10
  64. data/lib/cauldron/util/home.rb +0 -21
  65. data/lib/cauldron/util/saver.rb +0 -45
  66. data/lib/core/ActsAsCode.rb +0 -25
  67. data/lib/core/BlockToken.rb +0 -33
  68. data/lib/core/CCall.rb +0 -7
  69. data/lib/core/CTestCase.rb +0 -27
  70. data/lib/core/ClassMethodCallContainer.rb +0 -58
  71. data/lib/core/Container.rb +0 -95
  72. data/lib/core/InstanceCallContainer.rb +0 -298
  73. data/lib/core/MethodUsage.rb +0 -65
  74. data/lib/core/PrintVariables.rb +0 -25
  75. data/lib/core/TheoryGenerator.rb +0 -753
  76. data/lib/core/Token.rb +0 -7
  77. data/lib/core/assignment/Assignment.rb +0 -18
  78. data/lib/core/assignment/Equal.rb +0 -39
  79. data/lib/core/assignment/Equivalent.rb +0 -20
  80. data/lib/core/assignment/NotEqual.rb +0 -14
  81. data/lib/core/call_container/CallContainer.rb +0 -72
  82. data/lib/core/class_method_call/New.rb +0 -15
  83. data/lib/core/class_method_call/RuntimeClassMethodCall.rb +0 -31
  84. data/lib/core/declaration/Declaration.rb +0 -16
  85. data/lib/core/declaration/LiteralDeclaration.rb +0 -47
  86. data/lib/core/declaration/VariableDeclaration.rb +0 -59
  87. data/lib/core/instance_call/ArrayEach.rb +0 -23
  88. data/lib/core/instance_call/ArrayLength.rb +0 -15
  89. data/lib/core/instance_call/Chop.rb +0 -19
  90. data/lib/core/instance_call/Copy.rb +0 -22
  91. data/lib/core/instance_call/DeclaredVariable.rb +0 -18
  92. data/lib/core/instance_call/InstanceCall.rb +0 -77
  93. data/lib/core/instance_call/Params.rb +0 -15
  94. data/lib/core/instance_call/Push.rb +0 -20
  95. data/lib/core/instance_call/StringLength.rb +0 -32
  96. data/lib/core/instance_call/Times.rb +0 -20
  97. data/lib/core/instance_call/instance_calls.rb +0 -176
  98. data/lib/core/instance_call/length_equal.rb +0 -15
  99. data/lib/core/kernal/EvalCall.rb +0 -15
  100. data/lib/core/kernal/LocalVariablesCall.rb +0 -15
  101. data/lib/core/literal/Literal.rb +0 -111
  102. data/lib/core/literal/Raw.rb +0 -23
  103. data/lib/core/literal/RuntimeMethodLiteral.rb +0 -21
  104. data/lib/core/literal/StatementLiteral.rb +0 -28
  105. data/lib/core/method_call/AvailableVariablesCall.rb +0 -25
  106. data/lib/core/method_call/ClassCall.rb +0 -33
  107. data/lib/core/method_call/DefCall.rb +0 -72
  108. data/lib/core/method_call/EvaluateClassCall.rb +0 -29
  109. data/lib/core/method_call/MethodNameCall.rb +0 -27
  110. data/lib/core/method_call/ToDeclarationCall.rb +0 -15
  111. data/lib/core/requirement/Requirement.rb +0 -292
  112. data/lib/core/runtime_class/ArrayClass.rb +0 -19
  113. data/lib/core/runtime_class/ClassCallClass.rb +0 -23
  114. data/lib/core/runtime_class/ClassEvaluationClass.rb +0 -19
  115. data/lib/core/runtime_class/ClassName.rb +0 -18
  116. data/lib/core/runtime_class/DefCallClass.rb +0 -21
  117. data/lib/core/runtime_class/EqualClass.rb +0 -19
  118. data/lib/core/runtime_class/FixnumClass.rb +0 -15
  119. data/lib/core/runtime_class/InstanceCallClass.rb +0 -19
  120. data/lib/core/runtime_class/InstanceCallContainerClass.rb +0 -16
  121. data/lib/core/runtime_class/InstanceClassCallClass.rb +0 -19
  122. data/lib/core/runtime_class/LiteralClass.rb +0 -19
  123. data/lib/core/runtime_class/MethodParameterClass.rb +0 -27
  124. data/lib/core/runtime_class/MethodUsageClass.rb +0 -27
  125. data/lib/core/runtime_class/RequirementClass.rb +0 -19
  126. data/lib/core/runtime_class/ReturnClass.rb +0 -21
  127. data/lib/core/runtime_class/RuntimeClass.rb +0 -30
  128. data/lib/core/runtime_class/RuntimeClassClass.rb +0 -19
  129. data/lib/core/runtime_class/RuntimeMethodClass.rb +0 -34
  130. data/lib/core/runtime_class/StatementClass.rb +0 -53
  131. data/lib/core/runtime_class/StringClass.rb +0 -23
  132. data/lib/core/runtime_class/StringLengthClass.rb +0 -19
  133. data/lib/core/runtime_class/StringVariableClass.rb +0 -19
  134. data/lib/core/runtime_class/ThisClass.rb +0 -15
  135. data/lib/core/runtime_class/UnknownClass.rb +0 -23
  136. data/lib/core/runtime_class/class_names.rb +0 -95
  137. data/lib/core/runtime_class/runtime_class.rb +0 -123
  138. data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -293
  139. data/lib/core/runtime_method/ParametersContainer.rb +0 -29
  140. data/lib/core/runtime_method/RealisedRuntimeMethod.rb +0 -94
  141. data/lib/core/runtime_method/RuntimeMethod.rb +0 -814
  142. data/lib/core/runtime_method/WriteParameters.rb +0 -35
  143. data/lib/core/statement/ActsAsStatement.rb +0 -20
  144. data/lib/core/statement/ArrayAccess.rb +0 -122
  145. data/lib/core/statement/BlockStatement.rb +0 -348
  146. data/lib/core/statement/DeclarationStatement.rb +0 -19
  147. data/lib/core/statement/HackStatement.rb +0 -25
  148. data/lib/core/statement/HashAccess.rb +0 -18
  149. data/lib/core/statement/OpenStatement.rb +0 -178
  150. data/lib/core/statement/RealisedStatement.rb +0 -5
  151. data/lib/core/statement/SingleLineBlockStatement.rb +0 -39
  152. data/lib/core/statement/Statement.rb +0 -1091
  153. data/lib/core/statement/StatementGroup.rb +0 -157
  154. data/lib/core/statement/StatementStructure2.rb +0 -224
  155. data/lib/core/statement/TheoryStatement.rb +0 -68
  156. data/lib/core/statement/TopologicalStatements.rb +0 -34
  157. data/lib/core/syntax/Addition.rb +0 -26
  158. data/lib/core/syntax/BlockContainer.rb +0 -102
  159. data/lib/core/syntax/Boolean.rb +0 -15
  160. data/lib/core/syntax/Code.rb +0 -11
  161. data/lib/core/syntax/Do.rb +0 -20
  162. data/lib/core/syntax/False.rb +0 -12
  163. data/lib/core/syntax/If.rb +0 -36
  164. data/lib/core/syntax/Nil.rb +0 -15
  165. data/lib/core/syntax/Return.rb +0 -33
  166. data/lib/core/syntax/Subtract.rb +0 -19
  167. data/lib/core/syntax/This.rb +0 -40
  168. data/lib/core/syntax/True.rb +0 -20
  169. data/lib/core/syntax/syntax.rb +0 -24
  170. data/lib/core/tracking/ActsAsTrackable.rb +0 -65
  171. data/lib/core/tracking/History.rb +0 -167
  172. data/lib/core/tracking/RuntimeTrackingMethod.rb +0 -32
  173. data/lib/core/tracking/Step.rb +0 -52
  174. data/lib/core/variable/ArrayVariable.rb +0 -76
  175. data/lib/core/variable/BaseVariable.rb +0 -152
  176. data/lib/core/variable/BlockVariable.rb +0 -92
  177. data/lib/core/variable/FixnumVariable.rb +0 -35
  178. data/lib/core/variable/HistoryVariable.rb +0 -8
  179. data/lib/core/variable/MethodParameter.rb +0 -179
  180. data/lib/core/variable/MethodUsageVariable.rb +0 -60
  181. data/lib/core/variable/NilVariable.rb +0 -29
  182. data/lib/core/variable/RuntimeMethodParameter.rb +0 -67
  183. data/lib/core/variable/StatementVariable.rb +0 -72
  184. data/lib/core/variable/StepVariable.rb +0 -7
  185. data/lib/core/variable/StringVariable.rb +0 -46
  186. data/lib/core/variable/TypeVariable.rb +0 -72
  187. data/lib/core/variable/Unknown.rb +0 -102
  188. data/lib/core/variable/UnknownVariable.rb +0 -29
  189. data/lib/core/variable/Variable.rb +0 -70
  190. data/lib/core/variable/VariableContainer.rb +0 -28
  191. data/lib/core/variable/VariableIncluded.rb +0 -27
  192. data/lib/core/variable/VariableReference.rb +0 -85
  193. data/lib/error/FailedToFindStatementContainerError.rb +0 -7
  194. data/lib/error/FailedToFindStatementError.rb +0 -7
  195. data/lib/error/FailedToFindVariableError.rb +0 -7
  196. data/lib/error/FailedToLiteraliseError.rb +0 -7
  197. data/lib/error/FailedVariableMatch.rb +0 -7
  198. data/lib/error/ImproperStatementUsageError.rb +0 -7
  199. data/lib/error/IncompatiableRequirementsError.rb +0 -7
  200. data/lib/error/InvalidStatementError.rb +0 -7
  201. data/lib/error/MethodSizeError.rb +0 -7
  202. data/lib/error/RuntimeSyntaxError.rb +0 -7
  203. data/lib/error/UnexpectedStatementTypeError.rb +0 -7
  204. data/lib/error/UnknownStatementType.rb +0 -7
  205. data/lib/error/UnliteralisableError.rb +0 -7
  206. data/lib/implemented_chain.rb +0 -35
  207. data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +0 -20
  208. data/lib/intrinsic/IntrinsicLiteral.rb +0 -26
  209. data/lib/intrinsic/IntrinsicObject.rb +0 -22
  210. data/lib/intrinsic/IntrinsicRuntimeMethod.rb +0 -27
  211. data/lib/intrinsic/IntrinsicTestCases.rb +0 -17
  212. data/lib/logger/StandardLogger.rb +0 -62
  213. data/lib/required.rb +0 -222
  214. data/lib/ruby_code/Array.rb +0 -95
  215. data/lib/ruby_code/Fixnum.rb +0 -39
  216. data/lib/ruby_code/Hash.rb +0 -25
  217. data/lib/ruby_code/NilClass.rb +0 -19
  218. data/lib/ruby_code/Object.rb +0 -24
  219. data/lib/ruby_code/String.rb +0 -63
  220. data/lib/ruby_code/Symbol.rb +0 -7
  221. data/lib/standard_library/Tasks.rb +0 -12
  222. data/lib/theories.rb +0 -166
  223. data/lib/theory/ActionImplementation.rb +0 -17
  224. data/lib/theory/TheoryAction.rb +0 -100
  225. data/lib/theory/TheoryChainValidator.rb +0 -103
  226. data/lib/theory/TheoryComponent.rb +0 -59
  227. data/lib/theory/TheoryConnector.rb +0 -756
  228. data/lib/theory/TheoryDependent.rb +0 -135
  229. data/lib/theory/TheoryImplementation.rb +0 -75
  230. data/lib/theory/TheoryResult.rb +0 -131
  231. data/lib/theory/TheoryVariable.rb +0 -63
  232. data/lib/theory/theory_collection.rb +0 -62
  233. data/lib/util/ClassEvaluation.rb +0 -44
  234. data/lib/util/CodeEvaluation.rb +0 -39
  235. data/lib/util/DeclarationStatementEvaluation.rb +0 -32
  236. data/lib/util/MethodEvaluation.rb +0 -49
  237. data/lib/util/MethodTester.rb +0 -71
  238. data/lib/util/MethodValidation.rb +0 -149
  239. data/lib/util/MethodWriter.rb +0 -66
  240. data/lib/util/Parser.rb +0 -305
  241. data/lib/util/StatementCheck.rb +0 -44
  242. data/lib/util/StringToTheory.rb +0 -142
  243. data/lib/util/System.rb +0 -8
  244. data/spec/cauldron/chain_spec.rb +0 -24
  245. data/spec/cauldron/demos_spec.rb +0 -30
  246. data/spec/cauldron/runtime_method_spec.rb +0 -92
  247. data/spec/cauldron/saver_spec.rb +0 -45
  248. data/spec/cauldron/sexp_2_cauldron_spec.rb +0 -118
  249. data/spec/cauldron/theory_action_spec.rb +0 -25
  250. data/spec/cauldron/theory_connector_spec.rb +0 -52
  251. data/spec/cauldron/theory_spec.rb +0 -59
  252. data/spec/cauldron/unified_chain_spec.rb +0 -140
  253. data/test/fixtures/chains/1/declaration.txt +0 -26
  254. data/test/fixtures/chains/1/dump +0 -0
  255. data/test/fixtures/chains/2/declaration.txt +0 -26
  256. data/test/fixtures/chains/2/dump +0 -0
  257. data/test/fixtures/chains/3/declaration.txt +0 -26
  258. data/test/fixtures/chains/3/dump +0 -0
  259. data/test/fixtures/implementation_results/0/declaration.txt +0 -3
  260. data/test/fixtures/implementation_results/0/dump +0 -0
  261. data/test/fixtures/theories/0/declaration.txt +0 -9
  262. data/test/fixtures/theories/0/desc +0 -10
  263. data/test/fixtures/theories/0/dump +0 -0
  264. data/test/fixtures/theories/1/declaration.txt +0 -15
  265. data/test/fixtures/theories/1/desc +0 -11
  266. data/test/fixtures/theories/1/dump +0 -0
  267. data/test/fixtures/theories/10/declaration.txt +0 -23
  268. data/test/fixtures/theories/10/desc +0 -17
  269. data/test/fixtures/theories/10/dump +0 -0
  270. data/test/fixtures/theories/11/declaration.txt +0 -20
  271. data/test/fixtures/theories/11/desc +0 -14
  272. data/test/fixtures/theories/11/dump +0 -0
  273. data/test/fixtures/theories/12/declaration.txt +0 -18
  274. data/test/fixtures/theories/12/desc +0 -12
  275. data/test/fixtures/theories/12/dump +0 -0
  276. data/test/fixtures/theories/13/declaration.txt +0 -24
  277. data/test/fixtures/theories/13/desc +0 -20
  278. data/test/fixtures/theories/13/dump +0 -0
  279. data/test/fixtures/theories/14/declaration.txt +0 -26
  280. data/test/fixtures/theories/14/desc +0 -20
  281. data/test/fixtures/theories/14/dump +0 -0
  282. data/test/fixtures/theories/15/declaration.txt +0 -20
  283. data/test/fixtures/theories/15/desc +0 -14
  284. data/test/fixtures/theories/15/dump +0 -0
  285. data/test/fixtures/theories/16/declaration.txt +0 -30
  286. data/test/fixtures/theories/16/desc +0 -14
  287. data/test/fixtures/theories/16/dump +0 -0
  288. data/test/fixtures/theories/17/declaration.txt +0 -25
  289. data/test/fixtures/theories/17/desc +0 -11
  290. data/test/fixtures/theories/17/dump +0 -0
  291. data/test/fixtures/theories/18/declaration.txt +0 -23
  292. data/test/fixtures/theories/18/desc +0 -11
  293. data/test/fixtures/theories/18/dump +0 -0
  294. data/test/fixtures/theories/19/declaration.txt +0 -23
  295. data/test/fixtures/theories/19/desc +0 -11
  296. data/test/fixtures/theories/19/dump +0 -0
  297. data/test/fixtures/theories/2/declaration.txt +0 -12
  298. data/test/fixtures/theories/2/desc +0 -10
  299. data/test/fixtures/theories/2/dump +0 -0
  300. data/test/fixtures/theories/20/declaration.txt +0 -23
  301. data/test/fixtures/theories/20/desc +0 -17
  302. data/test/fixtures/theories/20/dump +0 -0
  303. data/test/fixtures/theories/3/declaration.txt +0 -19
  304. data/test/fixtures/theories/3/desc +0 -11
  305. data/test/fixtures/theories/3/dump +0 -0
  306. data/test/fixtures/theories/4/declaration.txt +0 -11
  307. data/test/fixtures/theories/4/desc +0 -11
  308. data/test/fixtures/theories/4/dump +0 -0
  309. data/test/fixtures/theories/5/declaration.txt +0 -6
  310. data/test/fixtures/theories/5/desc +0 -9
  311. data/test/fixtures/theories/5/dump +0 -0
  312. data/test/fixtures/theories/6/declaration.txt +0 -13
  313. data/test/fixtures/theories/6/desc +0 -11
  314. data/test/fixtures/theories/6/dump +0 -0
  315. data/test/fixtures/theories/7/declaration.txt +0 -19
  316. data/test/fixtures/theories/7/desc +0 -11
  317. data/test/fixtures/theories/7/dump +0 -0
  318. data/test/fixtures/theories/8/declaration.txt +0 -21
  319. data/test/fixtures/theories/8/desc +0 -11
  320. data/test/fixtures/theories/8/dump +0 -0
  321. data/test/fixtures/theories/9/declaration.txt +0 -24
  322. data/test/fixtures/theories/9/desc +0 -20
  323. data/test/fixtures/theories/9/dump +0 -0
  324. data/test/fixtures/theory_implementations/0/declaration.txt +0 -11
  325. data/test/fixtures/theory_implementations/0/desc.txt +0 -9
  326. data/test/fixtures/theory_implementations/0/dump +0 -0
  327. data/test/fixtures/theory_implementations/0/theory_id +0 -1
  328. data/test/fixtures/theory_implementations/1/declaration.txt +0 -11
  329. data/test/fixtures/theory_implementations/1/desc.txt +0 -9
  330. data/test/fixtures/theory_implementations/1/dump +0 -1
  331. data/test/fixtures/theory_implementations/1/theory_id +0 -1
  332. data/test/fixtures/theory_implementations/2/declaration.txt +0 -11
  333. data/test/fixtures/theory_implementations/2/desc.txt +0 -9
  334. data/test/fixtures/theory_implementations/2/dump +0 -0
  335. data/test/fixtures/theory_implementations/2/theory_id +0 -1
  336. data/test/output/simple_method.txt +0 -5
  337. data/test/output/test_method/first_possible_method.txt +0 -6
  338. data/test/output/test_simple_cases/simple_case_01.txt +0 -8
  339. data/test/output/test_simple_cases/simple_case_02.txt +0 -7
  340. data/test/output/test_simple_cases/simple_case_03.txt +0 -8
  341. data/test/output/test_simple_cases/simple_case_04.txt +0 -8
  342. data/test/output/test_simple_cases/simple_case_05.txt +0 -8
  343. data/test/output/test_simple_cases/simple_case_06.txt +0 -9
  344. data/test/output/test_simple_cases/simple_case_07.txt +0 -9
  345. data/test/output/test_simple_cases/simple_case_08.txt +0 -9
  346. data/test/tc_describe.rb +0 -46
  347. data/test/tc_method.rb +0 -130
  348. data/test/tc_requirement.rb +0 -30
  349. data/test/tc_suite_complete.rb +0 -26
  350. data/test/tc_variable.rb +0 -52
  351. data/test/ts_complete.rb +0 -74
  352. data/test/ts_stable.rb +0 -81
  353. data/test/unit/core/declaration/tc_literal_declaration.rb +0 -34
  354. data/test/unit/core/method_call/tc_class_call.rb +0 -20
  355. data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +0 -132
  356. data/test/unit/core/runtime_method/tc_runtime_method.rb +0 -546
  357. data/test/unit/core/statement/tc_array_access.rb +0 -63
  358. data/test/unit/core/statement/tc_block_statement.rb +0 -53
  359. data/test/unit/core/statement/tc_hack_statement.rb +0 -26
  360. data/test/unit/core/statement/tc_open_statement.rb +0 -79
  361. data/test/unit/core/statement/tc_statement.rb +0 -483
  362. data/test/unit/core/statement/tc_statement_group.rb +0 -35
  363. data/test/unit/core/statement/tc_statement_replace_variable.rb +0 -61
  364. data/test/unit/core/statement/tc_theory_statement.rb +0 -53
  365. data/test/unit/core/syntax/tc_block_container.rb +0 -32
  366. data/test/unit/core/syntax/tc_if_container.rb +0 -39
  367. data/test/unit/core/tc_class_method_call.rb +0 -34
  368. data/test/unit/core/tc_container.rb +0 -41
  369. data/test/unit/core/tc_ctest_case.rb +0 -25
  370. data/test/unit/core/tc_instance_call_container.rb +0 -93
  371. data/test/unit/core/tc_literal.rb +0 -30
  372. data/test/unit/core/tc_theory_generator.rb +0 -336
  373. data/test/unit/core/tc_theory_generator_heavy.rb +0 -42
  374. data/test/unit/core/tracking/tc_history.rb +0 -104
  375. data/test/unit/core/tracking/tc_step.rb +0 -65
  376. data/test/unit/core/variable/tc_array_variable.rb +0 -61
  377. data/test/unit/core/variable/tc_block_variable.rb +0 -17
  378. data/test/unit/core/variable/tc_fixnum_variable.rb +0 -54
  379. data/test/unit/core/variable/tc_method_parameter_variable.rb +0 -22
  380. data/test/unit/core/variable/tc_runtime_method_variable.rb +0 -32
  381. data/test/unit/core/variable/tc_string_variable.rb +0 -37
  382. data/test/unit/core/variable/tc_unknown.rb +0 -24
  383. data/test/unit/core/variable/tc_variable_reference.rb +0 -28
  384. data/test/unit/ruby_code/tc_array.rb +0 -64
  385. data/test/unit/ruby_code/tc_fixnum.rb +0 -18
  386. data/test/unit/ruby_code/tc_hash.rb +0 -41
  387. data/test/unit/ruby_code/tc_string.rb +0 -38
  388. data/test/unit/tc_chain.rb +0 -434
  389. data/test/unit/tc_chain_mapping.rb +0 -62
  390. data/test/unit/tc_chain_with_case_1.rb +0 -169
  391. data/test/unit/tc_instance_call.rb +0 -40
  392. data/test/unit/tc_method_usage.rb +0 -35
  393. data/test/unit/tc_pot.rb +0 -124
  394. data/test/unit/tc_runtime_tracking_method.rb +0 -40
  395. data/test/unit/tc_theory.rb +0 -531
  396. data/test/unit/tc_variable_declaration.rb +0 -32
  397. data/test/unit/theory/tc_theory_action.rb +0 -108
  398. data/test/unit/theory/tc_theory_action_implementation.rb +0 -23
  399. data/test/unit/theory/tc_theory_chain_validator.rb +0 -340
  400. data/test/unit/theory/tc_theory_connector.rb +0 -361
  401. data/test/unit/theory/tc_theory_dependent.rb +0 -153
  402. data/test/unit/theory/tc_theory_implementation.rb +0 -137
  403. data/test/unit/theory/tc_theory_result.rb +0 -112
  404. data/test/unit/theory/tc_theory_variable.rb +0 -45
  405. data/test/unit/util/tc_method_validation.rb +0 -101
  406. data/test/unit/util/tc_parser.rb +0 -110
  407. data/test/unit/util/tc_string_to_theory.rb +0 -300
  408. data/test/unit/variable/tc_method_usage_variable.rb +0 -25
  409. data/tmp/runtime_method_evaluation.rb +0 -16
@@ -1,298 +0,0 @@
1
- # This class represents any instance method call. For example:
2
- #
3
- # 'test'.length
4
- # foo.class
5
- # bar.nil?
6
- #
7
- # TODO The InstanceCallContainer should may be be replaced with just statement - the parser
8
- # just has :call types.
9
- #
10
- class InstanceCallContainer < CallContainer
11
- include PrintVariables
12
- include VariableIncluded
13
-
14
- attr_reader :subject, :method_call
15
- attr_reader :value
16
-
17
- #
18
- # @param subject The variable or literal that is being acted upon
19
- # @param method_call The method call being made against the variable
20
- # or literal
21
- #
22
- def initialize(subject,method_call,*params)
23
- raise StandardError.new('Use ClassMethodCallContainer here') if subject.kind_of?(ClassName)
24
- super(subject,method_call,*params)
25
- end
26
-
27
- def write_with_uniq_id
28
- if @subject.respond_to?('write_with_uniq_id')
29
- return @subject.write_with_uniq_id+'.'+method_call.write+write_params(@parameters)
30
- end
31
- return @subject.write+'.'+method_call.write+write_params(@parameters)
32
- end
33
-
34
- # TODO There are many similar version of this method used
35
- def replace_theory_variables!(mapping)
36
- if @subject.kind_of?(TheoryVariable) && mapping.has_key?(@subject.theory_variable_id)
37
- @subject = mapping[@subject.theory_variable_id].copy
38
- elsif @subject.respond_to?(:replace_theory_variables!)
39
- @subject.replace_theory_variables!(mapping)
40
- end
41
- @parameters.each_with_index do |x,i|
42
- if x.kind_of?(TheoryVariable) && mapping.has_key?(x.theory_variable_id)
43
- @parameters[i] = mapping[x.theory_variable_id].copy
44
- next
45
- end
46
- @parameters[i].replace_theory_variables!(mapping) if @parameters[i].respond_to?(:replace_theory_variables!)
47
- end
48
-
49
- end
50
-
51
- # TODO This can probably replace replace_theory_variables!
52
- def replace_variables!(mapping)
53
- if @subject.kind_of?(Variable) && mapping.has_key?(@subject.variable_id)
54
- @subject = mapping[@subject.variable_id].copy
55
- elsif @subject.respond_to?(:replace_variables!)
56
- @subject.replace_variables!(mapping)
57
- end
58
- @parameters.each_with_index do |x,i|
59
- if x.kind_of?(Variable) && mapping.has_key?(x.variable_id)
60
- @parameters[i] = mapping[x.variable_id].copy
61
- next
62
- end
63
- @parameters[i].replace_variables!(mapping) if @parameters[i].respond_to?(:replace_variables!)
64
- end
65
-
66
- end
67
-
68
- # Returns a duplicate instance call container with any matching
69
- # variables replaced with the variable supplied.
70
- #
71
- # @param var The variable that will replace any matching variables
72
- #
73
- def replace_variable_if(var,&block)
74
- container = self.copy.clear
75
- if block.call(@subject)
76
- container.subject = var if block.call(@subject)
77
- end
78
- @parameters.each do |x|
79
- if x.kind_of?(Variable)
80
- container.push(var) if block.call(x)
81
- end
82
- container.push(x.copy)
83
- end
84
- return container
85
- end
86
-
87
- def contains?(&block)
88
- return true if @parameters.contains?(&block)
89
- return true if block.call(@subject)
90
- return true if block.call(@method_call)
91
- return false
92
- end
93
-
94
- def write_in_context(context=self)
95
- return @subject.write_in_context(context)+'.'+method_call.write
96
- end
97
-
98
- def copy
99
- copied_subject = @subject.copy
100
- return InstanceCallContainer.new(copied_subject,@method_call.copy,*@parameters.collect {|x| x.copy})
101
- end
102
-
103
- def variable
104
- return @subject
105
- end
106
-
107
- def literalisable?
108
- return @subject.literalisable?
109
- end
110
-
111
- # Attempts to return a literal value for the result of calling
112
- # this instance call.
113
- #
114
- def literalise(context=self)
115
- unless(@subject.literalisable?)
116
- raise FailedToLiteraliseError.new('Failed to literalise '+self.write+' couln\'t literalise '+@subject.write)
117
- end
118
- return eval(@subject.literalise.write(context)+@method_call.write)
119
- end
120
-
121
- def value
122
- return literalise
123
- end
124
-
125
- # Returns the actual variable with the specified id.
126
- #
127
- # @param id
128
- #
129
- def find_actual_variable(id)
130
- return @subject if @subject.uniq_id == id
131
- @parameters.each do |x|
132
- return x if x.uniq_id == id
133
- end
134
- throw :variable_not_found
135
- end
136
-
137
- def response
138
- case value.class.to_s
139
- when 'string'.class.to_s
140
- return StringVariable.new(value)
141
- break
142
- when 8.class.to_s
143
- return FixnumVariable.new(value)
144
- else
145
- raise StandardError.new('Unknown class '+value.class.to_s)
146
- end
147
- end
148
-
149
- # Set the value of the container for the subject
150
- #
151
- def container=(val)
152
- @container = val
153
- @subject.container = @container
154
- end
155
-
156
- # Determines whether the is an imediate 'self' in the instance
157
- # call.
158
- def contains_self?
159
- return true if subject.kind_of? This
160
- return false
161
- end
162
-
163
- # Substitutes one variable for another one providing the
164
- # the block returns true.
165
- #
166
- def subst!(var,&block)
167
- @subject = var.copy if block.call(@subject)
168
- @parameters.each_with_index do |x,i|
169
- if block.call(x)
170
- @parameters[i] = var.copy
171
- end
172
- end
173
- return self
174
- end
175
-
176
- # Substitutes the 'self' in the instance call for a literal
177
- # value and evaluates it.
178
- #
179
- def subst_self_for literal
180
- if subject.kind_of? This
181
- @subject = literal
182
- end
183
- end
184
-
185
- def subject=(val)
186
- @subject = val
187
- end
188
-
189
- def variable_id
190
- return @subject.variable_id
191
- end
192
-
193
- def find_variable(id)
194
- raise StandardError.new('This instance call does not contain the variable with the id '+id.to_s) unless variable_id == id
195
- return contextual_subject
196
- end
197
-
198
- #
199
- def copy_contextual_variable
200
- return contextual_subject
201
- end
202
-
203
- def declaration_statement
204
- new_instance_call = ClassMethodCallContainer.new(InstanceCallContainerClass.new,New.new,@subject.copy.declaration_statement,@method_call.copy.declaration_statement)
205
- return Statement.new(new_instance_call)
206
- end
207
-
208
- # This method is used during tracking to print a general description of what
209
- # the instance call is doing. e.g. 'test'.chop.
210
- #
211
- def to_literal_string
212
- return @subject.to_literal_string+'.'+@method_call.to_literal_string
213
- end
214
-
215
- # Returns a declaration instance that will create a InstanceCallContainer with
216
- # same properies as this InstanceCallContainer.
217
- #
218
- def to_declaration
219
- return VariableDeclaration.new('InstanceCallContainer',*[@subject.to_declaration,@method_call.to_declaration,*@parameters.collect {|x| x.to_declaration}])
220
- end
221
-
222
- # Returns an array of all the variables used in this instance call.
223
- #
224
- def variables
225
- if @subject.kind_of?(Variable)
226
- results = [@subject.copy]
227
- end
228
- results ||= []
229
- @parameters.each do |x|
230
- results.push(x.copy)
231
- end
232
- return results
233
- end
234
-
235
- # Returns true if the supplied argument is equivant to this instance call
236
- # container. They are equivalent if the their classes are the same, their
237
- # subjects are equivalent, their method_calls are the same and use equivalent
238
- # arguments.
239
- #
240
- def equivalent?(to)
241
- return false unless self.class == to.class
242
- return false unless self.length == to.length
243
- return false unless @subject.equivalent?(to.subject)
244
- return false unless @method_call.class == to.method_call.class
245
- return false if @parameters.length != to.parameters.length
246
- @parameters.each_with_index do |x,i|
247
- return false unless x.equivalent?(to.parameters[i])
248
- end
249
- return true
250
- end
251
-
252
- def replace_variables_alt!(map)
253
- if @subject.kind_of?(TheoryVariable)
254
- map.each do |key,value|
255
- if @subject.theory_variable_id == key.theory_variable_id
256
- @subject = value
257
- break
258
- end
259
- end
260
- elsif(@subject.kind_of?(StringLengthClass))
261
- else
262
- @subject.replace_variables_alt!(map)
263
- end
264
-
265
- @parameters.each_with_index do |x,i|
266
- if x.kind_of?(TheoryVariable)
267
- map.each do |key,value|
268
- if x == key
269
- @parameters[i] = value
270
- end
271
- end
272
- else
273
- @parameters.replace_variables_alt!(map)
274
- end
275
- end
276
- end
277
-
278
- protected
279
-
280
- def contextual_subject
281
-
282
- # Check that the literal supports the method call
283
- if @subject.kind_of? Literal
284
- raise NameError.new('Literal '+self.write+' does not have the method call '+@method_call.write) unless @subject.allowed? @method_call
285
- end
286
-
287
- # Copy the subject variable
288
- copied_subject = @subject.copy
289
-
290
- # Retrieve any requirements associated with the method call
291
- # @method_call.requirements do |req|
292
- # copied_subject.push(req)
293
- # end
294
- return copied_subject
295
-
296
- end
297
-
298
- end
@@ -1,65 +0,0 @@
1
- # Instances of this class describe the parameters that a method uses
2
- # and is required to have
3
- #
4
- class MethodUsage < Array
5
-
6
- def initialize(*parameters)
7
- super()
8
-
9
- # Check the data type of the provided variables
10
- parameters.each do |x|
11
- unless x.kind_of? MethodParameter then raise StandardError.new('Unexpected data type: '+x.class.to_s+' expecting MethodParameter') end
12
- end
13
-
14
- # Add the method variables to your self
15
- parameters.collect {|param| self.push param}
16
-
17
- end
18
-
19
- # Check whether the rule matches the usage of the method. Essentially
20
- # checking that the number of parameters is correct and the data types
21
- # are acceptable.
22
- #
23
- def valid_rule? rule
24
-
25
- # Check that correct number of parameters are provided
26
- unless rule.paramater_count == self.length then raise ParameterCountError.new('Expected '+self.length.to_s+' parameters') end
27
-
28
- end
29
-
30
- def write
31
- line = 'MethodUsage.new('
32
- self.each do |x|
33
- line += x.to_declaration.write
34
- unless x.object_id == self.last.object_id then line += ', ' end
35
- end
36
- line += ')'
37
- return line
38
- end
39
-
40
- # Returns this method usage case as MethodUsageVariable instance.
41
- #
42
- # TODO I'm not sure I should be allow this to set it's id
43
- #
44
- def to_var(id=nil,uniq_id=nil)
45
- if id.nil? then return MethodUsageVariable.new(*self.collect {|x| x.copy}) end
46
- return MethodUsageVariable.new(*self.collect {|x| x.copy}) {{:variable_id => id,:uniq_id=>uniq_id}}
47
- end
48
-
49
- def copy
50
- return MethodUsage.new(*self.collect {|x| x.copy})
51
- end
52
-
53
- def to_declaration
54
- return VariableDeclaration.new('MethodUsage',*self.collect {|x| x.to_declaration})
55
- end
56
-
57
- end
58
-
59
- class ParameterCountError < StandardError
60
-
61
- def initialize(msg)
62
- super(msg)
63
- end
64
-
65
- end
@@ -1,25 +0,0 @@
1
- module PrintVariables
2
-
3
- #
4
- def display_name_for(var)
5
-
6
- # Has a name been given to this variable
7
- unless @variable_names[var.variable_id].nil? then return @variable_names[var.variable_id] end
8
-
9
- # Save the name of the new variable
10
- var_name = 'var_'+@variable_counter.to_s
11
- if var.kind_of? MethodParameter
12
- var_name = 'param_var_'+@variable_counter.to_s
13
- end
14
- if var.kind_of? ResponseVariable
15
- var_name = 'return_var_'+@variable_counter.to_s
16
- end
17
- @variable_counter += 1
18
-
19
- # Save the existing name
20
- @variable_names[var.variable_id] = var_name
21
- return @variable_names[var.variable_id]
22
-
23
- end
24
-
25
- end
@@ -1,753 +0,0 @@
1
- class TheoryGenerator
2
-
3
- def initialize(filters=[])
4
- @filters = filters
5
- end
6
-
7
- # Returns an array of master theories(huge theories) generated using the runtime
8
- # method at each stage of the chain.
9
- #
10
- def master_theories(chain,initial_runtime_method,test_cases)
11
- raise StandardError.new('Currently only able to generate master theories for complete chains') unless chain.complete?
12
-
13
- # Retrieve the full variable history for the chain - need to avoid duplicate variable creation especially if a variable
14
- # only exists in the action.
15
- creation_history = chain.variables_creation(initial_runtime_method,test_cases)
16
-
17
- # * Create the values array [{:value=>x,:statement=>:step=>}]
18
- master_theories = []
19
- chain.each_theory_progression(initial_runtime_method,test_cases) do |implemented_theory,theory|
20
-
21
- dependent_accessors = retrieve_accessors(implemented_theory.accessor_values[:before],creation_history)
22
- result_accessors = retrieve_accessors(implemented_theory.accessor_values[:after],creation_history)
23
-
24
- # Generate the dependents and results
25
- theory_dependents = get_theory_dependents(dependent_accessors.copy)[0..8]
26
- theory_results = get_theory_dependents(result_accessors.copy)[0..2]
27
-
28
- # Create the complete theory
29
- master_theories << Theory.new(
30
- theory_dependents.copy,
31
- theory.action.copy,
32
- theory_results
33
- )
34
-
35
- end
36
- return master_theories
37
-
38
- end
39
-
40
- # Returns a master and simplistic theory in conext of the supplied runtime
41
- # method after each of the actions is added. So for each action there is
42
- # new theory generated.
43
- #
44
- # NOTE: This is the first time I've started to introduce this master/simply
45
- # theory paradigm. The general rule I'm using is that the simple theory
46
- # only needs to be complex enough so it can indicate the order the actions
47
- # should be performed.
48
- #
49
- # NOTE: The variables that each of theories use always refer to the same value. So
50
- # if var1 is the rutime method then var1 is the runtime method for all the theories.
51
- #
52
- def generate_theories_for_actions(runtime_method,test_cases,actions)
53
-
54
- end
55
-
56
- # Returns true if adding the supplied actions to the runtime method results
57
- # in all the tests cases being met. This is useful to use before attempting
58
- # to generate the theories to solve the test cases.
59
- #
60
- # TODO I would rather the mapping was ChainMapping or ideally the mapping wasn't passed
61
- # all, just have it as internal to the chain.
62
- #
63
- def actions_validate_runtime_method?(runtime_method,test_cases,actions,mapping)
64
-
65
- # Declare the default finish for any problem
66
- head = Theory.new([],nil,[])
67
- tail = Parser.run("if(runtime_method.all_pass?(test_cases))\nreturn true\nend")
68
-
69
- # Create the chain
70
- chain = Chain.new
71
- chain.form_chain(head,tail,mapping)
72
-
73
- # Add each of the actions to the chain
74
- actions.each do |action|
75
- chain.add_link(Theory.new([],action,[]))
76
- end
77
-
78
- # Implement the chain so that all variables are unified
79
- implementd_chain = chain.implement
80
-
81
- end
82
-
83
- # This generates an inital set of theories using the initial values. It
84
- # then continues to generate additional theories after applying the action
85
- # of the previously generated theories.
86
- #
87
- def multiple_generate(runtime_method,test_cases,limit=1)
88
- theories = generate(test_cases,runtime_method,0)
89
-
90
- additional_theories = []
91
- theories.each_with_index do |x,i|
92
- additional_theories += recursive_generate(test_cases,x,1,(limit-1))
93
- end
94
- return theories+additional_theories
95
-
96
- end
97
-
98
- def recursive_generate(test_cases,theory,stage,limit=1,results=[])
99
-
100
- results << theory
101
- return results if limit == 0
102
-
103
- # TODO It seems a bit wasteful to generate a whole new set of accessors for each
104
- # new theory. It should maybe just up accessors that include the runtime method.
105
- new_theories = generate(test_cases.copy,theory.example_runtime_method.copy,stage)
106
-
107
- new_theories.each do |x|
108
- recursive_generate(test_cases.copy,x,(stage+1),(limit-1),results)
109
- end
110
- return results
111
-
112
- end
113
-
114
- # Returns an array of theories that add a variety of statements to the runtime
115
- # method. The theories will be quite bloated since they'll contain all the possible
116
- # dependents and results.
117
- #
118
- # @param values An array of literal values
119
- #
120
- def generate(test_cases,runtime_method,stage=0)
121
-
122
- #
123
- # TODO Not keen on this parallel assignment (should really just
124
- # have a single instance containing the accessors and
125
- # mapping or have the mappig generated)
126
- accessors, mapping = generate_accessors_and_mapping(test_cases,runtime_method,4,stage)
127
-
128
- # Now generate some possible theories using these values
129
- return generate_theories(test_cases,runtime_method,accessors,mapping)
130
-
131
- end
132
-
133
- # Returns an array of statements that use the values supplied but will return a
134
- # value(including boolean).
135
- #
136
- def generate_accessors_and_mapping(test_cases,runtime_method,itterations=1,stage=0)
137
-
138
- # TODO I'd like to drop this and just query the mapping instance
139
- theory_variable_ids = [0,1,2]
140
-
141
- # Create a theory variable for each of the values
142
- # runtime_method => 1
143
- # test_cases => 2
144
- mapping = Mapping.new({
145
- 1 => runtime_method.copy,
146
- 2 => test_cases.copy
147
- })
148
- results = [
149
- {:value=>runtime_method.copy,:statement=>TheoryStatement.new(TheoryVariable.new(1)),:step=>0},
150
- {:value=>test_cases.copy,:statement=>TheoryStatement.new(TheoryVariable.new(2)),:step=>0}
151
- ]
152
-
153
- # Generate a number of values that can be obtained from the current runtime method and test cases
154
- itterations.times do |step|
155
- results = extend_accessors(results,mapping,theory_variable_ids,(step+1))
156
- end
157
- return results, mapping
158
-
159
- end
160
-
161
- def generate_theories(test_cases,runtime_method,accessors,mapping)
162
-
163
- # Retreive theory dependets relating to the current method
164
- theory_dependents = get_theory_dependents(accessors.copy)
165
-
166
- # Retrieve possible statements to include in the theory
167
- theory_actions = get_theory_action(test_cases.copy,runtime_method.copy,accessors,mapping)
168
-
169
- # For each action retrieve the results of adding the statement
170
- theories = []
171
- theory_actions.each_with_index do |selected_action,i|
172
-
173
- # Add the statement to the runtime method and construct result theories based on it
174
- new_values = accessors.copy
175
-
176
- # Convert the mapping values into intrinsic values
177
- intrinsic_mapping = covert_to_intrinsic_mapping(mapping)
178
-
179
- # Re-create the action with intrinsic variables
180
- implementated_action = selected_action.map_to(intrinsic_mapping)
181
-
182
- # Generate the runtime method that would be created by using that action
183
- modified_runtime_method = TheoryChainValidator.new.add_statement_to_method(
184
- test_cases.copy,
185
- runtime_method.copy,
186
- implementated_action
187
- )
188
-
189
- # TODO I should maybe keep both runtime methods so the I can compare the runtime method's
190
- # before and after.
191
-
192
- # Create a new mapping using the update runtime method
193
- new_mapping = mapping.copy
194
- new_mapping[1] = modified_runtime_method
195
-
196
- # Re-build the results but using the new value for the runtime method
197
- # re_evaluate_results
198
- # TODO Using the same result statements is limiting - there might be more calls available.
199
- new_results = re_evaluate_results(accessors,new_mapping)
200
-
201
- # Get the theory results for this modified runtime method
202
- theory_results = get_theory_results(new_results)
203
-
204
- # Create the complete theory
205
- theories << Theory.new(
206
- theory_dependents.copy,
207
- selected_action,
208
- theory_results,
209
- modified_runtime_method
210
- )
211
-
212
- end
213
-
214
- return theories
215
-
216
- end
217
-
218
- def get_theory_action(test_cases,runtime_method,results,mapping)
219
-
220
- # Get possible statements ids
221
- statement_ids = results.select {|x| x[:value].kind_of?(Fixnum)}
222
-
223
- actions = []
224
-
225
- # Add 'return <val>' statement
226
- results.each do |x|
227
- statement_ids.each do |y|
228
- # TODO Shouldn't allow runtime methods to be included here
229
- actions << TheoryAction.new(
230
- TheoryStatement.new(StringToTheory.run("Statement.new(Return.new,#{x[:statement].write})")),
231
- StringToTheory.run(y[:statement].write)
232
- )
233
- end
234
- end
235
-
236
- # Exclude the runtime method from being included as a value (.write method becomes messy)
237
- # also excludes the orginal test_cases.
238
- valid_results = results.select do |x|
239
-
240
- # TODO For some reason "x[:value].all? {|y| y.kind_of?(CTestCase)}" returns true for method Parameter (which is why this is here)
241
- next true if x[:value].kind_of?(MethodParameter)
242
-
243
- next false if x[:value].kind_of?(RuntimeMethod)
244
-
245
- # NOTE: This is only temporary - I don't really see anything wrong with nil
246
- next false if x[:value].kind_of?(NilClass)
247
-
248
- next false if x[:value].kind_of?(Array) && x[:value].all? {|y| y.kind_of?(CTestCase)}
249
- next true
250
- end
251
-
252
- (results-valid_results).each do |x|
253
- next if x[:value].nil?
254
- end
255
-
256
- # Generate "if(varA == varB) statements"
257
- value_pairs = valid_results.permutation(2)
258
- value_pairs.each do |x,y|
259
- statement_ids.each do |z|
260
-
261
- # if(x == y)
262
- # COMPROMISE - Only include statements with the same data type
263
- # TODO They should be same type not identical so as long as the extend Array
264
- # TODO I need to get the value of the runtime method parameter e.g. 'var2.params[var5]'
265
- if x[:value].class != MethodParameter and y[:value].class != MethodParameter
266
- next unless x[:value].class == y[:value].class
267
- end
268
- actions << TheoryAction.new(
269
- TheoryStatement.new(
270
- StringToTheory.run(
271
- "OpenStatement.new(Statement.new(If.new,Container.new(#{x[:statement].write},Equivalent.new,#{y[:statement].write})))"
272
- )
273
- ),
274
- StringToTheory.run(z[:statement].write)
275
- )
276
- end
277
- end
278
-
279
- # TODO I haven't allowed last_runtime_method to be used yet
280
-
281
- # ========================================================
282
- # Remove the actions that don't work
283
- # ========================================================
284
- # TODO This duplicates the the "covert_to_intrinsic_mapping" method
285
- # Convert the mapping values into intrinsic values
286
- intrinsic_mapping = Mapping.new
287
- test_cases_key = nil
288
- runtime_method_key = nil
289
- mapping.each do |key,value|
290
-
291
- # Convert fixnum into intrinisic fixnums
292
- if value.kind_of?(Fixnum)
293
- intrinsic_mapping[key] = IntrinsicLiteral.new(value)
294
- next
295
- end
296
-
297
- end
298
- intrinsic_mapping[1] = Parser.run('runtime_method')
299
- intrinsic_mapping[2] = Parser.run('test_cases')
300
-
301
- # Attempt to add the statement to the actual runtime method
302
- valid_actions = []
303
- actions.each do |x|
304
- implementation = x.map_to(intrinsic_mapping)
305
- if action_works_with_runtime_method?(test_cases.copy,runtime_method.copy,implementation)
306
- valid_actions << x
307
- end
308
- end
309
-
310
- return valid_actions
311
-
312
- end
313
-
314
- def covert_to_intrinsic_mapping(mapping)
315
-
316
- # Convert the mapping values into intrinsic values
317
- intrinsic_mapping = Mapping.new
318
- test_cases_key = nil
319
- runtime_method_key = nil
320
- mapping.each do |key,value|
321
-
322
- # Convert fixnum into intrinisic fixnums
323
- if value.kind_of?(Fixnum)
324
- intrinsic_mapping[key] = IntrinsicLiteral.new(value)
325
- next
326
- end
327
-
328
- if value.kind_of?(RuntimeMethod)
329
- intrinsic_mapping[key] = Parser.run('runtime_method')
330
- runtime_method_key = key
331
- next
332
- end
333
-
334
- if value.kind_of?(Array) && value.first.has_key?(:params)
335
- intrinsic_mapping[key] = Parser.run('test_cases')
336
- test_cases_key = key
337
- next
338
- end
339
- raise StandardError.new('Unknown value '+value.class.to_s)
340
- end
341
- return intrinsic_mapping
342
- end
343
-
344
- # Attempt to use the generated action with the runtime method to determine if
345
- # it's valid syntax.
346
- #
347
- def action_works_with_runtime_method?(test_cases,runtime_method,action)
348
- return TheoryChainValidator.new.add_statement_to_method(test_cases,runtime_method,action) ? true : false
349
- rescue StandardError => e
350
- return false
351
- end
352
-
353
- # Returns an array of theory dependents
354
- #
355
- def get_theory_dependents(results)
356
-
357
- # Create the theory dependents for all the values
358
- value_pairs = results.permutation(2)
359
- theory_dependents = []
360
- value_pairs.each do |x,y|
361
- if x[:value] == y[:value]
362
- theory_dependents << TheoryDependent.new(
363
- StringToTheory.run("if(#{x[:statement].write} == #{y[:statement].write})\nreturn true\nend")
364
- )
365
- else
366
- theory_dependents << TheoryDependent.new(
367
- StringToTheory.run("if((#{x[:statement].write} == #{y[:statement].write})==false)\nreturn true\nend")
368
- )
369
- end
370
- end
371
- return theory_dependents
372
- end
373
-
374
- def get_theory_results(results)
375
- theory_results = []
376
-
377
- # Create the single statement theory results
378
- results.each do |x|
379
- if x[:value]
380
- theory_results << TheoryResult.new(
381
- StringToTheory.run("if(#{x[:statement].write})\nreturn true\nend")
382
- )
383
- elsif x[:value] == false
384
- theory_results << TheoryResult.new(
385
- StringToTheory.run("if((#{x[:statement].write})==false)\nreturn true\nend")
386
- )
387
- else
388
- StandardLogger.instance.error(x[:statement].write+' is '+x[:value].to_s)
389
- end
390
- # TODO Should probably have else x[:value].nil? and StringToTheory.run("if((#{x[:statement].write}).nil?)\nreturn true\nend")
391
- end
392
-
393
- # Create the theory dependents for all the values
394
- value_pairs = results.permutation(2)
395
- value_pairs.each do |x,y|
396
- if x[:value] == y[:value]
397
- theory_results << TheoryResult.new(
398
- StringToTheory.run("if(#{x[:statement].write} == #{y[:statement].write})\nreturn true\nend")
399
- )
400
- else
401
- theory_results << TheoryResult.new(
402
- StringToTheory.run("if((#{x[:statement].write} == #{y[:statement].write})==false)\nreturn true\nend")
403
- )
404
- end
405
- end
406
- return theory_results
407
-
408
- end
409
-
410
- # Re-evaluate the values of each of the results using an updated
411
- # runtime method instance.
412
- #
413
- def re_evaluate_results(results,mapping)
414
- new_results = []
415
- results.each do |x|
416
- v = obtain_value(x[:statement],mapping)
417
- new_results << {:value=>v,:statement=>x[:statement],:step=>x[:step]}
418
- end
419
- return new_results
420
- end
421
-
422
- # Extends the provided accessors by another method call. For example
423
- # if it is passed "test", it would return 'test'.length and
424
- # 'test'.lowercase etc.
425
- #
426
- # @param initial_accessors An array of initial accessors containing the statement used
427
- # to generate the value and the value itself.
428
- # {:value=>#<Some Literal Value>,:statement=><#Statement: A statement instance>}
429
- # @param mapping The current mapping being used. This is extended when a new
430
- # index is used. So if test_case[0] is used, then 0 needs to have
431
- # variable created for it and that added to the mapping.
432
- # @param variable_history This keeps track of each time a new variable is created via additional
433
- # array access calls. This allows the structure of the theories to remain
434
- # unified across the dependents and results.
435
- #
436
- def extend_accessors(values,mapping,theory_variable_id,step,variable_history=[])
437
-
438
- # Go through each of the values and get each of the cauldron method calls
439
- total_results = []
440
- values.each do |x|
441
-
442
- # Get the possible cauldron method calls
443
- results = []
444
- x[:value].cauldron_method_calls.each do |y|
445
-
446
- # Only get array access for values obtained in the last itteration
447
- if (step-1) == x[:step]
448
- results += params_output(x,y,mapping,theory_variable_id,step,values)
449
- results += array_access(x,y,mapping,theory_variable_id,step,values,variable_history)
450
- end
451
-
452
- # If the variable is new it should have all the paramters
453
- # If it isn't new it only needs the recent params
454
-
455
- # Only include parameters for recently created values
456
- if (step-1) == x[:step]
457
- results += use_method_call(x,y,mapping,theory_variable_id,step,values)
458
- else
459
- last_results = values.select {|z| z[:step] == (step-1)}
460
- results += use_method_call(x,y,mapping,theory_variable_id,step,last_results,true)
461
- end
462
-
463
- end
464
- total_results += results
465
- end
466
- return total_results+values
467
- end
468
-
469
- #
470
- #
471
- #
472
- def use_method_call(result,cauldron_method_call,mapping,theory_variable_id,step,available_params,params_only=false)
473
-
474
- # Does it start with a '.'
475
- results = []
476
- if cauldron_method_call =~ /^\./
477
-
478
- # Does it require any parameters
479
- if ['.any?','.all_pass?','.pass?','.history2','.realise2','.kind_of?'].include?(cauldron_method_call)
480
-
481
- case cauldron_method_call
482
- when '.pass?'
483
- # Uses one parameter - a test case
484
- cauldron_test_cases = available_params.select {|x| x[:value].kind_of?(CTestCase)}
485
- cauldron_test_cases.each do |x|
486
- s = TheoryStatement.new(
487
- StringToTheory.run(result[:statement].write+cauldron_method_call+'('+x[:statement].write+')')
488
- )
489
- v = obtain_value(s,mapping)
490
- results << {:value=>v,:statement=>s,:step=>step}
491
- end
492
- when '.kind_of?'
493
-
494
- # TODO Should probably include value class check here
495
- s = TheoryStatement.new(
496
- StringToTheory.run(result[:statement].write+cauldron_method_call+'(CTestCase)')
497
- )
498
- v = obtain_value(s,mapping)
499
- results << {:value=>v,:statement=>s,:step=>step}
500
-
501
- s2 = TheoryStatement.new(
502
- StringToTheory.run(result[:statement].write+cauldron_method_call+'(Fixnum)')
503
- )
504
- v2 = obtain_value(s,mapping)
505
- results << {:value=>v2,:statement=>s2,:step=>step}
506
- when '.all_pass?'
507
-
508
- available_params.each do |x|
509
- if x[:value].kind_of?(Array) and x[:value].any? {|y| y.kind_of?(CTestCase)}
510
- s = TheoryStatement.new(
511
- StringToTheory.run(
512
- result[:statement].write+cauldron_method_call+'('+x[:statement].write+')'
513
- )
514
- )
515
- v = obtain_value(s,mapping)
516
- results << {:value=>v,:statement=>s,:step=>step}
517
- end
518
- end
519
-
520
- when '.history2'
521
- return []
522
- cauldron_arrays = available_params.select {|x| x[:value].kind_of?(Array)}
523
- cauldron_test_case_params = cauldron_arrays.select {|x| x[:statement].write.include?(':params')}
524
- cauldron_test_case_params.each do |x|
525
- s = TheoryStatement.new(
526
- StringToTheory.run(result[:statement].write+cauldron_method_call+'('+x[:statement].write+')')
527
- )
528
- v = obtain_value(s,mapping)
529
- results << {:value=>v,:statement=>s,:step=>step}
530
- end
531
- when '.realise2'
532
- cauldron_arrays = available_params.select {|x| x[:value].kind_of?(Array)}
533
- cauldron_test_case_params = cauldron_arrays.select {|x| x[:statement].write =~ /:params\]$/}
534
- cauldron_test_case_params.each do |x|
535
- s = TheoryStatement.new(
536
- StringToTheory.run(result[:statement].write+cauldron_method_call+'('+x[:statement].write+')')
537
- )
538
- v = obtain_value(s,mapping)
539
- results << {:value=>v,:statement=>s,:step=>step}
540
- end
541
- when '.any?'
542
- return []
543
- # if(var5.history2(var2[var3][:params]).any?{ |x| x['statement_id'] == var1.last.statement_id} )
544
- if result[:value].kind_of?(Array)
545
- available_params.each do |x|
546
- # TODO Should probably only match values of the same type - I don't want
547
- # var1.any?{|x| x == var2.pass?(var1[var4])}
548
-
549
- # Only allow one block statement -
550
- next if x[:statement].write.include?('{')
551
-
552
- # TODO I should reduce the number of possible comparisons
553
- # (there is no point in comparing things will never be the same)
554
- s = TheoryStatement.new(
555
- StringToTheory.run(
556
- result[:statement].write+cauldron_method_call+'{|x| x == '+x[:statement].write+'}'
557
- )
558
- )
559
- v = obtain_value(s,mapping)
560
- results << {:value=>v,:statement=>s,:step=>step}
561
- end
562
-
563
- # TODO This is is a quick hack to get x[:statement] included - down the line it might
564
- # require a separate extend_accessors call.
565
- if(result[:value].first.class==Step)
566
- result[:value].first.cauldron_method_calls.each do |x|
567
-
568
- available_params.each do |y|
569
-
570
- # Only allow one block statement -
571
- next if y[:statement].write.include?('{')
572
-
573
- s = TheoryStatement.new(
574
- StringToTheory.run(
575
- result[:statement].write+cauldron_method_call+'{|x| x'+x+' == '+y[:statement].write+'}'
576
- )
577
- )
578
- v = obtain_value(s,mapping)
579
-
580
- results << {:value=>v,:statement=>s,:step=>step}
581
-
582
- end
583
- end
584
- end
585
-
586
- else
587
- raise StandardError.new("Not setup for call '#{cauldron_method_call}'")
588
- end
589
- else
590
- raise StandardError.new("Not setup for call '#{cauldron_method_call}'")
591
- end
592
-
593
- # NOTE: These don't take parameters
594
- elsif ['.length','.last','.statement_id','.params','.value'].include?(cauldron_method_call)
595
-
596
- # Don't include this call if only parameter calls are being considered
597
- return [] if params_only
598
-
599
- s = TheoryStatement.new(StringToTheory.run(result[:statement].write+cauldron_method_call))
600
- v = obtain_value(s,mapping)
601
- results << {
602
- :value=>v,
603
- :statement=>s,
604
- :step=>step,
605
- :intrinsic_statement=>self.convert_to_intrinsic_statement(s,mapping)
606
- }
607
- else
608
- raise StandardError.new('Unknown method '+cauldron_method_call)
609
- end
610
- end
611
- return results
612
- end
613
-
614
- def params_output(result,cauldron_method_call,mapping,theory_variable_id,step,results=[])
615
- results = []
616
- if cauldron_method_call.include?('[:params]') or cauldron_method_call.include?('[:output]')
617
- s = TheoryStatement.new(StringToTheory.run(result[:statement].write+cauldron_method_call))
618
- v = obtain_value(s,mapping)
619
- results << {:value=>v,:statement=>s,:step=>step}
620
- end
621
- return results
622
- end
623
-
624
- # TODO Why is results passed through if it is just overwritten?
625
- def array_access(result,cauldron_method_call,mapping,theory_variable_ids,step,results=[],variable_history=[])
626
-
627
- results = []
628
- if cauldron_method_call == '[]'
629
- if result[:value].length > 4 then raise StandardError.new('Cauldron has not been tested with arrays larger that 4') end
630
-
631
- # Generate theory variables for each of the new accessors
632
- array_indexs = []
633
- result[:value].length.times do |z|
634
-
635
- theory_id = theory_variable_ids.length
636
-
637
- # TODO Taking this complexity out for now.
638
- # # Find pre-exisitng variables of the same value
639
- # # TODO I should make sure I don't include unessary values here - I should check
640
- # # that the same array access has not already been included indirectly in
641
- # # via the action. var2, var3 both refer to same fixnum for case 1
642
- # existing_variables = mapping.select{|key,value| value == z}
643
- # array_indexs += existing_variables.collect {|key,value| TheoryVariable.new(key)}
644
-
645
- # Before adding a new variable - check that an existing one doesn't already exist
646
-
647
- # * Generate the intrinsic statement for it
648
- new_written_intrinsic_statement = result[:intrinsic_statement].write+'['+z.to_s+']'
649
- # TODO I might be able to use the results instead for the variable history now that I'm
650
- # saving the intrinsic_statement
651
- if variable_history.any? { |x| new_written_intrinsic_statement == x[:intrinsic_statement].write }
652
- StandardLogger.instance.warning('Identical array access already exists '+new_written_intrinsic_statement)
653
- saved_variable = variable_history.find {|x| x[:intrinsic_statement].write == new_written_intrinsic_statement}
654
-
655
- #mapping[saved_variable[:global_variable_id]] = saved_variable[:variable_value].value
656
- mapping[saved_variable[:global_variable_id]] = z
657
- array_indexs << TheoryVariable.new(saved_variable[:global_variable_id])
658
- else
659
-
660
- mapping[theory_id] = z
661
- array_indexs << TheoryVariable.new(theory_id)
662
- theory_variable_ids << theory_variable_ids.length
663
- end
664
- end
665
-
666
- # Generate a statement for each of the calls
667
- array_indexs.each do |z|
668
- s = TheoryStatement.new(StringToTheory.run(result[:statement].write+'['+z.write+']'))
669
- v = obtain_value(s,mapping)
670
- var_ids = s.variables.collect {|a| a.theory_variable_id}
671
- var_values = var_ids.collect {|a| mapping[a]}
672
- results << {
673
- :value=>v,
674
- :statement=>s,
675
- :step=>step,
676
- :variable_values=>var_values,
677
- :intrinsic_statement=>convert_to_intrinsic_statement(s,mapping)
678
- }
679
-
680
- # Save the array history as well
681
- unless variable_history.any? {|x| x[:global_variable_id] == z.theory_variable_id}
682
-
683
- variable_history << {
684
- :intrinsic_statement=>convert_to_intrinsic_statement(s,mapping),
685
- :written_statement=>s.write,
686
- :variable_value=>var_values.last.to_intrinsic,
687
- :global_variable_id=>z.theory_variable_id
688
- }
689
- #raise StandardError.new('This array index has not been saved in the history '+z.theory_variable_id.to_s)
690
-
691
- end
692
-
693
- end
694
- end
695
- return results
696
-
697
- end
698
-
699
- def obtain_value(statement,mapping)
700
-
701
- # Declare each of the theory variables with the correct value
702
- declaration = ''
703
- mapping.each do |key,value|
704
- declaration += 'var'+key.to_s+' = mapping['+key.to_s+']'+"\n"
705
- end
706
- eval(declaration)
707
- return eval(statement.write)
708
-
709
- end
710
-
711
- protected
712
-
713
- def retrieve_accessors(literal_values,variable_creation_history)
714
- value_accessors = []
715
- a = literal_values.copy
716
- literal_values.each do |key,val|
717
- s = TheoryStatement.new(StringToTheory.run('var'+key.to_s))
718
- value_accessors << {
719
- :value=>val.copy,
720
- :statement=>s,
721
- :variable_values=>[val.copy],
722
- :step=>0,
723
- :intrinsic_statement=>convert_to_intrinsic_statement(s.copy,a.copy)
724
- }
725
- end
726
- step = 0
727
-
728
- array_of_variable_ids = literal_values.keys.copy
729
- # TODO Hate the fact that mapping is modified via 'extend_accessors'
730
- mapping = literal_values.copy
731
-
732
- 2.times do
733
- value_accessors = self.extend_accessors( value_accessors,
734
- mapping,
735
- array_of_variable_ids,
736
- (step+1),
737
- variable_creation_history
738
- )
739
- step += 1
740
- end
741
-
742
- return value_accessors
743
- end
744
-
745
- # Converts the theory statement to an intrinsic statement.
746
- #
747
- def convert_to_intrinsic_statement(theory_statement,literal_values)
748
- intrinsic_values = literal_values.inject({}) {|total,(key,value)| total[key] = value.to_intrinsic; total}
749
- intrinsic_statement = theory_statement.map_to(intrinsic_values)
750
- return intrinsic_statement
751
- end
752
-
753
- end