Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
pub
frama-c
Commits
1703b536
Commit
1703b536
authored
3 years ago
by
Andre Maroneze
Browse files
Options
Downloads
Patches
Plain Diff
[Kernel] logic_lexer: refactor and update absolute position to fix pos_cnum
parent
b93824e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/kernel_internals/parsing/logic_lexer.mll
+21
-26
21 additions, 26 deletions
src/kernel_internals/parsing/logic_lexer.mll
with
21 additions
and
26 deletions
src/kernel_internals/parsing/logic_lexer.mll
+
21
−
26
View file @
1703b536
...
@@ -283,7 +283,7 @@
...
@@ -283,7 +283,7 @@
end
end
(* Update lexer buffer. *)
(* Update lexer buffer. *)
let
update_line_
loc
lexbuf
line
=
let
update_line_
pos
lexbuf
line
=
let
pos
=
lexbuf
.
Lexing
.
lex_curr_p
in
let
pos
=
lexbuf
.
Lexing
.
lex_curr_p
in
lexbuf
.
Lexing
.
lex_curr_p
<-
lexbuf
.
Lexing
.
lex_curr_p
<-
{
pos
with
{
pos
with
...
@@ -291,10 +291,7 @@
...
@@ -291,10 +291,7 @@
Lexing
.
pos_bol
=
pos
.
Lexing
.
pos_cnum
;
Lexing
.
pos_bol
=
pos
.
Lexing
.
pos_cnum
;
}
}
let
update_newline_loc
lexbuf
=
let
update_file_pos
lexbuf
file
=
update_line_loc
lexbuf
(
lexbuf
.
Lexing
.
lex_curr_p
.
Lexing
.
pos_lnum
+
1
)
let
update_file_loc
lexbuf
file
=
let
pos
=
lexbuf
.
Lexing
.
lex_curr_p
in
let
pos
=
lexbuf
.
Lexing
.
lex_curr_p
in
lexbuf
.
Lexing
.
lex_curr_p
<-
{
pos
with
Lexing
.
pos_fname
=
file
}
lexbuf
.
Lexing
.
lex_curr_p
<-
{
pos
with
Lexing
.
pos_fname
=
file
}
...
@@ -349,8 +346,8 @@ let utf8_char = ['\128'-'\254']+
...
@@ -349,8 +346,8 @@ let utf8_char = ['\128'-'\254']+
rule token = parse
rule token = parse
| space+ { token lexbuf }
| space+ { token lexbuf }
| '
\n
' {
update_
newline
_loc
lexbuf; token lexbuf }
| '
\n
' {
Lexing.
new
_
line lexbuf; token lexbuf }
| comment_line '
\n
' {
update_
newline
_loc
lexbuf; token lexbuf }
| comment_line '
\n
' {
Lexing.
new
_
line lexbuf; token lexbuf }
| comment_line eof { token lexbuf }
| comment_line eof { token lexbuf }
| "
*/
" { lex_error lexbuf "
unexpected
block
-
comment
closing
" }
| "
*/
" { lex_error lexbuf "
unexpected
block
-
comment
closing
" }
| "
/*
" { if !accept_c_comments_into_acsl_spec
| "
/*
" { if !accept_c_comments_into_acsl_spec
...
@@ -502,7 +499,7 @@ and chr buffer = parse
...
@@ -502,7 +499,7 @@ and chr buffer = parse
|
_
{
Buffer
.
add_string
buffer
(
lexeme
lexbuf
);
chr
buffer
lexbuf
}
|
_
{
Buffer
.
add_string
buffer
(
lexeme
lexbuf
);
chr
buffer
lexbuf
}
and
hash
=
parse
and
hash
=
parse
'\n'
{
update_
newline
_loc
lexbuf
;
token
lexbuf
}
'\n'
{
Lexing
.
new
_
line
lexbuf
;
token
lexbuf
}
|
[
'
'
'\t'
]
{
hash
lexbuf
}
|
[
'
'
'\t'
]
{
hash
lexbuf
}
|
rD
+
{
(* We are seeing a line number. This is the number for the
|
rD
+
{
(* We are seeing a line number. This is the number for the
* next line *)
* next line *)
...
@@ -517,14 +514,14 @@ and hash = parse
...
@@ -517,14 +514,14 @@ and hash = parse
"Bad line number in preprocessed file: %s"
s
;
"Bad line number in preprocessed file: %s"
s
;
(
-
1
)
(
-
1
)
in
in
update_line_
loc
lexbuf
(
lineno
-
1
);
update_line_
pos
lexbuf
(
lineno
-
1
);
(* A file name may follow *)
(* A file name may follow *)
file
lexbuf
}
file
lexbuf
}
|
"line"
{
hash
lexbuf
}
(* MSVC line number info *)
|
"line"
{
hash
lexbuf
}
(* MSVC line number info *)
|
_
{
endline
lexbuf
}
|
_
{
endline
lexbuf
}
and
file
=
parse
and
file
=
parse
'\n'
{
update_
newline
_loc
lexbuf
;
token
lexbuf
}
'\n'
{
Lexing
.
new
_
line
lexbuf
;
token
lexbuf
}
|
[
'
'
'\t''\r'
]
{
file
lexbuf
}
|
[
'
'
'\t''\r'
]
{
file
lexbuf
}
|
'
"' ([^ '
\012
' '
\t
' '"
'
]
|
"
\\\"
"
)
*
'
"' {
|
'
"' ([^ '
\012
' '
\t
' '"
'
]
|
"
\\\"
"
)
*
'
"' {
let n = Lexing.lexeme lexbuf in
let n = Lexing.lexeme lexbuf in
...
@@ -532,38 +529,36 @@ and file = parse
...
@@ -532,38 +529,36 @@ and file = parse
((String.length n) - 2) in
((String.length n) - 2) in
let unescape = Str.regexp_string "
\\\
""
in
let unescape = Str.regexp_string "
\\\
""
in
let
n1
=
Str
.
global_replace
unescape
"
\"
"
n1
in
let
n1
=
Str
.
global_replace
unescape
"
\"
"
n1
in
update_file_
loc
lexbuf
n1
;
update_file_
pos
lexbuf
n1
;
endline
lexbuf
endline
lexbuf
}
}
|
_
{
endline
lexbuf
}
|
_
{
endline
lexbuf
}
and
endline
=
parse
and
endline
=
parse
'\n'
{
update_
newline
_loc
lexbuf
;
token
lexbuf
}
'\n'
{
Lexing
.
new
_
line
lexbuf
;
token
lexbuf
}
|
eof
{
EOF
}
|
eof
{
EOF
}
|
_
{
endline
lexbuf
}
|
_
{
endline
lexbuf
}
and
comment
=
parse
and
comment
=
parse
'\n'
{
update_
newline
_loc
lexbuf
;
comment
lexbuf
}
'\n'
{
Lexing
.
new
_
line
lexbuf
;
comment
lexbuf
}
|
"*/"
{
token
lexbuf
}
|
"*/"
{
token
lexbuf
}
|
eof
{
lex_error
lexbuf
"non-terminating block-comment"
}
|
eof
{
lex_error
lexbuf
"non-terminating block-comment"
}
|
_
{
comment
lexbuf
}
|
_
{
comment
lexbuf
}
{
{
let
set_initial_location
dest_lexbuf
src_loc
=
(* When Ocaml 4.11+ becomes mandatory, we can probably replace this with
Lexing
.(
Lexing.set_position. *)
dest_lexbuf
.
lex_curr_p
<-
let
set_initial_position
dest_lexbuf
src_pos
=
{
src_loc
with
dest_lexbuf
.
Lexing
.
lex_curr_p
<-
src_pos
;
pos_bol
=
src_loc
.
pos_bol
-
src_loc
.
pos_cnum
;
dest_lexbuf
.
lex_abs_pos
<-
src_pos
.
pos_cnum
pos_cnum
=
0
;
};
)
let
parse_from_position
f
(
pos
,
s
:
Filepath
.
position
*
string
)
=
let
parse_from_location
f
(
loc
,
s
:
Filepath
.
position
*
string
)
=
let
finally
_
=
Logic_utils
.
exit_kw_c_mode
()
in
let
finally
_
=
Logic_utils
.
exit_kw_c_mode
()
in
let
output
=
Kernel
.
logwith
finally
~
wkey
:
Kernel
.
wkey_annot_error
let
output
=
Kernel
.
logwith
finally
~
wkey
:
Kernel
.
wkey_annot_error
in
in
let
lb
=
from_string
s
in
let
lb
=
from_string
s
in
set_initial_
loca
tion
lb
(
Cil_datatype
.
Position
.
to_lexing_pos
loc
);
set_initial_
posi
tion
lb
(
Cil_datatype
.
Position
.
to_lexing_pos
pos
);
try
try
let
res
=
f
token
lb
in
let
res
=
f
token
lb
in
Some
(
Cil_datatype
.
Position
.
of_lexing_pos
lb
.
Lexing
.
lex_curr_p
,
res
)
Some
(
Cil_datatype
.
Position
.
of_lexing_pos
lb
.
Lexing
.
lex_curr_p
,
res
)
...
@@ -584,11 +579,11 @@ and comment = parse
...
@@ -584,11 +579,11 @@ and comment = parse
Kernel
.
fatal
~
source
:
(
Cil_datatype
.
Position
.
of_lexing_pos
lb
.
lex_curr_p
)
"Unknown error (%s)"
Kernel
.
fatal
~
source
:
(
Cil_datatype
.
Position
.
of_lexing_pos
lb
.
lex_curr_p
)
"Unknown error (%s)"
(
Printexc
.
to_string
exn
)
(
Printexc
.
to_string
exn
)
let
lexpr
=
parse_from_
loca
tion
Logic_parser
.
lexpr_eof
let
lexpr
=
parse_from_
posi
tion
Logic_parser
.
lexpr_eof
let
annot
=
parse_from_
loca
tion
Logic_parser
.
annot
let
annot
=
parse_from_
posi
tion
Logic_parser
.
annot
let
spec
=
parse_from_
loca
tion
Logic_parser
.
spec
let
spec
=
parse_from_
posi
tion
Logic_parser
.
spec
let
ext_spec
lexbuf
=
try
let
ext_spec
lexbuf
=
try
accept_c_comments_into_acsl_spec
:=
true
;
accept_c_comments_into_acsl_spec
:=
true
;
...
...
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