Table of Contents |
---|
Overview
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Returns string length or bytes required to store a variable
...
...
...
...
...
...
...
...
...
...
...
...
...
<MetaLanguage>
<patterns>
. . .
...
...
...
...
...
...
...
...
...
...
...
...
Key Point
4) Apply and refine those rules for additional source codes as needed
Typically a large, mature code will not meet the assumptions of every migration rule 100% and you should plan to consider alternatives and to refine or extend the rule to deal with variations. This incremental refinement is an important aspect of our iterative methodology.
In this example, the new rule assumes that the type of original argument to Len has a Length property in .NET and that argument is not null at runtime. The first assumption is easy to check using the C# compiler. The second assumption can be checked by static analysis of the code and by runtime testing. We know that the rule will not work for situations where the argument is a struct; in fact the resulting code will not even build. A more appropriate translation of Len(struct), that still avoids using VBNET, is to use System.Runtime.Interop.Marshal.SizeOf().
In this type of situation, a Migration DLL can be used to implement a rule that specifies x.Length is used for strings and Marshal.SizeOf(x) for is used for structs. However, when you encounter exceptions to your coding/upgrade standards, take time to see what the code is actually doing. For example, in the case of code that uses Len with struct you will typically also find Win32 APIs calls or record-based file IO. Both of these things warrant additional redesign as they move to .NET. It may make more sense to rework that section of your code in a different way. Also beware that VB6 language frequently provides high-level services that can only be reproduced by runtime routines that integrate several .NET operations. The check for null in VBNET. Strings.Len is a good example of this.
Key Point |
Balancing manual and automated work is a central tenet of the tool-assisted rewrite methodology.
You should apply rules in a manner that fits the needs of your application and use a variety of techniques including the using gmStudio to systematically integrate hand-written code with the migration solution. |
Appendix X: Activating a Custom Metalanguage Configuration
This appendix describes how to modify the metalanguage configuration so gmStudio will produce translations that use your custom language replacement rules.
Metalanguage Files
Metalanguage files are XML documents that direct gmStudio as it rewrites your VB6 program for .NET.
Key Points |
|
There are two types of Metalanguage files: default Interface Description Files (IDFs) and default Language Files.
...
- Open the Settings dialog by clicking the [Settings] button on the toolbar.
- Click the [Configuration Files] tab
- Select the [Interface Descriptions] button
...
To list and inspect the default Language Files:
- Open the Settings dialog by clicking the [Settings] button on the toolbar.
- Click the [Configuration Files] tab
- Select the [Language] button
Customizing default interface description files
The [Configuration Files] tab on the Settings dialog is designed to help you inspect the metalanguage files and make a working copy in your project workspace. The following instructions explain how this is done for a default IDF.
- Open the Settings dialog by clicking the [Settings] button on the toolbar.
- Click the [Configuration Files] tab
- Copy the desired default IDF to your workspace.
- Click the [Interface Descriptions] button to list the default IDFs
- Click the desired default IDF, for example MigrationSupport.xml
- Click [Save As…] and save a copy of the file in the [workspace]\usr folder.
Key Points |
Once a default IDF file exists in your workdspace\usr folder it will take precedence over the default copy. This behavior is governed by gmStudio’s configuration folder search rules: Target before Local before System before Language.
|
Customizing default language files
The [Configuration Files] tab on the Settings dialog is designed to help you inspect and manage all the files that play a role in configuring gmStudio. The following instructions explain how to setup gmStudio to do custom language replacement.
Part 1: Activating project-specific metalanguage information
...
...
...
Clicking the [Project] option copies two files into your [workspace]\usr folder.
StartUp File (gmBasic.xml)
The StartUp file controls the global defaults for the translator including the location of the metalanguage information file.
The Project option uses a version of the gmBasic startup file that has the metalanguage attribute set so that the translator will use the language information file in your workspace.
...
Language Information Script (VB7Lang.xml)
The Language Information Script indicates which default language files should be processed to create the language information file. The Project option uses a version of the script that can be edited to specify that your custom language files should be used instead of the default files.
Key Points |
Once you have modified the gmBasic.xml and the VB7Lang.xml files is in your workspace, clicking the [Update Translator Configuration] button will create a new metalanguage information file (VB7Lang.vbi) in your workspace. This customized file will take precedence over the default copy that ships with gmStudio and will be used by the translator instead. of the default copy that ships with gmStudio.
|
Part 2: customizing default language files
...
- Click [Language Files] to list the default language files
...
...
...
:
...
...
...
<Include FileName="%MetaLangFolder%\vbasic.xml"/>
The convention follow for customized Language Files is to place them in the usr\lang folder in the workspace and specify this using %UserFolder% script variable; for example:
<Include FileName="%UserFolder%\lang\vbasic.xml"/>
- Rebuild the metalanguage information file by clicking the [Update Translator Configuration] button.
This process the VB7Lang.xml script and display the Translator Configuration Build Log into the text box. If the process is successful, the listing will show the directory listing for the new VB7Lang.VBI file in your workspace.
Appendix Y: Migration Dlls
Migration DLLs extend and alter the behavior of the gmStudio translator. Migration DLLs can manipulate the information about the system at the lowest level: symbol tables and operation streams. Migration DLLs can also be used to extend the gmBasic scripting language, for example, to develop specialized analysis, reporting, and code generation tools. Migration DLLs allow migration teams to make the translator do things that cannot be easily specified using the declarative refactoring statements or the gmStudio scripting language.
Migration DLLs contain "handlers". These are subroutines invoked by the translator when various "migration events" occur during processing. There is a large set of predefined migration events as well as a facility for attaching migration events to the specific types and members in COM libraries and to specific application types and variables. There is also an extensive gmStudio API that facilitates interacting with the translator and the system model in migration event handlers.
...