The Aspect-Oriented Design of the Puma C/C Parser Framework

56
The Aspect-Oriented Design of the Puma C/C ++ Parser Framework Matthias Urban pure systems GmbH Magdeburg Daniel Lohmann Friedrich-Alexander University Erlangen-Nuremberg Olaf Spinczyk Technical University Dortmund 9th International Conference on Aspect-Oriented Software Development Industry Track – March 16, 2010

Transcript of The Aspect-Oriented Design of the Puma C/C Parser Framework

Page 1: The Aspect-Oriented Design of the Puma C/C Parser Framework

The Aspect-Oriented Design of thePuma C/C++ Parser Framework

Matthias Urbanpure systems GmbH

Magdeburg

Daniel LohmannFriedrich-Alexander University

Erlangen-Nuremberg

Olaf SpinczykTechnical University

Dortmund

9th International Conference onAspect-Oriented Software Development

Industry Track – March 16, 2010

Page 2: The Aspect-Oriented Design of the Puma C/C Parser Framework

What is Puma

Puma

A generic framework for applications that have toparse, analyze, and optionally transform

various flavors of C and C++ source code.

freely available under the GPL

https://svn.aspectc.org/repos/Puma/trunk

83,000 lines of code

developed and maintained by pure::systems GmbH, Magdeburg

internally used for the development of client-specific solutions

commercial licenses and support available

used by – and implemented in – AspectC++

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 2

Page 3: The Aspect-Oriented Design of the Puma C/C Parser Framework

What is Puma

Puma

A generic framework for applications that have toparse, analyze, and optionally transform

various flavors of C and C++ source code.

freely available under the GPL

https://svn.aspectc.org/repos/Puma/trunk

83,000 lines of code

developed and maintained by pure::systems GmbH, Magdeburg

internally used for the development of client-specific solutions

commercial licenses and support available

used by – and implemented in – AspectC++

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 2

Page 4: The Aspect-Oriented Design of the Puma C/C Parser Framework

Puma Application Examples

The AspectC++ weaver ac++

aspect Cool {. . .

};

int main() {. . .

}

AspectC++ Source

ac++Weaver

Puma

. . .int main() {

_Cool_invoke_a0();. . .

}

(Woven) C++ Source

A mutation testing tool for SystemC

SC_MODULE(adder) {sc_in<int> a, b;sc_out<int> sum;void do_add() {

sum.write(a.read()+ b.read());

}. . .

};

SystemC Source

scmMutator

Puma

SC_MODULE(adder) {sc_in<int> a, b;sc_out<int> sum;void do_add() {

sum.write(a.read()+ b.read()) + ERR;

}. . .

};

(Mutated) SystemC Source

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 3

Page 5: The Aspect-Oriented Design of the Puma C/C Parser Framework

Puma Application Examples

The AspectC++ weaver ac++

aspect Cool {. . .

};

int main() {. . .

}

AspectC++ Source

ac++Weaver

Puma

. . .int main() {

_Cool_invoke_a0();. . .

}

(Woven) C++ Source

A mutation testing tool for SystemC

SC_MODULE(adder) {sc_in<int> a, b;sc_out<int> sum;void do_add() {

sum.write(a.read()+ b.read());

}. . .

};

SystemC Source

scmMutator

Puma

SC_MODULE(adder) {sc_in<int> a, b;sc_out<int> sum;void do_add() {

sum.write(a.read()+ b.read()) + ERR;

}. . .

};

(Mutated) SystemC Source

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 3

Page 6: The Aspect-Oriented Design of the Puma C/C Parser Framework

Concerns of a C/C++ Parser

Primary job of a parser (greatly simplified)

read tokens from input stream

(keywords, identifier, operator symbols)

invoke matching grammar rules

Additional concerns (there are many!)

syntax tree construction

tentative parsing

error handling

connection to the semantic analysis

lookahead optimizations

State of the Art (for example, gcc/g++)

All these concerns are tangled and scattered in the implementation!

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 4

Page 7: The Aspect-Oriented Design of the Puma C/C Parser Framework

Concerns of a C/C++ Parser

Primary job of a parser (greatly simplified)

read tokens from input stream

(keywords, identifier, operator symbols)

invoke matching grammar rules

Additional concerns (there are many!)

syntax tree construction

tentative parsing

error handling

connection to the semantic analysis

lookahead optimizations

State of the Art (for example, gcc/g++)

All these concerns are tangled and scattered in the implementation!

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 4

Page 8: The Aspect-Oriented Design of the Puma C/C Parser Framework

The Challenge

512 pages

816 pages of spec!

700 pages(without .NET!)

647 pages

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 5

Page 9: The Aspect-Oriented Design of the Puma C/C Parser Framework

The Challenge

512 pages

816 pages of spec!

700 pages(without .NET!)

647 pages

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 5

Page 10: The Aspect-Oriented Design of the Puma C/C Parser Framework

The Challenge

512 pages

816 pages of spec!

700 pages(without .NET!)

647 pages

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 5

Page 11: The Aspect-Oriented Design of the Puma C/C Parser Framework

The Challenge

512 pages

816 pages of spec!

700 pages(without .NET!)

647 pages

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 5

Page 12: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 13: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 14: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 15: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 16: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 17: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 18: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 19: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 20: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 21: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 22: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 23: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Family of C/C++ Parsers and Manipulators

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

Goal: Configurability and Extensibility

Separation of concerns crucial for success!

å Aspect-oriented design and implementation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 24: The Aspect-Oriented Design of the Puma C/C Parser Framework

Focus of this Talk: Puma Parsers

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

Goal: Configurability and Extensibility

Separation of concerns crucial for success!

å Aspect-oriented design and implementation

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Introduction 6

Page 25: The Aspect-Oriented Design of the Puma C/C Parser Framework

Agenda

1 Introduction

2 Design Methodology

3 Separation of Concerns in Puma

4 Achievements

5 Wrap up

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 7

Page 26: The Aspect-Oriented Design of the Puma C/C Parser Framework

Obliviousness and Quantification demystified

C

callee()

P

caller()

calle

e

know

s

(a)

«aspect»C

exec("caller")

P

caller()

knows

"caller"

(b)

Provider–Consumer Relationship without AOP

Event provider has to know event consumer

Control flows specified in the direction of knowledge

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 8

Page 27: The Aspect-Oriented Design of the Puma C/C Parser Framework

Obliviousness and Quantification demystified

C

callee()

P

caller()

calle

e

know

s

(a)

«aspect»C

exec("caller")

P

caller()

knows

"caller"

(b)

C

callee()

P

caller()

calle

e

know

s

(a)

«aspect»C

exec("caller")

P

caller()know

s

"caller"

(b)

Provider–Consumer Relationship with AOP

Event consumer has to know event provider

Advice specifies control flows against the direction of knowledge

å the mechanism behind “obliviousness”

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 8

Page 28: The Aspect-Oriented Design of the Puma C/C Parser Framework

Obliviousness and Quantification demystified

C

callee()

P

caller()

calle

e

know

s

(a)

«aspect»C

exec("caller")

P

caller()

knows

"caller"

(b)

«aspect»C

exec("%")

P1

foo()

P2

bar()

Pn

zoo(). . .

(a)

. . .

«aspect»C

exec("caller")

P

caller()

"caller"

knows

(b)

Provider–Consumer Relationship with AOP

Advice specifies control flows against the direction of knowledge

Control flow specification is inherently loose

å the mechanism behind “quantification”

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 8

Page 29: The Aspect-Oriented Design of the Puma C/C Parser Framework

Methodology: Aspect-Aware System Design [USENIX 09]

Basic Idea: Separation of Concerns in the Implementation

one feature per implementation unit

strict decoupling of policies and mechanisms

å use aspects as primary composition technique

Design Principles 7→ Development Idioms

1. loose coupling

2. visible transitions

3. minimal extensions

by

by

by

advice-based binding

explicit join points

extension slices

å we partly give up the obliviousness idea!

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 9

Page 30: The Aspect-Oriented Design of the Puma C/C Parser Framework

Methodology: Aspect-Aware System Design [USENIX 09]

Basic Idea: Separation of Concerns in the Implementation

one feature per implementation unit

strict decoupling of policies and mechanisms

å use aspects as primary composition technique

Design Principles 7→ Development Idioms

1. loose coupling

2. visible transitions

3. minimal extensions

by

by

by

advice-based binding

explicit join points

extension slices

å we partly give up the obliviousness idea!

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 9

Page 31: The Aspect-Oriented Design of the Puma C/C Parser Framework

Methodology: Aspect-Aware System Design [USENIX 09]

Basic Idea: Separation of Concerns in the Implementation

one feature per implementation unit

strict decoupling of policies and mechanisms

å use aspects as primary composition technique

Design Principles 7→ Development Idioms

1. loose coupling

2. visible transitions

3. minimal extensions

by

by

by

advice-based binding

explicit join points

extension slices

å we partly give up the obliviousness idea!

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 9

Page 32: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Minimal Example (also: AspectC++ in 2 Minutes)

class PreprocessorParser implements the ISO standard

aspect GNUMacros extends it by gcc/g++’s predefined macros

GnuMacros is a minimal extensionbrought in as an extension slice into class PreprocessorParserintegrated by advice-based binding to configure()

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 10

Page 33: The Aspect-Oriented Design of the Puma C/C Parser Framework

A Minimal Example (also: AspectC++ in 2 Minutes)

class PreprocessorParser implements the ISO standard

aspect GNUMacros extends it by gcc/g++’s predefined macros

GnuMacros is a minimal extensionbrought in as an extension slice into class PreprocessorParserintegrated by advice-based binding to configure()

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 10

Page 34: The Aspect-Oriented Design of the Puma C/C Parser Framework

Methodology: Roles of Aspects and Classes

What to model as a class and what as an aspect?

< thing > is modelled as a class if – and only if – it is adistinguishable, instantiable concept of Puma:

a system component, instantiated internally on behalf of Puma

a system abstraction, instantiated as objects on behalf of the user

both are sparse 7→ provide a minimal implementation only

otherwise < thing > is an aspect!

we came up with three idiomatic aspect roles

extension aspects

policy aspects

upcall aspects

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Design Methodology 11

Page 35: The Aspect-Oriented Design of the Puma C/C Parser Framework

Agenda

1 Introduction

2 Design Methodology

3 Separation of Concerns in Puma

4 Achievements

5 Wrap up

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 12

Page 36: The Aspect-Oriented Design of the Puma C/C Parser Framework

Aspect-Aware System Abstractions

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 13

Page 37: The Aspect-Oriented Design of the Puma C/C Parser Framework

Aspect-Aware System Abstractions

struct CSyntax : public Syntax {

struct Literal {static bool check (CSyntax &s) { return s.literal(); }static bool parse (CSyntax &s) { return s.token(ID); }

};virtual bool literal() { return Literal::parse(*this); }

struct Primary {static bool check (CSyntax &s) { return s.primary(); }static bool parse (CSyntax &s) {

return Literal::check(s) ||(s.token(’(’) && Expr::check(s) && s.token(’)’));

}};virtual bool primary() { return Primary::parse(*this); }

. . .};

Grammar rule 7→ a virtual function and an inner class

virtual function delegates implementation to inner class

inner class unambigious scope for minimal extensions

class members unambigious join points for visible transitions

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 14

Page 38: The Aspect-Oriented Design of the Puma C/C Parser Framework

Aspect-Aware System Abstractions

struct CSyntax : public Syntax {

struct Literal {static bool check (CSyntax &s) { return s.literal(); }static bool parse (CSyntax &s) { return s.token(ID); }

};virtual bool literal() { return Literal::parse(*this); }

struct Primary {static bool check (CSyntax &s) { return s.primary(); }static bool parse (CSyntax &s) {

return Literal::check(s) ||(s.token(’(’) && Expr::check(s) && s.token(’)’));

}};virtual bool primary() { return Primary::parse(*this); }

. . .};

Grammar rule 7→ a virtual function and an inner class

virtual function delegates implementation to inner class

inner class unambigious scope for minimal extensions

class members unambigious join points for visible transitions

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 14

Page 39: The Aspect-Oriented Design of the Puma C/C Parser Framework

Aspect-Aware System Abstractions

struct CSyntax : public Syntax {

struct Literal {static bool check (CSyntax &s) { return s.literal(); }static bool parse (CSyntax &s) { return s.token(ID); }

};virtual bool literal() { return Literal::parse(*this); }

struct Primary {static bool check (CSyntax &s) { return s.primary(); }static bool parse (CSyntax &s) {

return Literal::check(s) ||(s.token(’(’) && Expr::check(s) && s.token(’)’));

}};virtual bool primary() { return Primary::parse(*this); }

. . .};

Grammar rule 7→ a virtual function and an inner class

virtual function delegates implementation to inner class

inner class unambigious scope for minimal extensions

class members unambigious join points for visible transitions

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 14

Page 40: The Aspect-Oriented Design of the Puma C/C Parser Framework

Simple Policy Aspect: Backtracking Support

aspect SyntaxState {// intercept all calls of rules (after dynamic dispatch)advice Syntax::rule_call() : around () {Syntax &s = *tjp->arg<0>(); // get 0th argument (CSyntax obj.)Syntax::State state; // local variable to store states.get_state(state); // save current parser statetjp->proceed(); // perform the intercepted callif (!*tjp->result()) // check whether result is false

s.set_state(state); // restore the state}

};

SyntaxState implements a mandatory, but crosscutting policycurrently matches 104/118 grammar rules in the C/C++ syntaximplementation as aspects keeps backtracking policy configurable

inherently scales with extension aspects that add more rules

VisualC++, GNU, AspectC++, OpenMP, MPI, C++ 1x, . . .

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 15

Page 41: The Aspect-Oriented Design of the Puma C/C Parser Framework

Extension/Upcall Aspects: Syntax Tree Construction

CSyntaxCSyntax

SyntaxSyntax

advice "CSyntax::Literal" : slice struct { static CTree *build(CSyntax &s) { return new CT_Literal(s.get_node(0));} };

advice "CSyntax::Primary" : slice struct { static CTree *build(CSyntax &s) { if (s.nodes() == 3) return new CT_BracedExpr(s.get_node(0), s.get_node(1), s.get_node(2)); else return s.get_node(0);} };...

LiteralLiteral

PrimaryPrimary

ExprExprextensions ofthe syntax ruleclasses bybuild() functions

...

<aspect>CBuilder

CBuilder extends grammar rules for syntax tree constructioneach rule gets a build() method to construct corresponding element

Builder binds this extension by upcallseach rule invokation by the parser now also triggers build()

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 16

Page 42: The Aspect-Oriented Design of the Puma C/C Parser Framework

Extension/Upcall Aspects: Syntax Tree Construction

CSyntaxCSyntax

SyntaxSyntax

advice "CSyntax::Literal" : slice struct { static CTree *build(CSyntax &s) { return new CT_Literal(s.get_node(0));} };

advice "CSyntax::Primary" : slice struct { static CTree *build(CSyntax &s) { if (s.nodes() == 3) return new CT_BracedExpr(s.get_node(0), s.get_node(1), s.get_node(2)); else return s.get_node(0);} };...

LiteralLiteral

PrimaryPrimary

ExprExprextensions ofthe syntax ruleclasses bybuild() functions

...

advice for ...::parse() → control flowredirection to introduced build() functions

<aspect>CBuilder

<aspect>Builder

extensions ofSyntax::Statewith Builderstate information

advice Syntax::rule_call(): after () { if (*tjp->result()) { Tree *t = JoinPoint::Target::build(*tjp->arg<0>()); if (t) tjp->arg<0>()->push_node(t); else *tjp->result () = false;} }...

CBuilder extends grammar rules for syntax tree constructioneach rule gets a build() method to construct corresponding element

Builder binds this extension by upcallseach rule invokation by the parser now also triggers build()

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 16

Page 43: The Aspect-Oriented Design of the Puma C/C Parser Framework

Extension Aspects: Language Extensions

Dialect aspects extend both, CSyntax and CCSyntaxfacilitates implicit reuse of C extensions in the C++ parser

Example for loose couplingIn C-only projects, CCSyntax is just not present C++ extensions are silently skipped

inherent property of advice-based binding

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 17

Page 44: The Aspect-Oriented Design of the Puma C/C Parser Framework

Extension Aspects: Language Extensions

Dialect aspects extend both, CSyntax and CCSyntaxfacilitates implicit reuse of C extensions in the C++ parser

Example for loose couplingIn C-only projects, CCSyntax is just not present C++ extensions are silently skipped

inherent property of advice-based binding

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Separation of Concerns in Puma 17

Page 45: The Aspect-Oriented Design of the Puma C/C Parser Framework

Agenda

1 Introduction

2 Design Methodology

3 Separation of Concerns in Puma

4 Achievements

5 Wrap up

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 18

Page 46: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Configurability

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

Achieved: Complete “Plug & Play” of Features

Loose coupling of feature implements

distinct sets of implementation units

integrate themselves by advice-based binding

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 19

Page 47: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Configurability

Puma

Input Languages

C++

AspectC++

C Dialects

MS Visual C++ GNU gcc/g++

Analyses

CPP Parsing & Sem. Analysis

Full Sem. Analysis

AST Matching

Transformation

Achieved: Complete “Plug & Play” of Features

Loose coupling of feature implements

distinct sets of implementation units

integrate themselves by advice-based binding

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 19

Page 48: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Maintainability

LoC taken by the C parser and C++ parser implementations

cpp-parser.cc 22,964

c-parser.c 8,676

GNU

CCParser.cc 2,802

CParser.cc 1,786

Puma

Achieved: Cost Effectiveness

Even though Puma is a complex piece of software, itremains maintainable by a single, part-time engineer.

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 20

Page 49: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Maintainability

LoC taken by the C parser and C++ parser implementations

cpp-parser.cc 22,964

c-parser.c 8,676

GNU

CCParser.cc 2,802

CParser.cc 1,786

Puma

Achieved: Cost Effectiveness

Even though Puma is a complex piece of software, itremains maintainable by a single, part-time engineer.

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 20

Page 50: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Extensibility

An unanticipated Extension: C++ 1x static assertions

static assert ( constant-expr, error-message) ;

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 21

Page 51: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Extensibility

An unanticipated Extension: C++ 1x static assertions

static assert ( constant-expr, error-message) ;

We could translate the impact description (“proposed wording”)of this new C++ feature almost literally into aspect code

policy aspect for binding the code and [LoC]

enabling/disabling it by a new command line options 112

syntax tree class for static assertions 102

syntax rule (extension slice) 77

syntax tree creation (extension slice) 73

function for semantic analysis (extension slice) 100

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 21

Page 52: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Extensibility

An unanticipated Extension: C++ 1x static assertions

static assert ( constant-expr, error-message) ;

“A compiler writer could certainly implement this feature,as specified, in two or three days. . . ”

It took us just one day!

including documentation and testing

including extra work for the very first C++ 1x feature

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 21

Page 53: The Aspect-Oriented Design of the Puma C/C Parser Framework

Separation of Concerns Extensibility

An unanticipated Extension: C++ 1x static assertions

static assert ( constant-expr, error-message) ;

“A compiler writer could certainly implement this feature,as specified, in two or three days. . . ”

It took us just one day!

including documentation and testing

including extra work for the very first C++ 1x feature

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Achievements 21

Page 54: The Aspect-Oriented Design of the Puma C/C Parser Framework

Agenda

1 Introduction

2 Design Methodology

3 Separation of Concerns in Puma

4 Achievements

5 Wrap up

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Wrap up 22

Page 55: The Aspect-Oriented Design of the Puma C/C Parser Framework

Summary and Conclusions

A Parser for “real-world” C/C++ code is a complex thing

Many concerns to deal with

C++ is one of the most challenging languages at all

Various language dialects and extensions

Puma copes well with this variability and complexity

Relatively small code base, separation of concerns

Configurability

Extensibility

Achieved by AOP and an aspect-aware design

Sparse classes, explicit join points

Employed aspects as the fundamental extension and binding mechanism

“Plug&Play” configuration and extension

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Wrap up 23

Page 56: The Aspect-Oriented Design of the Puma C/C Parser Framework

Future Work

Advertise it more! :-)

Puma is the best and most feature-complete open-source

C++ analysis and transformation framework we are aware of!

(BTW: commercial support is available as well. . . )

But it is still a bit hidden (published as part of AspectC++)

Incorporate C++ 1x features

Incrementally, start with the most probable ones

A lot of work, but we are now optimistic that this is feasible!

Get Puma at:https://svn.aspectc.org/repos/Puma/trunk

[email protected] The Puma C/C++ Parser Framework (AOSD ’10) Wrap up 24