2021-01-30 20:27:10 +00:00
|
|
|
module analysis
|
|
|
|
|
2021-02-14 18:25:23 +00:00
|
|
|
signature
|
|
|
|
sorts
|
|
|
|
TYPE
|
|
|
|
|
|
|
|
constructors
|
|
|
|
INT : TYPE
|
|
|
|
STRING : TYPE
|
|
|
|
STREAM : TYPE
|
|
|
|
|
2021-01-30 20:27:10 +00:00
|
|
|
imports
|
|
|
|
|
|
|
|
statixruntime
|
|
|
|
statix/api
|
|
|
|
|
|
|
|
pp
|
|
|
|
injections/-
|
|
|
|
|
|
|
|
libspoofax/term/origin
|
2021-02-10 20:47:34 +00:00
|
|
|
desugar
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
rules // Analysis
|
|
|
|
|
|
|
|
// single-file analysis
|
|
|
|
editor-analyze = stx-editor-analyze(pre-analyze, post-analyze|"statics", "programOk")
|
|
|
|
|
2021-01-30 23:37:53 +00:00
|
|
|
// see docs/implementation.md for details on how to switch to multi-file analysis
|
2021-01-30 20:27:10 +00:00
|
|
|
// multi-file analysis
|
|
|
|
// editor-analyze = stx-editor-analyze(pre-analyze, post-analyze|"statics", "projectOk", "fileOk")
|
|
|
|
|
2021-02-10 20:47:34 +00:00
|
|
|
pre-analyze = desugar-fostr
|
|
|
|
; origin-track-forced(explicate-injections-fostr-Start)
|
2021-02-01 08:29:00 +00:00
|
|
|
post-analyze = origin-track-forced(implicate-injections-fostr-Start)
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
rules // Editor Services
|
|
|
|
|
|
|
|
editor-resolve = stx-editor-resolve
|
|
|
|
|
|
|
|
editor-hover = stx-editor-hover
|
|
|
|
|
|
|
|
rules // Debugging
|
|
|
|
|
|
|
|
// Prints the abstract syntax ATerm of a selection.
|
2021-02-10 20:47:34 +00:00
|
|
|
debug-show-aterm: (sel, _, _, path, projp) -> (filename, result)
|
2021-01-30 20:27:10 +00:00
|
|
|
with filename := <guarantee-extension(|"aterm")> path
|
2021-02-10 20:47:34 +00:00
|
|
|
; result := sel
|
|
|
|
|
|
|
|
// Prints the desugared abstract syntax ATerm of a selection.
|
|
|
|
debug-desugar-fostr: (sel, _, _, path, projp) -> (filename, result)
|
|
|
|
with filename := <guarantee-extension(|"desugared.aterm")> path
|
|
|
|
; result := <desugar-fostr> sel
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
// Prints the pre-analyzed abstract syntax ATerm of a selection.
|
2021-02-10 20:47:34 +00:00
|
|
|
debug-show-pre-analyzed: (sel, _, _, path, projp) -> (filename, result)
|
2021-01-30 20:27:10 +00:00
|
|
|
with filename := <guarantee-extension(|"pre-analyzed.aterm")> path
|
2021-02-10 20:47:34 +00:00
|
|
|
; result := <pre-analyze> sel
|
2021-01-30 20:27:10 +00:00
|
|
|
|
|
|
|
// Prints the analyzed annotated abstract syntax ATerm of a selection.
|
2021-02-10 20:47:34 +00:00
|
|
|
debug-show-analyzed: (sel, _, _, path, projp) -> (filename, result)
|
2021-01-30 20:27:10 +00:00
|
|
|
with filename := <guarantee-extension(|"analyzed.aterm")> path
|
2021-02-10 20:47:34 +00:00
|
|
|
; result := sel
|
2021-02-14 18:25:23 +00:00
|
|
|
|
|
|
|
// Extract the type assigned to a node by Statix
|
|
|
|
get-type: node -> type
|
|
|
|
where
|
|
|
|
// Assigns variable a to be the result of the Statix analysis of the entire program (or throws an error)
|
|
|
|
a := <stx-get-ast-analysis <+ fail-msg(|$[no analysis on node [<strip-annos;write-to-string> node]])>;
|
|
|
|
// Gets the type of the given node (or throws an error)
|
|
|
|
type := <stx-get-ast-type(|a) <+ fail-msg(|$[no type on node [<strip-annos;write-to-string> node]])> node
|
|
|
|
|
|
|
|
fail-msg(|msg) = err-msg(|$[get-type: [msg]]); fail
|
|
|
|
|
|
|
|
// Prints the analyzed type of a selection.
|
|
|
|
debug-show-type: (sel, _, _, path, projp) -> (filename, result)
|
|
|
|
with filename := <guarantee-extension(|"type.aterm")> path
|
|
|
|
; result := <get-type> sel
|