Browse Prior Art Database

A Mechanism to Allow Orderless Processing of Pragmas in a C++ Program

IP.com Disclosure Number: IPCOM000012959D
Original Publication Date: 1999-Oct-01
Included in the Prior Art Database: 2003-Jun-11
Document File: 4 page(s) / 53K

Publishing Venue

IBM

Related People

Allen Chan: AUTHOR [+2]

Abstract

Some modern compilers can process C++ constructs in an orderless fashion and also provide for incremental compilation. However, during incremental compilation, orderless processing of pragmas (also known as compiler directives) can result in a large number of unnecessary change propagations. The main reason is that many pragmas are order dependent and are sensitive to their locations in a source file. This disclosure describes a mechanism to correctly process pragmas to allow rapid incremental recompilation of C++ programs containing pragmas in an orderless compilation environment. There are many different kinds of pragmas some of which are sensitive to their locations in a source file (order dependent). In general, these kind of pragmas will only affect declarations/definitions that appear after them, and their effective value may depend on pragmas that appear before them. One example is #pragma pack, which also supports "stack" operations. For example, #pragma pack(push, 1) will set the current packing alignment value to 1, while #pragma pack(pop) will reset the current packing alignment value to the previous setting. In the orderless processing environment of the present disclosure, if a component (i.e. a set of C++ instructions) asks for the value of a C++ pragma, a dependency relationship will be created between the component and the pragma with the component being a dependent of the pragma. Accordingly, if the pragma is ever changed, all its dependent components would be reprocessed by virtue of the dependency relationship. Take the following C++ program as an example:

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 32% of the total text.

Page 1 of 4

A Mechanism to Allow Orderless Processing of Pragmas in a C++ Program

     Some modern compilers can process C++ constructs in an orderless fashion and also provide for incremental compilation. However, during incremental compilation, orderless processing of pragmas (also known as compiler directives) can result in a large number of unnecessary change propagations. The main reason is that many pragmas are order dependent and are sensitive to their locations in a source file. This disclosure describes a mechanism to correctly process pragmas to allow rapid incremental recompilation of C++ programs containing pragmas in an orderless compilation environment.

There are many different kinds of pragmas some of which are sensitive to their locations in a source file (order dependent). In general, these kind of pragmas will only affect declarations/definitions that appear after them, and their effective value may depend on pragmas that appear before them. One example is #pragma pack, which also supports "stack" operations. For example, #pragma pack(push, 1) will set the current packing alignment value to 1, while #pragma pack(pop) will reset the current packing alignment value to the previous setting.

In the orderless processing environment of the present disclosure, if a component (i.e. a set of C++ instructions) asks for the value of a C++ pragma, a dependency relationship will be created between the component and the pragma with the component being a dependent of the pragma. Accordingly, if the pragma is ever changed, all its dependent components would be reprocessed by virtue of the dependency relationship.

Take the following C++ program as an example:

Line: Code:

1

2

3

4

5

6

7

8

9

10

#pragma pack(push, 4) #pragma pack(push, 1)

#pragma pack(push, 2)

class A { char a; int b; };

#pragma pack(pop) // effective packing value is 1

class B { char c; int d; };

1

Page 2 of 4

During a first compilation in the orderless processing environment, the compiler will break up the program into source regions. A source region is a sequence of tokens that represent a declaration, a function body, a linkage structure, a namespace or a pragma. A pragma source region contains all the tokens specified in the #pragma statement. During the processing of source regions, individual pragmas and declarations will be created. Referring to the example C++ program, at the end of the first compilation, a dependency arc will be created between "#pragma pack(push, 2)" and "declaration class A", as well as between "#pragma pack(pop)" and "declaration class B". Given this orderless processing process, this disclosure describes a method to handle the following four scenarios (by reference to the example program) by allowing the propagation of necessary changes with a minimum number of change propagations.

Scenario 1: The user moves the source region "#pragma pack(pop)" from line 8 to line 3.

Scenario 2: The user moves the source region "#pragma pack(pop)" from line 8 to line 5...