Beispiel #1
0
        internal ClassConstant TryResolveClassConstantGlobally(GenericQualifiedName typeName, VariableName constantName)
        {
            if (typeName.GenericParams.Length != 0)
            {
                return(null);
            }

            QualifiedName?alias;
            DType         type = ResolveTypeName(typeName.QualifiedName, Scope.Global, out alias, null, Position.Invalid, false);

            ClassConstant constant;

            if (type != null && type.IsDefinite && type.GetConstant(constantName, null, out constant) == GetMemberResult.OK)
            {
                return(constant);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
		internal DConstant ResolveClassConstantName(DType/*!*/ type, VariableName constantName,
			Position position, PhpType referringType, PhpRoutine referringRoutine, out bool checkVisibilityAtRuntime)
		{
			checkVisibilityAtRuntime = false;

			// we cannot resolve a class constant unless we know the inherited members:
			if (type.IsDefinite)
			{
				ClassConstant constant;
				GetMemberResult member_result = type.GetConstant(constantName, referringType, out constant);

				switch (member_result)
				{
					case GetMemberResult.OK:
						return constant;

					case GetMemberResult.NotFound:
						ErrorSink.Add(Errors.UnknownClassConstantAccessed, SourceUnit, position, type.FullName, constantName);
						return new UnknownClassConstant(type, constantName.Value);

					case GetMemberResult.BadVisibility:
						if (referringType == null && referringRoutine == null)
						{
							// visibility must be checked at run-time:
							checkVisibilityAtRuntime = true;
							return constant;
						}
						else
						{
							// definitive error:
							if (constant.IsPrivate)
							{
								ErrorSink.Add(Errors.PrivateConstantAccessed, SourceUnit, position, type.FullName, constantName.Value,
				  referringType.FullName);
							}
							else
							{
								ErrorSink.Add(Errors.ProtectedConstantAccessed, SourceUnit, position, type.FullName, constantName.Value,
				  referringType.FullName);
							}

							return new UnknownClassConstant(type, constantName.Value);
						}

					default:
						Debug.Fail();
						throw null;
				}
			}
			else
			{
				// warning (if any) reported by the type resolver:
				return new UnknownClassConstant(type, constantName.Value);
			}
		}