www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - More on AOP

reply h3r3tic <foo bar.baz> writes:
As some of you know, I've been playing around with parsing D in an 
extended form and translating it back to native D code. I've been trying 
to add some AOP stuff to D. Here's the result: ADP (AspectD 
Preprocessor) in its first 0.(0)1 version :)

http://codeinsane.info/download/adp.zip
(if the DNS doesn't work, use: http://158.75.59.9/~h3/download/adp.zip)

There's only a Windows version, tested only on DMD 0.109. Will check GDC 
later.


It lets you use the 'advice' and 'pointcut' expressions. While only the 
'call' join point is supported at the moment, a few interesting things 
can already be done. This is by no means a full-fledged release of 
reliable software. It's a toy to play with and see if AOP could be a 
GoodThing(tm) to do natively in D. It must be easier to have it natively 
in the language than to translate... (some things are hardly possible 
when translating/prepsocessing).

How reliable is it ? It can process its own source correctly, as well as 
some other projects I'm writing.

What does it do ? It does incomplete parsing of the D language (the 
subset it needs) and analyzing the source, modifies it, writing to new 
files and compiling them instead of the original files by invoking the D 
compiler.
The lexing is done using my sick invention with regular expressions 
(sorry folks, I had not too many alternatives at the moment when I 
started playing around with the project ;) ).

The methods that 'advice' supports are at the moment:
- before  - called on function entry
- after   - called when normally (not throwing) returning from the function
- finally - just like wrapping the function in a try block with 
'finally' in the end. literally.
- catch (params) - ditto

In each advice-enhanced function, there's an additional struct 
accessible, called 'thisf'. It contains the following members:

char[] name - name of the function
char[] scope - its scope
char[] returnType - return type...
char[] params - the parameters the function accepts
char[] signature - return type + scope + name + params
char[] moduleFile - the file in which the function exists


Additionally to using pointcuts, a list of advices can be given to a 
function at its definition like this:

void foo() : advice1, advice2, advice3, ...
{
}


Somebody wanted a to have a simple way to return false instead of 
throwin an exception. That example is given in the .zip file 
(simplePredicate.d). The syntax is quite nice and the result is just as 
it should be.


Looking at the examples in the .zip file will be easier than reading my 
explanations :>

Make sure dmd\bin and dm\bin are on your path.


PS. Modified it just a few minutes ago, I hope nothing's broken :D
Dec 22 2004
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"h3r3tic" <foo bar.baz> wrote in message
news:cqdahr$1fjk$1 digitaldaemon.com...
 As some of you know, I've been playing around with parsing D in an
 extended form and translating it back to native D code. I've been trying
 to add some AOP stuff to D. Here's the result: ADP (AspectD
 Preprocessor) in its first 0.(0)1 version :)

 http://codeinsane.info/download/adp.zip
 (if the DNS doesn't work, use: http://158.75.59.9/~h3/download/adp.zip)

 There's only a Windows version, tested only on DMD 0.109. Will check GDC
 later.


 It lets you use the 'advice' and 'pointcut' expressions. While only the
 'call' join point is supported at the moment, a few interesting things
 can already be done. This is by no means a full-fledged release of
 reliable software. It's a toy to play with and see if AOP could be a
 GoodThing(tm) to do natively in D. It must be easier to have it natively
 in the language than to translate... (some things are hardly possible
 when translating/prepsocessing).

 How reliable is it ? It can process its own source correctly, as well as
 some other projects I'm writing.

 What does it do ? It does incomplete parsing of the D language (the
 subset it needs) and analyzing the source, modifies it, writing to new
 files and compiling them instead of the original files by invoking the D
 compiler.
 The lexing is done using my sick invention with regular expressions
 (sorry folks, I had not too many alternatives at the moment when I
 started playing around with the project ;) ).

 The methods that 'advice' supports are at the moment:
 - before  - called on function entry
 - after   - called when normally (not throwing) returning from the
function
 - finally - just like wrapping the function in a try block with
 'finally' in the end. literally.
 - catch (params) - ditto

 In each advice-enhanced function, there's an additional struct
 accessible, called 'thisf'. It contains the following members:

 char[] name - name of the function
 char[] scope - its scope
 char[] returnType - return type...
 char[] params - the parameters the function accepts
 char[] signature - return type + scope + name + params
 char[] moduleFile - the file in which the function exists


 Additionally to using pointcuts, a list of advices can be given to a
 function at its definition like this:

 void foo() : advice1, advice2, advice3, ...
 {
 }


 Somebody wanted a to have a simple way to return false instead of
 throwin an exception. That example is given in the .zip file
 (simplePredicate.d). The syntax is quite nice and the result is just as
 it should be.


 Looking at the examples in the .zip file will be easier than reading my
 explanations :>

 Make sure dmd\bin and dm\bin are on your path.


 PS. Modified it just a few minutes ago, I hope nothing's broken :D
Very nice! I like it.
Dec 25 2004
parent h3r3tic <foo bar.baz> writes:
Ivan Senji wrote:
 "h3r3tic" <foo bar.baz> wrote in message
 news:cqdahr$1fjk$1 digitaldaemon.com...
 
As some of you know, I've been playing around with parsing D in an
extended form and translating it back to native D code. I've been trying
to add some AOP stuff to D. Here's the result: ADP (AspectD
Preprocessor) in its first 0.(0)1 version :)

(...)
Very nice! I like it.
Thanks :] Now I've got an xmas present: the network segment with my server is down :( Now I will shamelessly attach the thing here :) (apologies Walter's server)
Dec 25 2004