Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verified Software
jsexplain
Commits
edf0e1e5
Commit
edf0e1e5
authored
9 years ago
by
Cesar Roux Dit Buisson
Browse files
Options
Downloads
Patches
Plain Diff
Add function log detection
Pre step before function calls get wrapped.
parent
e54cc29c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
generator/js_of_ast.ml
+2
-2
2 additions, 2 deletions
generator/js_of_ast.ml
generator/log.ml
+17
-11
17 additions, 11 deletions
generator/log.ml
with
19 additions
and
13 deletions
generator/js_of_ast.ml
+
2
−
2
View file @
edf0e1e5
...
...
@@ -280,8 +280,8 @@ and js_of_expression ?(mod_gen=[]) e =
|>
List
.
map
(
fun
(
_
,
eo
,
_
)
->
match
eo
with
None
->
out_of_scope
locn
"optional apply arguments"
|
Some
ei
->
js_of_expression
~
mod_gen
ei
)
in
let
se
=
js_of_expression
~
mod_gen
f
in
if
is_infix
f
sl'
&&
List
.
length
exp_l
=
2
then
ppf_apply_infix
se
(
List
.
hd
sl
)
(
List
.
hd
(
List
.
tl
sl
))
else
ppf_apply
se
(
String
.
concat
", "
sl
)
then
L
.
log_line
(
ppf_apply_infix
se
(
List
.
hd
sl
)
(
List
.
hd
(
List
.
tl
sl
))
)
(
L
.
ApplyInfix
(
se
,
(
List
.
hd
sl
)
,
(
List
.
hd
(
List
.
tl
sl
))))
else
L
.
log_line
(
ppf_apply
se
(
String
.
concat
", "
sl
)
)
(
L
.
ApplyFunc
(
se
,
(
String
.
concat
", "
sl
)))
|
Texp_match
(
exp
,
l
,
[]
,
Total
)
->
let
se
=
js_of_expression
~
mod_gen
exp
in
...
...
This diff is collapsed.
Click to expand it.
generator/log.ml
+
17
−
11
View file @
edf0e1e5
...
...
@@ -29,11 +29,12 @@ sig
type
token_info
type
ident
=
string
type
typ
=
string
type
func
=
string
type
ctx_operation
=
|
Add
of
ident
*
typ
|
Redef
of
ident
*
typ
|
Del
of
ident
*
typ
|
ApplyInfix
of
func
*
ident
*
ident
|
ApplyFunc
of
func
*
ident
val
log_line
:
string
->
ctx_operation
->
string
val
strip_log_info
:
string
->
string
...
...
@@ -45,12 +46,13 @@ struct
open
Str
type
token
=
G
.
token
type
ident
=
string
type
typ
=
string
type
typ
=
string
type
func
=
string
type
ctx_operation
=
|
Add
of
ident
*
typ
|
Redef
of
ident
*
typ
|
Del
of
ident
*
typ
|
ApplyInfix
of
func
*
ident
*
ident
|
ApplyFunc
of
func
*
ident
type
token_info
=
ctx_operation
...
...
@@ -67,6 +69,7 @@ struct
let
free_token
=
G
.
withdraw
(* Takes a string and inserts a new token after the first new line character or at the end of the string.*)
let
bind_token
str
=
let
len
=
String
.
length
str
in
let
endline
=
...
...
@@ -78,8 +81,10 @@ struct
else
len
in
aux
0
in
let
token
=
free_token
()
(* Insert a token after the first '\n' character by creating a substring of before and after. *)
in
token
,
String
.
sub
str
0
endline
^
token_delim
^
G
.
string_of_token
token
^
token_delim
^
String
.
sub
str
endline
(
len
-
endline
)
(* Appears unused in codebase *)
let
token_info
=
Hashtbl
.
find
info_tbl
let
token_from_line
l
=
...
...
@@ -120,11 +125,12 @@ struct
(* Wrap the entire logged version in a callable run_trm function, and add a call to return run(code). *)
(* Assumes entry point called run *)
let
ppf_run_wrap
s
=
Format
.
sprintf
"function run_trm(code) {@;<1 2>@[<v 1>@,%s@
,
return run(code);@
,
}@]"
s
Format
.
sprintf
"function run_trm(code) {@;<1 2>@[<v 1>@,%s@
;<1 0>
return run(code);@
;
}@]"
s
let
add_log_info
s
=
let
buf
=
Buffer
.
create
16
in
let
ls
=
lines
s
in
(* i is line number of line preceding return *)
let
rec
aux
i
=
function
|
[]
->
()
|
(
None
,
str
)
::
xs
->
...
...
@@ -150,10 +156,10 @@ struct
|>
global_replace
(
regexp
"var "
)
""
|>
split
(
regexp
", "
)
|>
List
.
map
(
fun
x
->
List
.
hd
(
split
(
regexp
" = "
)
x
))
|>
aux
in
ctx_processing
id
^
"
\n
"
^
pad
^
"log("
^
string_of_int
i
^
" , ctx, "
^
typ
^
");
\n
"
|
Redef
_
->
""
(* Actually not used *)
|
Del
_
->
""
(* Actually not used *)
|
ApplyInfix
(
f
,
e1
,
e2
)
->
""
(* Actually not used *)
|
ApplyFunc
(
f
,
args
)
->
""
(* Actually not used *)
in
Buffer
.
add_string
buf
log_info
;
Buffer
.
add_string
buf
str
;
(* i is line number of line preceding return *)
Buffer
.
add_string
buf
(
str
ip_log_info
str
);
aux
(
i
+
1
)
xs
in
aux
0
ls
;
Buffer
.
contents
buf
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment