public static ProgramImports GetProgramImports([NotNull] IProcCaller procCaller) { ProgramImports imports = new ProgramImports(); if (procCaller.ProcStyleCalls != null) { //All imported program. string name_low = procCaller.Name.ToLower(); //For each entry in the Procedure Style Call Dictionary foreach (var e in procCaller.ProcStyleCalls) { var hash = e.Key; var call = e.Value; ProcedureStyleCall proc_style_call = call.Item2; //Only import Public Functions FunctionDeclaration fun_decl = proc_style_call.FunctionDeclaration; if (fun_decl != null) { if (fun_decl.CodeElement().Visibility == AccessModifier.Private) { continue;//Ignore a Private function ==> Cannot Import It. } } var item_pgm = call.Item1[call.Item1.Count - 1]; if (name_low.Equals(item_pgm.Name.ToLower())) { //Avoid imports to itself. continue; } string item_pgm_name = Hash.CalculateCobolProgramNameShortcut(item_pgm.Name); string item_pgm_name_low = item_pgm_name.ToLower(); ProgramImport prg_imp = null; if (!imports.Programs.ContainsKey(item_pgm_name_low)) { prg_imp = new ProgramImport(); prg_imp.Name = item_pgm_name; imports.Programs[item_pgm_name_low] = prg_imp; } if (prg_imp == null) { prg_imp = imports.Programs[item_pgm_name_low]; } //Store the Procedure if it is not alreday there string proc_hash = hash; if (!prg_imp.Procedures.ContainsKey(proc_hash)) { ProcedureImport proc_imp = new ProcedureImport(); string item_proc_name = call.Item1[0].Name; proc_imp.Name = item_proc_name; proc_imp.Hash = proc_hash; proc_imp.ProcStyleCall = proc_style_call; prg_imp.Procedures[proc_hash] = proc_imp; } } } return(imports); }
/// <summary> /// Checks and handles any procedure call resolution. /// </summary> /// <param name="items">The items to check if they correspond to the procedure qualified name</param> /// <returns>true if it was a Procedure style call, false otherwise.</returns> private bool IsProcedureStyleCallItems(IList <SymbolReference> items, out string hashFunction) { hashFunction = null; if (CurrentNode is TypeCobol.Compiler.Nodes.ProcedureStyleCall) { TypeCobol.Compiler.Nodes.ProcedureStyleCall procStyleCall = CurrentNode as TypeCobol.Compiler.Nodes.ProcedureStyleCall; if (procStyleCall.CodeElement is TypeCobol.Compiler.CodeElements.ProcedureStyleCallStatement) { TypeCobol.Compiler.CodeElements.ProcedureStyleCallStatement procStyleCallStmt = procStyleCall.CodeElement as TypeCobol.Compiler.CodeElements.ProcedureStyleCallStatement; if (procStyleCallStmt.ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction is TypeCobol.Compiler.CodeElements.TypeCobolQualifiedSymbolReference) { TypeCobol.Compiler.CodeElements.TypeCobolQualifiedSymbolReference tcqsr = procStyleCallStmt.ProgramOrProgramEntryOrProcedureOrFunctionOrTCProcedureFunction as TypeCobol.Compiler.CodeElements.TypeCobolQualifiedSymbolReference; IList <SymbolReference> names_items = tcqsr.AsList(); if (names_items.Count != items.Count) { return(false); } if (EqualItems(items, names_items)) {//This is a reference to a Function Call. hashFunction = procStyleCall.FunctionDeclaration.Hash; if (ProgramStack != null && ProgramStack.Count > 0) { //Memoïze the (hash,ProcedureStyleCall) In the Program procedure style call dictionary. var program = ProgramStack.Peek(); if (!program.ProcStyleCalls.ContainsKey(hashFunction)) { program.ProcStyleCalls[hashFunction] = new Tuple <IList <SymbolReference>, TypeCobol.Compiler.Nodes.ProcedureStyleCall>(items, procStyleCall); } } return(true); } } } } return(false); }
public object GetValue(object o, SymbolTable table) { ProgramImports imports = new ProgramImports(); var program = o as Program; if (program != null) { if (program.ProcStyleCalls != null) { //All imported program. var name = program.Name; string name_low = name.ToLower(); string pgm_name = program.Name.Substring(0, Math.Min(name.Length, 8)); string pgm_name_low = pgm_name.ToLower(); //For each entry in the Procedure Style Call Dictionary foreach (var e in program.ProcStyleCalls) { var hash = e.Key; var call = e.Value; ProcedureStyleCall proc_style_call = call.Item2; //Only import Public Functions FunctionDeclaration fun_decl = proc_style_call.FunctionDeclaration; if (fun_decl != null) { if (fun_decl.CodeElement().Visibility == AccessModifier.Private) { continue;//Ignore a Private function ==> Cannot Import It. } } var item_pgm = call.Item1[call.Item1.Count - 1]; if (name_low.Equals(item_pgm.Name.ToLower())) { //Avoid imports to itself. continue; } string item_pgm_name = item_pgm.Name.Substring(0, Math.Min(item_pgm.Name.Length, 8)); string item_pgm_name_low = item_pgm_name.ToLower(); ProgramImport prg_imp = null; if (!imports.Programs.ContainsKey(item_pgm_name_low)) { prg_imp = new ProgramImport(); prg_imp.Name = item_pgm_name; imports.Programs[item_pgm_name_low] = prg_imp; } if (prg_imp == null) { prg_imp = imports.Programs[item_pgm_name_low]; } //Store the Procedure if it is not alreday there string proc_hash = hash; if (!prg_imp.Procedures.ContainsKey(proc_hash)) { ProcedureImport proc_imp = new ProcedureImport(); string item_proc_name = call.Item1[0].Name; proc_imp.Name = item_proc_name; proc_imp.Hash = proc_hash; proc_imp.ProcStyleCall = proc_style_call; prg_imp.Procedures[proc_hash] = proc_imp; } } } } return(imports); }