|
| 1 | +;; Copyright (c) Nicola Mometto, Rich Hickey & contributors. |
| 2 | +;; The use and distribution terms for this software are covered by the |
| 3 | +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
| 4 | +;; which can be found in the file epl-v10.html at the root of this distribution. |
| 5 | +;; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +;; the terms of this license. |
| 7 | +;; You must not remove this notice, or any other, from this software. |
| 8 | + |
| 9 | +(ns clojure.tools.analyzer.passes.jvm.process-method-value |
| 10 | + (:require [clojure.tools.analyzer.utils :refer [source-info]] |
| 11 | + [clojure.tools.analyzer.passes.jvm.analyze-host-expr :refer [analyze-host-expr]])) |
| 12 | + |
| 13 | +(defn process-method-value |
| 14 | + "Transforms :invoke nodes whose :fn is a :method-value into the |
| 15 | + corresponding :instance-call, :static-call, or :new node. " |
| 16 | + {:pass-info {:walk :post :depends #{#'analyze-host-expr}}} |
| 17 | + [{:keys [op] :as ast}] |
| 18 | + (if (and (= :invoke op) |
| 19 | + (= :method-value (:op (:fn ast)))) |
| 20 | + (let [{:keys [args env]} ast |
| 21 | + {:keys [class method kind param-tags]} (:fn ast)] |
| 22 | + (when (and (= :instance kind) (empty? args)) |
| 23 | + (throw (ex-info (str "Qualified instance method " (.getName ^Class class) "/." method |
| 24 | + " must have a target") |
| 25 | + (merge {:class class :method method} |
| 26 | + (source-info env))))) |
| 27 | + (merge (dissoc ast :fn :args) |
| 28 | + (case kind |
| 29 | + :instance |
| 30 | + {:op :instance-call |
| 31 | + :method method |
| 32 | + :class class |
| 33 | + :instance (first args) |
| 34 | + :args (vec (rest args)) |
| 35 | + :children [:instance :args]} |
| 36 | + |
| 37 | + :static |
| 38 | + {:op :static-call |
| 39 | + :method method |
| 40 | + :class class |
| 41 | + :args args |
| 42 | + :children [:args]} |
| 43 | + |
| 44 | + :ctor |
| 45 | + {:op :new |
| 46 | + :class {:op :const :type :class :val class |
| 47 | + :form class :env env} |
| 48 | + :args args |
| 49 | + :children [:class :args]}) |
| 50 | + (when param-tags |
| 51 | + {:param-tags param-tags}))) |
| 52 | + ast)) |
0 commit comments