Class: C::Call
- Inherits:
-
Object
- Object
- C::Call
- Defined in:
- lib/csquare.rb
Instance Method Summary collapse
- #decorate_calls!(type_symbol, blueprint_obj) ⇒ Object
-
#depth ⇒ Object
Determine the depth of this tree of binary expressions.
-
#recombine!(function, blueprint, type_symbol, return_type = nil) ⇒ Object
Replace some expression with the pattern from Blueprint.
-
#recursively_decorate_calls!(blueprint, type_symbol) ⇒ Object
Recursively decorate function calls as appropriate.
- #return_typename(function, blueprint) ⇒ Object
Instance Method Details
#decorate_calls!(type_symbol, blueprint_obj) ⇒ Object
865 866 867 868 |
# File 'lib/csquare.rb', line 865 def decorate_calls! type_symbol, blueprint_obj super(type_symbol, blueprint_obj) self.expr.name = blueprint_obj.decorated_call(self.expr.name, type_symbol) end |
#depth ⇒ Object
Determine the depth of this tree of binary expressions. Only include BinaryExpression nodes.
889 890 891 892 893 |
# File 'lib/csquare.rb', line 889 def depth left_depth = expr1.respond_to?(:depth) ? expr1.depth : 0 right_depth = expr2.respond_to?(:depth) ? expr2.depth : 0 (left_depth > right_depth ? left_depth : right_depth) + 1 end |
#recombine!(function, blueprint, type_symbol, return_type = nil) ⇒ Object
Replace some expression with the pattern from Blueprint.
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'lib/csquare.rb', line 896 def recombine! function, blueprint, type_symbol, return_type=nil args_types = {} call_returns = self.return_typename(function, blueprint) expr_name = self.expr.Index? ? self.expr.expr.name : self.expr.name #if expr_name == "ew_bool" # require 'pry' # binding.pry #end # Handle externs if blueprint.externs.has_key?(expr_name) field_key = blueprint.externs[expr_name] current_type = blueprint.types[type_symbol] if current_type.keys.has_key?(field_key) field_type_symbol = current_type.keys[field_key] new_expr_name = blueprint.generator.types[field_type_symbol].blueprint.decorated_call(expr_name, field_type_symbol) # Correctly update the expression name if self.expr.Index? self.expr.expr.name = new_expr_name else self.expr.name = new_expr_name end elsif self.expr.Index? self.expr.expr.name = blueprint.decorated_call(expr_name, type_symbol) elsif self.expr.Variable? self.expr.name = blueprint.force_decorated_call(expr_name, type_symbol) end end # Don't do fields -- do args instead. We don't want to recombine the expression name, as it won't have a return type. self.args.each_with_index do |n,i| if n.respond_to?(:recombine!) n = (n) if blueprint.has_op?(n.op) result = n.recombine! function, blueprint, type_symbol, return_type replace_node(n, result[0]) unless result.nil? || result[0].nil? || result[0] == n end end [self, call_returns] end |
#recursively_decorate_calls!(blueprint, type_symbol) ⇒ Object
Recursively decorate function calls as appropriate.
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
# File 'lib/csquare.rb', line 871 def recursively_decorate_calls! blueprint, type_symbol each do |n| n.recursively_decorate_calls! blueprint, type_symbol end if blueprint.externs.has_key?(self.expr.name) # Let's figure out what to replace this call with. Ask the template type for the # decorated function names corresponding to *this* function. decorated_externs = blueprint.decorated_externs(type_symbol, self.expr.name) self.expr.name = decorated_externs[self.expr.name].keys.first else blueprint.generator.externs[self.expr.name] end end |
#return_typename(function, blueprint) ⇒ Object
861 862 863 |
# File 'lib/csquare.rb', line 861 def return_typename function, blueprint function.type_of(self.expr.name, blueprint) end |