private static ParameterDescription GetParameter(int index, FunctionDeclaration function) { int offset = 0; if (index - offset < function.Profile.InputParameters.Count) { return(function.Profile.InputParameters[index - offset]); } offset += function.Profile.InputParameters.Count; if (index - offset < function.Profile.InoutParameters.Count) { return(function.Profile.InoutParameters[index - offset]); } offset += function.Profile.InoutParameters.Count; if (index - offset < function.Profile.OutputParameters.Count) { return(function.Profile.OutputParameters[index - offset]); } offset += function.Profile.OutputParameters.Count; if (index - offset < 1) { return(function.Profile.ReturningParameter); } throw new System.ArgumentOutOfRangeException("Expected: " + index + " < " + function.Profile.InputParameters.Count + '+' + function.Profile.InoutParameters.Count + '+' + function.Profile.OutputParameters.Count + '+' + (function.Profile.ReturningParameter != null?1:0)); }
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); }
public override bool Visit(FunctionDeclaration node) { if (node.CodeElement().Visibility != AccessModifier.Public) { node.Remove(); return(false); } //Note : There is only 1 FunctionEnd var functionEnds = node.GetChildren <FunctionEnd>(); node.RemoveAllChildren(); foreach (var child in functionEnds) { node.Add(child); } return(false); }
private static FunctionCallInfo Create(FunctionCall call, FunctionDeclaration declaration) { var result = new FunctionCallInfo(new URI(call.FunctionName), declaration.Library, declaration.Copy); if (declaration.Profile == null) { return(result); } int count = declaration.Profile.InputParameters.Count + declaration.Profile.InoutParameters.Count + declaration.Profile.OutputParameters.Count; // declaration.Profile.ReturningParameter is not used because // the same data is always used by (and hardcoded in) function call codegen: <function.Name>-RESULT for (int i = 0; i < count; i++) { var pAsDefined = GetParameter(i, declaration); var pAsUsed = GetParameter(i, call); result.InputParameters.Add(Create(pAsDefined, pAsUsed)); } return(result); }
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); }