120 likes | 137 Views
Implementation of Programming Languages. Modular type checking for AspectJ. Aspect-Oriented programming promotes to increase modularity Crosscutting code can be factored out into its own module, an aspect. Modular type checking for AspectJ.
E N D
Implementation of Programming Languages 4 January 2020 | Software Technology Group | 1
Modular type checking for AspectJ • Aspect-Oriented programming promotes to increase modularity • Crosscutting code can be factored out into its own module,an aspect 4 January 2020 | Software Technology Group | 2
Modular type checking for AspectJ pointcut setXY(FigureElement fe, int x, int y):call(void FigureElement.setXY(int, int))&& target(fe)&& args(x, y); after(FigureElement fe, int x, int y) returning:setXY(fe, x, y) { System.out.println(fe + " moved to (" + x + ", " + y + ")."); } What if method setXY is renamed? 4 January 2020 | Software Technology Group | 3
Prob. 1: Fragile-Pointcut Problem Aspect fragile Pointcut Base Program Advice 4 January 2020 | Software Technology Group | 4
Proposed solution Module Base Program Aspect Joinpoint Types Needs to bemaintained Advice Module Definition Binding:Joinpoint typesto pointcuts stable 4 January 2020 | Software Technology Group | 5
Problem 2: around-advice and polymorphism //matches on any sub-type of Person, including Student void around(Person p) : call(* Person.*(..)) && target(p) { proceed( new Person() ); } Student s = new Student(); s.enrol(); //cannot enrol a general “Person” 4 January 2020 | Software Technology Group | 6
Proposed Solution //matches on any sub-type of Person that is also a //super-type of student void around(Person p) : call(* Person.*(..)) && target(p) :void proceed(Student) { proceed( new Person() ); } Student s = new Student(); s.enrol(); //cannot enrol a general “Person” 4 January 2020 | Software Technology Group | 7
Proposed Solution //does NOT match Student any more! void around(Person p) : call(* Person.*(..)) && target(p) { proceed( new Person() ); } Student s = new Student(); s.enrol(); //cannot enrol a general “Person” 4 January 2020 | Software Technology Group | 8
Modular definition – Aspect side aspect DrawingLogger { joinpoint void settingXY(FigureElement fe, int x, int y); after settingXY(FigureElement fe, int x, int y) returning { System.out.println(fe + " moved to (" + x + ", " + y + ")."); } } 4 January 2020 | Software Technology Group | 9
Modular definition – Base-Code side class FigureElement{ void setXY(int x, int y); } module Drawing { includes FigureElement; bind settingXY(FigureElement fe, int x, int y) to call(void FigureElement.setXY(int, int)) && target(fe) && args(x, y); } 4 January 2020 | Software Technology Group | 10
Modular type checking for AspectJ Tasks • To address Problem 1 (Fragile-Pointcut Problem): • extend AspectBench Compiler (www.aspectbench.org) to: • provide new syntax for module definitions • implement binding of pointcuts to joinpoint-type definitions • implement corresponding type checks • To address Problem 2 (around-advice/polymorphism problem): • extend AspectBench Compiler to: • allow (generic) type bounds for around advice 4 January 2020 | Software Technology Group | 11
What do you gain from this? • experience with a extending a real language in a real compiler • you can contribute your own ideas to the language design • possibly a publication later-on, if you want to 4 January 2020 | Software Technology Group | 12