The company I work with is Semantic Designs Inc. provides tools that include a common infrastructure for the analysis and transformation of programs and specific analysis components for various programming languages. Together they are known as DMS. In the case of C ++, DMS includes integrated lexers, preprocessors, parsers, the name and type of permission component for each of GCC3, GCC4, ISO14882c1998 (ANSI), Visual C ++ 6.0, and Unmanaged Visual Studio 2005 C ++. For various C dialects, there is also control flow analysis, side effects of the character analyzer and character dependency analyzer, with which tools such as a pointer, code deactivator, profiling function and slicer were implemented.
Name and type resolution components provide a complete table of information and search character characters, so identifier references can be easily associated with their types and other declarative information. The information is similar to what was captured and used by the compiler, but stored together with abstract syntax trees in a form suitable for adaptive reuse by any tool that includes a component.
Semantic Designs recently created its own tool that is specifically related to the types of index variables in the declaration loop, for example, in your example. In this case, the problem was to update the GCC2 code using the -fno-for-scope compiler switch, which provided a scope resolution rule for loop variables that was not supported in later GCC dialects. The tool was to convert the loops, moving the declarations of their loop variables to an external context that retained the -fno-for-scope scoping rule. Where such changes were not necessary, no changes were made.
Thus, the tool had to distinguish between the type associated with each reference to the loop variable, differentiating in the case of masking areas and recover the code to resolve the name GCC3 and GCC4 lead to the same semantic interpretation as GCC2 with -fno-for-sphere. This requires access to the symbol table information associated with each reference to the variables, and in the case where the code was moved, to restore the correct syntax for the type declaration for any variable whose declaration was moved. A table of references to symbol and identifier tables provided by DMS The C ++ name and type resolution component contains all the necessary information and the module for restoring the syntax of the prescribed type allowed us to synthesize the correct declarations of the new type.
For example, consider an example:
// loop variable hides variable in global scope // will change meaning without -fno-for-scope // fix: move decl. of cnt before for-loop // optionally rename globcnt loop variable float globcnt = 0.0; int Foo::foo3() { for (int globcnt = 0; globcnt < 5; globcnt++) { globalInt += globcnt; } globalInt += 2*globcnt + 1; return 0; }
GCC2 -fno-for-scope semantics indicates that references to globcnt outside of a loop are related to a loop variable, although GCC3 consider a loop variable outside of scope and allow references to a global variable. The tool converted this code to:
float globcnt = 0.0; int Foo::foo3() { int globcnt = 0; for (; globcnt < 5; globcnt++) { globalInt += globcnt; } globalInt += 2*globcnt + 1; return 0; }
If the code had not been converted, GCC4 would always return the value 1 from Foo: foo3. However, the converted value would have been exposed to the loop iterations that were originally developed for Gcc2. The tool had to recognize that the final reference to globcnt was a local variable of type int, and not a global variable of type float, which it could perform by searching the symbol table and act accordingly.
On the other hand, the tool is recognized in the following code, which had no references to me outside the loop, so it was acceptable (and preferable) to leave the declaration of the loop variable unchanged.
int Foo::foo0() { for (int i = 0; i < 10; i++) { globalInt += i*i; } return 0; }