FAMIX C++ language plug-in 1.0

 

Author

Holger Bär (baer@fzi.de)

Version

1.0

Last modified

1999-09-07

  1. Abstract
  2. This document defines a language plug-in for FAMIX, the FAMOOS information exchange model [Deme99]. It extends, instantiates and modifies the FAMIX core model to cover most of the entities and relationships that can be found in C++ source code.

  3. Notation

The common exchange model is modified in three different ways to handle C++ sources:

  1. Modified classes
    1. Class (interpreted and extended)

Class

instantiatesTemplate (): Name # new

friendsAt (pos Integer): Name # new

isUnion (): Boolean

isAbstract

Figure 1: Class

Each definition of a class in source code constitutes this entity. A class definition in C++ takes the form
class A { ... };
in contrast to a class declaration of the form:
class A;

Structures (struct) are modelled as classes. They differ only from classes in their members and base classes being public by default in spite of private in the case of classes. So only the parser must know the difference between classes and structures.

Unions (union) are also modelled as classes. They are a kind of restricted classes: they can’t have any base classes, can’t be used as base classes, have no virtual methods, have no static methods or attributes. For a detailed description of all restrictions to unions please refer to [ISO98].

The new or modified attributes are:

    1. BehaviouralEntity (interpreted and extended)

BehaviouralEntity

baseReturnType (): Name # new

instantiatesTemplate (): Name # new

accessControlQualifier

signature

Figure 2: BehaviouralEntity

The new and modified attributes are:

    1. Method (interpreted and extended)

Method

isDestructor (): Boolean # new

isOperator (): Boolean # new

isVirtual (): Boolean # new

isConst (): Boolean # new

accessControlQualifier

signature

isAbstract

isConstructor

uniqueName

Figure 3: Method

Each declaration of a method in source code constitutes this entity. One could have expected each method definition to constitute this entity, but in C++ a method declaration can be used to just manipulate the access to inherited methods. This can only be represented by a new Method entity.

The new or modified attributes are:

    1. Function (interpreted)

Function

accessControlQualifier

Figure 4: Function

Each definition of a global function in source code constitutes this entity.

The modified attributes are:

    1. StructuralEntity (extended)

Attribute

baseType (): Name # new

isConstant (): Boolean # new

Figure 5: StructuralEntity

The new or modified attributes are:

    1. Attribute (interpreted)

Attribute

accessControlQualifier

Figure 6: Attribute

The new or modified attributes are:

    1. GlobalVariable (interpreted)

GlobalVariable

accessControlQualifier (): Qualifier # new

Figure 7: GlobalVariable

Each definition of a global variable in source code constitutes this entity.

The new or modified attributes are:

    1. InheritanceDefinition (interpreted and extended)

InheritanceDefinition

isVirtual (): Boolean # new

accessControlQualifier

index

Figure 8: InheritanceDefinition

The new or modified attributes are:

    1. Access (extended)

Access

receivingClass (): Name # new

receivingVariable (): Name # new

Figure 9: Access

The new or modified attributes are:

    1. Invocation (extended)

Invocation

receivingVariable (): Name # new

base

Figure 10: Invocation

The new or modified attributes are:

  1. New classes
  2. The new classes from 4.3 to 4.6 all define entities representing a type in C++. Consequently they can be referred in the attributes baseType and baseReturnType.

    1. ClassTemplate

ClassTemplate

templateParameterAt (pos Integer): Qualifier

Figure 11: ClassTemplate

This new entity models class templates of C++. It inherits from the entity Class of the core model. One could argue that Class Templates are no proper subclasses of Classes, because they cannot be used in every place a Class can be used, e.g., as the target of a reference via a declaredClass attribute. This is because class templates are no classes but only a template for a class that needs its template parameters to be instantiated to become a proper class. On the other hand the ClassTemplate entity needs all the attributes of a Class entity plus an attribute describing its template parameters. Even the newly defined attribute instantiatesTemplate makes sense, since class templates can be partially instantiated. So letting ClassTemplate not inherit from Class would mean to define a new entity with exactly the same attributes like an existing one plus one attribute. Therefore ClassTemplate inherits from Class. The same argumentation also applies to the new entity FunctionTemplate defined below also inheriting from its corresponding core model entity Function.

The methods an attributes of a class template are modelled as Method and Attribute respectively. If it is necessary to determine whether a method/attribute is part of a template definition, this can be decided by looking at the type of the entity referred by the belongsToClass attribute of the method/attribute.

The usage of one of the template parameters within the class template, e.g., for a type declaration of an attribute or within a function signature, is modelled by a reference to the template parameter. Template parameters are defined in 4.3.

Fully instantiated class templates are modelled as ordinary classes with their template parameters substituted accordingly. Partially instantiated templates are themselves templates with only the bound template parameters substituted accordingly. Each different instantiation produces a different Class or ClassTemplate entity. The instantiated copies have the bound template parameters appended to the uniqueName attribute they would get as an ordinary class in the form of a comma separated list in <> without spaces, e.g.: P::C<D,int>.

Besides the attributes inherited from Class, the new or modified attributes are:

    1. FunctionTemplate

FunctionTemplate

templateParameterAt (pos Integer): Qualifier

Figure 12: FunctionTemplate

This new entity models function templates. It inherits from the entity Function of the core model instead of defining a new heir of Entity for the same reasons as with class templates (see 4.1 for a discussion).

The usage of one of the template parameters within the function template, e.g., within the function signature or the type of a local variable, is modelled by a reference to the template parameter. Template parameters are defined in 4.3.

Fully instantiated function templates are modelled as ordinary functions with their template parameters substituted accordingly. Partially instantiated templates are themselves templates with only the bound template parameters substituted accordingly.

Besides the attributes inherited from Function, the new or modified attributes are:

    1. TemplateParameter

TemplateParameter

belongsToTemplate (): Name

Figure 13: TemplateParameter

This new entity models template parameters of a ClassTemplate or FunctionTemplate entity. It inherits from Entity and defines no new attributes.

Besides the attributes inherited from Entity, the new or modified attributes are:

The formula for uniqueName is:

uniqueName (templParam) = belongsToTemplate (templParam) + "." + name (templParam)

    1. FunctionType

FunctionType

signature (): Qualifier

declaredReturnType (): Qualifier

declaredReturnClass (): Name

baseReturnType (): Name

belongsToContext (): Name

isOperator (): Boolean

Figure 14: FunctionType

This new entity models the declaration of a function type.

It shares some attributes with BehaviouralEntity but the attributes of BehaviouralEntity describing its role as an callable piece of code do not apply. Unlike Method and Function a FunctionType can be defined in any scope resulting in an attribute belongsToContext that can refer to Package, Class, Method or Function.

The attributes of FunctionType are then:

The formula for uniqueName is:

uniqueName (funcType) = belongsToContext (funcType) + "." + signature (funcType)

    1. EnumerationType

EnumerationType

belongsToContext (): Name

Figure 15: EnumerationType

This new entity models the declaration of an enumeration type (enum).

Enumeration types are modelled because they are often used, especially in not pure object-oriented systems, to describe different options or states (e.g., drawing modes, output destinations). This way they introduce dependencies within the system.

The only attribute of EnumerationType is:

The formula for uniqueName is:

uniqueName (enumeration) = belongsToContext (enumeration) + "." + name (enumeration)

 

    1. TypeDef

TypeDef

declaredReturnType (): Qualifier

declaredReturnClass (): Name

baseReturnType (): Name

belongsToContext (): Name

Figure 16: TypeDef

This new entity models type aliasing via the typedef keyword.

The attributes of TypeDef are:

The formula for uniqueName is:

uniqueName (typeDef) = belongsToContext (typeDef) + "." + name (typeDef)

    1. TypeCast

TypeCast

belongsToBehaviour (): Name

fromType (): Name

toType (): Name

Figure 17: TypeCast

This new association models type cast like (C*)pointer.

Type casts are interesting for re-engineering as they often point to problems in the design of a system. There will be an instance of this class for every type cast occuring in the source code, even if the cast is between the same types, because we are interested in all the places where casts occur.

The attributes of TypeCast are:

    1. SourceFile
    2. SourceFile

       

      Figure 18: SourceFile

      This new entity models a file of the source code (header file or implementation file). It defines no additional attributes.

      Source files are a grouping unit in C++. An implementation file plus all included header files even defines a scoping unit, the compilation unit (see the definition of Function 3.4 and GlobalVariable 3.7).

      The structure of the relationships between source files created by include directives gives a rough overview about the dependencies in the system, because a dependency between two entities always is only possible with an include dependency between the files the two entities are defined in. This makes source files together with their include relations quite important for re-engineering purposes.

      The values of the name and uniqueName attributes are specific to the operating system used to compile the sources. One could think of the full path or of a relative path starting from a common root directory that contains any source files of the system in one of its subdirectories.

    3. Include

Include

includingFile (): Name

includedFile (): Name

Figure 19: Include

This new association models an include directive of the preprocessor.

The structure of the relationships between source files created by include directives gives a rough overview about the dependencies in the system, because a dependency between two entities always is only possible with an include dependency between the files the two entities are defined in. This makes source files together with their include relations quite important for re-engineering purposes.

The attributes of Include are:

  1. Excluded features of C++

Some features of C++ are not covered by this language plug-in:

  1. References

[Deme99] Serge Demeyer, Sander Tichelaar and Patrick Steyaert, FAMIX – The FAMOOS Information Exchange Model, version 2.0 alpha, July 1999. See http://www.iam.unibe.ch/~famoos/FAMIX/.

[ISO98] International Standard ISO/IEC 14882, Programming Languages — C++, First Edition 1998-09-01, American Natinal Standards Institute, New York.

 

Cover Pages

Achievement 2.4.1a

FAMIX C++ language plug-in 1.0

1) Identification

Project Id:

Esprit IV #21975 "FAMOOS"

Deliverable Id:

D 2.2 – FINALFHB Final FAMOOS Methodology Handbook

Date for delivery:

31.08.99

Planned date for delivery:

31.08.99

WP(s) contributing to:

1

Author(s):

Holger Bär

2) Abstract

This document defines a language plug-in for FAMIX, the FAMOOS information exchange model [Deme99]. It extends, instantiates and modifies the FAMIX core model to cover most of the entities and relationships that can be found in C++ source code.

3) Keywords

Object-oriented, reengineering, reverse engineering, code repository, round-trip engineering, FAMOOS, FAMIX, C++.

4) Version History

Ver

Date

Editor(s)

Status & Notes

1.0beta

24.08.99

Holger Bär

 

1.0

25.08.99

Sander Tichelaar

 

5) Issues for future releases

6) Table of Contents

FAMIX C++ language plug-in 1.0 *

1 Abstract *

2 Notation *

3 Modified classes *

3.1 Class (interpreted and extended) *

3.2 BehaviouralEntity (interpreted and extended) *

3.3 Method (interpreted and extended) *

3.4 Function (interpreted) *

3.5 StructuralEntity (extended) *

3.6 Attribute (interpreted) *

3.7 GlobalVariable (interpreted) *

3.8 InheritanceDefinition (interpreted and extended) *

3.9 Access (extended) *

3.10 Invocation (extended) *

4 New classes *

4.1 ClassTemplate *

4.2 FunctionTemplate *

4.3 TemplateParameter *

4.4 FunctionType *

4.5 EnumerationType *

4.6 TypeDef *

4.7 TypeCast *

4.8 SourceFile *

4.9 Include *

5 Excluded features of C++ *

6 References *

Cover Pages *

FAMIX C++ language plug-in 1.0 *

1) Identification *

2) Abstract *

3) Keywords *

4) Version History *

5) Issues for future releases *

6) Table of Contents *

7) List of Figures *

8) List of Tables *

 

7) List of Figures

Figure 1: Class *

Figure 2: BehaviouralEntity *

Figure 3: Method *

Figure 4: Function *

Figure 5: StructuralEntity *

Figure 6: Attribute *

Figure 7: GlobalVariable *

Figure 8: InheritanceDefinition *

Figure 9: Access *

Figure 10: Invocation *

Figure 11: ClassTemplate *

Figure 12: FunctionTemplate *

Figure 13: TemplateParameter *

Figure 14: FunctionType *

Figure 15: EnumerationType *

Figure 16: TypeDef *

Figure 17: TypeCast *

Figure 18: SourceFile *

Figure 19: Include *

 

8) List of Tables