public static void FeelField_ReferencesToGlobalVars(ref TFunction[] Function, int functions_count) { int max_references_count = 100; int index_References; for (int index_Functions = 0; index_Functions < functions_count; index_Functions++) { Function[index_Functions].ReferencesToGlobalVariables = new string[max_references_count]; index_References = 0; int index_Declaration = 0; while (Function[index_Functions].Declaration[index_Declaration] != '{') index_Declaration++; int Length = Function[index_Functions].Declaration.Length; // Находим вхождение global в объявлении функции (IndexOf нежадный) int index_global = Function[index_Functions].Declaration.IndexOf( "global", index_Declaration, Length - index_Declaration - 1, StringComparison.OrdinalIgnoreCase ); while (index_global >= 0) { if (Function[index_Functions].Declaration[index_global - 1] == '$') // Если это массив GLOBALS { while (Function[index_Functions].Declaration[index_global] != '\'') index_global++; string VariableIdentifier = FindVariable(Function[index_Functions].Declaration, ref index_global); // Проверка на то, встречалась ли у нас эта переменная if (isNeedToAdd(Function[index_Functions].ReferencesToGlobalVariables, VariableIdentifier)) Function[index_Functions].ReferencesToGlobalVariables[index_References++] = VariableIdentifier; } else // если обращение через ключевое слово global { index_global += 6; // Проходим global от g до первого пробельного символа // После следующего цикла index_global будет указывать на первую переменнную после ключевого слова global (на $) while (isSpaceSymbol(Function[index_Functions].Declaration[index_global])) index_global++; while (Function[index_Functions].Declaration[index_global] != ';') { if (Function[index_Functions].Declaration[index_global] == '$') { string VariableIdentifier = FindVariable(Function[index_Functions].Declaration, ref index_global); // Проверка на то, встречалась ли у нас эта переменная if (isNeedToAdd(Function[index_Functions].ReferencesToGlobalVariables, VariableIdentifier)) Function[index_Functions].ReferencesToGlobalVariables[index_References++] = VariableIdentifier; } else index_global++; } } index_global = Function[index_Functions].Declaration.IndexOf( "global", index_global, Length - index_global - 1, StringComparison.OrdinalIgnoreCase ); } Function[index_Functions].LengthOfReferencesToGlobalVariablesArray = index_References; } }
// Возвращает количество функций public static int getFunctionElements( out TFunction[] Function, string source_string, string pattern_Identifier, string pattern_Declaration, int array_length) { Function = new TFunction[array_length]; int index = 0; Regex regular_expression = new Regex(pattern_Identifier); Match match = regular_expression.Match(source_string); while (match.Success) { Function[index++].Identifier = match.Groups[0].Value; match = match.NextMatch(); } index = 0; regular_expression = new Regex(pattern_Declaration); match = regular_expression.Match(source_string); while (match.Success) { int index_source_string = match.Index; StringBuilder Declaration = new StringBuilder(); while (source_string[index_source_string] != '{') Declaration.Append(source_string[index_source_string++]); Declaration.Append(source_string[index_source_string++]); int depth = 1; while (depth > 0) { if (source_string[index_source_string] == '{') depth++; else if (source_string[index_source_string] == '}') depth--; Declaration.Append(source_string[index_source_string++]); } Function[index++].Declaration = Declaration.ToString(); match = match.NextMatch(); } return index; }