private static PlTerm ModuleTerm(string module, PlTerm term) { if (module == null) { return(term); } if (term.IsCompound && term.Arity == 2 && term.Name == ":") { return(term); } return(PlC(":", new[] { PlTerm.PlAtom(module), term })); }
public static PlTerm PlNamed(string name) { return(PlTerm.PlAtom(name)); }
private static PlTerm AFlag(bool tf) { PlTerm plTermPlAtom = PlTerm.PlAtom(tf ? "true" : "false"); return(plTermPlAtom); }
private static PlTerm AFlag(bool tf, string name) { PlTerm plTermPlAtom = PlTerm.PlAtom(tf ? "true" : "false"); return(PlC(name, plTermPlAtom)); }
private static PlTerm MemberTerm(MemberInfo info, string cname, int ordinal) { string mn = info.Name; switch (info.MemberType) { case MemberTypes.Constructor: { var fi = (ConstructorInfo)info; var mi = fi; return(PlC("c", new PlTerm(ordinal), PlTerm.PlAtom(mn), ToPlListParams(fi.GetParameters()), (mi.IsGenericMethodDefinition ? ToPlListTypes(mi.GetGenericArguments()) : ATOM_NIL), PlC("decl", AFlag(mi.IsStatic, "static"), typeToSpec(fi.DeclaringType)), PlC("access_pafv", AFlag(mi.IsPublic), AFlag(mi.IsAssembly), AFlag(mi.IsFamily), AFlag(mi.IsPrivate)), ToProlog(info))); } break; case MemberTypes.Event: { var fi = (EventInfo)info; MethodInfo mi = (fi.GetRaiseMethod() ?? (fi.EventHandlerType != null ? fi.EventHandlerType.GetMethod("Invoke") : null) ?? fi.GetAddMethod() ?? fi.GetRemoveMethod()); ParameterInfo[] parme = GetParmeters(fi); return(PlC("e", new PlTerm(ordinal), PlTerm.PlAtom(mn), typeToSpec(fi.EventHandlerType), ToPlListParams(parme), (mi.IsGenericMethodDefinition ? ToPlListTypes(mi.GetGenericArguments()) : ATOM_NIL), PlC("decl", AFlag(mi.IsStatic, "static"), typeToSpec(fi.DeclaringType)), PlC("access_pafv", AFlag(mi.IsPublic), AFlag(mi.IsAssembly), AFlag(mi.IsFamily), AFlag(mi.IsPrivate)), ToProlog(info))); } break; case MemberTypes.Field: { var fi = (FieldInfo)info; var mi = fi; return(PlC("f", new PlTerm(ordinal), PlTerm.PlAtom(mn), typeToSpec(fi.FieldType), PlC("decl", AFlag(mi.IsStatic, "static"), typeToSpec(fi.DeclaringType)), PlC("access_pafv", AFlag(mi.IsPublic), AFlag(mi.IsAssembly), AFlag(mi.IsFamily), AFlag(mi.IsPrivate)), ToProlog(info))); } break; case MemberTypes.Method: { var fi = (MethodInfo)info; var mi = fi; return(PlC("m", new PlTerm(ordinal), PlTerm.PlAtom(mn), typeToSpec(fi.ReturnParameter.ParameterType), ToPlListParams(fi.GetParameters()), (mi.IsGenericMethodDefinition ? ToPlListTypes(mi.GetGenericArguments()) : ATOM_NIL), PlC("decl", AFlag(mi.IsStatic, "static"), typeToSpec(fi.DeclaringType)), PlC("access_pafv", AFlag(mi.IsPublic), AFlag(mi.IsAssembly), AFlag(mi.IsFamily), AFlag(mi.IsPrivate)), ToProlog(info))); } break; case MemberTypes.Property: { var fi = (PropertyInfo)info; MethodInfo mi = (fi.CanRead ? fi.GetGetMethod(true) : fi.GetSetMethod(true)); return(PlC("p", new PlTerm(ordinal), PlTerm.PlAtom(mn), typeToSpec(fi.PropertyType), ToPlListParams(fi.GetIndexParameters()), (mi.IsGenericMethodDefinition ? ToPlListTypes(mi.GetGenericArguments()) : ATOM_NIL), AFlag(fi.CanRead, "CanRead"), AFlag(fi.CanWrite, "CanWrite"), PlC("decl", AFlag(mi.IsStatic, "static"), typeToSpec(fi.DeclaringType)), PlC("access_pafv", AFlag(mi.IsPublic), AFlag(mi.IsAssembly), AFlag(mi.IsFamily), AFlag(mi.IsPrivate)), ToProlog(info))); } break; case MemberTypes.TypeInfo: break; case MemberTypes.Custom: break; case MemberTypes.NestedType: break; case MemberTypes.All: break; default: throw new ArgumentOutOfRangeException(); } return(default(PlTerm)); }
private static PlTerm typeToSpec(Class type) { if (type == null) { return(PLNULL); } if (type.IsArray && type.HasElementType) { if (type.GetArrayRank() != 1) { return(PlC("arrayOf", typeToSpec(type.GetElementType()), ToProlog(type.GetArrayRank()))); } return(PlC("arrayOf", typeToSpec(type.GetElementType()))); } if (type.IsGenericParameter) { Type[] gt = type.GetGenericParameterConstraints(); return(PlC("<" + type.FullName ?? type.Name + ">", ToPlTermVSpecs(gt))); } if (type.IsPointer) { Type gt = type.GetElementType(); return(PlC("pointer", typeToSpec(gt))); } if (type.IsByRef) { Type gt = type.GetElementType(); return(PlC("byref", typeToSpec(gt))); } // @todo if false , use IsGenericType if (false) { if (typeof(Nullable <>).IsAssignableFrom(type)) { Error("@todo Not Implemented NULLABLE"); Type gt = type.GetElementType(); return(PlC("nullable", typeToSpec(gt))); } } if (type.IsGenericType) { Type gt = type.GetGenericTypeDefinition(); Type[] gtp = type.GetGenericArguments(); PlTermV vt = ToPlTermVSpecs(gtp); string typeName = type.FullName ?? type.Name; int gtpLength = gtp.Length; int indexOf = typeName.IndexOf("`" + gtpLength); if (indexOf > 0) { typeName = typeName.Substring(0, indexOf); } else { Debug("cant chop arity {0} off string '{1}' ", gtpLength, typeName); } return(PlC(typeName, vt)); } if (type.HasElementType) { string named = typeToName(type); Error("@todo Not Implemented " + named); Type gt = type.GetElementType(); if (gt == type) { gt = typeof(object); } return(PlC("elementType", PlTerm.PlAtom(named), typeToSpec(gt))); } if (type.IsSpecialName || string.IsNullOrEmpty(type.Name) || string.IsNullOrEmpty(type.FullName) || string.IsNullOrEmpty(type.Namespace)) { string named = typeToName(type); Error("@todo Not Implemented " + named); Type gt = type.UnderlyingSystemType; if (gt == type) { gt = typeof(object); } return(PlC("static", PlTerm.PlAtom(named), typeToSpec(gt))); } return(PlTerm.PlAtom(typeToName(type))); }