laser 0.7.0.pre1
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE +661 -0
- data/README.md +158 -0
- data/Rakefile +104 -0
- data/VERSION +1 -0
- data/bin/laser +7 -0
- data/design_docs/goals.md +57 -0
- data/design_docs/object_regex.md +426 -0
- data/design_docs/type_annotations.md +80 -0
- data/ext/laser/BasicBlock.cpp +572 -0
- data/ext/laser/BasicBlock.h +118 -0
- data/ext/laser/extconf.rb +3 -0
- data/features/laser.feature +25 -0
- data/features/step_definitions/laser_steps.rb +39 -0
- data/features/support/env.rb +14 -0
- data/features/support/testdata/1_input +1 -0
- data/features/support/testdata/1_output +1 -0
- data/features/support/testdata/2_input +4 -0
- data/features/support/testdata/2_output +4 -0
- data/features/support/testdata/3_input +8 -0
- data/features/support/testdata/3_output +11 -0
- data/features/support/testdata/4_input +5 -0
- data/features/support/testdata/4_output +5 -0
- data/features/support/testdata/5_input +13 -0
- data/laser.gemspec +382 -0
- data/lib/laser.rb +98 -0
- data/lib/laser/analysis/annotations.rb +95 -0
- data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
- data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
- data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
- data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
- data/lib/laser/analysis/argument_expansion.rb +132 -0
- data/lib/laser/analysis/arity.rb +34 -0
- data/lib/laser/analysis/bindings.rb +144 -0
- data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
- data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
- data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
- data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
- data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
- data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
- data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
- data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
- data/lib/laser/analysis/comments.rb +35 -0
- data/lib/laser/analysis/control_flow.rb +28 -0
- data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
- data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
- data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
- data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
- data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
- data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
- data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
- data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
- data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
- data/lib/laser/analysis/control_flow/simulation.rb +385 -0
- data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
- data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
- data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
- data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
- data/lib/laser/analysis/errors.rb +131 -0
- data/lib/laser/analysis/laser_utils.rb +18 -0
- data/lib/laser/analysis/lexical_analysis.rb +172 -0
- data/lib/laser/analysis/method_call.rb +68 -0
- data/lib/laser/analysis/protocol_registry.rb +30 -0
- data/lib/laser/analysis/scope.rb +118 -0
- data/lib/laser/analysis/sexp.rb +159 -0
- data/lib/laser/analysis/sexp_analysis.rb +40 -0
- data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
- data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
- data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
- data/lib/laser/analysis/signature.rb +76 -0
- data/lib/laser/analysis/special_methods/send.rb +67 -0
- data/lib/laser/analysis/unused_methods.rb +21 -0
- data/lib/laser/analysis/visitor.rb +141 -0
- data/lib/laser/annotation_parser/annotations.treetop +126 -0
- data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
- data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
- data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
- data/lib/laser/annotation_parser/overload.treetop +24 -0
- data/lib/laser/annotation_parser/overload_parser.rb +167 -0
- data/lib/laser/annotation_parser/parsers.rb +6 -0
- data/lib/laser/annotation_parser/structural.treetop +37 -0
- data/lib/laser/annotation_parser/structural_parser.rb +406 -0
- data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
- data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
- data/lib/laser/rake/task.rb +46 -0
- data/lib/laser/runner.rb +189 -0
- data/lib/laser/scanner.rb +169 -0
- data/lib/laser/standard_library/_thread.rb +110 -0
- data/lib/laser/standard_library/abbrev.rb +103 -0
- data/lib/laser/standard_library/array.rb +418 -0
- data/lib/laser/standard_library/base64.rb +91 -0
- data/lib/laser/standard_library/basic_object.rb +55 -0
- data/lib/laser/standard_library/benchmark.rb +556 -0
- data/lib/laser/standard_library/bignum.rb +185 -0
- data/lib/laser/standard_library/cgi.rb +275 -0
- data/lib/laser/standard_library/cgi/cookie.rb +147 -0
- data/lib/laser/standard_library/cgi/core.rb +791 -0
- data/lib/laser/standard_library/cgi/html.rb +1021 -0
- data/lib/laser/standard_library/cgi/session.rb +537 -0
- data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
- data/lib/laser/standard_library/cgi/util.rb +188 -0
- data/lib/laser/standard_library/class_definitions.rb +333 -0
- data/lib/laser/standard_library/comparable.rb +125 -0
- data/lib/laser/standard_library/complex.rb +162 -0
- data/lib/laser/standard_library/enumerable.rb +178 -0
- data/lib/laser/standard_library/exceptions.rb +135 -0
- data/lib/laser/standard_library/fixnum.rb +188 -0
- data/lib/laser/standard_library/float.rb +180 -0
- data/lib/laser/standard_library/hash.rb +237 -0
- data/lib/laser/standard_library/integer.rb +123 -0
- data/lib/laser/standard_library/laser_magic.rb +7 -0
- data/lib/laser/standard_library/nil_false_true.rb +113 -0
- data/lib/laser/standard_library/numbers.rb +192 -0
- data/lib/laser/standard_library/proc.rb +31 -0
- data/lib/laser/standard_library/set.rb +1348 -0
- data/lib/laser/standard_library/string.rb +666 -0
- data/lib/laser/standard_library/stringio.rb +2 -0
- data/lib/laser/standard_library/symbol.rb +125 -0
- data/lib/laser/standard_library/tsort.rb +242 -0
- data/lib/laser/support/acts_as_struct.rb +66 -0
- data/lib/laser/support/frequency.rb +55 -0
- data/lib/laser/support/inheritable_attributes.rb +145 -0
- data/lib/laser/support/module_extensions.rb +94 -0
- data/lib/laser/support/placeholder_object.rb +13 -0
- data/lib/laser/third_party/rgl/adjacency.rb +221 -0
- data/lib/laser/third_party/rgl/base.rb +228 -0
- data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
- data/lib/laser/third_party/rgl/condensation.rb +47 -0
- data/lib/laser/third_party/rgl/connected_components.rb +138 -0
- data/lib/laser/third_party/rgl/control_flow.rb +170 -0
- data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
- data/lib/laser/third_party/rgl/dominators.rb +124 -0
- data/lib/laser/third_party/rgl/dot.rb +93 -0
- data/lib/laser/third_party/rgl/graphxml.rb +51 -0
- data/lib/laser/third_party/rgl/implicit.rb +174 -0
- data/lib/laser/third_party/rgl/mutable.rb +117 -0
- data/lib/laser/third_party/rgl/rdot.rb +445 -0
- data/lib/laser/third_party/rgl/topsort.rb +72 -0
- data/lib/laser/third_party/rgl/transitivity.rb +180 -0
- data/lib/laser/third_party/rgl/traversal.rb +348 -0
- data/lib/laser/types/types.rb +433 -0
- data/lib/laser/version.rb +14 -0
- data/lib/laser/warning.rb +149 -0
- data/lib/laser/warning_sets/default.yml +13 -0
- data/lib/laser/warnings/assignment_in_condition.rb +20 -0
- data/lib/laser/warnings/comment_spacing.rb +31 -0
- data/lib/laser/warnings/extra_blank_lines.rb +30 -0
- data/lib/laser/warnings/extra_whitespace.rb +16 -0
- data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
- data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
- data/lib/laser/warnings/line_length.rb +115 -0
- data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
- data/lib/laser/warnings/operator_spacing.rb +68 -0
- data/lib/laser/warnings/parens_on_declaration.rb +30 -0
- data/lib/laser/warnings/rescue_exception.rb +42 -0
- data/lib/laser/warnings/semicolon.rb +25 -0
- data/lib/laser/warnings/sexp_errors.rb +24 -0
- data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
- data/lib/laser/warnings/useless_double_quotes.rb +38 -0
- data/spec/analysis_specs/annotations_spec.rb +47 -0
- data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
- data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
- data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
- data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
- data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
- data/spec/analysis_specs/bindings_spec.rb +36 -0
- data/spec/analysis_specs/comment_spec.rb +93 -0
- data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
- data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
- data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
- data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
- data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
- data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
- data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
- data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
- data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
- data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
- data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
- data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
- data/spec/analysis_specs/error_spec.rb +30 -0
- data/spec/analysis_specs/laser_class_spec.rb +322 -0
- data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
- data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
- data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
- data/spec/analysis_specs/scope_spec.rb +126 -0
- data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
- data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
- data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
- data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
- data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
- data/spec/analysis_specs/sexp_spec.rb +167 -0
- data/spec/analysis_specs/spec_helper.rb +27 -0
- data/spec/analysis_specs/unused_methods_spec.rb +65 -0
- data/spec/analysis_specs/visitor_spec.rb +64 -0
- data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
- data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
- data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
- data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
- data/spec/annotation_parser_specs/spec_helper.rb +1 -0
- data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
- data/spec/laser_spec.rb +14 -0
- data/spec/rake_specs/spec_helper.rb +1 -0
- data/spec/rake_specs/task_spec.rb +67 -0
- data/spec/runner_spec.rb +207 -0
- data/spec/scanner_spec.rb +75 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/standard_library/exceptions_spec.rb +19 -0
- data/spec/standard_library/globals_spec.rb +14 -0
- data/spec/standard_library/set_spec.rb +31 -0
- data/spec/standard_library/spec_helper.rb +1 -0
- data/spec/standard_library/standard_library_spec.rb +302 -0
- data/spec/support_specs/acts_as_struct_spec.rb +94 -0
- data/spec/support_specs/frequency_spec.rb +23 -0
- data/spec/support_specs/module_extensions_spec.rb +117 -0
- data/spec/support_specs/spec_helper.rb +1 -0
- data/spec/type_specs/spec_helper.rb +1 -0
- data/spec/type_specs/types_spec.rb +133 -0
- data/spec/warning_spec.rb +95 -0
- data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
- data/spec/warning_specs/comment_spacing_spec.rb +65 -0
- data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
- data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
- data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
- data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
- data/spec/warning_specs/line_length_spec.rb +173 -0
- data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
- data/spec/warning_specs/operator_spacing_spec.rb +104 -0
- data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
- data/spec/warning_specs/rescue_exception_spec.rb +105 -0
- data/spec/warning_specs/semicolon_spec.rb +58 -0
- data/spec/warning_specs/spec_helper.rb +1 -0
- data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
- data/status_reports/2010/12/2010-12-14.md +163 -0
- data/status_reports/2010/12/2010-12-23.md +298 -0
- data/status_reports/2010/12/2010-12-24.md +6 -0
- data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
- data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
- data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
- data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
- data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
- data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
- data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
- data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
- data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
- data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
- data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
- data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
- data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
- data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
- data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
- metadata +470 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
class Symbol
|
|
2
|
+
# builtin: true
|
|
3
|
+
# pure: true
|
|
4
|
+
# returns: Fixnum= | NilClass
|
|
5
|
+
def <=>(other)
|
|
6
|
+
end
|
|
7
|
+
# builtin: true
|
|
8
|
+
# pure: true
|
|
9
|
+
# returns: Boolean
|
|
10
|
+
def ==(other)
|
|
11
|
+
end
|
|
12
|
+
# builtin: true
|
|
13
|
+
# pure: true
|
|
14
|
+
# returns: Boolean
|
|
15
|
+
def ===(other)
|
|
16
|
+
end
|
|
17
|
+
# builtin: true
|
|
18
|
+
# pure: true
|
|
19
|
+
# returns: Fixnum= | Bignum= | NilClass
|
|
20
|
+
def =~(other)
|
|
21
|
+
end
|
|
22
|
+
# builtin: true
|
|
23
|
+
# pure: true
|
|
24
|
+
# returns: String=
|
|
25
|
+
def [](arg1, arg2 = :__unset__)
|
|
26
|
+
end
|
|
27
|
+
# builtin: true
|
|
28
|
+
# pure: true
|
|
29
|
+
# returns: String=
|
|
30
|
+
def capitalize
|
|
31
|
+
end
|
|
32
|
+
# builtin: true
|
|
33
|
+
# pure: true
|
|
34
|
+
# returns: Fixnum= | NilClass
|
|
35
|
+
def casecmp(other)
|
|
36
|
+
end
|
|
37
|
+
# builtin: true
|
|
38
|
+
# pure: true
|
|
39
|
+
# returns: String=
|
|
40
|
+
def downcase
|
|
41
|
+
end
|
|
42
|
+
# builtin: true
|
|
43
|
+
# pure: true
|
|
44
|
+
# returns: Boolean
|
|
45
|
+
def empty?
|
|
46
|
+
end
|
|
47
|
+
# builtin: true
|
|
48
|
+
# pure: true
|
|
49
|
+
# returns: Encoding
|
|
50
|
+
def encoding
|
|
51
|
+
end
|
|
52
|
+
# builtin: true
|
|
53
|
+
# pure: true
|
|
54
|
+
# returns: String=
|
|
55
|
+
def id2name
|
|
56
|
+
end
|
|
57
|
+
# builtin: true
|
|
58
|
+
# pure: true
|
|
59
|
+
# returns: String=
|
|
60
|
+
def inspect
|
|
61
|
+
end
|
|
62
|
+
# builtin: true
|
|
63
|
+
# pure: true
|
|
64
|
+
# returns: Symbol=
|
|
65
|
+
def intern
|
|
66
|
+
end
|
|
67
|
+
# builtin: true
|
|
68
|
+
# pure: true
|
|
69
|
+
# returns: Fixnum= | Bignum=
|
|
70
|
+
def length
|
|
71
|
+
end
|
|
72
|
+
# builtin: true
|
|
73
|
+
# pure: true
|
|
74
|
+
def match(other)
|
|
75
|
+
end
|
|
76
|
+
# builtin: true
|
|
77
|
+
# pure: true
|
|
78
|
+
# returns: String=
|
|
79
|
+
def next
|
|
80
|
+
end
|
|
81
|
+
# builtin: true
|
|
82
|
+
# pure: true
|
|
83
|
+
# returns: Fixnum= | Bignum=
|
|
84
|
+
def size
|
|
85
|
+
end
|
|
86
|
+
# builtin: true
|
|
87
|
+
# pure: true
|
|
88
|
+
def slice(arg1, arg2 = :__unset__)
|
|
89
|
+
end
|
|
90
|
+
# builtin: true
|
|
91
|
+
# pure: true
|
|
92
|
+
# returns: String=
|
|
93
|
+
def succ
|
|
94
|
+
end
|
|
95
|
+
# builtin: true
|
|
96
|
+
# pure: true
|
|
97
|
+
# returns: String=
|
|
98
|
+
def swapcase
|
|
99
|
+
end
|
|
100
|
+
# pure: true
|
|
101
|
+
def to_proc
|
|
102
|
+
sym = self
|
|
103
|
+
proc { |*args| args.shift.__send__(sym, *args) }
|
|
104
|
+
end
|
|
105
|
+
# builtin: true
|
|
106
|
+
# pure: true
|
|
107
|
+
# returns: String=
|
|
108
|
+
def to_s
|
|
109
|
+
end
|
|
110
|
+
# builtin: true
|
|
111
|
+
# pure: true
|
|
112
|
+
# returns: Symbol=
|
|
113
|
+
def to_sym
|
|
114
|
+
end
|
|
115
|
+
# builtin: true
|
|
116
|
+
# pure: true
|
|
117
|
+
# returns: String=
|
|
118
|
+
def to_yaml
|
|
119
|
+
end
|
|
120
|
+
# builtin: true
|
|
121
|
+
# pure: true
|
|
122
|
+
# returns: String=
|
|
123
|
+
def upcase
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# tsort.rb - provides a module for topological sorting and strongly connected components.
|
|
3
|
+
#++
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# TSort implements topological sorting using Tarjan's algorithm for
|
|
8
|
+
# strongly connected components.
|
|
9
|
+
#
|
|
10
|
+
# TSort is designed to be able to be used with any object which can be
|
|
11
|
+
# interpreted as a directed graph.
|
|
12
|
+
#
|
|
13
|
+
# TSort requires two methods to interpret an object as a graph,
|
|
14
|
+
# tsort_each_node and tsort_each_child.
|
|
15
|
+
#
|
|
16
|
+
# * tsort_each_node is used to iterate for all nodes over a graph.
|
|
17
|
+
# * tsort_each_child is used to iterate for child nodes of a given node.
|
|
18
|
+
#
|
|
19
|
+
# The equality of nodes are defined by eql? and hash since
|
|
20
|
+
# TSort uses Hash internally.
|
|
21
|
+
#
|
|
22
|
+
# == A Simple Example
|
|
23
|
+
#
|
|
24
|
+
# The following example demonstrates how to mix the TSort module into an
|
|
25
|
+
# existing class (in this case, Hash). Here, we're treating each key in
|
|
26
|
+
# the hash as a node in the graph, and so we simply alias the required
|
|
27
|
+
# #tsort_each_node method to Hash's #each_key method. For each key in the
|
|
28
|
+
# hash, the associated value is an array of the node's child nodes. This
|
|
29
|
+
# choice in turn leads to our implementation of the required #tsort_each_child
|
|
30
|
+
# method, which fetches the array of child nodes and then iterates over that
|
|
31
|
+
# array using the user-supplied block.
|
|
32
|
+
#
|
|
33
|
+
# require 'tsort'
|
|
34
|
+
#
|
|
35
|
+
# class Hash
|
|
36
|
+
# include TSort
|
|
37
|
+
# alias tsort_each_node each_key
|
|
38
|
+
# def tsort_each_child(node, &block)
|
|
39
|
+
# fetch(node).each(&block)
|
|
40
|
+
# end
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
|
|
44
|
+
# #=> [3, 2, 1, 4]
|
|
45
|
+
#
|
|
46
|
+
# {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
|
|
47
|
+
# #=> [[4], [2, 3], [1]]
|
|
48
|
+
#
|
|
49
|
+
# == A More Realistic Example
|
|
50
|
+
#
|
|
51
|
+
# A very simple `make' like tool can be implemented as follows:
|
|
52
|
+
#
|
|
53
|
+
# require 'tsort'
|
|
54
|
+
#
|
|
55
|
+
# class Make
|
|
56
|
+
# def initialize
|
|
57
|
+
# @dep = {}
|
|
58
|
+
# @dep.default = []
|
|
59
|
+
# end
|
|
60
|
+
#
|
|
61
|
+
# def rule(outputs, inputs=[], &block)
|
|
62
|
+
# triple = [outputs, inputs, block]
|
|
63
|
+
# outputs.each {|f| @dep[f] = [triple]}
|
|
64
|
+
# @dep[triple] = inputs
|
|
65
|
+
# end
|
|
66
|
+
#
|
|
67
|
+
# def build(target)
|
|
68
|
+
# each_strongly_connected_component_from(target) {|ns|
|
|
69
|
+
# if ns.length != 1
|
|
70
|
+
# fs = ns.delete_if {|n| Array === n}
|
|
71
|
+
# raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
|
|
72
|
+
# end
|
|
73
|
+
# n = ns.first
|
|
74
|
+
# if Array === n
|
|
75
|
+
# outputs, inputs, block = n
|
|
76
|
+
# inputs_time = inputs.map {|f| File.mtime f}.max
|
|
77
|
+
# begin
|
|
78
|
+
# outputs_time = outputs.map {|f| File.mtime f}.min
|
|
79
|
+
# rescue Errno::ENOENT
|
|
80
|
+
# outputs_time = nil
|
|
81
|
+
# end
|
|
82
|
+
# if outputs_time == nil ||
|
|
83
|
+
# inputs_time != nil && outputs_time <= inputs_time
|
|
84
|
+
# sleep 1 if inputs_time != nil && inputs_time.to_i == Time.now.to_i
|
|
85
|
+
# block.call
|
|
86
|
+
# end
|
|
87
|
+
# end
|
|
88
|
+
# }
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# def tsort_each_child(node, &block)
|
|
92
|
+
# @dep[node].each(&block)
|
|
93
|
+
# end
|
|
94
|
+
# include TSort
|
|
95
|
+
# end
|
|
96
|
+
#
|
|
97
|
+
# def command(arg)
|
|
98
|
+
# print arg, "\n"
|
|
99
|
+
# system arg
|
|
100
|
+
# end
|
|
101
|
+
#
|
|
102
|
+
# m = Make.new
|
|
103
|
+
# m.rule(%w[t1]) { command 'date > t1' }
|
|
104
|
+
# m.rule(%w[t2]) { command 'date > t2' }
|
|
105
|
+
# m.rule(%w[t3]) { command 'date > t3' }
|
|
106
|
+
# m.rule(%w[t4], %w[t1 t3]) { command 'cat t1 t3 > t4' }
|
|
107
|
+
# m.rule(%w[t5], %w[t4 t2]) { command 'cat t4 t2 > t5' }
|
|
108
|
+
# m.build('t5')
|
|
109
|
+
#
|
|
110
|
+
# == Bugs
|
|
111
|
+
#
|
|
112
|
+
# * 'tsort.rb' is wrong name because this library uses
|
|
113
|
+
# Tarjan's algorithm for strongly connected components.
|
|
114
|
+
# Although 'strongly_connected_components.rb' is correct but too long.
|
|
115
|
+
#
|
|
116
|
+
# == References
|
|
117
|
+
#
|
|
118
|
+
# R. E. Tarjan, "Depth First Search and Linear Graph Algorithms",
|
|
119
|
+
# <em>SIAM Journal on Computing</em>, Vol. 1, No. 2, pp. 146-160, June 1972.
|
|
120
|
+
#
|
|
121
|
+
|
|
122
|
+
module TSort
|
|
123
|
+
class Cyclic < StandardError
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# Returns a topologically sorted array of nodes.
|
|
128
|
+
# The array is sorted from children to parents, i.e.
|
|
129
|
+
# the first element has no child and the last node has no parent.
|
|
130
|
+
#
|
|
131
|
+
# If there is a cycle, TSort::Cyclic is raised.
|
|
132
|
+
#
|
|
133
|
+
def tsort
|
|
134
|
+
result = []
|
|
135
|
+
tsort_each {|element| result << element}
|
|
136
|
+
result
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
#
|
|
140
|
+
# The iterator version of the #tsort method.
|
|
141
|
+
# <tt><em>obj</em>.tsort_each</tt> is similar to <tt><em>obj</em>.tsort.each</tt>, but
|
|
142
|
+
# modification of _obj_ during the iteration may lead to unexpected results.
|
|
143
|
+
#
|
|
144
|
+
# #tsort_each returns +nil+.
|
|
145
|
+
# If there is a cycle, TSort::Cyclic is raised.
|
|
146
|
+
#
|
|
147
|
+
def tsort_each # :yields: node
|
|
148
|
+
each_strongly_connected_component {|component|
|
|
149
|
+
if component.size == 1
|
|
150
|
+
yield component.first
|
|
151
|
+
else
|
|
152
|
+
raise Cyclic.new("topological sort failed: #{component.inspect}")
|
|
153
|
+
end
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
# Returns strongly connected components as an array of arrays of nodes.
|
|
159
|
+
# The array is sorted from children to parents.
|
|
160
|
+
# Each elements of the array represents a strongly connected component.
|
|
161
|
+
#
|
|
162
|
+
def strongly_connected_components
|
|
163
|
+
result = []
|
|
164
|
+
each_strongly_connected_component {|component| result << component}
|
|
165
|
+
result
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
#
|
|
169
|
+
# The iterator version of the #strongly_connected_components method.
|
|
170
|
+
# <tt><em>obj</em>.each_strongly_connected_component</tt> is similar to
|
|
171
|
+
# <tt><em>obj</em>.strongly_connected_components.each</tt>, but
|
|
172
|
+
# modification of _obj_ during the iteration may lead to unexpected results.
|
|
173
|
+
#
|
|
174
|
+
#
|
|
175
|
+
# #each_strongly_connected_component returns +nil+.
|
|
176
|
+
#
|
|
177
|
+
def each_strongly_connected_component # :yields: nodes
|
|
178
|
+
id_map = {}
|
|
179
|
+
stack = []
|
|
180
|
+
tsort_each_node {|node|
|
|
181
|
+
unless id_map.include? node
|
|
182
|
+
each_strongly_connected_component_from(node, id_map, stack) {|c|
|
|
183
|
+
yield c
|
|
184
|
+
}
|
|
185
|
+
end
|
|
186
|
+
}
|
|
187
|
+
nil
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
#
|
|
191
|
+
# Iterates over strongly connected component in the subgraph reachable from
|
|
192
|
+
# _node_.
|
|
193
|
+
#
|
|
194
|
+
# Return value is unspecified.
|
|
195
|
+
#
|
|
196
|
+
# #each_strongly_connected_component_from doesn't call #tsort_each_node.
|
|
197
|
+
#
|
|
198
|
+
def each_strongly_connected_component_from(node, id_map={}, stack=[]) # :yields: nodes
|
|
199
|
+
minimum_id = node_id = id_map[node] = id_map.size
|
|
200
|
+
stack_length = stack.length
|
|
201
|
+
stack << node
|
|
202
|
+
|
|
203
|
+
tsort_each_child(node) {|child|
|
|
204
|
+
if id_map.include? child
|
|
205
|
+
child_id = id_map[child]
|
|
206
|
+
minimum_id = child_id if child_id && child_id < minimum_id
|
|
207
|
+
else
|
|
208
|
+
sub_minimum_id =
|
|
209
|
+
each_strongly_connected_component_from(child, id_map, stack) {|c|
|
|
210
|
+
yield c
|
|
211
|
+
}
|
|
212
|
+
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
|
213
|
+
end
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if node_id == minimum_id
|
|
217
|
+
component = stack.slice!(stack_length .. -1)
|
|
218
|
+
component.each {|n| id_map[n] = nil}
|
|
219
|
+
yield component
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
minimum_id
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
#
|
|
226
|
+
# Should be implemented by a extended class.
|
|
227
|
+
#
|
|
228
|
+
# #tsort_each_node is used to iterate for all nodes over a graph.
|
|
229
|
+
#
|
|
230
|
+
def tsort_each_node # :yields: node
|
|
231
|
+
raise NotImplementedError.new
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
#
|
|
235
|
+
# Should be implemented by a extended class.
|
|
236
|
+
#
|
|
237
|
+
# #tsort_each_child is used to iterate for child nodes of _node_.
|
|
238
|
+
#
|
|
239
|
+
def tsort_each_child(node) # :yields: child
|
|
240
|
+
raise NotImplementedError.new
|
|
241
|
+
end
|
|
242
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Laser
|
|
2
|
+
# Lets a class act as a struct by extending the module and using acts_as_struct.
|
|
3
|
+
# This is useful if you need to inherit from another class so you can't subclass
|
|
4
|
+
# Struct.new. However, reads will be slower due to optimizations that the C version
|
|
5
|
+
# of Struct that comes with the standard library can do.
|
|
6
|
+
module ActsAsStruct
|
|
7
|
+
# Mixes in struct behavior to the current class.
|
|
8
|
+
def acts_as_struct(*members)
|
|
9
|
+
include Comparable
|
|
10
|
+
extend InheritedAttributes
|
|
11
|
+
class_inheritable_array :current_members unless respond_to?(:current_members)
|
|
12
|
+
|
|
13
|
+
self.current_members ||= []
|
|
14
|
+
self.current_members.concat members
|
|
15
|
+
all_members = self.current_members
|
|
16
|
+
# Only add new members
|
|
17
|
+
attr_accessor *members
|
|
18
|
+
# NOT backwards compatible with a Struct's initializer. If you
|
|
19
|
+
# try to initialize the first argument to a Hash and don't provide
|
|
20
|
+
# other arguments, you trigger the hash extraction initializer instead
|
|
21
|
+
# of the positional initializer. That's a bad idea.
|
|
22
|
+
define_method :initialize do |*args|
|
|
23
|
+
if args.size == 1 && Hash === args.first
|
|
24
|
+
initialize_hash(args.first)
|
|
25
|
+
else
|
|
26
|
+
if args.size > all_members.size
|
|
27
|
+
raise ArgumentError.new("#{self.class} has #{all_members.size} members " +
|
|
28
|
+
"- you provided #{args.size}")
|
|
29
|
+
end
|
|
30
|
+
initialize_positional(args)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Initializes by treating the input as key-value assignments.
|
|
35
|
+
define_method :initialize_hash do |hash|
|
|
36
|
+
hash.each { |k, v| send("#{k}=", v) }
|
|
37
|
+
end
|
|
38
|
+
private :initialize_hash
|
|
39
|
+
|
|
40
|
+
# Initialize by treating the input as positional arguments that
|
|
41
|
+
# line up with the struct members provided to acts_as_struct.
|
|
42
|
+
define_method :initialize_positional do |args|
|
|
43
|
+
args.each_with_index do |value, idx|
|
|
44
|
+
key = all_members[idx]
|
|
45
|
+
send("#{key}=", value)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
private :initialize_positional
|
|
49
|
+
|
|
50
|
+
# Helper methods for keys/values.
|
|
51
|
+
define_method(:keys_and_values) { keys.zip(values) }
|
|
52
|
+
define_method(:values) { keys.map { |member| send member } }
|
|
53
|
+
define_method(:keys) { all_members }
|
|
54
|
+
define_method(:each) { |&blk| keys_and_values.each { |k, v| blk.call([k, v]) } }
|
|
55
|
+
define_method(:'<=>') do |other|
|
|
56
|
+
each do |key, value|
|
|
57
|
+
res = (value <=> other.send(key))
|
|
58
|
+
if res != 0
|
|
59
|
+
return res
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
0
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Laser
|
|
2
|
+
class Frequency
|
|
3
|
+
include Comparable
|
|
4
|
+
attr_reader :name, :val
|
|
5
|
+
def initialize(name, val)
|
|
6
|
+
@name = name
|
|
7
|
+
@val = val
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def ===(other)
|
|
11
|
+
equal? other
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@name.to_s
|
|
16
|
+
end
|
|
17
|
+
alias inspect to_s
|
|
18
|
+
|
|
19
|
+
def <=>(other)
|
|
20
|
+
@val <=> other.val
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
NEVER = self.new(:never, 0)
|
|
24
|
+
MAYBE = self.new(:maybe, 1)
|
|
25
|
+
ALWAYS = self.new(:always, 2)
|
|
26
|
+
|
|
27
|
+
LOOKUP = {never: NEVER, maybe: MAYBE, always: ALWAYS}
|
|
28
|
+
def self.[](sym)
|
|
29
|
+
LOOKUP[sym]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.combine_samples(samples)
|
|
33
|
+
return NEVER if samples.empty?
|
|
34
|
+
base = samples.first
|
|
35
|
+
samples[1..-1].each do |sample|
|
|
36
|
+
return MAYBE if sample > base || sample < base
|
|
37
|
+
end
|
|
38
|
+
base
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.for_samples(yes, no)
|
|
42
|
+
if no && !yes
|
|
43
|
+
NEVER
|
|
44
|
+
elsif no && yes
|
|
45
|
+
MAYBE
|
|
46
|
+
else # !no && yes
|
|
47
|
+
ALWAYS
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class << self
|
|
52
|
+
undef new
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|