| 1 |
#LyX 1.3 created this file. For more info see http://www.lyx.org/ |
| 2 |
\lyxformat 221 |
| 3 |
\textclass article |
| 4 |
\begin_preamble |
| 5 |
|
| 6 |
%-------------------------------------------------------------------- |
| 7 |
% PDF related |
| 8 |
%-------------------------------------------------------------------- |
| 9 |
\newif\ifpdf |
| 10 |
\ifx\pdfoutput\undefined |
| 11 |
\pdffalse % we are not running PDFLaTeX |
| 12 |
\else |
| 13 |
\pdfoutput=1 % we are running PDFLaTeX |
| 14 |
\pdftrue |
| 15 |
\fi |
| 16 |
|
| 17 |
%-------------------------------------------------------------------- |
| 18 |
% setup hyperref |
| 19 |
%-------------------------------------------------------------------- |
| 20 |
\ifpdf |
| 21 |
\usepackage{color} |
| 22 |
\pagecolor{white} |
| 23 |
\usepackage{hyperref} |
| 24 |
\hypersetup{% |
| 25 |
% |
| 26 |
%% general document information |
| 27 |
pdftitle = {AspectC++ Language Reference}, |
| 28 |
pdfsubject = {Dokumentation}, |
| 29 |
pdfkeywords = {AOP, AspectC++, pure-systems}, |
| 30 |
pdfauthor = {\textcopyright\ pure-systems GmbH and Olaf Spinczyk}, |
| 31 |
pdfcreator = {\LaTeX\ with package \flqq hyperref\frqq}, |
| 32 |
pdfproducer = {pdfTeX-0.\the\pdftexversion\pdftexrevision}, |
| 33 |
% |
| 34 |
%% document style |
| 35 |
colorlinks=true, % colored link |
| 36 |
urlcolor=blue, % blue URL links |
| 37 |
bookmarks=true, % generate bookmarks |
| 38 |
bookmarksnumbered=true, % generate section numbers |
| 39 |
pdfpagemode=None % don't open bookmarks |
| 40 |
} |
| 41 |
|
| 42 |
%% set document creation date to 10.7.2003 00:00 |
| 43 |
\pdfinfo {/CreationDate (D:20040628000000)} |
| 44 |
\fi |
| 45 |
|
| 46 |
%-------------------------------------------------------------------- |
| 47 |
% create hyperrefs depending on the use of pdflatex |
| 48 |
%-------------------------------------------------------------------- |
| 49 |
\newcommand\depref[2]{% |
| 50 |
\ifpdf |
| 51 |
\href{#1}{#2} |
| 52 |
\else |
| 53 |
{#2} |
| 54 |
\fi |
| 55 |
} |
| 56 |
|
| 57 |
\usepackage{listings} |
| 58 |
\usepackage{color} |
| 59 |
\definecolor{darkgrey}{rgb}{.4, .4, .4} |
| 60 |
\definecolor{lightgrey}{rgb}{.95, .95, .95} |
| 61 |
\definecolor{lightyellow}{rgb}{.99, .97, .90} |
| 62 |
|
| 63 |
\lstloadlanguages{C++} |
| 64 |
\lstdefinelanguage[Aspect]{C++}[ISO]{C++}{ |
| 65 |
morekeywords={aspect, advice, pointcut, tjp}, |
| 66 |
morekeywords=[2]{call, execution, within, |
| 67 |
cflow, before, around, after, baseclass |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
\lstdefinestyle{acstyle}{ |
| 72 |
basicstyle=\footnotesize\ttfamily, |
| 73 |
keywordstyle=[2]\bfseries\emph, |
| 74 |
showstringspaces=false, |
| 75 |
language=[Aspect]{C++}, |
| 76 |
escapechar={@}, |
| 77 |
} |
| 78 |
\lstdefinestyle{ac}{ |
| 79 |
style=acstyle, |
| 80 |
xleftmargin=6mm, |
| 81 |
lineskip=-5.5pt |
| 82 |
} |
| 83 |
\lstdefinestyle{aclisting}{ |
| 84 |
style=acstyle, |
| 85 |
backgroundcolor=\color{lightyellow}, |
| 86 |
frame=single, |
| 87 |
%frameround=tttt, |
| 88 |
rulecolor=\color{yellow} |
| 89 |
} |
| 90 |
\lstset{style=ac} |
| 91 |
\rhead{AspectC++ Language Overview} |
| 92 |
\lfoot{\copyright 2005 Olaf Spinczyk} |
| 93 |
\end_preamble |
| 94 |
\language english |
| 95 |
\inputencoding auto |
| 96 |
\fontscheme pslatex |
| 97 |
\graphics default |
| 98 |
\paperfontsize default |
| 99 |
\spacing single |
| 100 |
\papersize a4paper |
| 101 |
\paperpackage a4 |
| 102 |
\use_geometry 0 |
| 103 |
\use_amsmath 0 |
| 104 |
\use_natbib 0 |
| 105 |
\use_numerical_citations 0 |
| 106 |
\paperorientation portrait |
| 107 |
\leftmargin 1cm |
| 108 |
\topmargin 0.7cm |
| 109 |
\rightmargin 2.5cm |
| 110 |
\bottommargin 0.7cm |
| 111 |
\secnumdepth 3 |
| 112 |
\tocdepth 3 |
| 113 |
\paragraph_separation skip |
| 114 |
\defskip smallskip |
| 115 |
\quotes_language english |
| 116 |
\quotes_times 2 |
| 117 |
\papercolumns 1 |
| 118 |
\papersides 1 |
| 119 |
\paperpagestyle fancy |
| 120 |
|
| 121 |
\layout Title |
| 122 |
\noindent |
| 123 |
|
| 124 |
\series bold |
| 125 |
\emph on |
| 126 |
AspectC++ -- A Language Overview |
| 127 |
\layout Author |
| 128 |
|
| 129 |
|
| 130 |
\begin_inset ERT |
| 131 |
status Collapsed |
| 132 |
|
| 133 |
\layout Standard |
| 134 |
|
| 135 |
\backslash |
| 136 |
copyright |
| 137 |
\end_inset |
| 138 |
|
| 139 |
2005 Olaf Spinczyk <[email protected]> |
| 140 |
\newline |
| 141 |
Friedrich-Alexander University Erlangen-Nuremberg |
| 142 |
\newline |
| 143 |
Computer Science 4 |
| 144 |
\layout Standard |
| 145 |
|
| 146 |
This is an overview about the AspectC++ language, an aspect-oriented extension |
| 147 |
for C/C++, prepared for the European AOSD Network of Excellence. |
| 148 |
Detailed information on AspectC++ including manuals and tutorial slides |
| 149 |
with lots of examples is available from |
| 150 |
\begin_inset ERT |
| 151 |
status Open |
| 152 |
|
| 153 |
\layout Standard |
| 154 |
|
| 155 |
\backslash |
| 156 |
depref{http://www.aspectc.org/}{ |
| 157 |
\backslash |
| 158 |
emph{the AspectC++ Project Homepage}} |
| 159 |
\backslash |
| 160 |
hspace{-4pt} |
| 161 |
\end_inset |
| 162 |
|
| 163 |
. |
| 164 |
\layout Standard |
| 165 |
|
| 166 |
The overview is based on the documentation for AspectC++ 0.9.3. |
| 167 |
The language is still |
| 168 |
\begin_inset Quotes eld |
| 169 |
\end_inset |
| 170 |
|
| 171 |
work in progress |
| 172 |
\begin_inset Quotes erd |
| 173 |
\end_inset |
| 174 |
|
| 175 |
. |
| 176 |
\layout Section* |
| 177 |
|
| 178 |
Joinpoint Model and Pointcut Language |
| 179 |
\layout Standard |
| 180 |
|
| 181 |
AspectC++ supports |
| 182 |
\emph on |
| 183 |
static |
| 184 |
\emph default |
| 185 |
joinpoints as well as |
| 186 |
\emph on |
| 187 |
dynamic |
| 188 |
\emph default |
| 189 |
joinpoints. |
| 190 |
While static joinpoints are named entities in the static program structure, |
| 191 |
dynamic joinpoints are events that happen during the program execution. |
| 192 |
\layout Subsection* |
| 193 |
|
| 194 |
Static Joinpoints |
| 195 |
\layout Standard |
| 196 |
|
| 197 |
The following kinds of C++ program entities are considered as static joinpoints: |
| 198 |
\layout Itemize |
| 199 |
|
| 200 |
classes, structs, and unions |
| 201 |
\layout Itemize |
| 202 |
|
| 203 |
namespaces |
| 204 |
\layout Itemize |
| 205 |
|
| 206 |
all kinds of functions (member, non-member, operator, conversion, etc.) |
| 207 |
\layout Standard |
| 208 |
|
| 209 |
Static joinpoints are described by |
| 210 |
\emph on |
| 211 |
match expressions |
| 212 |
\emph default |
| 213 |
. |
| 214 |
For example, |
| 215 |
\family typewriter |
| 216 |
\size small |
| 217 |
"% ...::foo(...)" |
| 218 |
\family default |
| 219 |
\size default |
| 220 |
is a match expression that describes all functions called |
| 221 |
\family typewriter |
| 222 |
\size small |
| 223 |
foo |
| 224 |
\family default |
| 225 |
\size default |
| 226 |
(in any scope, with any argument list, and any result type). |
| 227 |
More information on match expressions is given below. |
| 228 |
Note that not all of these static joinpoint types are currently supported |
| 229 |
as a target of advice (see section 'Advice for Static Joinpoints'). |
| 230 |
|
| 231 |
\layout Subsection* |
| 232 |
|
| 233 |
Dynamic Joinpoints |
| 234 |
\layout Standard |
| 235 |
|
| 236 |
The following kinds of events that might happen during the execution of |
| 237 |
a program are considered as dynamic joinpoints: |
| 238 |
\layout Itemize |
| 239 |
|
| 240 |
function call |
| 241 |
\layout Itemize |
| 242 |
|
| 243 |
function execution |
| 244 |
\layout Itemize |
| 245 |
|
| 246 |
object construction |
| 247 |
\layout Itemize |
| 248 |
|
| 249 |
object destruction |
| 250 |
\layout Standard |
| 251 |
|
| 252 |
The description of dynamic joinpoints is based upon the description mechanism |
| 253 |
for static joinpoints in conjunction with joinpoint type specific |
| 254 |
\emph on |
| 255 |
pointcut functions |
| 256 |
\emph default |
| 257 |
. |
| 258 |
For example: |
| 259 |
\layout Itemize |
| 260 |
|
| 261 |
|
| 262 |
\family typewriter |
| 263 |
\series bold |
| 264 |
\size small |
| 265 |
\emph on |
| 266 |
call |
| 267 |
\series default |
| 268 |
\emph default |
| 269 |
("% ...::foo(...)") |
| 270 |
\layout Itemize |
| 271 |
|
| 272 |
|
| 273 |
\family typewriter |
| 274 |
\series bold |
| 275 |
\size small |
| 276 |
\emph on |
| 277 |
execution |
| 278 |
\series default |
| 279 |
\emph default |
| 280 |
("float MathFuncs::%(float)") |
| 281 |
\layout Itemize |
| 282 |
|
| 283 |
|
| 284 |
\family typewriter |
| 285 |
\series bold |
| 286 |
\size small |
| 287 |
\emph on |
| 288 |
construction |
| 289 |
\series default |
| 290 |
\emph default |
| 291 |
("SomeClassName") |
| 292 |
\layout Itemize |
| 293 |
|
| 294 |
|
| 295 |
\family typewriter |
| 296 |
\series bold |
| 297 |
\size small |
| 298 |
\emph on |
| 299 |
destruction |
| 300 |
\series default |
| 301 |
\emph default |
| 302 |
("A"||"B") |
| 303 |
\layout Standard |
| 304 |
|
| 305 |
While |
| 306 |
\family typewriter |
| 307 |
\size small |
| 308 |
"% ...::foo(...)" |
| 309 |
\family default |
| 310 |
\size default |
| 311 |
represents a set of static joinpoints, i.e. |
| 312 |
all functions called |
| 313 |
\family typewriter |
| 314 |
\size small |
| 315 |
foo |
| 316 |
\family default |
| 317 |
\size default |
| 318 |
, the expression |
| 319 |
\family typewriter |
| 320 |
\size small |
| 321 |
call("% ...::foo(...)") |
| 322 |
\family default |
| 323 |
\size default |
| 324 |
describes all calls to these functions. |
| 325 |
A similar mapping from static to dynamic joinpoints is done by the |
| 326 |
\family typewriter |
| 327 |
\size small |
| 328 |
execution() |
| 329 |
\family default |
| 330 |
\size default |
| 331 |
, |
| 332 |
\family typewriter |
| 333 |
\size small |
| 334 |
construction() |
| 335 |
\family default |
| 336 |
\size default |
| 337 |
, and |
| 338 |
\family typewriter |
| 339 |
\size small |
| 340 |
destruction() |
| 341 |
\family default |
| 342 |
\size default |
| 343 |
pointcut functions. |
| 344 |
\layout Subsection* |
| 345 |
|
| 346 |
Pointcut Functions |
| 347 |
\layout Standard |
| 348 |
|
| 349 |
Further pointcut functions are used to filter or select joinpoints with |
| 350 |
specific properties. |
| 351 |
Some of them can be evaluated at compile time while others yield conditions |
| 352 |
that have to be checked at run time: |
| 353 |
\layout Itemize |
| 354 |
|
| 355 |
|
| 356 |
\family typewriter |
| 357 |
\series bold |
| 358 |
\size small |
| 359 |
\emph on |
| 360 |
cflow |
| 361 |
\series default |
| 362 |
\emph default |
| 363 |
( |
| 364 |
\emph on |
| 365 |
pointcut |
| 366 |
\emph default |
| 367 |
) |
| 368 |
\family default |
| 369 |
\size default |
| 370 |
-- captures all joinpoints in the dynamic execution context of the joinpoints |
| 371 |
in |
| 372 |
\emph on |
| 373 |
pointcut |
| 374 |
\emph default |
| 375 |
. |
| 376 |
\layout Itemize |
| 377 |
|
| 378 |
|
| 379 |
\family typewriter |
| 380 |
\series bold |
| 381 |
\size small |
| 382 |
\emph on |
| 383 |
base |
| 384 |
\series default |
| 385 |
\emph default |
| 386 |
( |
| 387 |
\emph on |
| 388 |
pointcut |
| 389 |
\emph default |
| 390 |
) |
| 391 |
\family default |
| 392 |
\size default |
| 393 |
and |
| 394 |
\family typewriter |
| 395 |
\series bold |
| 396 |
\size small |
| 397 |
\emph on |
| 398 |
derived |
| 399 |
\series default |
| 400 |
\emph default |
| 401 |
( |
| 402 |
\emph on |
| 403 |
pointcut |
| 404 |
\emph default |
| 405 |
) |
| 406 |
\family default |
| 407 |
\size default |
| 408 |
-- yield classes based on queries in the class hierarchy |
| 409 |
\layout Itemize |
| 410 |
|
| 411 |
|
| 412 |
\family typewriter |
| 413 |
\series bold |
| 414 |
\size small |
| 415 |
\emph on |
| 416 |
within |
| 417 |
\series default |
| 418 |
\emph default |
| 419 |
( |
| 420 |
\emph on |
| 421 |
pointcut |
| 422 |
\emph default |
| 423 |
) |
| 424 |
\family default |
| 425 |
\size default |
| 426 |
-- filters joinpoints depending on their lexical scope |
| 427 |
\layout Itemize |
| 428 |
|
| 429 |
|
| 430 |
\family typewriter |
| 431 |
\series bold |
| 432 |
\size small |
| 433 |
\emph on |
| 434 |
that |
| 435 |
\series default |
| 436 |
\emph default |
| 437 |
( |
| 438 |
\emph on |
| 439 |
type\SpecialChar ~ |
| 440 |
pattern |
| 441 |
\emph default |
| 442 |
) |
| 443 |
\family default |
| 444 |
\size default |
| 445 |
, |
| 446 |
\family typewriter |
| 447 |
\series bold |
| 448 |
\size small |
| 449 |
\emph on |
| 450 |
target |
| 451 |
\series default |
| 452 |
\emph default |
| 453 |
( |
| 454 |
\emph on |
| 455 |
type\SpecialChar ~ |
| 456 |
pattern |
| 457 |
\emph default |
| 458 |
) |
| 459 |
\family default |
| 460 |
\size default |
| 461 |
, |
| 462 |
\family typewriter |
| 463 |
\series bold |
| 464 |
\size small |
| 465 |
\emph on |
| 466 |
result |
| 467 |
\series default |
| 468 |
\emph default |
| 469 |
( |
| 470 |
\emph on |
| 471 |
type\SpecialChar ~ |
| 472 |
pattern |
| 473 |
\emph default |
| 474 |
) |
| 475 |
\family default |
| 476 |
\size default |
| 477 |
, and |
| 478 |
\family typewriter |
| 479 |
\series bold |
| 480 |
\size small |
| 481 |
\emph on |
| 482 |
args |
| 483 |
\series default |
| 484 |
\emph default |
| 485 |
( |
| 486 |
\emph on |
| 487 |
type\SpecialChar ~ |
| 488 |
pattern |
| 489 |
\emph default |
| 490 |
) |
| 491 |
\family default |
| 492 |
\size default |
| 493 |
-- filters joinpoints depending on the current object type, the target |
| 494 |
object type in a call, and the result and arguments types of a dynamic |
| 495 |
joinpoint. |
| 496 |
\layout Itemize |
| 497 |
|
| 498 |
|
| 499 |
\family typewriter |
| 500 |
\series bold |
| 501 |
\size small |
| 502 |
&& |
| 503 |
\family default |
| 504 |
\series default |
| 505 |
\size default |
| 506 |
, |
| 507 |
\family typewriter |
| 508 |
\series bold |
| 509 |
\size small |
| 510 |
|| |
| 511 |
\family default |
| 512 |
\series default |
| 513 |
\size default |
| 514 |
, |
| 515 |
\family typewriter |
| 516 |
\series bold |
| 517 |
\size small |
| 518 |
! |
| 519 |
\family default |
| 520 |
\series default |
| 521 |
\size default |
| 522 |
-- intersection, union, and exclusion of joinpoints in pointcuts |
| 523 |
\layout Standard |
| 524 |
|
| 525 |
Instead of the |
| 526 |
\emph on |
| 527 |
type pattern |
| 528 |
\emph default |
| 529 |
it is also possible to pass the name of a |
| 530 |
\emph on |
| 531 |
context variable |
| 532 |
\emph default |
| 533 |
to which context information from the joinpoint shall be bound. |
| 534 |
In this case the type of the context variable is used for the type matching. |
| 535 |
\layout Subsection* |
| 536 |
|
| 537 |
Match Mechanism Capabilities |
| 538 |
\layout Standard |
| 539 |
|
| 540 |
The match mechanism provides |
| 541 |
\family typewriter |
| 542 |
\size small |
| 543 |
% |
| 544 |
\family default |
| 545 |
\size default |
| 546 |
and |
| 547 |
\family typewriter |
| 548 |
\size small |
| 549 |
... |
| 550 |
|
| 551 |
\family default |
| 552 |
\size default |
| 553 |
as wildcard symbols. |
| 554 |
Thereby the following features are supported: |
| 555 |
\layout Itemize |
| 556 |
|
| 557 |
pattern based name matching, e.g. |
| 558 |
|
| 559 |
\family typewriter |
| 560 |
\size small |
| 561 |
"%X%" |
| 562 |
\family default |
| 563 |
\size default |
| 564 |
matches all names that contain an uppercase |
| 565 |
\family typewriter |
| 566 |
\size small |
| 567 |
X |
| 568 |
\layout Itemize |
| 569 |
|
| 570 |
flexible scope matching, e.g. |
| 571 |
|
| 572 |
\family typewriter |
| 573 |
\size small |
| 574 |
"Foo::...::Bar" |
| 575 |
\family default |
| 576 |
\size default |
| 577 |
matches Bar in the scope |
| 578 |
\family typewriter |
| 579 |
\size small |
| 580 |
Foo |
| 581 |
\family default |
| 582 |
\size default |
| 583 |
or any of its nested scopes |
| 584 |
\layout Itemize |
| 585 |
|
| 586 |
flexible matching of function argument type lists, e.g. |
| 587 |
|
| 588 |
\family typewriter |
| 589 |
\size small |
| 590 |
"% foo(...,int)" |
| 591 |
\family default |
| 592 |
\size default |
| 593 |
matches |
| 594 |
\family typewriter |
| 595 |
\size small |
| 596 |
foo |
| 597 |
\family default |
| 598 |
\size default |
| 599 |
with an |
| 600 |
\family typewriter |
| 601 |
\size small |
| 602 |
int |
| 603 |
\family default |
| 604 |
\size default |
| 605 |
as its last argument type |
| 606 |
\layout Itemize |
| 607 |
|
| 608 |
matching template argument lists, e.g. |
| 609 |
|
| 610 |
\family typewriter |
| 611 |
\size small |
| 612 |
"C<T,...>" |
| 613 |
\family default |
| 614 |
\size default |
| 615 |
matches an instance of the class template |
| 616 |
\family typewriter |
| 617 |
\size small |
| 618 |
C |
| 619 |
\family default |
| 620 |
\size default |
| 621 |
with a first template argument type |
| 622 |
\family typewriter |
| 623 |
\size small |
| 624 |
T |
| 625 |
\layout Itemize |
| 626 |
|
| 627 |
type patterns, e.g. |
| 628 |
|
| 629 |
\family typewriter |
| 630 |
\size small |
| 631 |
"const % *" |
| 632 |
\family default |
| 633 |
\size default |
| 634 |
matches all pointer types that reference objects of a constant type |
| 635 |
\layout Subsection* |
| 636 |
|
| 637 |
Named Pointcuts |
| 638 |
\layout Standard |
| 639 |
|
| 640 |
Pointcut expressions can be given a name. |
| 641 |
The definition of a named pointcut can be placed in any aspect, class, |
| 642 |
or namespace. |
| 643 |
The mechanism can be used for dynamic as well as static joinpoints. |
| 644 |
For example: |
| 645 |
\layout Standard |
| 646 |
|
| 647 |
|
| 648 |
\begin_inset ERT |
| 649 |
status Inlined |
| 650 |
|
| 651 |
\layout Standard |
| 652 |
|
| 653 |
\backslash |
| 654 |
begin{lstlisting}[style=ac] |
| 655 |
\layout Standard |
| 656 |
class OStream { |
| 657 |
\layout Standard |
| 658 |
// ... |
| 659 |
\layout Standard |
| 660 |
pointcut manipulator_types() = "hex"||"oct"||"bin"||"endl"; |
| 661 |
\layout Standard |
| 662 |
}; |
| 663 |
\layout Standard |
| 664 |
|
| 665 |
\backslash |
| 666 |
end{lstlisting} |
| 667 |
\end_inset |
| 668 |
|
| 669 |
|
| 670 |
\layout Standard |
| 671 |
|
| 672 |
In the context of an aspect, named pointcuts can also be defined as virtual |
| 673 |
or pure virtual, which allows refinement/definition in a derived aspect |
| 674 |
(see example at the end of this overview). |
| 675 |
\layout Section* |
| 676 |
|
| 677 |
Advice Model and Language |
| 678 |
\layout Subsection* |
| 679 |
|
| 680 |
Advice for Static Joinpoints |
| 681 |
\layout Standard |
| 682 |
|
| 683 |
The only kind of advice for static joinpoints that is currently supported |
| 684 |
by AspectC++ is the |
| 685 |
\emph on |
| 686 |
introduction |
| 687 |
\emph default |
| 688 |
. |
| 689 |
By using this kind of advice the aspect code is able to add new elements |
| 690 |
to classes, structures, or unions. |
| 691 |
Everything that is syntactically permitted in the body of a C++ class can |
| 692 |
be introduced by advice: |
| 693 |
\layout Itemize |
| 694 |
|
| 695 |
attribute introduction, e.g. |
| 696 |
|
| 697 |
\family typewriter |
| 698 |
\size small |
| 699 |
advice "AClass" : int _introduced_attribute; |
| 700 |
\layout Itemize |
| 701 |
|
| 702 |
type introduction, e.g. |
| 703 |
|
| 704 |
\family typewriter |
| 705 |
\size small |
| 706 |
advice "AClass" : typedef int INT; |
| 707 |
\layout Itemize |
| 708 |
|
| 709 |
member function introduction, e.g. |
| 710 |
|
| 711 |
\family typewriter |
| 712 |
\size small |
| 713 |
advice "AClass" : void f(); |
| 714 |
\layout Itemize |
| 715 |
|
| 716 |
nested type introduction, e.g. |
| 717 |
|
| 718 |
\family typewriter |
| 719 |
\size small |
| 720 |
advice "AClass" : class Inner { ... |
| 721 |
}; |
| 722 |
\layout Itemize |
| 723 |
|
| 724 |
constructor introduction, e.g. |
| 725 |
|
| 726 |
\family typewriter |
| 727 |
\size small |
| 728 |
advice "AClass" : AspectName(int, double); |
| 729 |
\layout Itemize |
| 730 |
|
| 731 |
destructor introduction, e.g. |
| 732 |
|
| 733 |
\family typewriter |
| 734 |
\size small |
| 735 |
advice "AClass" : ~AspectName() { ... |
| 736 |
} |
| 737 |
\layout Itemize |
| 738 |
|
| 739 |
base class introduction, e.g. |
| 740 |
|
| 741 |
\family typewriter |
| 742 |
\size small |
| 743 |
advice "AClass" : baseclass(ANewBaseclass); |
| 744 |
\layout Standard |
| 745 |
|
| 746 |
The syntax |
| 747 |
\family typewriter |
| 748 |
\size small |
| 749 |
advice < |
| 750 |
\emph on |
| 751 |
target |
| 752 |
\emph default |
| 753 |
- |
| 754 |
\emph on |
| 755 |
pointcut |
| 756 |
\emph default |
| 757 |
> : < |
| 758 |
\emph on |
| 759 |
introduction |
| 760 |
\emph default |
| 761 |
> |
| 762 |
\family default |
| 763 |
\size default |
| 764 |
supports the introduction of an element into an arbitrary set of target |
| 765 |
classes with a single advice. |
| 766 |
\layout Subsection* |
| 767 |
|
| 768 |
Advice for Dynamic Joinpoints |
| 769 |
\layout Standard |
| 770 |
|
| 771 |
Advice for dynamic joinpoints is used to affect the flow of control, when |
| 772 |
the joinpoint is reached. |
| 773 |
The following kinds of advice are supported: |
| 774 |
\layout Itemize |
| 775 |
|
| 776 |
before advice |
| 777 |
\layout Itemize |
| 778 |
|
| 779 |
after advice |
| 780 |
\layout Itemize |
| 781 |
|
| 782 |
around advice |
| 783 |
\layout Standard |
| 784 |
|
| 785 |
These advice types can orthogonally be combined with all dynamic joinpoint |
| 786 |
types. |
| 787 |
Advice for dynamic joinpoints is defined with the following syntax: |
| 788 |
\layout LyX-Code |
| 789 |
|
| 790 |
|
| 791 |
\series bold |
| 792 |
\size small |
| 793 |
advice |
| 794 |
\series default |
| 795 |
< |
| 796 |
\emph on |
| 797 |
target-pointcut |
| 798 |
\emph default |
| 799 |
> : ( |
| 800 |
\series bold |
| 801 |
before |
| 802 |
\series default |
| 803 |
| |
| 804 |
\series bold |
| 805 |
after |
| 806 |
\series default |
| 807 |
| |
| 808 |
\series bold |
| 809 |
around |
| 810 |
\series default |
| 811 |
) (< |
| 812 |
\emph on |
| 813 |
arguments |
| 814 |
\emph default |
| 815 |
>) { |
| 816 |
\layout LyX-Code |
| 817 |
|
| 818 |
|
| 819 |
\size small |
| 820 |
< |
| 821 |
\emph on |
| 822 |
advice-body |
| 823 |
\emph default |
| 824 |
> |
| 825 |
\layout LyX-Code |
| 826 |
|
| 827 |
|
| 828 |
\size small |
| 829 |
} |
| 830 |
\layout Standard |
| 831 |
|
| 832 |
While the before and after advice bodies are executed before or after the |
| 833 |
event described by |
| 834 |
\family typewriter |
| 835 |
\size small |
| 836 |
\emph on |
| 837 |
<target-pointcut> |
| 838 |
\family default |
| 839 |
\size default |
| 840 |
\emph default |
| 841 |
, an around advice body is executed instead of the event. |
| 842 |
\layout Subsubsection* |
| 843 |
|
| 844 |
Advice Language and Joinpoint API |
| 845 |
\layout Standard |
| 846 |
|
| 847 |
The advice body is implemented in standard C++. |
| 848 |
Additionally, the |
| 849 |
\emph on |
| 850 |
joinpoint API |
| 851 |
\emph default |
| 852 |
can be used to access (read and write) |
| 853 |
\emph on |
| 854 |
context information |
| 855 |
\emph default |
| 856 |
(e.g. |
| 857 |
function argument and result values) as well as |
| 858 |
\emph on |
| 859 |
static type information |
| 860 |
\emph default |
| 861 |
about the current joinpoint. |
| 862 |
To access the joinpoint API the object |
| 863 |
\family typewriter |
| 864 |
\size small |
| 865 |
JoinPoint *tjp |
| 866 |
\family default |
| 867 |
\size default |
| 868 |
can be used, which is implicitly available in advice code. |
| 869 |
Advice that uses the static type information provided by the joinpoint |
| 870 |
API is called |
| 871 |
\emph on |
| 872 |
generic advice |
| 873 |
\emph default |
| 874 |
. |
| 875 |
This concept is the key for generic, type-safe, |
| 876 |
\emph on |
| 877 |
and |
| 878 |
\emph default |
| 879 |
efficient advice in AspectC++. |
| 880 |
The static type information from the joinpoint API can even be used to |
| 881 |
instantiate template metaprograms, which is a technique for joinpoint specific |
| 882 |
code generation at compile time. |
| 883 |
\layout Standard |
| 884 |
|
| 885 |
The joinpoint API is also used to proceed the execution from within around |
| 886 |
advice ( |
| 887 |
\family typewriter |
| 888 |
\size small |
| 889 |
tjp->proceed() |
| 890 |
\family default |
| 891 |
\size default |
| 892 |
). |
| 893 |
Alternatively, |
| 894 |
\family typewriter |
| 895 |
\size small |
| 896 |
tjp->action() |
| 897 |
\family default |
| 898 |
\size default |
| 899 |
may be called to retrieve and store the |
| 900 |
\emph on |
| 901 |
proceed context |
| 902 |
\emph default |
| 903 |
as an |
| 904 |
\family typewriter |
| 905 |
\size small |
| 906 |
AC::Action |
| 907 |
\family default |
| 908 |
\size default |
| 909 |
object. |
| 910 |
Later, |
| 911 |
\family typewriter |
| 912 |
\size small |
| 913 |
action.trigger() |
| 914 |
\family default |
| 915 |
\size default |
| 916 |
may be called to proceed the intercepted flow of control. |
| 917 |
\layout Standard |
| 918 |
|
| 919 |
Catching and changing exceptions can be done by standard C++ features in |
| 920 |
around advice (try, catch, throw). |
| 921 |
\layout Subsubsection* |
| 922 |
|
| 923 |
Example |
| 924 |
\layout Standard |
| 925 |
|
| 926 |
The following advice is |
| 927 |
\emph on |
| 928 |
generic advice |
| 929 |
\emph default |
| 930 |
, because its implementation can deal with multiple overloaded |
| 931 |
\family typewriter |
| 932 |
\size small |
| 933 |
C::foo(...) |
| 934 |
\family default |
| 935 |
\size default |
| 936 |
implementations that have different result types: |
| 937 |
\layout Standard |
| 938 |
|
| 939 |
|
| 940 |
\begin_inset ERT |
| 941 |
status Open |
| 942 |
|
| 943 |
\layout Standard |
| 944 |
|
| 945 |
\backslash |
| 946 |
begin{lstlisting}[style=ac] |
| 947 |
\layout Standard |
| 948 |
advice execution("% C::foo(...)") : around() { |
| 949 |
\layout Standard |
| 950 |
cout << "executing " << JoinPoint::signature() |
| 951 |
\layout Standard |
| 952 |
<< " on " << *tjp->that() << endl; |
| 953 |
\layout Standard |
| 954 |
tjp->proceed (); |
| 955 |
\layout Standard |
| 956 |
cout << "the result was " << *tjp->result() << endl; |
| 957 |
\layout Standard |
| 958 |
} |
| 959 |
\layout Standard |
| 960 |
|
| 961 |
\backslash |
| 962 |
end{lstlisting} |
| 963 |
\end_inset |
| 964 |
|
| 965 |
|
| 966 |
\layout Section* |
| 967 |
|
| 968 |
Aspect Module Model |
| 969 |
\layout Standard |
| 970 |
|
| 971 |
The following example code shows an aspect |
| 972 |
\family typewriter |
| 973 |
\size small |
| 974 |
Logging |
| 975 |
\family default |
| 976 |
\size default |
| 977 |
defined in AspectC++: |
| 978 |
\layout Standard |
| 979 |
|
| 980 |
|
| 981 |
\begin_inset ERT |
| 982 |
status Inlined |
| 983 |
|
| 984 |
\layout Standard |
| 985 |
|
| 986 |
\backslash |
| 987 |
begin{lstlisting}[style=ac] |
| 988 |
\layout Standard |
| 989 |
aspect Logging { |
| 990 |
\layout Standard |
| 991 |
ostream *_out; // ordinary attributes |
| 992 |
\layout Standard |
| 993 |
public: |
| 994 |
\layout Standard |
| 995 |
void bind_stream(ostream *o) { _out = o; } // member function |
| 996 |
\layout Standard |
| 997 |
pointcut virtual logged_classes() = 0; // pure virtual pointcut |
| 998 |
\layout Standard |
| 999 |
// some advice |
| 1000 |
\layout Standard |
| 1001 |
advice execution("% ...::%(...)") && within(logged_classes()) : |
| 1002 |
\layout Standard |
| 1003 |
before () { |
| 1004 |
\layout Standard |
| 1005 |
*_out << "executing " << JoinPoint::signature () << endl; |
| 1006 |
\layout Standard |
| 1007 |
} |
| 1008 |
\layout Standard |
| 1009 |
}; |
| 1010 |
\layout Standard |
| 1011 |
|
| 1012 |
\backslash |
| 1013 |
end{lstlisting} |
| 1014 |
\end_inset |
| 1015 |
|
| 1016 |
|
| 1017 |
\layout Standard |
| 1018 |
|
| 1019 |
Aspects are the language element that is used to group all the definitions |
| 1020 |
that are needed to implement a crosscutting concern. |
| 1021 |
An aspect definition is allowed to contain member functions, attributes, |
| 1022 |
nested classes, named pointcuts, etc. |
| 1023 |
as ordinary classes. |
| 1024 |
Additionally, aspects normally contain advice definitions. |
| 1025 |
\layout Standard |
| 1026 |
|
| 1027 |
Aspects that contain pure virtual member functions or pure virtual pointcuts |
| 1028 |
are called |
| 1029 |
\emph on |
| 1030 |
abstract aspects |
| 1031 |
\emph default |
| 1032 |
. |
| 1033 |
These aspects only affect the system if a (concrete) aspect is derived, |
| 1034 |
which defines an implementation for the pure virtual functions and the |
| 1035 |
pure virtual pointcuts. |
| 1036 |
Abstract aspects are the AspectC++ mechanism to implement reusable aspect |
| 1037 |
code. |
| 1038 |
\layout Standard |
| 1039 |
|
| 1040 |
Aspect inheritance is slighly restricted. |
| 1041 |
Aspects can inherit from ordinary classes and abstract aspects but not |
| 1042 |
from concrete aspects. |
| 1043 |
Derived aspects can redefine virtual pointcuts and virtual functions defined |
| 1044 |
by base aspects. |
| 1045 |
\layout Section* |
| 1046 |
|
| 1047 |
Aspect Instantiation Model |
| 1048 |
\layout Standard |
| 1049 |
|
| 1050 |
By default, aspects are singletons, i.e. |
| 1051 |
there is one global instance automatically created for each non-abstract |
| 1052 |
aspect in the program. |
| 1053 |
However, by defining the |
| 1054 |
\family typewriter |
| 1055 |
\size small |
| 1056 |
aspectof() |
| 1057 |
\family default |
| 1058 |
\size default |
| 1059 |
static member function of an aspect the user can implement arbitrary instantiat |
| 1060 |
ion schemes, such as |
| 1061 |
\emph on |
| 1062 |
per-target |
| 1063 |
\emph default |
| 1064 |
, |
| 1065 |
\emph on |
| 1066 |
per-thread |
| 1067 |
\emph default |
| 1068 |
, or |
| 1069 |
\emph on |
| 1070 |
per-joinpoint |
| 1071 |
\emph default |
| 1072 |
. |
| 1073 |
For each dynamic joinpoint that is affected by the aspect the |
| 1074 |
\family typewriter |
| 1075 |
\size small |
| 1076 |
aspectof() |
| 1077 |
\family default |
| 1078 |
\size default |
| 1079 |
function has to return the right aspect instance on which the advice bodies |
| 1080 |
are invoked. |
| 1081 |
The instances themselfs are usually created with the introduction mechanism. |
| 1082 |
The |
| 1083 |
\family typewriter |
| 1084 |
\size small |
| 1085 |
aspectof() |
| 1086 |
\family default |
| 1087 |
\size default |
| 1088 |
function has access to the joinpoint API in order to find the right aspect |
| 1089 |
instance for the current joinpoint. |
| 1090 |
Here is an example: |
| 1091 |
\layout Standard |
| 1092 |
|
| 1093 |
|
| 1094 |
\begin_inset ERT |
| 1095 |
status Inlined |
| 1096 |
|
| 1097 |
\layout Standard |
| 1098 |
|
| 1099 |
\backslash |
| 1100 |
begin{lstlisting}[style=ac] |
| 1101 |
\layout Standard |
| 1102 |
aspect InstancePerTargetAspect { |
| 1103 |
\layout Standard |
| 1104 |
pointcut target_class() = "TargetName"; |
| 1105 |
\layout Standard |
| 1106 |
// an attribute of the aspect (stored per target) |
| 1107 |
\layout Standard |
| 1108 |
int _calls; |
| 1109 |
\layout Standard |
| 1110 |
// aspect instance created by introduction: |
| 1111 |
\layout Standard |
| 1112 |
advice target_class() : InstancePerTargetAspect _instance; |
| 1113 |
\layout Standard |
| 1114 |
// definition of the instantiation scheme in aspectof(): |
| 1115 |
\layout Standard |
| 1116 |
static InstancePerTargetAspect *aspectof() { |
| 1117 |
\layout Standard |
| 1118 |
return tjp->target()->_instance; |
| 1119 |
\layout Standard |
| 1120 |
} |
| 1121 |
\layout Standard |
| 1122 |
// the advice |
| 1123 |
\layout Standard |
| 1124 |
advice call("% ...::%(...)") && target(target_class()) : before () { |
| 1125 |
\layout Standard |
| 1126 |
_calls++; |
| 1127 |
\layout Standard |
| 1128 |
} |
| 1129 |
\layout Standard |
| 1130 |
// attribute initialization in the aspect constructor |
| 1131 |
\layout Standard |
| 1132 |
InstancePerTargetAspect () : _calls (0) {} |
| 1133 |
\layout Standard |
| 1134 |
}; |
| 1135 |
\layout Standard |
| 1136 |
|
| 1137 |
\backslash |
| 1138 |
end{lstlisting} |
| 1139 |
\end_inset |
| 1140 |
|
| 1141 |
|
| 1142 |
\layout Section* |
| 1143 |
|
| 1144 |
Aspect Composition Model |
| 1145 |
\layout Standard |
| 1146 |
|
| 1147 |
In AspectC++ any number of aspects can be used in the same application. |
| 1148 |
Aspect composition is currently restricted to inheritance from abstract |
| 1149 |
aspects. |
| 1150 |
Concrete aspects cannot be used for the implementation of new aspects. |
| 1151 |
\layout Standard |
| 1152 |
|
| 1153 |
Aspect interactions can be handled by the developer on a per joinpoint basis |
| 1154 |
with |
| 1155 |
\emph on |
| 1156 |
order advice |
| 1157 |
\emph default |
| 1158 |
, e.g. |
| 1159 |
|
| 1160 |
\family typewriter |
| 1161 |
\size small |
| 1162 |
advice execution("void f%(...)") : order("Me", !"Me") |
| 1163 |
\family default |
| 1164 |
\size default |
| 1165 |
gives the aspect |
| 1166 |
\family typewriter |
| 1167 |
\size small |
| 1168 |
Me |
| 1169 |
\family default |
| 1170 |
\size default |
| 1171 |
the highest precedence at all joinpoint described by the pointcut expression. |
| 1172 |
Order advice can be given by any aspect for any aspect, thus can be separated |
| 1173 |
from the affected aspects. |
| 1174 |
Aspect names in order advice declarations are match expressions and may |
| 1175 |
contain wildcards, e.g. |
| 1176 |
|
| 1177 |
\family typewriter |
| 1178 |
\size small |
| 1179 |
order("kernel::%", !"kernel::%") |
| 1180 |
\family default |
| 1181 |
\size default |
| 1182 |
gives every aspect declared in the namespace |
| 1183 |
\family typewriter |
| 1184 |
\size small |
| 1185 |
kernel |
| 1186 |
\family default |
| 1187 |
\size default |
| 1188 |
precedence over all other aspects. |
| 1189 |
Besides this partial order in the precedence of aspects, the precedence |
| 1190 |
of advice within one aspect is determined according to its position in |
| 1191 |
the aspect definition. |
| 1192 |
As long as it does not conflict with order advice AspectC++ aims to give |
| 1193 |
aspects the same precedence at all joinpoints. |
| 1194 |
\layout Section* |
| 1195 |
|
| 1196 |
Aspect Weaving Model |
| 1197 |
\layout Standard |
| 1198 |
|
| 1199 |
The only implementation of AspectC++ is based on static source to source |
| 1200 |
transformation. |
| 1201 |
Nevertheless, the language could also be used for dynamic weavers if some |
| 1202 |
really hard technical challenges like runtime introductions were solved. |
| 1203 |
\layout Section* |
| 1204 |
|
| 1205 |
Example |
| 1206 |
\layout Standard |
| 1207 |
|
| 1208 |
A reusable observer pattern implementation in AspectC++: |
| 1209 |
\layout Standard |
| 1210 |
|
| 1211 |
|
| 1212 |
\begin_inset ERT |
| 1213 |
status Inlined |
| 1214 |
|
| 1215 |
\layout Standard |
| 1216 |
|
| 1217 |
\backslash |
| 1218 |
begin{lstlisting}[style=ac] |
| 1219 |
\layout Standard |
| 1220 |
aspect ObserverPattern { |
| 1221 |
\layout Standard |
| 1222 |
// Data structures to manage subjects and observers |
| 1223 |
\layout Standard |
| 1224 |
... |
| 1225 |
\layout Standard |
| 1226 |
public: |
| 1227 |
\layout Standard |
| 1228 |
// Interfaces for each role |
| 1229 |
\layout Standard |
| 1230 |
struct ISubject {}; |
| 1231 |
\layout Standard |
| 1232 |
struct IObserver { |
| 1233 |
\layout Standard |
| 1234 |
virtual void update(ISubject *) = 0; |
| 1235 |
\layout Standard |
| 1236 |
}; |
| 1237 |
\layout Standard |
| 1238 |
|
| 1239 |
\layout Standard |
| 1240 |
// To be defined by the concrete derived aspect |
| 1241 |
\layout Standard |
| 1242 |
pointcut virtual observers() = 0; |
| 1243 |
\layout Standard |
| 1244 |
pointcut virtual subjects() = 0; |
| 1245 |
\layout Standard |
| 1246 |
// subjectChange() matches all non-const methods by default |
| 1247 |
\layout Standard |
| 1248 |
pointcut virtual subjectChange() = |
| 1249 |
\layout Standard |
| 1250 |
execution("% ...::%(...)" && !"% ...::%(...) const") |
| 1251 |
\layout Standard |
| 1252 |
&& within(subjects()); |
| 1253 |
\layout Standard |
| 1254 |
|
| 1255 |
\layout Standard |
| 1256 |
// Add new baseclass to each subject/observer class |
| 1257 |
\layout Standard |
| 1258 |
// and insert code to inform observers |
| 1259 |
\layout Standard |
| 1260 |
advice observers() : baseclass(IObserver); |
| 1261 |
\layout Standard |
| 1262 |
advice subjects() : baseclass(ISubject); |
| 1263 |
\layout Standard |
| 1264 |
advice subjectChange() : after() { |
| 1265 |
\layout Standard |
| 1266 |
ISubject* subject = tjp->that(); |
| 1267 |
\layout Standard |
| 1268 |
updateObservers(subject); |
| 1269 |
\layout Standard |
| 1270 |
} |
| 1271 |
\layout Standard |
| 1272 |
|
| 1273 |
\layout Standard |
| 1274 |
// Operations to add, remove and notify observers |
| 1275 |
\layout Standard |
| 1276 |
void updateObservers(ISubject* sub) { ... } |
| 1277 |
\layout Standard |
| 1278 |
void addObserver(ISubject* sub, IObserver* ob) { ... } |
| 1279 |
\layout Standard |
| 1280 |
void remObserver(ISubject* sub, IObserver* ob) { ... } |
| 1281 |
\layout Standard |
| 1282 |
}; |
| 1283 |
\layout Standard |
| 1284 |
|
| 1285 |
\backslash |
| 1286 |
end{lstlisting} |
| 1287 |
\end_inset |
| 1288 |
|
| 1289 |
|
| 1290 |
\layout Standard |
| 1291 |
|
| 1292 |
Concrete aspect, which applies the pattern: |
| 1293 |
\layout Standard |
| 1294 |
|
| 1295 |
|
| 1296 |
\begin_inset ERT |
| 1297 |
status Open |
| 1298 |
|
| 1299 |
\layout Standard |
| 1300 |
|
| 1301 |
\backslash |
| 1302 |
begin{lstlisting}[style=ac] |
| 1303 |
\layout Standard |
| 1304 |
#include "ObserverPattern.ah" |
| 1305 |
\layout Standard |
| 1306 |
#include "ClockTimer.h" |
| 1307 |
\layout Standard |
| 1308 |
|
| 1309 |
\layout Standard |
| 1310 |
aspect ClockObserver : public ObserverPattern { |
| 1311 |
\layout Standard |
| 1312 |
// define the pointcuts |
| 1313 |
\layout Standard |
| 1314 |
pointcut subjects() = "ClockTimer"; |
| 1315 |
\layout Standard |
| 1316 |
pointcut observers() = "DigitalClock"||"AnalogClock"; |
| 1317 |
\layout Standard |
| 1318 |
public: |
| 1319 |
\layout Standard |
| 1320 |
advice observers() : |
| 1321 |
\layout Standard |
| 1322 |
void update( ObserverPattern::ISubject* sub ) { |
| 1323 |
\layout Standard |
| 1324 |
Draw(); |
| 1325 |
\layout Standard |
| 1326 |
} |
| 1327 |
\layout Standard |
| 1328 |
}; |
| 1329 |
\layout Standard |
| 1330 |
|
| 1331 |
\backslash |
| 1332 |
end{lstlisting} |
| 1333 |
\end_inset |
| 1334 |
|
| 1335 |
|
| 1336 |
\the_end |