Beispiel #1
0
 private static string ComputeName(PrologVisible pm, MethodInfo m)
 {
     if (pm.Name == null)
     {
         if (char.IsLower(m.Name[0]))
         {
             string mName = m.Name;
             if (ForceJanCase)
             {
                 return(ToPrologCase(mName));
             }
             else
             {
                 return(mName);
             }
         }
         else
         {
             string mName = m.Name;
             return(ToPrologCase(mName));
         }
     }
     else
     {
         if (ForceJanCase)
         {
             return(ToPrologCase(pm.Name));
         }
     }
     return(pm.Name);
 }
Beispiel #2
0
 public static void InternMethod(MethodInfo m, PrologVisible pm)
 {
     pm.Name = ComputeName(pm, m);
     if (pm.DelegateType != null)
     {
         ExportedMethodInfos.Add(m);
         PlEngine.RegisterForeign(pm.ModuleName, pm.Name, pm.Arity, pm.Delegate, pm.ForeignSwitches);
         return;
     }
     InternMethod(pm.ModuleName, pm.Name, m);
 }
Beispiel #3
0
        private static void CheckRequiredPrefix(MethodInfo m, PrologVisible f1, string requiredPrefix)
        {
            if (f1.Name != null || requiredPrefix == null)
            {
                return;
            }
            string proposal = ComputeName(f1, m);

            if (!proposal.StartsWith(requiredPrefix))
            {
                proposal = requiredPrefix + proposal;
            }
            f1.Name = proposal;
        }
Beispiel #4
0
        private static void InternMethod(MethodInfo m, string requiredPrefix)
        {
            if (ExportedMethodInfos.Contains(m))
            {
                return;
            }
            if (m.IsAbstract)
            {
                return;
            }
            object[] f = m.GetCustomAttributes(typeof(PrologVisible), false);
            if (f != null && f.Length > 0)
            {
                PrologVisible f1 = (PrologVisible)f[0];
                f1.Method = m;
                try
                {
                    CheckRequiredPrefix(m, f1, requiredPrefix);
                    InternMethod(m, f1);
                    ExportedMethodInfos.Add(m);
                }
                catch (Exception e)
                {
                    Error("{0} caused {1}", m, e);
                }
                return;
            }
            var ForeignSwitches = PlForeignSwitches.None;
            var pm = m.GetParameters();

            if (pm.Length == 3)
            {
                if (pm[1].ParameterType == typeof(int) && pm[2].ParameterType == typeof(IntPtr) &&
                    m.ReturnType == typeof(int))
                {
                    ForeignSwitches |= PlForeignSwitches.VarArgs | PlForeignSwitches.Nondeterministic;
                    PrologVisible f1 = new NonDet();
                    f1.Method = m;
                    try
                    {
                        CheckRequiredPrefix(m, f1, requiredPrefix);
                        InternMethod(m, f1);
                        ExportedMethodInfos.Add(m);
                    }
                    catch (Exception e)
                    {
                        Error("{0} caused {1}", m, e);
                    }
                    return;
                }
            }
            else
            {
                PrologVisible f1 = (PrologVisible) new PrologVisible();
                f1.ForeignSwitches = ForeignSwitches;
                f1.Method          = m;
                try
                {
                    CheckRequiredPrefix(m, f1, requiredPrefix);
                    InternMethod(m, f1);
                    ExportedMethodInfos.Add(m);
                }
                catch (Exception e)
                {
                    Error("{0} caused {1}", m, e);
                }
            }
        }