<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi Nir,<br>
</p>
<div class="moz-cite-prefix">On 02/10/2022 22:31, Nir Lisker wrote:<br>
</div>
<blockquote type="cite" cite="mid:CA+0ynh-QQrdhWCf650ZLivxkGs0sXiNYddiYQPW3hV0HTno56Q@mail.gmail.com">
<div>5. When analyzing the symbols of a header using the dump
option, I need to read the file that jextract creates from disk
and then delete it. Is there a way to read the jextract output
directly? Either through the output stream, or writing to a file
in memory? Dealing with disk I/O is cumbersome, comes with
permission restrictions, and might be slow if done for many
files in a batch.</div>
</blockquote>
<p>I think ultimately, working with files might be not ideal for
your use case.</p>
<p>There is a pseudo-stable API to parse jextract files, in the
JextractTool class (in the org.openjdk.jextract package, which
should be exported by the jextract module):</p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">`public
static Declaration.Scoped parse(List<Path> headers,
String... parserOptions) {`</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">We do not
make any promise (at this stage at least) on the stability of
the API. That said, it has not changed much (at all?) in the
last couple of years.</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">What you get
back is a "Declaration", which is used to model vars, structs,
unions, typedefs, functions<br>
</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">Then,
attached to declarations, there are "Type"s, which are used...
well, to model types. Since some type can be structured (e.g. a
struct type), they can point back to their declaration (e.g.
Type.Declared).</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">Jextract does
all it does by defining visitors on this basic declaration tree,
which is obtained by wrapping the results of parsing a C header
using the clang API (e.g. clang Cursors).<br>
</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">We did this
to "sanitize" the output of clang, as well as to make our
implementation more robust and less dependent from clang
internals.</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;">One option
for you would be to invoke the parsing process this way, then
get the tree and look at the results (e.g. with a visitor),
which sounds better than parsing an option file.</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;"><br>
Cheers<br>
Maurizio<br>
</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;"><br>
</span></p>
<p><span style="color: rgb(29, 28, 29); font-family: Slack-Lato,
Slack-Fractions, appleLogo, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: common-ligatures;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(255, 255, 255); text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial; display: inline !important; float: none;"><br>
</span></p>
</body>
</html>