public static object ApplyMethod(GtFunc Func, object Self, object[] Params) { try { return ((MethodInfo)Func.FuncBody).Invoke(Self, Params); } catch (TargetInvocationException e) { LibGreenTea.VerboseException(e); } catch (ArgumentException e) { LibGreenTea.VerboseException(e); } catch (MemberAccessException e) { LibGreenTea.VerboseException(e); } return null; }
public static GtNode ApplyTypeFunc(GtFunc TypeFunc, GtTypeEnv Gamma, GtSyntaxTree ParsedTree, GtType ContextType) { return (GtNode)ApplyMethodV(TypeFunc, null, Gamma, ParsedTree, ContextType); }
public static long ApplyTokenFunc(GtFunc TokenFunc, object TokenContext, string Text, long pos) { return (long)ApplyMethodV(TokenFunc, null, TokenContext, Text, pos); }
public static GtSyntaxTree ApplyParseFunc(GtFunc ParseFunc, GtNameSpace NameSpace, GtTokenContext TokenContext, GtSyntaxTree LeftTree, GtSyntaxPattern Pattern) { return (GtSyntaxTree)ApplyMethodV(ParseFunc, null, NameSpace, TokenContext, LeftTree, Pattern); }
public static object ApplyMethodV(GtFunc Func, object Self, params object[] Params) { return ApplyMethod(Func, Self, Params); }
public static GtFunc LoadNativeField(GtParserContext Context, GtType ClassType, String FieldName, Boolean GetSetter) { //GtParserContext Context = ClassType.Context; try { Type NativeClass = (Type)ClassType.TypeBody; FieldInfo NativeField = NativeClass.GetField(FieldName); if (NativeField.IsPublic) { var GtFieldType = GetNativeType(NativeField.GetType()); var GetterNativeFunc = new GtFunc(GreenTeaConsts.GetterFunc, FieldName, 0, new List<GtType>() { GtFieldType, ClassType }); GetterNativeFunc.SetNativeMethod(0, NativeField); Context.RootNameSpace.SetGetterFunc(ClassType, FieldName, GetterNativeFunc, null); var SetterNativeFunc = new GtFunc(GreenTeaConsts.SetterFunc, FieldName, 0, new List<GtType>() { GtStaticTable.VoidType, ClassType, GtFieldType }); SetterNativeFunc.SetNativeMethod(0, NativeField); Context.RootNameSpace.SetSetterFunc(ClassType, FieldName, SetterNativeFunc, null); return GetSetter ? SetterNativeFunc : GetterNativeFunc; } } catch (System.Security.SecurityException e) { LibGreenTea.VerboseException(e); } catch (MissingFieldException) { } Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.GetterSymbol(FieldName)), null); Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.SetterSymbol(FieldName)), null); // for setter return null; }
public static void LoadNativeConstructors(GtParserContext Context, GtType ClassType, List<GtFunc> FuncList) { var NativeClass = (Type)ClassType.TypeBody; var GtConstructors = NativeClass.GetConstructors().Where(c => c.IsPublic).Select(c => { var TypeList = new List<GtType>() { ClassType }; TypeList.AddRange(c.GetParameters().Select(p => LibNative.GetNativeType(p.ParameterType))); var Func = new GtFunc(GreenTeaConsts.ConstructorFunc, ClassType.ShortName, 0, TypeList); Func.SetNativeMethod(0, c); Context.RootNameSpace.AppendConstructor(ClassType, Func, null); return Func; }).ToList(); FuncList.AddRange(GtConstructors); if (GtConstructors.Count == 0) { Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.ConstructorSymbol()), null); } }