public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb) { ConstInfo ci = new ConstInfo(fb); defs[cnst] = ci; return(ci); }
public ConstInfo GetConstant(IConstantDefinitionNode cnst) { ConstInfo ci = (ConstInfo)defs[cnst]; return(ci); }
public ConstInfo GetConstant(IConstantDefinitionNode cnst) { ConstInfo ci = (ConstInfo)defs[cnst]; return ci; }
public virtual void visit(IConstantDefinitionNode value) { }
private void ConvertSetConstantDef(IConstantDefinitionNode cnst, string name, ITypeNode type, IConstantNode constant_value) { TypeInfo ti = helper.GetTypeReference(type); FieldAttributes attrs = FieldAttributes.Public | FieldAttributes.Static; if (comp_opt.target == TargetType.Dll) attrs |= FieldAttributes.InitOnly; FieldBuilder fb = cur_type.DefineField(name, ti.tp, attrs); //il.Emit(OpCodes.Newobj, ti.tp.GetConstructor(Type.EmptyTypes)); //il.Emit(OpCodes.Stsfld, fb); if (cnst != null) helper.AddConstant(cnst, fb); bool tmp = save_debug_info; save_debug_info = false; constant_value.visit(this); save_debug_info = tmp; il.Emit(OpCodes.Stsfld, fb); if (!ConvertedConstants.ContainsKey(constant_value)) ConvertedConstants.Add(constant_value, fb); }
public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb) { ConstInfo ci = new ConstInfo(fb); defs[cnst] = ci; return ci; }
private void ConvertArrayConstantDef(IConstantDefinitionNode cnst, string name, ITypeNode type, IConstantNode constant_value) { //ConvertedConstants.ContainsKey(ArrayConstant) TypeInfo ti = helper.GetTypeReference(type); FieldAttributes attrs = FieldAttributes.Public | FieldAttributes.Static; if (comp_opt.target == TargetType.Dll) attrs |= FieldAttributes.InitOnly; FieldBuilder fb = cur_type.DefineField(name, ti.tp, attrs); if (cnst != null) helper.AddConstant(cnst, fb); CreateArrayGlobalVariable(il, fb, ti, constant_value as IArrayConstantNode, type); if (!ConvertedConstants.ContainsKey(constant_value)) ConvertedConstants.Add(constant_value, fb); }
private void ConvertConstantDefinitionNode(IConstantDefinitionNode cnst, string name, ITypeNode type, IConstantNode constant_value) { if (constant_value is IArrayConstantNode) ConvertArrayConstantDef(cnst, name, type, constant_value); else if (constant_value is IRecordConstantNode || constant_value is ICompiledStaticMethodCallNodeAsConstant) ConvertConstantDefWithInitCall(cnst, name, type, constant_value); else if (constant_value is ICommonNamespaceFunctionCallNodeAsConstant || constant_value is IBasicFunctionCallNodeAsConstant || constant_value is ICommonConstructorCallAsConstant || constant_value is ICompiledStaticFieldReferenceNodeAsConstant) ConvertSetConstantDef(cnst, name, type, constant_value); else ConvertSimpleConstant(cnst, name, type, constant_value); }
private void ConvertConstantDefWithInitCall(IConstantDefinitionNode cnst, string name, ITypeNode type, IConstantNode constant_value) { TypeInfo ti = helper.GetTypeReference(type); FieldAttributes attrs = FieldAttributes.Public | FieldAttributes.Static; if (comp_opt.target == TargetType.Dll) attrs |= FieldAttributes.InitOnly; FieldBuilder fb = cur_type.DefineField(name, ti.tp, attrs); if (cnst != null) helper.AddConstant(cnst, fb); bool tmp = save_debug_info; save_debug_info = false; AddInitCall(il, fb, ti.init_meth, constant_value); save_debug_info = tmp; if (!ConvertedConstants.ContainsKey(constant_value)) ConvertedConstants.Add(constant_value, fb); }
private void ConvertSimpleConstant(IConstantDefinitionNode cnst, string name, ITypeNode type, IConstantNode constant_value) { FieldBuilder fb = cur_type.DefineField(name, helper.GetTypeReference(type).tp, FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.Literal); Type t = helper.GetTypeReference(type).tp; if (t.IsEnum) { if (!(t is EnumBuilder)) fb.SetConstant(Enum.ToObject(t, (constant_value as IEnumConstNode).constant_value)); else fb.SetConstant(constant_value.value); } else if (!(constant_value is INullConstantNode)) { if (constant_value.value.GetType() != t) { } else fb.SetConstant(constant_value.value); } }
public void visit(IConstantDefinitionNode value) { string s = value.GetType().ToString() + "."; prepare_string_node(value.name, s + "name"); prepare_string_node(value.constant_value.ToString(), s + "constant_value"); prepare_node(value.type, s + "type"); }
public void visit(IConstantDefinitionNode value) { throw new System.NotSupportedException(value.GetType().ToString()); }