Пример #1
0
        static void EmitTypeCheck(CodeGenerator cg, IPlace valueplace, SourceParameterSymbol srcparam)
        {
            // TODO: check callable, iterable, type if not resolved in ct

            // check NotNull
            if (srcparam.IsNotNull)
            {
                if (valueplace.TypeOpt.IsReferenceType && valueplace.TypeOpt != cg.CoreTypes.PhpAlias)
                {
                    cg.EmitSequencePoint(srcparam.Syntax);

                    // Template: if (<param> == null) { PhpException.ArgumentNullError(param_name); }
                    var lbl_notnull = new object();
                    cg.EmitNotNull(valueplace);
                    cg.Builder.EmitBranch(ILOpCode.Brtrue_s, lbl_notnull);

                    // PhpException.ArgumentNullError(param_name);
                    // Consider: just Debug.Assert(<param> != null) for private methods
                    cg.Builder.EmitStringConstant(srcparam.Name);
                    cg.EmitPop(cg.EmitCall(ILOpCode.Call, cg.CoreTypes.PhpException.Method("ArgumentNullError", cg.CoreTypes.String)));

                    //
                    cg.Builder.EmitOpCode(ILOpCode.Nop);

                    cg.Builder.MarkLabel(lbl_notnull);
                }
            }
        }
Пример #2
0
            public IndirectParameterSource(SourceParameterSymbol p, ParameterSymbol varargparam)
            {
                Debug.Assert(p.IsFake);
                Debug.Assert(varargparam.Type.IsSZArray());

                _p            = p;
                _varargsplace = new ParamPlace(varargparam);
                _index        = p.Ordinal - varargparam.Ordinal;
                Debug.Assert(_index >= 0);
            }
Пример #3
0
        bool CheckParameterDefaultValue(SourceParameterSymbol p)
        {
            var thint = p.Syntax.TypeHint;

            if (thint != null)
            {
                // check type hint and default value
                var defaultvalue = p.Initializer;
                if (defaultvalue != null && !defaultvalue.TypeRefMask.IsAnyType && !defaultvalue.TypeRefMask.IsDefault)
                {
                    var valuetype = defaultvalue.TypeRefMask;

                    if (TypeCtx.IsNull(valuetype))
                    {
                        // allow NULL anytime
                        return(true);
                    }

                    if (thint is NullableTypeRef nullable)
                    {
                        // unwrap nullable type hint
                        thint = nullable.TargetType;
                    }

                    if (thint is PrimitiveTypeRef primitive)
                    {
                        switch (primitive.PrimitiveTypeName)
                        {
                        case PrimitiveTypeRef.PrimitiveType.@bool:
                            return(TypeCtx.IsBoolean(valuetype));

                        case PrimitiveTypeRef.PrimitiveType.array:
                            return(TypeCtx.IsArray(valuetype));

                        case PrimitiveTypeRef.PrimitiveType.@string:
                            return(TypeCtx.IsAString(valuetype));

                        case PrimitiveTypeRef.PrimitiveType.@object:
                            return(false);

                        case PrimitiveTypeRef.PrimitiveType.@float:
                        case PrimitiveTypeRef.PrimitiveType.@int:
                            return(TypeCtx.IsNumber(valuetype));
                        }
                    }
                    else if (thint is ClassTypeRef classtref)
                    {
                        return(false); // cannot have default value other than NULL
                    }
                }
            }

            // ok
            return(true);
        }
Пример #4
0
 public void EmitTypeCheck(CodeGenerator cg, SourceParameterSymbol srcp)
 {
     // throw new NotImplementedException();
 }
Пример #5
0
 public void EmitTypeCheck(CodeGenerator cg, SourceParameterSymbol srcp)
 {
     BoundParameter.EmitTypeCheck(cg, _place, srcp);
 }
Пример #6
0
 public void Bind(SourceParameterSymbol parameter) => parameter.Initializer?.Accept(this);