private AggregateSymbol FindPredefinedType(ErrorHandling errorContext, string pszType, KAID aid, AggKindEnum aggKind, int arity, bool isRequired)
{
Debug.Assert(!string.IsNullOrEmpty(pszType)); // Shouldn't be the empty string!
NamespaceOrAggregateSymbol bagCur = _pBSymmgr.GetRootNS();
Name name = null;
string[] nameParts = pszType.Split(s_nameSeparators);
for (int i = 0, n = nameParts.Length; i < n; i++)
{
name = _pBSymmgr.GetNameManager().Add(nameParts[i]);
if (i == n - 1)
{
// This is the last component. Handle it special below.
break;
}
// first search for an outer type which is also predefined
// this must be first because we always create a namespace for
// outer names, even for nested types
AggregateSymbol aggNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol();
if (aggNext != null && aggNext.InAlias(aid) && aggNext.IsPredefined())
{
bagCur = aggNext;
}
else
{
// ... if no outer type, then search for namespaces
NamespaceSymbol nsNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol();
bool bIsInAlias = true;
if (nsNext == null)
{
bIsInAlias = false;
}
else
{
bIsInAlias = nsNext.InAlias(aid);
}
if (!bIsInAlias)
{
// Didn't find the namespace in this aid.
if (isRequired)
{
errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
}
return null;
}
bagCur = nsNext;
}
}
AggregateSymbol aggAmbig;
AggregateSymbol aggBad;
AggregateSymbol aggFound = FindPredefinedTypeCore(name, bagCur, aid, aggKind, arity, out aggAmbig, out aggBad);
if (aggFound == null)
{
// Didn't find the AggregateSymbol.
if (aggBad != null && (isRequired || aid == KAID.kaidGlobal && aggBad.IsSource()))
errorContext.ErrorRef(ErrorCode.ERR_PredefinedTypeBadType, aggBad);
else if (isRequired)
errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
return null;
}
if (aggAmbig == null && aid != KAID.kaidGlobal)
{
// Look in kaidGlobal to make sure there isn't a conflicting one.
AggregateSymbol tmp;
AggregateSymbol agg2 = FindPredefinedTypeCore(name, bagCur, KAID.kaidGlobal, aggKind, arity, out aggAmbig, out tmp);
Debug.Assert(agg2 != null);
if (agg2 != aggFound)
aggAmbig = agg2;
}
return aggFound;
}