Example #1
0
        public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb)
        {
            ConstInfo ci = new ConstInfo(fb);

            defs[cnst] = ci;
            return(ci);
        }
Example #2
0
        public ConstInfo GetConstant(IConstantDefinitionNode cnst)
        {
            ConstInfo ci = (ConstInfo)defs[cnst];

            return(ci);
        }
Example #3
0
		public ConstInfo GetConstant(IConstantDefinitionNode cnst)
		{
			ConstInfo ci = (ConstInfo)defs[cnst];
			return ci;
		}
 public virtual void visit(IConstantDefinitionNode value)
 {
 }
Example #5
0
        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);
        }
Example #6
0
		public ConstInfo AddConstant(IConstantDefinitionNode cnst, FieldBuilder fb)
		{
			ConstInfo ci = new ConstInfo(fb);
			defs[cnst] = ci;
			return ci;
		}
Example #7
0
        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);
        }
Example #8
0
 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);
 }
Example #9
0
 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);
 }
Example #10
0
        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);
            }
        }
Example #11
0
 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");              
 }
Example #12
0
		public virtual void visit(IConstantDefinitionNode value)
		{
		}
Example #13
0
 public void visit(IConstantDefinitionNode value)
 {
     throw new System.NotSupportedException(value.GetType().ToString());
 }