Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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);
        }