//private void CatchUpToAddress(ref Expression expression, List<string> functionLines, int address)
        //{
        //    while (expression != null && expression.address < address)
        //    {
        //        string enumerationName = null;
        //        var variable = expression.Variable.Canonicalize();
        //        if (variable != null && VariablesUsingEnumerationType.Contains(variable))
        //        {
        //            var metaData = variable.GetMetadata();
        //            if (metaData.EnumerationType == AnnotateEnumerationType)
        //            {
        //                var otherExpression = expression.GetOtherSideOfBinaryExpression();
        //                if (otherExpression != null)
        //                {
        //                    otherExpression = otherExpression.SkipChildCastOperations();
        //                    if (otherExpression.ExpressionType == Instruction.PUSH)
        //                    {
        //                        enumerationName = AnnotateEnumerationType.GetOrDefault(otherExpression.Value, otherExpression.Value.ToString());
        //                    }
        //                    else if (otherExpression.ExpressionType == Instruction.SH_LOCALASSIGN)
        //                    {
        //                        enumerationName = AnnotateEnumerationType.GetOrDefault(otherExpression.Value, otherExpression.Value.ToString());
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                var func = expression as IFunction;
        //                if (func != null)
        //                {
        //                    for (int i = 0; i < func.ParameterCount; i++)
        //                    {
        //                        var para = func.GetNonVoidFunctionParameter(i);
        //                        if (para == null) break;
        //                        var metaData2 = para.GetMetadata();
        //                        if (metaData2.EnumerationType == AnnotateEnumerationType)
        //                        {
        //                            var arg = expression.GetFunctionCallArgument(i);
        //                            if (arg != null)
        //                            {
        //                                arg = arg.SkipChildCastOperations();
        //                                if (arg.ExpressionType == Instruction.PUSH)
        //                                {
        //                                    enumerationName = AnnotateEnumerationType.GetOrDefault(arg.Value, arg.Value.ToString());
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        if (enumerationName != null)
        //        {
        //            functionLines.Add("#" + enumerationName);
        //        }
        //        expression = expression.GetNextExpression();
        //    }
        //}

        private void AddString(ref int numberOfNonCommentedLines, ref int numberOfStrings, List <string> functionLines, int stringNumber, string str)
        {
            StringExclusionReason exclude = stringExportImport.stringsToExclude.GetOrDefault(stringNumber, StringExclusionReason.None);
            string stringLine             = "s " + numberOfStrings.ToString("000") + " " + StringExportImport.EscapeText(str);

            if (exclude != StringExclusionReason.None)
            {
                stringLine = "#" + stringLine + "#\t\t" + exclude.GetText();
            }
            else
            {
                if (str != "")
                {
                    numberOfNonCommentedLines++;
                }
            }
            if (!(stringNumber == 0 && str == ""))
            {
                if (useStringsToMatch == false || StringsToMatch.Contains(str))
                {
                    if (this.IncludeStrings == true)
                    {
                        functionLines.Add(stringLine);
                    }
                }
            }
            numberOfStrings++;
        }
        private List <string> GetTextFromFunction(Function function)
        {
            int numberOfNonCommentedLines = 0;
            int numberOfStrings           = 0;
            int numberOfMessages          = 0;

            //Expression expression = null;
            //int expressionLastAddress = function.Address;

            useStringsToMatch = StringsToMatch != null && StringsToMatch.Count > 0;
            //List<string> strings = new List<string>();
            //List<string> messages = new List<string>();
            List <string> functionLines      = new List <string>();
            string        functionLineString = "FUNCTION " + /*function.Index.ToString() + " " + */ AssemblerProjectWriter.SanitizeVariableName(function.Name);

            functionLines.Add(functionLineString);
            functionLines.Add("#x strings, x messages");  //this line gets changed later (it's index 1)
            int    address  = function.Address;
            string lastName = null;

            while (address < ainFile.Code.Length)
            {
                var instructionInfo = ainFile.Peek(address);
                if (instructionInfo.instruction == Instruction.ENDFUNC || instructionInfo.instruction == Instruction.FUNC)
                {
                    break;
                }
                if (this.AnnotateEnumerationType != null && instructionInfo.instruction == Instruction.CALLFUNC)
                {
                    var func = ainFile.GetFunction(instructionInfo.word1);
                    if (VariablesUsingEnumerationType.Contains(func))
                    {
                        var parameters = GetParametersThatUsesEnumerationType(func);
                        if (parameters.FirstOrDefault() != null)
                        {
                            foreach (var parameter in parameters)
                            {
                                int i    = parameter.Index;
                                int addr = instructionInfo.CurrentAddress - (func.ParameterCount) * 6 + i * 6;
                                var ins2 = ainFile.Peek(addr);
                                if (ins2.instruction == Instruction.PUSH)
                                {
                                    string enumerationValue = this.AnnotateEnumerationType.GetOrDefault(ins2.word1, "");
                                    if (!String.IsNullOrEmpty(enumerationValue))
                                    {
                                        functionLines.Add("");
                                        functionLines.Add("#" + enumerationValue);
                                    }
                                }
                                else if (ins2.instruction == Instruction.S_PUSH)
                                {
                                    string str = ainFile.GetString(ins2.word1);
                                    if (!String.IsNullOrEmpty(str))
                                    {
                                        if (this.replacementStringsForAnnotations != null && this.replacementStringsForAnnotations.ContainsKey(str))
                                        {
                                            string nextStr = this.replacementStringsForAnnotations[str];
                                            if (!nextStr.StartsWith("*"))
                                            {
                                                str = nextStr;
                                            }
                                            else
                                            {
                                                str = lastName;
                                            }
                                        }
                                        else
                                        {
                                        }
                                        if (lastName != str)
                                        {
                                            lastName = str;
                                            functionLines.Add("");
                                            functionLines.Add("#" + str);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (instructionInfo.instruction == Instruction.MSG)
                {
                    //if (this.AnnotateEnumerationType != null)
                    //{
                    //    if (expression == null)
                    //    {
                    //        expression = ainFile.DecompiledCodeCache.GetDecompiledCode(function);
                    //    }
                    //    CatchUpToAddress(ref expression, functionLines, address);
                    //}
                    int    messageNumber = instructionInfo.word1;
                    string message       = ainFile.GetMessage(messageNumber);
                    if (message != null)
                    {
                        if (useStringsToMatch == false || StringsToMatch.Contains(message))
                        {
                            string messageLine = "m " + numberOfMessages.ToString("000") + " " + StringExportImport.EscapeText(message);
                            functionLines.Add(messageLine);
                        }
                        numberOfMessages++;
                        numberOfNonCommentedLines++;
                    }
                }
                else if (instructionInfo.instruction == Instruction.STRSWITCH)
                {
                    int switchBlockNumber = instructionInfo.word1;
                    var switchBlock       = ainFile.Switches.GetOrNull(switchBlockNumber);
                    if (switchBlock != null)
                    {
                        foreach (var switchCase in switchBlock.SwitchCases)
                        {
                            int    stringNumber = switchCase.Value;
                            string str          = ainFile.GetString(stringNumber);
                            if (str != null)
                            {
                                AddString(ref numberOfNonCommentedLines, ref numberOfStrings, functionLines, stringNumber, str);
                            }
                        }
                    }
                }
                else
                {
                    int indexOfStringArgument = instructionInfo.instruction.IndexOfStringArgument();
                    if (indexOfStringArgument != -1)
                    {
                        int    stringNumber = instructionInfo.words[indexOfStringArgument];
                        string str          = ainFile.GetString(stringNumber);
                        if (str != null)
                        {
                            AddString(ref numberOfNonCommentedLines, ref numberOfStrings, functionLines, stringNumber, str);
                        }
                    }
                }
                address = instructionInfo.nextAddress;
            }
            functionLines[1] = "#" + numberOfStrings.ToString() + " strings, " + numberOfMessages.ToString() + " messages";
            if (numberOfNonCommentedLines == 0)
            {
                functionLines.Clear();
            }
            return(functionLines);
        }