コード例 #1
0
 private void btnGenerate_Click(object sender, EventArgs e)
 {
     foreach (var fileName in VB6Compiler.GetFiles(Folder))
     {
         var compileResult = VB6Compiler.Compile(fileName, null, false);
         var tree          = new VB6NodeTree(compileResult);
         ASTPatternGenerator.GetCode(tree);
     }
 }
コード例 #2
0
 private void ShowFiles()
 {
     lstFileNames.Items.Clear();
     foreach (var fileName in VB6Compiler.GetFiles(Folder))
     {
         lstFileNames.Items.Add(fileName);
     }
     //TranslatorForPattern.IntializeTranslatorForPattern();
 }
コード例 #3
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            var enabled = DebugClass.Enabled;

            DebugClass.Enabled      = false;
            frmPatternsForm         = new frmPatterns(new List <string>(VB6Compiler.GetFiles(Folder)));
            frmPatternsForm.Visible = true;
            //var tfp = new TranslatorForPattern();
            DebugClass.Enabled = enabled;
        }
コード例 #4
0
        private void btnTranslateWithLogging_Click(object sender, EventArgs e)
        {
            var outFolder       = Folder + "-out";
            var extraModuleName = "VB6CompilerExtra.bas";

            var extraModule = @"
Public Sub Log(ByVal Msg As String)
    Static FileNum As Single
    If FileNum = 0 Then
        FileNum = FreeFile
        Open App.Path & ""\ProgramLog.txt"" For Output As FileNum
    End If
    Print #FileNum, Msg
End Sub

Public Sub LogEnter(ParamArray Text() As Variant)
    Dim intLoopIndex As Integer, Serialized As String
    Serialized = """"
    For intLoopIndex = 0 To UBound(Text)
      Serialized = Serialized & "", "" & Text(intLoopIndex)
    Next intLoopIndex
    Log ""ENTER "" & Serialized
End Sub

Public Sub LogLeave(ParamArray Text() As Variant)
    Dim intLoopIndex As Integer, Serialized As String
    Serialized = """"
    For intLoopIndex = 0 To UBound(Text)
      Serialized = Serialized & "", "" & Text(intLoopIndex)
    Next intLoopIndex
    Log ""LEAVE "" & Serialized
End Sub

Public Function SerializeInteger(arg as Integer) as String
    SerializeInteger = CStr(arg)
End Function

Public Function SerializeDouble(arg as Double) as String
    SerializeDouble = CStr(arg)
End Function

Public Function SerializeSingle(arg as Single) as String
    SerializeSingle = CStr(arg)
End Function

Public Function SerializeBoolean(arg as Boolean) as String
    If arg Then
        SerializeBoolean = ""True""
    Else
        SerializeBoolean = ""False""
    End If
End Function

Public Function SerializeForm(arg as Form) as String
    SerializeForm = arg.Name
End Function

Public Function SerializeString(arg As String) As String
    SerializeString = arg
End Function

Public Function SerializeDate(arg As Date) As String
    SerializeDate = CStr(arg)
End Function
";

            foreach (var fileName in VB6Compiler.GetFiles(Folder, true, true))
            {
                var    bname       = Path.GetFileName(fileName);
                string outFileName = Path.Combine(outFolder, bname);
                if (
                    (fileName.EndsWith(".frx", System.StringComparison.InvariantCulture)) ||
                    (fileName.EndsWith(".vbw", System.StringComparison.InvariantCulture)))
                {
                    System.IO.File.Copy(fileName, outFileName, true);
                    continue;
                }
                if (fileName.EndsWith(".vbp", System.StringComparison.InvariantCulture))
                {
                    var text = System.IO.File.ReadAllText(fileName, Encoding.GetEncoding(1252));
                    text += "Module=mod_VB6CompilerExtra; " + extraModuleName + "\r\n";
                    System.IO.File.WriteAllText(outFileName, text, Encoding.GetEncoding(1252));
                    continue;
                }

                var compileResult = VB6Compiler.Compile(fileName, null, false);
                var tree          = new VB6NodeTree(compileResult);
                tree.AddExtraModule = (a, b) =>
                {
                    extraModule += b;
                };
                var se = VB6NodeTranslatorLoader.Translate(tree);
                var sl = se.ToList();
                sl.AddRange(GetComments(compileResult));
                sl.Sort((a, b) => a.index.CompareTo(b.index));
                //var s = String.Join("", sl.Select(x => x.index.ToString() + ":" + x.token));
                var s = String.Join("", sl.Select(x => x.token));
                System.IO.Directory.CreateDirectory(outFolder);
                s = Regex.Replace(s, "([^\r])\n", "$1\r\n");
                System.IO.File.WriteAllText(outFileName, s, Encoding.GetEncoding(1252));
            }

            System.IO.File.WriteAllText(Path.Combine(outFolder, extraModuleName), extraModule, Encoding.GetEncoding(1252));

            string            message = "Wrote new files to: " + outFolder;
            string            caption = "Compilation Successful!";
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            var result = MessageBox.Show(message, caption, buttons);
        }