//------------------------------------------------------------ // CLSDREC.SetForPartialMethod // /// <summary></summary> /// <param name="treeNode"></param> /// <param name="partialMethSym">the partial method</param> /// <param name="otherMethSym">the other method with the same signiture</param> /// <param name="errorID"></param> /// <returns></returns> //------------------------------------------------------------ internal bool CheckForDulicatePartialMethod( BASENODE treeNode, METHSYM partialMethSym, METHSYM otherMethSym) { if (partialMethSym == null || otherMethSym == null) { return(true); } if (!otherMethSym.IsPartialMethod) { Compiler.Error( treeNode, CSCERRID.ERR_MemberAlreadyExists, new ErrArg(partialMethSym), new ErrArg(partialMethSym.ClassSym)); return(false); } if (!partialMethSym.HasNoBody && !otherMethSym.HasNoBody) { Compiler.Error( treeNode, CSCERRID.ERR_MultiplePartialMethodImplementation); return(false); } return(true); }
//------------------------------------------------------------ // CreateGetTypeFromHandleMethodSym // /// <summary> /// <para>Defined in FuncBindUtil.cs</para> /// </summary> /// <param name="treeNode"></param> /// <returns></returns> //------------------------------------------------------------ internal METHSYM CreateGetTypeFromHandleMethodSym(BASENODE treeNode) { if (GetTypeFromHandleMethodSym != null) { return(GetTypeFromHandleMethodSym); } // System.RuntimeTypeHandle TYPESYM handleTypeSym = this.GetRequiredPredefinedType(PREDEFTYPE.TYPEHANDLE); DebugUtil.Assert(handleTypeSym != null); TypeArray paramArray = new TypeArray(); paramArray.Add(handleTypeSym); paramArray = Compiler.MainSymbolManager.AllocParams(paramArray); GetTypeFromHandleMethodSym = FindPredefMeth( treeNode, PREDEFNAME.GETTYPEFROMHANDLE, this.GetRequiredPredefinedType(PREDEFTYPE.TYPE), paramArray, true, MemLookFlagsEnum.None); DebugUtil.Assert(GetTypeFromHandleMethodSym != null); return(GetTypeFromHandleMethodSym); }
//------------------------------------------------------------ // MethWithInst Constructor (2) // /// <summary></summary> /// <param name="meth"></param> /// <param name="ats"></param> /// <param name="typeArgs"></param> //------------------------------------------------------------ internal MethWithInst( METHSYM meth, AGGTYPESYM ats, TypeArray typeArgs) // = NULL) { Set(meth, ats, typeArgs); }
//------------------------------------------------------------ // FUNCBREC.GetActionInvokeMethod // /// <summary></summary> /// <param name="arity"></param> /// <returns></returns> //------------------------------------------------------------ internal METHSYM GetActionInvokeMethod(int arity) { if (arity < 0 || arity >= systemActionDelegateCount) { return(null); } InitSystemActionInvokeMethodSyms(); METHSYM invokeSym = systemActionInvokeMethodSyms[arity]; if (invokeSym != null) { return(invokeSym); } AGGTYPESYM actionAts = GetActionTypeSym(arity); if (actionAts == null) { return(null); } invokeSym = Compiler.MainSymbolManager.LookupAggMember( "Invoke", actionAts.GetAggregate(), SYMBMASK.METHSYM) as METHSYM; systemActionInvokeMethodSyms[arity] = invokeSym; return(invokeSym); }
//------------------------------------------------------------ // FUNCBREC.IsNubCtor (1) // /// <summary> /// Return true iff the method is the nullable ctor taking one parameter. /// </summary> /// <param name="meth"></param> /// <returns></returns> //------------------------------------------------------------ private bool IsNubCtor(METHSYM meth) { return( meth != null && meth.ClassSym.IsPredefAgg(PREDEFTYPE.G_OPTIONAL) && meth.ParameterTypes.Count == 1 && meth.ParameterTypes[0].IsTYVARSYM && meth.IsCtor); }
//------------------------------------------------------------ // CLSDREC.SetForPartialMethod // /// <summary></summary> /// <param name="treeNode"></param> /// <param name="methodSym"></param> //------------------------------------------------------------ internal void SetForPartialMethod(BASENODE treeNode, METHSYM methodSym) { if (!IsPartialMethod(treeNode)) { return; } methodSym.IsPartialMethod = true; methodSym.HasNoBody = ((treeNode.NodeFlagsEx & NODEFLAGS.EX_METHOD_NOBODY) != 0); }
//------------------------------------------------------------ // FUNCBREC.BindNubNew // /// <summary> /// Create an expr for new T?(exprSrc) where T is exprSrc->type. /// </summary> /// <param name="treeNode"></param> /// <param name="srcExpr"></param> /// <returns></returns> //------------------------------------------------------------ private EXPR BindNubNew(BASENODE treeNode, EXPR srcExpr) { DebugUtil.Assert(srcExpr != null); // Create a NUBSYM instance whose base bype is represented by srcExpr.TypeSym. NUBSYM nubSym = Compiler.MainSymbolManager.GetNubType(srcExpr.TypeSym); // Get a TYPESYM instance representing Nullable<> for nubSym. AGGTYPESYM aggTypeSym = nubSym.GetAggTypeSym(); if (aggTypeSym == null) { return(NewError(treeNode, nubSym)); } Compiler.EnsureState(aggTypeSym, AggStateEnum.Prepared); METHSYM methSym = Compiler.MainSymbolManager.NullableCtorMethodSym; if (methSym == null) { string name = Compiler.NameManager.GetPredefinedName(PREDEFNAME.CTOR); for (SYM sym = Compiler.MainSymbolManager.LookupAggMember(name, aggTypeSym.GetAggregate(), SYMBMASK.ALL); ; sym = sym.NextSameNameSym) { if (sym == null) { Compiler.Error(treeNode, CSCERRID.ERR_MissingPredefinedMember, new ErrArg(aggTypeSym), new ErrArg(name)); return(NewError(treeNode, nubSym)); } if (sym.IsMETHSYM) { methSym = sym as METHSYM; if (methSym.ParameterTypes.Count == 1 && methSym.ParameterTypes[0].IsTYVARSYM && methSym.Access == ACCESS.PUBLIC) { break; } } } Compiler.MainSymbolManager.NullableCtorMethodSym = methSym; } EXPRCALL resExpr = NewExpr(treeNode, EXPRKIND.CALL, nubSym) as EXPRCALL; resExpr.MethodWithInst.Set(methSym, aggTypeSym, BSYMMGR.EmptyTypeArray); resExpr.ArgumentsExpr = srcExpr; resExpr.ObjectExpr = null; resExpr.Flags |= EXPRFLAG.NEWOBJCALL | EXPRFLAG.CANTBENULL; return(resExpr); }
//------------------------------------------------------------ // FUNCBREC.BindNubGetValOrDef // /// <summary> /// Create an expr for exprSrc.GetValueOrDefault() /// where exprSrc->type is a NUBSYM. /// </summary> /// <param name="treeNode"></param> /// <param name="srcExpr"></param> /// <returns></returns> //------------------------------------------------------------ private EXPR BindNubGetValOrDef(BASENODE treeNode, EXPR srcExpr) { DebugUtil.Assert(srcExpr != null && srcExpr.TypeSym.IsNUBSYM); TYPESYM baseTypeSym = (srcExpr.TypeSym as NUBSYM).BaseTypeSym; // If srcExpr is null, just return the appropriate default value. if (srcExpr.GetConst() != null) { return(AddSideEffects(treeNode, NewExprZero(treeNode, baseTypeSym), srcExpr, true, true)); } // For new T?(x), the answer is x. if (IsNubCtor(srcExpr)) { DebugUtil.Assert( (srcExpr as EXPRCALL).ArgumentsExpr != null && (srcExpr as EXPRCALL).ArgumentsExpr.Kind != EXPRKIND.LIST); return((srcExpr as EXPRCALL).ArgumentsExpr); } AGGTYPESYM aggTypeSym = (srcExpr.TypeSym as NUBSYM).GetAggTypeSym(); if (aggTypeSym == null) { return(NewError(treeNode, baseTypeSym)); } Compiler.EnsureState(aggTypeSym, AggStateEnum.Prepared); METHSYM methSym = EnsureNubGetValOrDef(treeNode); if (methSym == null) { return(NewError(treeNode, baseTypeSym)); } CheckFieldUse(srcExpr, true); EXPRCALL resExpr = NewExpr(treeNode, EXPRKIND.CALL, baseTypeSym) as EXPRCALL; resExpr.MethodWithInst.Set(methSym, aggTypeSym, BSYMMGR.EmptyTypeArray); resExpr.ArgumentsExpr = null; resExpr.ObjectExpr = srcExpr; return(resExpr); }
//------------------------------------------------------------ // CLSDREC.DefineExtensionMethodCore // /// <summary></summary> /// <param name="methodSym"></param> //------------------------------------------------------------ internal void DefineExtensionMethodCore(METHSYM methodSym) { DebugUtil.Assert(methodSym != null); DebugUtil.Assert(methodSym.ParameterTypes.Count > 0); TypeArray paramTypes = methodSym.ParameterTypes; AGGTYPESYM ats = paramTypes[0] as AGGTYPESYM; if (ats == null) { return; } AGGSYM targetAggSym = ats.GetAggregate(); METHSYM instanceMethSym = Compiler.MainSymbolManager.CreateGlobalSym( SYMKIND.METHSYM, methodSym.Name, targetAggSym) as METHSYM; instanceMethSym.ContainingAggDeclSym = targetAggSym.FirstDeclSym; instanceMethSym.IsUnsafe = methodSym.IsUnsafe; instanceMethSym.TypeVariables = methodSym.TypeVariables; TypeArray instParamTypes = new TypeArray(); for (int i = 1; i < paramTypes.Count; ++i) { instParamTypes.Add(paramTypes[i]); } instanceMethSym.ParameterTypes = Compiler.MainSymbolManager.AllocParams(instParamTypes); instanceMethSym.ReturnTypeSym = methodSym.ReturnTypeSym; instanceMethSym.Access = methodSym.Access; instanceMethSym.IsStatic = false; instanceMethSym.IsParameterArray = methodSym.IsParameterArray; instanceMethSym.IsVarargs = methodSym.IsVarargs; instanceMethSym.StaticExtensionMethodSym = methodSym; }
//------------------------------------------------------------ // FUNCBREC.EnsureNubGetValOrDef // /// <summary> /// Make sure the HasValue property of System.Nullable<T> is appropriate (and return it). /// </summary> /// <param name="treeNode"></param> /// <returns></returns> //------------------------------------------------------------ private METHSYM EnsureNubGetValOrDef(BASENODE treeNode) { METHSYM methSym = Compiler.MainSymbolManager.NullableGetValOrDefMethodSym; if (methSym == null) { AGGSYM nubAggSym = Compiler.GetOptPredefAggErr(PREDEFTYPE.G_OPTIONAL, true); if (nubAggSym == null) { return(null); } string name = Compiler.NameManager.GetPredefinedName(PREDEFNAME.GET_VALUE_OR_DEF); for (SYM sym = Compiler.MainSymbolManager.LookupAggMember(name, nubAggSym, SYMBMASK.ALL); ; sym = sym.NextSameNameSym) { if (sym == null) { Compiler.Error(treeNode, CSCERRID.ERR_MissingPredefinedMember, new ErrArg(nubAggSym), new ErrArg(name)); return(null); } if (sym.IsMETHSYM) { methSym = sym as METHSYM; if (methSym.ParameterTypes.Count == 0 && methSym.ParameterTypes.Count == 0 && methSym.ReturnTypeSym.IsTYVARSYM && !methSym.IsStatic && methSym.Access == ACCESS.PUBLIC) { break; } } } Compiler.MainSymbolManager.NullableGetValOrDefMethodSym = methSym; } return(methSym); }
//------------------------------------------------------------ // FUNCBREC.CreateAutoImplementedGetAccessor // /// <summary></summary> /// <param name="methodSym"></param> /// <returns></returns> //------------------------------------------------------------ internal EXPR CreateAutoImplementedGetAccessor(METHSYM methodSym) { CreateNewScope(); SCOPESYM scopeSym = this.currentScopeSym; this.currentScopeSym.ScopeFlags = SCOPEFLAGS.NONE; this.currentBlockExpr = NewExprBlock(treeNode); this.currentBlockExpr.ScopeSym = this.currentScopeSym; SymWithType symWithType = new SymWithType(); AGGTYPESYM parentAts = methodSym.ParentAggSym.GetThisType(); symWithType.Set( methodSym.PropertySym.BackFieldSym, parentAts); EXPR fieldExpr = BindToField( null, BindThisImplicit(null), FieldWithType.Convert(symWithType), BindFlagsEnum.RValueRequired); //TYPESYM retTypeSym = methodSym.ReturnTypeSym; EXPRRETURN returnExpr = NewExpr(null, EXPRKIND.RETURN, null) as EXPRRETURN; returnExpr.ObjectExpr = fieldExpr; this.currentBlockExpr.StatementsExpr = returnExpr; EXPRBLOCK blockExpr = this.currentBlockExpr; this.currentBlockExpr = blockExpr.OwingBlockExpr; CloseScope(); CorrectAnonMethScope(blockExpr.ScopeSym); return(blockExpr); }
//------------------------------------------------------------ // CLSDREC.DefineExtensionMethod // /// <summary></summary> /// <param name="methodNode"></param> /// <param name="methodSym"></param> //------------------------------------------------------------ internal void DefineExtensionMethod(METHODNODE methodNode, METHSYM methodSym) { DebugUtil.Assert( methodNode != null && methodNode.IsExtensionMethod && methodSym != null); //-------------------------------------------------------- // //-------------------------------------------------------- AGGSYM parentAggSym = methodSym.ParentAggSym; DebugUtil.Assert(parentAggSym != null); if (!methodSym.IsStatic) { Compiler.Error( methodNode, CSCERRID.ERR_NonStaticExtensionMethod); return; } if (!parentAggSym.IsStatic || (parentAggSym.AllTypeVariables != null && parentAggSym.AllTypeVariables.Count > 0)) { Compiler.Error( methodNode, CSCERRID.ERR_ExtensionMethodInImproperClass); return; } if (parentAggSym.IsNested) { Compiler.Error( methodNode, CSCERRID.ERR_ExtensionMethodInNestedClass, new ErrArg(parentAggSym.Name)); return; } DefineExtensionMethodCore(methodSym); }
//------------------------------------------------------------ // FUNCBREC.BindExtensionMethod // /// <summary></summary> /// <param name="callExpr"></param> /// <returns></returns> //------------------------------------------------------------ internal EXPR BindExtensionMethod(EXPRCALL instanceCallExpr) { DebugUtil.Assert( instanceCallExpr != null && instanceCallExpr.MethodWithInst != null && instanceCallExpr.MethodWithInst.MethSym != null); MethWithInst instanceMwi = instanceCallExpr.MethodWithInst; METHSYM instanceMethSym = instanceMwi.MethSym; METHSYM staticMethSym = instanceMethSym.StaticExtensionMethodSym; if (staticMethSym == null) { return(instanceCallExpr); } MethWithInst staticMwi = new MethWithInst( staticMethSym, staticMethSym.ParentAggSym.GetThisType(), // non-generic type. instanceMwi.TypeArguments); EXPR topArgExpr = instanceCallExpr.ObjectExpr; EXPR lastArgExpr = topArgExpr; if (instanceCallExpr.ArgumentsExpr != null) { NewList(instanceCallExpr.ArgumentsExpr, ref topArgExpr, ref lastArgExpr); } EXPRCALL staticCallExpr = NewExpr( treeNode, EXPRKIND.CALL, instanceCallExpr.TypeSym) as EXPRCALL; staticCallExpr.MethodWithInst = staticMwi; staticCallExpr.ArgumentsExpr = topArgExpr; staticCallExpr.ObjectExpr = null; return(staticCallExpr); }
//------------------------------------------------------------ // CLSDREC.CheckFlagsAndSigOfPartialMethod // /// <summary></summary> /// <param name="nodeFlags"></param> /// <param name="methodSym"></param> /// <returns></returns> //------------------------------------------------------------ internal void CheckFlagsAndSigOfPartialMethod( BASENODE treeNode, NODEFLAGS nodeFlags, METHSYM methodSym) { const NODEFLAGS forbidden = 0 | NODEFLAGS.MOD_ABSTRACT | NODEFLAGS.MOD_NEW | NODEFLAGS.MOD_OVERRIDE | NODEFLAGS.MOD_PRIVATE | NODEFLAGS.MOD_PROTECTED | NODEFLAGS.MOD_INTERNAL | NODEFLAGS.MOD_PUBLIC | NODEFLAGS.MOD_SEALED | NODEFLAGS.MOD_VIRTUAL | NODEFLAGS.MOD_EXTERN; if ((nodeFlags & forbidden) != 0) { Compiler.Error(treeNode, CSCERRID.ERR_BadModifierForPartialMethod); } TypeArray paramTypes = methodSym.ParameterTypes; if (paramTypes != null && paramTypes.Count > 0) { for (int i = 0; i < paramTypes.Count; ++i) { TYPESYM typeSym = paramTypes[i]; if (typeSym.Kind == SYMKIND.PARAMMODSYM && (typeSym as PARAMMODSYM).IsOut) { Compiler.Error( treeNode, CSCERRID.ERR_PartialMethodHasOutParameter); } } } }
//------------------------------------------------------------ // MethWithType.Set (1) // /// <summary></summary> /// <param name="meth"></param> /// <param name="ats"></param> //------------------------------------------------------------ internal void Set(METHSYM meth, AGGTYPESYM ats) { base.Set(meth, ats); }
//------------------------------------------------------------ // MethWithType Constructor (2) // /// <summary></summary> /// <param name="meth"></param> /// <param name="ats"></param> //------------------------------------------------------------ internal MethWithType(METHSYM meth, AGGTYPESYM ats) { Set(meth, ats); }
//------------------------------------------------------------ // MethWithInst.Set (1) // /// <summary></summary> /// <param name="meth"></param> /// <param name="ats"></param> /// <param name="typeArgs"></param> //------------------------------------------------------------ internal void Set(METHSYM meth, AGGTYPESYM ats, TypeArray typeArgs) { base.Set(meth, ats, typeArgs); }
//------------------------------------------------------------ // ReflectionUtil.GetConstructedMethodInfo // /// <summary></summary> /// <param name="compiler"></param> /// <param name="methodSym"></param> /// <param name="aggTypeSym"></param> /// <param name="methTypeArguments"></param> /// <returns></returns> //------------------------------------------------------------ internal static MethodInfo GetConstructedMethodInfo( COMPILER compiler, METHSYM methodSym, AGGTYPESYM aggTypeSym, TypeArray methTypeArguments) { DebugUtil.Assert(compiler != null && compiler.Emitter != null); EMITTER emitter = compiler.Emitter; DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null); SymUtil.EmitParentSym(emitter, aggTypeSym); SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null); emitter.EmitMethodDef(methodSym); Type parentType = aggTypeSym.Type; MethodInfo methodDefInfo = methodSym.MethodInfo; bool isGenericType = parentType.IsGenericType; bool isGenericMethod = methodDefInfo.IsGenericMethod; //-------------------------------------------------------- // (1-1) Non-generic Type, non-generic method //-------------------------------------------------------- if (!isGenericType && !isGenericMethod) { return(methodDefInfo); } //-------------------------------------------------------- // Parameter types //-------------------------------------------------------- TypeArray paramTypeArray = methodSym.ParameterTypes; TypeArray paramTypeArray2 = null; Type[] paramTypes = null; if (paramTypeArray != null && paramTypeArray.Count > 0) { paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray( paramTypeArray, aggTypeSym.AllTypeArguments, methTypeArguments, SubstTypeFlagsEnum.NormNone); paramTypes = SymUtil.GetSystemTypesFromTypeArray( paramTypeArray2, methodSym.ClassSym, methodSym); } else { paramTypes = Type.EmptyTypes; } //-------------------------------------------------------- // (1-2) Non-generic Type, generic method //-------------------------------------------------------- if (!isGenericType) { DebugUtil.Assert(methTypeArguments != null); Exception ex = null; Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray( methTypeArguments, methodSym.ClassSym, methodSym); return(ReflectionUtil.GetGenericMethod( methodDefInfo, typeArgs, out ex)); } //-------------------------------------------------------- // (2) Generic Type //-------------------------------------------------------- else { string methodName = methodDefInfo.Name; MethodInfo cstrMethInfo = null; Exception ex = null; try { cstrMethInfo = parentType.GetMethod(methodName, paramTypes); } catch (NotSupportedException) { cstrMethInfo = GetMethodInfo(parentType, methodDefInfo, out ex); } if (!isGenericMethod) { return(cstrMethInfo); } DebugUtil.Assert(methTypeArguments != null); Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray( methTypeArguments, methodSym.ClassSym, methodSym); return(ReflectionUtil.GetGenericMethod( cstrMethInfo, typeArgs, out ex)); } }
//------------------------------------------------------------ // ReflectionUtil.GetConstructedConstructorInfo // /// <summary></summary> /// <param name="compiler"></param> /// <param name="methodSym"></param> /// <param name="aggTypeSym"></param> /// <returns></returns> //------------------------------------------------------------ internal static ConstructorInfo GetConstructedConstructorInfo( COMPILER compiler, METHSYM methodSym, AGGTYPESYM aggTypeSym) { DebugUtil.Assert(compiler != null && compiler.Emitter != null); EMITTER emitter = compiler.Emitter; DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null); SymUtil.EmitParentSym(emitter, aggTypeSym); SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null); emitter.EmitMethodDef(methodSym); Type parentType = aggTypeSym.Type; ConstructorInfo cnstrDefInfo = methodSym.ConstructorInfo; DebugUtil.Assert(cnstrDefInfo != null); bool isGenericType = parentType.IsGenericType; //-------------------------------------------------------- // (1) Non-generic Type //-------------------------------------------------------- if (!isGenericType) { return(cnstrDefInfo); } //-------------------------------------------------------- // (2) Generic Type //-------------------------------------------------------- TypeArray paramTypeArray = methodSym.ParameterTypes; TypeArray paramTypeArray2 = null; Type[] paramTypes = null; if (paramTypeArray != null && paramTypeArray.Count > 0) { paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray( paramTypeArray, aggTypeSym.AllTypeArguments, null, SubstTypeFlagsEnum.NormNone); paramTypes = SymUtil.GetSystemTypesFromTypeArray( paramTypeArray2, methodSym.ClassSym, methodSym); } else { paramTypes = Type.EmptyTypes; } ConstructorInfo constructedInfo = null; Exception ex = null; try { constructedInfo = parentType.GetConstructor(paramTypes); } catch (NotSupportedException) { constructedInfo = GetConstructorInfo(parentType, cnstrDefInfo, out ex); } return(constructedInfo); }
//------------------------------------------------------------ // FUNCBREC.CreateAutoImplementedSetAccessor // /// <summary></summary> /// <param name="methodSym"></param> /// <returns></returns> //------------------------------------------------------------ internal EXPR CreateAutoImplementedSetAccessor(METHSYM methodSym) { CreateNewScope(); SCOPESYM scopeSym = this.currentScopeSym; this.currentScopeSym.ScopeFlags = SCOPEFLAGS.NONE; this.currentBlockExpr = NewExprBlock(treeNode); this.currentBlockExpr.ScopeSym = this.currentScopeSym; //-------------------------------------------------------- // Back filed //-------------------------------------------------------- SymWithType fieldSwt = new SymWithType(); AGGTYPESYM parentAts = methodSym.ParentAggSym.GetThisType(); fieldSwt.Set( methodSym.PropertySym.BackFieldSym, parentAts); EXPR fieldExpr = BindToField( null, BindThisImplicit(null), FieldWithType.Convert(fieldSwt), BindFlagsEnum.RValueRequired); //-------------------------------------------------------- // Parameter "value" //-------------------------------------------------------- // The SYM instance of parameter "value" is a LOCVARSYM instance, // and is created in CLSDREC.FillMethInfoCommon. LOCVARSYM locSym = Compiler.LocalSymbolManager.LookupLocalSym( Compiler.NameManager.GetPredefinedName(PREDEFNAME.VALUE), this.OuterScopeSym, SYMBMASK.LOCVARSYM) as LOCVARSYM; DebugUtil.Assert(locSym != null); SymWithType valueSwt = new SymWithType(); valueSwt.Set(locSym, null); EXPR valueExpr = BindToLocal(null, locSym, BindFlagsEnum.RValueRequired); //-------------------------------------------------------- // BackField = value //-------------------------------------------------------- EXPR assignExpr = NewExprBinop( null, EXPRKIND.ASSG, fieldExpr.TypeSym, fieldExpr, valueExpr); //-------------------------------------------------------- // Statement //-------------------------------------------------------- EXPRSTMTAS stmt = NewExpr(null, EXPRKIND.STMTAS, null) as EXPRSTMTAS; stmt.Expr = assignExpr; //-------------------------------------------------------- // Block //-------------------------------------------------------- this.currentBlockExpr.StatementsExpr = stmt; EXPRBLOCK blockExpr = this.currentBlockExpr; this.currentBlockExpr = blockExpr.OwingBlockExpr; CloseScope(); CorrectAnonMethScope(blockExpr.ScopeSym); return(blockExpr); }
//------------------------------------------------------------ // SecurityUtil.EmitSecurityAttributes (2) Method // /// <summary></summary> /// <param name="methodSym"></param> /// <param name="permissionSets"></param> //------------------------------------------------------------ internal static bool EmitSecurityAttributes( METHSYM methodSym, Dictionary <SecurityAction, PermissionSet> permissionSets, out Exception excp) { excp = null; bool rval = true; if (methodSym == null) { return(false); } if (permissionSets == null || permissionSets.Count == 0) { return(true); } foreach (KeyValuePair <SecurityAction, PermissionSet> kv in permissionSets) { switch (kv.Key) { case SecurityAction.Assert: case SecurityAction.Demand: case SecurityAction.Deny: case SecurityAction.InheritanceDemand: case SecurityAction.LinkDemand: case SecurityAction.PermitOnly: default: try { if (methodSym.MethodBuilder != null) { methodSym.MethodBuilder.AddDeclarativeSecurity(kv.Key, kv.Value); } else if (methodSym.ConstructorBuilder != null) { methodSym.ConstructorBuilder.AddDeclarativeSecurity(kv.Key, kv.Value); } else { // to do: set the message to excp. rval = false; } } catch (ArgumentException ex) { if (excp == null) { excp = ex; } rval = false; } catch (InvalidOperationException ex) { if (excp == null) { excp = ex; } rval = false; } break; case SecurityAction.RequestMinimum: case SecurityAction.RequestOptional: case SecurityAction.RequestRefuse: break; } } return(rval); }