Пример #1
0
            private bool ResolveConstructor(Analyzer /*!*/ analyzer)
            {
                if (!type.IsDefinite)
                {
                    // attribute type has to be known definitely:
                    analyzer.ErrorSink.Add(Errors.UnknownCustomAttribute, analyzer.SourceUnit, node.Span,
                                           type.FullName, type.FullName + "Attribute");

                    return(false);
                }

                if (!type.IsCustomAttributeType)
                {
                    analyzer.ErrorSink.Add(Errors.NotCustomAttributeClass, analyzer.SourceUnit, node.Span, type.FullName);
                    return(false);
                }

                // resolve ctor overload in global context (only public ctors are visible):
                bool     check_visibility;
                DRoutine constructor = analyzer.ResolveConstructor(type, node.Span, null, null, out check_visibility);

                Debug.Assert(!check_visibility);

                if (constructor.ResolveOverload(analyzer, node.CallSignature, node.Span, out overload) == DRoutine.InvalidOverloadIndex)
                {
                    analyzer.ErrorSink.Add(Errors.ClassHasNoVisibleCtor, analyzer.SourceUnit, node.Span, type.FullName);
                    return(false);
                }

                return(true);
            }
Пример #2
0
        internal override Evaluation Analyze(Analyzer /*!*/ analyzer, ExInfoFromParent info)
        {
            Debug.Assert(this.IsMemberOf == null);

            access = info.Access;

            this.typeArgsResolved = classNameRef.Analyze(analyzer);

            DType            type = classNameRef.ResolvedType;
            RoutineSignature signature;

            if (typeArgsResolved)
            {
                analyzer.AnalyzeConstructedType(type);
            }

            if (type != null)
            {
                bool error_reported = false;

                // make checks if we are sure about character of the type:
                if (type.IsIdentityDefinite)
                {
                    if (type.IsAbstract || type.IsInterface)
                    {
                        analyzer.ErrorSink.Add(Errors.AbstractClassOrInterfaceInstantiated, analyzer.SourceUnit,
                                               position, type.FullName);
                        error_reported = true;
                    }
                }

                // disallow instantiation of Closure
                if (type.RealType == typeof(PHP.Library.SPL.Closure))
                {
                    analyzer.ErrorSink.Add(Errors.ClosureInstantiated, analyzer.SourceUnit, position, type.FullName);
                    error_reported = true;
                }

                // type name resolved, look the constructor up:
                constructor = analyzer.ResolveConstructor(type, position, analyzer.CurrentType, analyzer.CurrentRoutine,
                                                          out runtimeVisibilityCheck);

                if (constructor.ResolveOverload(analyzer, callSignature, position, out signature) == DRoutine.InvalidOverloadIndex)
                {
                    if (!error_reported)
                    {
                        analyzer.ErrorSink.Add(Errors.ClassHasNoVisibleCtor, analyzer.SourceUnit,
                                               position, type.FullName);
                    }
                }
            }
            else
            {
                signature = UnknownSignature.Default;
            }

            callSignature.Analyze(analyzer, signature, info, false);

            return(new Evaluation(this));
        }
Пример #3
0
        public static PHP.Core.Compiler.AST.FunctionCallEvaluateInfo Exists_Analyze(Analyzer analyzer, string name)
        {
            QualifiedName?alias;

            DRoutine routine = analyzer.SourceUnit.ResolveFunctionName(
                new QualifiedName(new Name(name)),
                analyzer.CurrentScope,
                out alias,
                null,
                Core.Text.Span.Invalid,
                false);

            if (routine == null || routine.IsUnknown)
            {
                return(null);  // function is not known at the compilation time. However it can be defined at the runtime (dynamic include, script library, etc).
            }
            return(new PHP.Core.Compiler.AST.FunctionCallEvaluateInfo()
            {
                value = true    // function is definitely known the the compilation time
            });
        }