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
ae5790dc
Commit
ae5790dc
authored
4 years ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
[parsing] more efficient concatenation of consecutive strings
parent
c6b7b94a
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/cparser.mly
+19
-20
19 additions, 20 deletions
src/kernel_internals/parsing/cparser.mly
with
19 additions
and
20 deletions
src/kernel_internals/parsing/cparser.mly
+
19
−
20
View file @
ae5790dc
...
...
@@ -66,7 +66,7 @@ let smooth_expression lst =
let
end_loc
=
snd
(
Extlib
.
last
lst
)
.
expr_loc
in
{
expr_loc
=
(
beg_loc
,
end_loc
);
expr_node
=
COMMA
(
lst
)
}
let
merge_string
(
c1
,
(
b1
,_
))
(
c
2
,
(
_
,
e2
))
=
c1
@
c
2
,
(
b1
,
e2
)
let
merge_string
(
c1
,
(
b1
,_
))
(
l
2
,
(
_
,
e2
))
=
c1
::
l
2
,
(
b1
,
e2
)
(* To be called only inside a grammar rule. *)
let
make_expr
e
=
...
...
@@ -213,12 +213,13 @@ let int64_to_char value =
Char
.
chr
(
Int64
.
to_int
value
)
(* takes a not-nul-terminated list, and converts it to a string. *)
let
intlist_to_string
(
str
:
int64
list
)
:
string
=
let
buffer
=
Buffer
.
create
(
List
.
length
str
)
in
let
intlist_to_string
str
=
let
buffer
=
Buffer
.
create
64
in
let
add_char
c
=
Buffer
.
add_char
buffer
(
int64_to_char
c
)
in
List
.
iter
add_char
str
;
let
add_char_list
l
=
List
.
iter
add_char
l
in
List
.
iter
add_char_list
str
;
Buffer
.
contents
buffer
let
fst3
(
result
,
_
,
_
)
=
result
...
...
@@ -407,8 +408,6 @@ let in_ghost_block ?(battrs=[]) l =
%
type
<
Cabs
.
expression
list
>
paren_comma_expression
%
type
<
Cabs
.
expression
list
>
arguments
%
type
<
Cabs
.
expression
list
>
bracket_comma_expression
%
type
<
int64
list
*
cabsloc
>
string_list
%
type
<
int64
list
*
cabsloc
>
wstring_list
%
type
<
Cabs
.
initwhat
*
Cabs
.
init_expression
>
initializer_single
%
type
<
(
Cabs
.
initwhat
*
Cabs
.
init_expression
)
list
>
initializer_list
...
...
@@ -746,12 +745,12 @@ expression: /*(* 6.5.17 *)*/
constant
:
CST_INT
{
CONST_INT
(
fst
$
1
)
,
snd
$
1
}
|
CST_FLOAT
{
CONST_FLOAT
(
fst
$
1
)
,
snd
$
1
}
|
CST_CHAR
{
CONST_CHAR
(
fst
$
1
)
,
snd
$
1
}
|
CST_WCHAR
{
CONST_WCHAR
(
fst
$
1
)
,
snd
$
1
}
|
string_constant
{
CONST_STRING
(
fst
$
1
)
,
snd
$
1
}
|
wstring_list
{
CONST_WSTRING
(
fst
$
1
)
,
snd
$
1
}
CST_INT
{
CONST_INT
(
fst
$
1
)
,
snd
$
1
}
|
CST_FLOAT
{
CONST_FLOAT
(
fst
$
1
)
,
snd
$
1
}
|
CST_CHAR
{
CONST_CHAR
(
fst
$
1
)
,
snd
$
1
}
|
CST_WCHAR
{
CONST_WCHAR
(
fst
$
1
)
,
snd
$
1
}
|
string_constant
{
CONST_STRING
(
fst
$
1
)
,
snd
$
1
}
|
wstring_list
{
CONST_WSTRING
(
List
.
concat
(
fst
$
1
)
)
,
snd
$
1
}
;
string_constant
:
...
...
@@ -761,15 +760,15 @@ string_constant:
;
string_list
:
one_string
{
fst
$
1
,
snd
$
1
}
|
string_list
one_string
{
merge_string
$
1
$
2
}
one_string
{
[
fst
$
1
]
,
snd
$
1
}
|
one_string
string_list
{
merge_string
$
1
$
2
}
;
wstring_list
:
CST_WSTRING
{
$
1
}
|
wstring_list
one_string
{
merge_string
$
1
$
2
}
|
wstring_list
CST_WSTRING
{
merge_string
$
1
$
2
}
|
string_list
CST_WSTRING
{
merge_string
$
1
$
2
}
CST_WSTRING
{
[
fst
$
1
]
,
snd
$
1
}
|
one_string
wstring_list
{
merge_string
$
1
$
2
}
|
CST_WSTRING
wstring_list
{
merge_string
$
1
$
2
}
|
CST_WSTRING
string_list
{
merge_string
$
1
$
2
}
/*
If
a
wstring
is
present
anywhere
in
the
list
,
the
whole
is
a
wstring
*/
one_string
:
...
...
@@ -1751,8 +1750,8 @@ asmattr:
|
CONST
asmattr
{
(
"const"
,
[]
)
::
$
2
}
;
asmtemplate
:
one_string
{
[
intlist_to_string
(
fst
$
1
)
]
}
|
one_string
asmtemplate
{
intlist_to_string
(
fst
$
1
)
::
$
2
}
one_string
{
[
intlist_to_string
[
fst
$
1
]
]
}
|
one_string
asmtemplate
{
intlist_to_string
[
fst
$
1
]
::
$
2
}
;
asmoutputs
:
/*
empty
*/
{
None
}
...
...
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