Module: Laser::Analysis

Extended by:
ModuleExtensions
Included in:
Bootstrap
Defined in:
lib/laser/analysis/sexp_analysis.rb,
lib/laser/analysis/sexp.rb,
lib/laser/analysis/arity.rb,
lib/laser/analysis/scope.rb,
lib/laser/analysis/visitor.rb,
lib/laser/analysis/bindings.rb,
lib/laser/analysis/signature.rb,
lib/laser/analysis/laser_utils.rb,
lib/laser/analysis/method_call.rb,
lib/laser/analysis/annotations.rb,
lib/laser/analysis/control_flow.rb,
lib/laser/analysis/protocol_registry.rb,
lib/laser/analysis/argument_expansion.rb,
lib/laser/analysis/bootstrap/bootstrap.rb,
lib/laser/analysis/bootstrap/laser_proc.rb,
lib/laser/analysis/override_safety_info.rb,
lib/laser/analysis/special_methods/send.rb,
lib/laser/analysis/bootstrap/laser_class.rb,
lib/laser/analysis/bootstrap/laser_module.rb,
lib/laser/analysis/bootstrap/laser_method.rb,
lib/laser/analysis/bootstrap/laser_object.rb,
lib/laser/analysis/control_flow/simulation.rb,
lib/laser/analysis/control_flow/cfg_builder.rb,
lib/laser/analysis/control_flow/basic_block.rb,
lib/laser/analysis/bootstrap/dispatch_results.rb,
lib/laser/analysis/control_flow/alias_analysis.rb,
lib/laser/analysis/bootstrap/laser_module_copy.rb,
lib/laser/analysis/control_flow/cfg_instruction.rb,
lib/laser/analysis/control_flow/raise_properties.rb,
lib/laser/analysis/control_flow/unused_variables.rb,
lib/laser/analysis/control_flow/yield_properties.rb,
lib/laser/analysis/control_flow/lifetime_analysis.rb,
lib/laser/analysis/annotations/runtime_annotation.rb,
lib/laser/analysis/sexp_extensions/type_inference.rb,
lib/laser/analysis/method_analysis/unused_methods.rb,
lib/laser/analysis/bootstrap/laser_singleton_class.rb,
lib/laser/analysis/control_flow/control_flow_graph.rb,
lib/laser/analysis/sexp_extensions/source_location.rb,
lib/laser/analysis/control_flow/method_call_search.rb,
lib/laser/analysis/method_analysis/method_analysis.rb,
lib/laser/analysis/control_flow/constant_propagation.rb,
lib/laser/analysis/sexp_extensions/constant_extraction.rb,
lib/laser/analysis/control_flow/unreachability_analysis.rb,
lib/laser/analysis/annotations/node_pointers_annotation.rb,
lib/laser/analysis/control_flow/static_single_assignment.rb,
lib/laser/analysis/control_flow/guaranteed_super_detection.rb,
lib/laser/analysis/annotations/comment_attachment_annotation.rb,
lib/laser/analysis/method_analysis/incorrect_predicate_method_detection.rb

Overview

This is a set of methods that get provided to Warnings so they can perform parse-tree analysis of their bodies.

Defined Under Namespace

Modules: Annotations, ArgumentListHandling, Bindings, Bootstrap, ClassRegistry, ControlFlow, IncorrectPredicateMethodDetection, MethodAnalysis, OverrideSafetyInfo, ProtocolRegistry, SexpExtensions, Signature, SingletonClassFactory, SpecialMethods, UnusedMethodDetection, Utilities, Visitor Classes: ArgumentExpansion, Arity, BasicAnnotation, ClosedScope, CommentAttachmentAnnotation, DispatchResults, LaserClass, LaserMethod, LaserModule, LaserModuleCopy, LaserObject, LaserProc, LaserSingletonClass, MethodCall, NodePointersAnnotation, OpenScope, RuntimeAnnotation, Scope, Sexp

Constant Summary

PARSING_CACHE =
{}
UNDEFINED =
PlaceholderObject.new('UNDEFINED')
VARYING =
PlaceholderObject.new('VARYING')

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModuleExtensions

attr_accessor_with_default, cattr_accessor, cattr_accessor_with_default, cattr_get_and_setter, cattr_reader, cattr_writer, opposite_method

Class Method Details

.analyze_inputs(inputs) ⇒ Object

inputs: Array<(String, String)>

Array of (filename, body) tuples.


9
10
11
# File 'lib/laser/analysis/sexp_analysis.rb', line 9

def self.analyze_inputs(inputs)
  Annotations.annotate_inputs(inputs)
end

Instance Method Details

#find_sexps(type, tree = self.parse(self.body)) ⇒ Array<Sexp>

Finds all sexps of the given type in the given Sexp tree.



32
33
34
35
36
37
38
# File 'lib/laser/analysis/sexp_analysis.rb', line 32

def find_sexps(type, tree = self.parse(self.body))
  result = tree[0] == type ? [tree] : []
  tree.each do |node|
    result.concat find_sexps(type, node) if node.is_a?(Array)
  end
  result
end

#parse(body = self.body) ⇒ Sexp, NilClass

Parses the given text.



19
20
21
22
23
# File 'lib/laser/analysis/sexp_analysis.rb', line 19

def parse(body = self.body)
  return PARSING_CACHE[body] if PARSING_CACHE[body]
  pairs = Analysis.analyze_inputs([[file, body]])
  PARSING_CACHE[body] = pairs[0][1]
end