C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Introduction to Programming in C++ John Galletly.
Programming Languages and Paradigms
C++ Programming Languages
Software Engineering COMP 201
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Typed AG Alexey Rodriquez Y Faridah Liduan Type Systems Project 26 Jun 2003.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Software Testing and Quality Assurance
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Object-Oriented Databases
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Transformation of Java Card into Diet Java Semester Project Presentation Erich Laube.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ fundamentals.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Implementation Considerations Yonglei Tao. Components of Coding Standards 2  File header  file location, version number, author, project, update history.
An Introduction to Software Architecture
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Reviewing Recent ICSE Proceedings For:.  Defining and Continuous Checking of Structural Program Dependencies  Automatic Inference of Structural Changes.
RELATIONAL FAULT TOLERANT INTERFACE TO HETEROGENEOUS DISTRIBUTED DATABASES Prof. Osama Abulnaja Afraa Khalifah
Lecture 3 Software Engineering Models (Cont.)
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Eurostat Expression language (EL) in Eurostat SDMX - TWG Luxembourg, 5 Jun 2013 Adam Wroński.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Introduction to Exception Handling and Defensive Programming.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
XML Grammar and Parser for WSOL Kruti Patel, Vladimir Tosic, Bernard Pagurek Network Management & Artificial Intelligence Lab Department of Systems & Computer.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CASE/Re-factoring and program slicing
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Gordana Rakić, Zoran Budimac
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Classes, Interfaces and Packages
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
The PLA Model: On the Combination of Product-Line Analyses 강태준.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Software Testing.
Chapter3:Software Processes
Chapter 1 Introduction.
Abstract Data Types and Encapsulation Concepts
Type Checking, and Scopes
SOFTWARE DESIGN AND ARCHITECTURE
Review: Two Programming Paradigms
Chapter 1 Introduction.
Chapter 1: Introduction to Compiling (Cont.)
Object-Orientated Programming
Abstract Data Types and Encapsulation Concepts
Subprograms and Programmer Defined Data Type
An Introduction to Software Architecture
Chapter 11: Inheritance and Composition
Object-Oriented PHP (1)
Abstract Types Defined as Classes of Variables
Presentation transcript:

C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica

ITC/CERN collaboration The collaboration aims at improving the quality of the code developed at CERN, by means of: n Automatic check of coding rules. n Recovery of the design from the code. n Refactoring of the design. All objectives share a common C++ code analysis functionality.

Outline of the talk n C++ analysis model n Tool architecture n Preprocessing n Language issues n Implementation of coding rules n State of development

C++ analysis model

The model of the C++ language enjoys the following properties: n Generality. n Extensibility. n Abstraction.

Tool Architecture Packages syntax and entities collaborate to generate a network of objects according to the C++ model. Package rules contains the coding conventions to be checked.

Tool architecture The adoption of this architecture provides a remarkable flexibility. n All rules relying on properties of entities in the C++ model can be directly encoded. n The C++ model can be extended if additional properties need to be collected. n Adding a new application package is simple.

Preprocessing C++ macros are expanded in the code by the preprocessor. Macros do not necessarily comply with the C++ syntax. #define BEGIN { #define END } void f() BEGIN int x = 0;... END

Strip filter The C++ preprocessor prepends all directly and indirectly included files. The strip filter removes those that are not user defined. Moreover, the C++ preprocessor inserts some flags that are useful for the successive compilation step. Examples are: __extension__, __const__ The output of the strip filtering is a legal C++ module, that can be analyzed by the parser.

C++ language C++ was conceived as an object oriented evolution of C. A strong requirement in its design was a total backward compatibility with C. C++ had also a controversial evolution in its more advanced features, like exception handling and generic classes. Is it a function declaration or a global object creation? A x();

Language issues To deal with the complexity of C++, it is important to distinguish between the compilation perspective and the analysis perspective. n The analyzer can assume that the input program is compilable with no errors. n The compiler needs to capture the statement level semantics. n The performances expected from the compiler are substantially superior. All these considerations led to the choice of a javacc based C++ grammar

Compatibility with C n Structures and unions are reinterpreted as classes. n Although methods are available from classes, functions are still usable. n Functions may operate on class objects, and classes may invoke functions. n Global variables violate encapsulation, but are allowed. Types other than classes can be defined with the typedef.

Language issues (cont.) n The language model contains C as a subset. n Type equivalence affects the association between declaration and definition. Additional difficulties: n Body of methods within class definition. n Constructors, destructors, conversion functions and operators. Encapsulation violation via friend construct. Generic classes (template). n Exception throwing and catching.

Coding rules Adding a new coding rule involves the following steps: n A new class is defined which extends the general class Rule. n Its constructor passes the rule name and description to the superclass constructor. n A method check must be defined to implement the interface of the superclass. n The body of the method check can use the access functions of the analysis package.

Coding rule example The following coding rule is taken from the Naming Rules enforced within the CERN experiment ALICE: RN3 No special characters in names are allowed (_, #, -, %). check() { classes = Module.getClasses(); foreach (c in classes) { if (c.getName().hasChar(_, #, -, %)) printViolationMessage(...); methods = c.getMethods(); foreach (m in methods) { if (m.getName().hasChar(_, #, -, %)) printViolationMessage(...); locals = m.getLocals(); foreach (l in locals)...

Adding new coding rules The only constraint is that a formal description of the rule can be derived, for which a procedure can be written. n It may be necessary to augment the set of entities extracted by the CPPParser. n When entities are available, rule introduction is simple. n There is a clear and sharp separation between the responsibilities of packages rules and analysis.

Current limitations Known limitations are related to the difficulties of covering the whole range of C++. n Genericity is not handled. n Exception throwing and catching is not detected. n Type equivalence is implemented only in a simplified form. Such limitations did not substantially limit the possibility of analyzing ALICE code, which does not exploits genericity and exceptions.

State of development See:

State of development (cont.) Coverage of the coding conventions for which an automatic check is feasible:

Analyzed code The RuleChecker tool was successfully executed with no errors on all the code in the current release of the ALICE experiment software. A violation report was generated for each module under analysis.

Conclusion To make analysis independent from the applications using its outcomes: n a C++ language model was defined, n a simple query protocol was used to access code entities. Executed on ALICE code, the tool RuleChecker: n collected information about lines of code, n reported no parse error, n produced a violation report associated to each input module.