コード例 #1
0
ファイル: Analyzer.cs プロジェクト: Ashod/Phalanger
		/// <summary>
		/// Resolves constructor of the specified type within the current context (location).
		/// </summary>
		public DRoutine/*!*/ ResolveConstructor(DType/*!*/ type, Position position, PhpType referringType,
			PhpRoutine referringRoutine, out bool checkVisibilityAtRuntime)
		{
			checkVisibilityAtRuntime = false;
			KnownRoutine ctor;

			// Do resolve ctor despite of the indefiniteness of the type to make error reporting consistent
			// when accessing the constructors thru the new operator.

			switch (type.GetConstructor(referringType, out ctor))
			{
				case GetMemberResult.OK:
					return ctor;

				case GetMemberResult.NotFound:
					// default ctor to be used:
					return new UnknownMethod(type);

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

						return new UnknownMethod(type);
					}

				default:
					Debug.Fail();
					return null;
			}
		}