Skip to content

Commit 7f468d0

Browse files
author
dnolen
committed
docstrings
1 parent 41af5fe commit 7f468d0

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@
298298
(or (-> x meta :column) (:column env)))
299299

300300
(defn intern-macros
301+
"Given a Clojure namespace intern all macros into the ambient ClojureScript
302+
analysis environment."
301303
([ns] (intern-macros ns false))
302304
([ns reload]
303305
(when (or (nil? (get-in @env/*compiler* [::namespaces ns :macros]))
@@ -338,7 +340,9 @@
338340
*cljs-macros-is-classpath* false]
339341
~@body)))
340342

341-
(defn empty-env []
343+
(defn empty-env
344+
"Construct an empty analysis environment. Required to analyze forms."
345+
[]
342346
(env/ensure
343347
{:ns (get-namespace *cljs-ns*)
344348
:context :statement
@@ -427,7 +431,10 @@
427431
(let [sym (symbol name)]
428432
(get (:require-macros (:ns env)) sym sym)))
429433

430-
(defn confirm-ns [env ns-sym]
434+
(defn confirm-ns
435+
"Given env, an analysis environment, and ns-sym, a symbol identifying a
436+
namespace, confirm that the namespace exists. Warn if not found."
437+
[env ns-sym]
431438
(when (and (nil? (get '#{cljs.core goog Math goog.string} ns-sym))
432439
(nil? (get (-> env :ns :requires) ns-sym))
433440
;; something else may have loaded the namespace, i.e. load-file
@@ -512,19 +519,27 @@
512519
{:name (symbol (str full-ns) (str sym))
513520
:ns full-ns})))))))
514521

515-
(defn resolve-existing-var [env sym]
522+
(defn resolve-existing-var
523+
"Given env, an analysis environment, and sym, a symbol, resolve an existing var.
524+
Emits a warning if no such var exists."
525+
[env sym]
516526
(if-not (-> sym meta ::no-resolve)
517527
(resolve-var env sym confirm-var-exists)
518528
(resolve-var env sym)))
519529

520-
(defn confirm-bindings [env names]
530+
(defn confirm-bindings
531+
"Given env, an analysis environment env, and names, a list of symbols, confirm
532+
that all correspond to declared dynamic vars."
533+
[env names]
521534
(doseq [name names]
522535
(let [env (assoc env :ns (get-namespace *cljs-ns*))
523536
ev (resolve-existing-var env name)]
524537
(when (and ev (not (-> ev :dynamic)))
525538
(warning :dynamic env {:ev ev :name (:name ev)})))))
526539

527-
(defn resolve-macro-var [env sym]
540+
(defn resolve-macro-var
541+
"Given env, an analysis environment, and sym, a symbol, resolve a macro."
542+
[env sym]
528543
(let [ns (-> env :ns :name)
529544
namespaces (get @env/*compiler* ::namespaces)]
530545
(cond
@@ -619,7 +634,10 @@
619634
('#{cljs.core/PersistentHashMap
620635
cljs.core/List} t)))))
621636

622-
(defn infer-tag [env e]
637+
(defn infer-tag
638+
"Given env, an analysis environment, and e, an AST node, return the inferred
639+
type of the node"
640+
[env e]
623641
(if-let [tag (get-tag e)]
624642
tag
625643
(case (:op e)
@@ -1249,6 +1267,9 @@
12491267
false)))
12501268

12511269
(defn analyze-deps
1270+
"Given a lib, a namespace, deps, its dependencies, env, an analysis environment
1271+
and opts, compiler options - analyze all of the dependencies. Required to
1272+
correctly analyze usage of other namespaces."
12521273
([lib deps env] (analyze-deps lib deps env nil))
12531274
([lib deps env opts]
12541275
(let [compiler @env/*compiler*]
@@ -1793,7 +1814,10 @@
17931814
(resolve-var env sym)))
17941815
(assoc ret :op :var :info (resolve-var env sym)))))))
17951816

1796-
(defn get-expander [sym env]
1817+
(defn get-expander
1818+
"Given a sym, a symbol identifying a macro, and env, an analysis environment
1819+
return the corresponding Clojure macroexpander."
1820+
[sym env]
17971821
(let [mvar
17981822
(when-not (or (-> env :locals sym) ;locals hide macros
17991823
(and (or (-> env :ns :excludes sym)
@@ -1814,7 +1838,10 @@
18141838
(when (and mvar (.isMacro ^clojure.lang.Var mvar))
18151839
(with-meta @mvar (meta mvar)))))
18161840

1817-
(defn macroexpand-1 [env form]
1841+
(defn macroexpand-1
1842+
"Given a env, an analysis environment, and form, a ClojureScript form,
1843+
macroexpand the form once."
1844+
[env form]
18181845
(env/ensure
18191846
(wrapping-errors env
18201847
(let [op (first form)]
@@ -2121,6 +2148,9 @@
21212148
(io/file (str target-file ".cache.edn"))))))
21222149

21232150
(defn requires-analysis?
2151+
"Given a src, a resource, and output-dir, a compilation output directory
2152+
return true or false depending on whether src needs to be (re-)analyzed.
2153+
Can optionally pass cache, the analysis cache file."
21242154
([src] (requires-analysis? src "out"))
21252155
([src output-dir]
21262156
(let [cache (cache-file src output-dir)]

0 commit comments

Comments
 (0)