RE: RE: [abc-users] Using abc for instrumentation

From: Eric Bodden <eric.bodden@mail.mcgill.ca>
Date: Mon May 29 2006 - 02:27:05 BST

Hello.

> Thank you for your reply and hints.

No problem.
 
> By following your papers, tutorials and EAJ code, I've managed to
> insert a new pass into abc and rewrite some AST nodes to inject
> instrumentation code. I'm now injecting the code by inserting AST
> nodes, which are constructed by hard coding. I was wondering, by any
> chance, if we can insert code with plain text like "System.out.println
> ("hello");" instead of its corresponding AST nodes? or if there is an
> easy way to convert/parse a statement into its AST representation?
> Guess not...It sounds unreasonable to me.

I know it's very tedious indeed. Sorry about that - but that's how
compilers work unfortunately. However, if you insert pure java code AST
nodes only (i.e. no AspectJ AST nodes), then polyglot (which is part of
abc) actually does have a means of generating an AST from a plaintext
statement or expression. Look at the class polyglot.ext.jl.qq.QQ
("QuasiQuoter") please. You might want to download the polyglot source
code from our website for reference. You can instantiate a QQ object
with your abc extensioninfo and then you can invoke methods like "Stmt
QQ.parseStmt(String)" etc. Note that this might be relatively slow,
since polyglot actually has to parse the string it gives you, which is
much more expensive than inserting the AST nodes directly. But for a
prototype that should be fine.

> Well, another workaround to the tediousness of constructing AST nodes
> for inserted statements is rewriting source files while instrumenting.

I am not sure what you mean. You mean by sort of textual find/replace?
That would be very error prone and I don't think you can or even want to
do that within a compiler.

> Can you please advice me of if and how we can instruct abc to start
> over the compilation process from my extension?

Again, I don't really see what you mean here. But I think you should
find the abovementioned hint helpful.

Eric

--
Eric Bodden
Sable Research Group, McGill University
Montreal, Canada
http://bodden.de
Received on Mon May 29 02:27:36 2006

This archive was generated by hypermail 2.1.8 : Mon May 29 2006 - 22:20:09 BST