public override void DefineMembers(DefinitionContext c) { if (method != null) { throw new InvalidOperationException(); } if (!c.Types.TryGetValue(returntype, out realreturntype)) { throw new ApplicationException(); } realparametertypes = new Type [parametertypes.Length + 1]; realparametertypes[0] = typeof(ScriptEnvironment); for (int i = 0; i < parametertypes.Length; i++) { if (!c.Types.TryGetValue(parametertypes[i], out realparametertypes[i + 1])) { throw new ApplicationException(); } } method = c.Module.DefineGlobalMethod(name, MethodAttributes.Static | MethodAttributes.Public, realreturntype, realparametertypes); for (int i = 0; i < parameternames.Length; i++) { method.DefineParameter(i + 1, ParameterAttributes.None, parameternames[i]); } c.DefineMethod(name, method); }
public override void Compile(DefinitionContext c) { if (method == null) { throw new InvalidOperationException(); } CodeContext c2 = new CodeContext(c, method); // Fixed local is used for some expressions c2.IL.DeclareLocal(typeof(Fixed)); c2.ParameterTypes.Add(typeof(ScriptEnvironment)); for (int i = 0; i < parametertypes.Length; i++) { c2.ParameterTypes.Add(realparametertypes[i + 1]); c2.Parameters.Add(parameternames[i], i + 1); } statement.Compile(c2); if (realreturntype == typeof(void)) { c2.IL.Emit(OpCodes.Ret); } else { c2.IL.Emit(OpCodes.Newobj, typeof(ApplicationException).GetConstructor(Type.EmptyTypes)); c2.IL.ThrowException(typeof(ApplicationException)); } }
public override void DefineMembers(DefinitionContext c) { if (method != null) { throw new InvalidOperationException(); } method = c.GlobalType.DefineMethod("LineSpecial", MethodAttributes.Static | MethodAttributes.Public, typeof(bool), parametertypes); foreach (LinedefSpecialAttribute attribute in attributes) { Type attrtype = typeof(LinedefSpecialAttribute); Type[] argtypes = new Type [1]; argtypes[0] = typeof(int); ConstructorInfo ctor = attrtype.GetConstructor(argtypes); object[] args = new object [1]; args[0] = attribute.Number; PropertyInfo[] properties = new PropertyInfo [2]; properties[0] = attrtype.GetProperty("ActivationType"); properties[1] = attrtype.GetProperty("Repeatable"); object[] values = new object [2]; values[0] = attribute.ActivationType; values[1] = attribute.Repeatable; CustomAttributeBuilder builder = new CustomAttributeBuilder(ctor, args, properties, values); method.SetCustomAttribute(builder); } }
protected DefinitionContext(DefinitionContext next) { if (next == null) throw new ArgumentNullException("next"); this.module = next.module; this.types = next.types; this.methods = next.methods; }
protected DefinitionContext(DefinitionContext next) { if (next == null) { throw new ArgumentNullException("next"); } this.module = next.module; this.types = next.types; this.methods = next.methods; }
public CodeContext(DefinitionContext next,MethodBuilder method) : base(next) { if (method == null) throw new ArgumentNullException("method"); this.method = method; this.il = method.GetILGenerator(); this.locals = new Dictionary<string,LocalBuilder>(); this.parameters = new Dictionary<string,int>(); this.parametertypes = new List<Type>(); }
public CodeContext(DefinitionContext next, MethodBuilder method) : base(next) { if (method == null) { throw new ArgumentNullException("method"); } this.method = method; this.il = method.GetILGenerator(); this.locals = new Dictionary <string, LocalBuilder>(); this.parameters = new Dictionary <string, int>(); this.parametertypes = new List <Type>(); }
public override void Compile(DefinitionContext c) { if (method == null) throw new InvalidOperationException(); CodeContext c2 = new CodeContext(c,method); // Fixed local is used for some expressions c2.IL.DeclareLocal(typeof(Fixed)); c2.ParameterTypes.Add(typeof(ScriptLinedefSpecialEnvironment)); statement.Compile(c2); c2.IL.Emit(OpCodes.Newobj,typeof(ApplicationException).GetConstructor(Type.EmptyTypes)); c2.IL.ThrowException(typeof(ApplicationException)); }
public override void Compile(DefinitionContext c) { if (method == null) { throw new InvalidOperationException(); } CodeContext c2 = new CodeContext(c, method); // Fixed local is used for some expressions c2.IL.DeclareLocal(typeof(Fixed)); c2.ParameterTypes.Add(typeof(ScriptLinedefSpecialEnvironment)); statement.Compile(c2); c2.IL.Emit(OpCodes.Newobj, typeof(ApplicationException).GetConstructor(Type.EmptyTypes)); c2.IL.ThrowException(typeof(ApplicationException)); }
public override void DefineMembers(DefinitionContext c) { if (method != null) throw new InvalidOperationException(); method = c.GlobalType.DefineMethod("LineSpecial",MethodAttributes.Static | MethodAttributes.Public,typeof(bool),parametertypes); foreach (LinedefSpecialAttribute attribute in attributes) { Type attrtype = typeof(LinedefSpecialAttribute); Type[] argtypes = new Type [1]; argtypes[0] = typeof(int); ConstructorInfo ctor = attrtype.GetConstructor(argtypes); object[] args = new object [1]; args[0] = attribute.Number; PropertyInfo[] properties = new PropertyInfo [2]; properties[0] = attrtype.GetProperty("ActivationType"); properties[1] = attrtype.GetProperty("Repeatable"); object[] values = new object [2]; values[0] = attribute.ActivationType; values[1] = attribute.Repeatable; CustomAttributeBuilder builder = new CustomAttributeBuilder(ctor,args,properties,values); method.SetCustomAttribute(builder); } }
public override void Compile(DefinitionContext c) { if (method == null) throw new InvalidOperationException(); CodeContext c2 = new CodeContext(c,method); // Fixed local is used for some expressions c2.IL.DeclareLocal(typeof(Fixed)); c2.ParameterTypes.Add(typeof(ScriptEnvironment)); for (int i = 0;i < parametertypes.Length;i++) { c2.ParameterTypes.Add(realparametertypes[i + 1]); c2.Parameters.Add(parameternames[i],i + 1); } statement.Compile(c2); if (realreturntype == typeof(void)) { c2.IL.Emit(OpCodes.Ret); } else { c2.IL.Emit(OpCodes.Newobj,typeof(ApplicationException).GetConstructor(Type.EmptyTypes)); c2.IL.ThrowException(typeof(ApplicationException)); } }
public override void DefineMembers(DefinitionContext c) { if (method != null) throw new InvalidOperationException(); if (!c.Types.TryGetValue(returntype,out realreturntype)) { throw new ApplicationException(); } realparametertypes = new Type [parametertypes.Length + 1]; realparametertypes[0] = typeof(ScriptEnvironment); for (int i = 0;i < parametertypes.Length;i++) { if (!c.Types.TryGetValue(parametertypes[i],out realparametertypes[i + 1])) { throw new ApplicationException(); } } method = c.Module.DefineGlobalMethod(name,MethodAttributes.Static | MethodAttributes.Public,realreturntype,realparametertypes); for (int i = 0;i < parameternames.Length;i++) { method.DefineParameter(i + 1,ParameterAttributes.None,parameternames[i]); } c.DefineMethod(name,method); }