Ejemplo n.º 1
0
        internal static void ReflectConstants(Assembly /*!*/ realAssembly, DModule /*!*/ declaringModule,
                                              DualDictionary <string, DConstantDesc> /*!*/ constants)
        {
            Debug.Assert(realAssembly != null && constants != null);

            foreach (FieldInfo real_field in ReflectionUtils.GetGlobalFields(realAssembly, BindingFlags.Public | BindingFlags.Static))
            {
                if (real_field.IsLiteral && !real_field.IsSpecialName)
                {
                    string full_name = ClrNotationUtils.FromClrNotation(real_field.Name, true).ToString();

                    DConstantDesc existing;
                    if (constants.TryGetValue(full_name, out existing))
                    {
                        // can be already loaded from different module (CRL or CLib):
                        existing.MemberAttributes |= PhpMemberAttributes.Ambiguous;
                    }
                    else
                    {
                        object        value      = real_field.GetValue(null);
                        DConstantDesc const_desc = new DConstantDesc(declaringModule, PhpMemberAttributes.Public | PhpMemberAttributes.Static, value);
                        constants.Add(full_name, const_desc, false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal static void ReflectConstants(Assembly/*!*/ realAssembly, DModule/*!*/ declaringModule,
            DualDictionary<string, DConstantDesc>/*!*/ constants)
        {
            Debug.Assert(realAssembly != null && constants != null);

            foreach (FieldInfo real_field in ReflectionUtils.GetGlobalFields(realAssembly, BindingFlags.Public | BindingFlags.Static))
            {
                if (real_field.IsLiteral && !real_field.IsSpecialName)
                {
                    string full_name = QualifiedName.FromClrNotation(real_field.Name, true).ToString();

                    DConstantDesc existing;
                    if (constants.TryGetValue(full_name, out existing))
                    {
                        // can be already loaded from different module (CRL or CLib):
                        existing.MemberAttributes |= PhpMemberAttributes.Ambiguous;
                    }
                    else
                    {
                        object value = real_field.GetValue(null);
                        DConstantDesc const_desc = new DConstantDesc(declaringModule, PhpMemberAttributes.Public | PhpMemberAttributes.Static, value);
                        constants.Add(full_name, const_desc, false);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Used by full-reflect (PHP).
 /// </summary>
 public ClassConstant(VariableName name, DConstantDesc /*!*/ constantDesc, FieldInfo /*!*/ fieldInfo)
     : base(constantDesc)
 {
     this.name      = name;
     this.realField = fieldInfo;
 }
Ejemplo n.º 4
0
        private void Bake()
        {
            if (types != null)
            {
                bakedTypes = new KeyValuePair <string, PhpTypeDesc> [types.Count];

                int i = 0;
                foreach (Declaration declaration in types.Values)
                {
                    PhpType type = (PhpType)declaration.Declaree;

                    // store full name before calling Bake() as it nulls the PhpType:
                    string      full_name = type.FullName;
                    PhpTypeDesc baked     = type.Bake();

                    // baked is null if the type is indefinite
                    // (its base class may be evaluated when the module's main method is executed):
                    if (baked != null && !declaration.IsConditional)
                    {
                        bakedTypes[i++] = new KeyValuePair <string, PhpTypeDesc>(full_name, baked);
                    }
                }

                // trim:
                Array.Resize(ref bakedTypes, i);

                types = null;
            }

            if (functions != null)
            {
                bakedFunctions = new KeyValuePair <string, PhpRoutineDesc> [functions.Count];

                int i = 0;
                foreach (Declaration declaration in functions.Values)
                {
                    PhpFunction function = (PhpFunction)declaration.Declaree;

                    string         full_name = function.FullName;
                    PhpRoutineDesc baked     = function.Bake();

                    if (!declaration.IsConditional)
                    {
                        bakedFunctions[i++] = new KeyValuePair <string, PhpRoutineDesc>(full_name, baked);
                    }
                }

                // trim:
                Array.Resize(ref bakedFunctions, i);

                functions = null;
            }

            if (constants != null)
            {
                bakedConstants = new KeyValuePair <string, DConstantDesc> [constants.Count];

                int i = 0;
                foreach (Declaration declaration in constants.Values)
                {
                    GlobalConstant constant = (GlobalConstant)declaration.Declaree;

                    string        full_name = constant.FullName;
                    DConstantDesc baked     = constant.Bake();

                    if (!declaration.IsConditional)
                    {
                        bakedConstants[i++] = new KeyValuePair <string, DConstantDesc>(full_name, baked);
                    }
                }

                // trim:
                Array.Resize(ref bakedConstants, i);

                constants = null;
            }
        }
Ejemplo n.º 5
0
 public KnownConstant(DConstantDesc /*!*/ constantDesc)
     : base(constantDesc)
 {
     Debug.Assert(constantDesc != null);
     this.node = null;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Used by known constant subclasses.
 /// </summary>
 public DConstant(DConstantDesc /*!*/ constantDesc)
     : base(constantDesc)
 {
     Debug.Assert(constantDesc != null);
 }
Ejemplo n.º 7
0
		/// <summary>
		/// Used by full-reflect (PHP).
		/// </summary>
		public ClassConstant(VariableName name, DConstantDesc/*!*/ constantDesc, FieldInfo/*!*/ fieldInfo)
			: base(constantDesc)
		{
			this.name = name;
			this.realField = fieldInfo;
		}
Ejemplo n.º 8
0
		public KnownConstant(DConstantDesc/*!*/ constantDesc)
			: base(constantDesc)
		{
			Debug.Assert(constantDesc != null);
			this.node = null;
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Used by known constant subclasses.
		/// </summary>
		public DConstant(DConstantDesc/*!*/ constantDesc)
			: base(constantDesc)
		{
			Debug.Assert(constantDesc != null);
		}