public Lookup ( Microsoft.CSharp.RuntimeBinder.Semantics.CSemanticChecker checker, |
||
checker | Microsoft.CSharp.RuntimeBinder.Semantics.CSemanticChecker | |
typeSrc | ||
obj | ||
symWhere | Microsoft.CSharp.RuntimeBinder.Semantics.ParentSymbol | |
name | ||
arity | int | |
flags | MemLookFlags | |
return | bool |
///////////////////////////////////////////////////////////////////////////////// internal SymWithType LookupMember( string name, EXPR callingObject, ParentSymbol context, int arity, MemberLookup mem, bool allowSpecialNames, bool requireInvocable) { CType type = callingObject.type; if (type.IsArrayType()) { type = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_ARRAY); } if (type.IsNullableType()) { type = type.AsNullableType().GetAts(_semanticChecker.GetSymbolLoader().GetErrorContext()); } if (!mem.Lookup( _semanticChecker, type, callingObject, context, GetName(name), arity, MemLookFlags.TypeVarsAllowed | (allowSpecialNames ? 0 : MemLookFlags.UserCallable) | (name == SpecialNames.Indexer ? MemLookFlags.Indexer : 0) | (name == SpecialNames.Constructor ? MemLookFlags.Ctor : 0) | (requireInvocable ? MemLookFlags.MustBeInvocable : 0))) { return null; } return mem.SwtFirst(); }
protected EXPR bindIndexer(EXPR pObject, EXPR args, BindingFlag bindFlags) { CType type = pObject.type; if (!type.IsAggregateType() && !type.IsTypeParameterType()) { ErrorContext.Error(ErrorCode.ERR_BadIndexLHS, type); MethWithInst mwi = new MethWithInst(null, null); EXPRMEMGRP pMemGroup = GetExprFactory().CreateMemGroup(pObject, mwi); EXPRCALL rval = GetExprFactory().CreateCall(0, type, args, pMemGroup, null); rval.SetError(); return rval; } Name pName = GetSymbolLoader().GetNameManager().GetPredefName(PredefinedName.PN_INDEXERINTERNAL); MemberLookup mem = new MemberLookup(); if (!mem.Lookup(GetSemanticChecker(), type, pObject, ContextForMemberLookup(), pName, 0, (bindFlags & BindingFlag.BIND_BASECALL) != 0 ? (MemLookFlags.BaseCall | MemLookFlags.Indexer) : MemLookFlags.Indexer)) { mem.ReportErrors(); type = GetTypes().GetErrorSym(); Symbol pSymbol = null; if (mem.SwtInaccessible().Sym != null) { Debug.Assert(mem.SwtInaccessible().Sym.IsMethodOrPropertySymbol()); type = mem.SwtInaccessible().MethProp().RetType; pSymbol = mem.SwtInaccessible().Sym; } EXPRMEMGRP memgrp = null; if (pSymbol != null) { memgrp = GetExprFactory().CreateMemGroup((EXPRFLAG)mem.GetFlags(), pName, BSYMMGR.EmptyTypeArray(), pSymbol.getKind(), mem.GetSourceType(), null/*pMPS*/, mem.GetObject(), mem.GetResults()); memgrp.SetInaccessibleBit(); } else { MethWithInst mwi = new MethWithInst(null, null); memgrp = GetExprFactory().CreateMemGroup(mem.GetObject(), mwi); } EXPRCALL rval = GetExprFactory().CreateCall(0, type, args, memgrp, null); rval.SetError(); return rval; } Debug.Assert(mem.SymFirst().IsPropertySymbol() && mem.SymFirst().AsPropertySymbol().isIndexer()); EXPRMEMGRP grp = GetExprFactory().CreateMemGroup((EXPRFLAG)mem.GetFlags(), pName, BSYMMGR.EmptyTypeArray(), mem.SymFirst().getKind(), mem.GetSourceType(), null/*pMPS*/, mem.GetObject(), mem.GetResults()); EXPR pResult = BindMethodGroupToArguments(bindFlags, grp, args); Debug.Assert(pResult.HasObject()); if (pResult.getObject() == null) { // We must be in an error scenario where the object was not allowed. // This can happen if the user tries to access the indexer off the // type and not an instance or if the incorrect type/number of arguments // were passed for binding. pResult.SetObject(pObject); pResult.SetError(); } return pResult; }