Пример #1
0
        public static RuntimeBinderException Error(ErrorCode id, params ErrArg[] args)
        {
            // Create an argument array manually using the type information in the ErrArgs.
            string[] prgpsz  = new string[args.Length];
            int[]    prgiarg = new int[args.Length];

            int ppsz       = 0;
            int piarg      = 0;
            int cargUnique = 0;

            UserStringBuilder builder = new UserStringBuilder();

            for (int iarg = 0; iarg < args.Length; iarg++)
            {
                ErrArg arg = args[iarg];

                // If the NoStr bit is set we don't add it to prgpsz.
                if (0 != (arg.eaf & ErrArgFlags.NoStr))
                {
                    continue;
                }


                if (!builder.ErrArgToString(out prgpsz[ppsz], arg, out bool fUserStrings))
                {
                    if (arg.eak == ErrArgKind.Int)
                    {
                        prgpsz[ppsz] = arg.n.ToString(CultureInfo.InvariantCulture);
                    }
                }
                ppsz++;

                int iargRec;
                if (!fUserStrings || 0 == (arg.eaf & ErrArgFlags.Unique))
                {
                    iargRec = -1;
                }
                else
                {
                    iargRec = iarg;
                    cargUnique++;
                }
                prgiarg[piarg] = iargRec;
                piarg++;
            }

            int cpsz = ppsz;

            if (cargUnique > 1)
            {
                // Copy the strings over to another buffer.
                string[] prgpszNew = new string[cpsz];
                Array.Copy(prgpsz, 0, prgpszNew, 0, cpsz);

                for (int i = 0; i < cpsz; i++)
                {
                    if (prgiarg[i] < 0 || prgpszNew[i] != prgpsz[i])
                    {
                        continue;
                    }

                    ErrArg arg = args[prgiarg[i]];
                    Debug.Assert(0 != (arg.eaf & ErrArgFlags.Unique) && 0 == (arg.eaf & ErrArgFlags.NoStr));

                    Symbol sym   = null;
                    CType  pType = null;

                    switch (arg.eak)
                    {
                    case ErrArgKind.Sym:
                        sym = arg.sym;
                        break;

                    case ErrArgKind.Type:
                        pType = arg.pType;
                        break;

                    case ErrArgKind.SymWithType:
                        sym = arg.swtMemo.sym;
                        break;

                    case ErrArgKind.MethWithInst:
                        sym = arg.mpwiMemo.sym;
                        break;

                    default:
                        Debug.Assert(false, "Shouldn't be here!");
                        continue;
                    }

                    bool fMunge = false;

                    for (int j = i + 1; j < cpsz; j++)
                    {
                        if (prgiarg[j] < 0)
                        {
                            continue;
                        }
                        Debug.Assert(0 != (args[prgiarg[j]].eaf & ErrArgFlags.Unique));
                        if (prgpsz[i] != prgpsz[j])
                        {
                            continue;
                        }

                        // The strings are identical. If they are the same symbol, leave them alone.
                        // Otherwise, munge both strings. If j has already been munged, just make
                        // sure we munge i.
                        if (prgpszNew[j] != prgpsz[j])
                        {
                            fMunge = true;
                            continue;
                        }

                        ErrArg arg2 = args[prgiarg[j]];
                        Debug.Assert(0 != (arg2.eaf & ErrArgFlags.Unique) && 0 == (arg2.eaf & ErrArgFlags.NoStr));

                        Symbol sym2   = null;
                        CType  pType2 = null;

                        switch (arg2.eak)
                        {
                        case ErrArgKind.Sym:
                            sym2 = arg2.sym;
                            break;

                        case ErrArgKind.Type:
                            pType2 = arg2.pType;
                            break;

                        case ErrArgKind.SymWithType:
                            sym2 = arg2.swtMemo.sym;
                            break;

                        case ErrArgKind.MethWithInst:
                            sym2 = arg2.mpwiMemo.sym;
                            break;

                        default:
                            Debug.Assert(false, "Shouldn't be here!");
                            continue;
                        }

                        if (sym2 == sym && pType2 == pType && !fMunge)
                        {
                            continue;
                        }


                        prgpszNew[j] = prgpsz[j];

                        fMunge = true;
                    }

                    if (fMunge)
                    {
                        prgpszNew[i] = prgpsz[i];
                    }
                }

                prgpsz = prgpszNew;
            }

            return(new RuntimeBinderException(string.Format(CultureInfo.InvariantCulture, ErrorFacts.GetMessage(id), prgpsz)));
        }
Пример #2
0
 public void checkUnsafe(CType type, ErrorCode errCode, ErrArg pArg)
 {
     Debug.Assert((errCode != ErrorCode.ERR_SizeofUnsafe) || pArg != null);
     if (type == null || type.isUnsafe())
     {
         if (!isUnsafeContext() && ReportUnsafeErrors())
         {
             if (pArg != null)
                 ErrorContext.Error(errCode, pArg);
             else
                 ErrorContext.Error(errCode);
         }
         RecordUnsafeUsage();
     }
 }
Пример #3
0
        // Returns true if the argument could be converted to a string.
        public bool ErrArgToString(out string psz, ErrArg parg, out bool fUserStrings)
        {
            fUserStrings = false;
            psz          = null;
            bool result = true;

            switch (parg.eak)
            {
            case ErrArgKind.Ids:
                ErrId(out psz, parg.ids);
                break;

            case ErrArgKind.SymKind:
                ErrSK(out psz, parg.sk);
                break;

            case ErrArgKind.Type:
                BeginString();
                ErrAppendType(parg.pType, null);
                EndString(out psz);
                fUserStrings = true;
                break;

            case ErrArgKind.Sym:
                BeginString();
                ErrAppendSym(parg.sym, null);
                EndString(out psz);
                fUserStrings = true;
                break;

            case ErrArgKind.Name:
                if (parg.name == NameManager.GetPredefinedName(PredefinedName.PN_INDEXERINTERNAL))
                {
                    psz = "this";
                }
                else
                {
                    psz = parg.name.Text;
                }
                break;

            case ErrArgKind.Str:
                psz = parg.psz;
                break;

            case ErrArgKind.SymWithType:
            {
                SubstContext ctx = new SubstContext(parg.swtMemo.ats, null);
                BeginString();
                ErrAppendSym(parg.swtMemo.sym, ctx, true);
                EndString(out psz);
                fUserStrings = true;
                break;
            }

            case ErrArgKind.MethWithInst:
            {
                SubstContext ctx = new SubstContext(parg.mpwiMemo.ats, parg.mpwiMemo.typeArgs);
                BeginString();
                ErrAppendSym(parg.mpwiMemo.sym, ctx, true);
                EndString(out psz);
                fUserStrings = true;
                break;
            }

            default:
                result = false;
                break;
            }

            return(result);
        }
        public CError RealizeError(CParameterizedError parameterizedError)
        {
            // Create an arg array manually using the type information in the ErrArgs.
            string[] prgpsz  = new string[parameterizedError.GetParameterCount()];
            int[]    prgiarg = new int[parameterizedError.GetParameterCount()];

            int ppsz       = 0;
            int piarg      = 0;
            int cargUnique = 0;

            m_userStringBuilder.ResetUndisplayableStringFlag();

            for (int iarg = 0; iarg < parameterizedError.GetParameterCount(); iarg++)
            {
                ErrArg arg = parameterizedError.GetParameter(iarg);

                // If the NoStr bit is set we don't add it to prgpsz.
                if (0 != (arg.eaf & ErrArgFlags.NoStr))
                {
                    continue;
                }

                bool fUserStrings = false;

                if (!m_userStringBuilder.ErrArgToString(out prgpsz[ppsz], arg, out fUserStrings))
                {
                    if (arg.eak == ErrArgKind.Int)
                    {
                        prgpsz[ppsz] = arg.n.ToString(CultureInfo.InvariantCulture);
                    }
                }
                ppsz++;

                int iargRec;
                if (!fUserStrings || 0 == (arg.eaf & ErrArgFlags.Unique))
                {
                    iargRec = -1;
                }
                else
                {
                    iargRec = iarg;
                    cargUnique++;
                }
                prgiarg[piarg] = iargRec;
                piarg++;
            }

            // don't ever display undisplayable strings to the user
            // if this happens we should track down the caller to not display the error
            // this should only ever occur in a cascading error situation due to
            // error tolerance
            if (m_userStringBuilder.HadUndisplayableString())
            {
                return(null);
            }

            int cpsz = ppsz;

            if (cargUnique > 1)
            {
                // Copy the strings over to another buffer.
                string[] prgpszNew = new string[cpsz];
                Array.Copy(prgpsz, 0, prgpszNew, 0, cpsz);;

                for (int i = 0; i < cpsz; i++)
                {
                    if (prgiarg[i] < 0 || prgpszNew[i] != prgpsz[i])
                    {
                        continue;
                    }

                    ErrArg arg = parameterizedError.GetParameter(prgiarg[i]);
                    Debug.Assert(0 != (arg.eaf & ErrArgFlags.Unique) && 0 == (arg.eaf & ErrArgFlags.NoStr));

                    Symbol sym   = null;
                    CType  pType = null;

                    switch (arg.eak)
                    {
                    case ErrArgKind.Sym:
                        sym = arg.sym;
                        break;

                    case ErrArgKind.Type:
                        pType = arg.pType;
                        break;

                    case ErrArgKind.SymWithType:
                        sym = arg.swtMemo.sym;
                        break;

                    case ErrArgKind.MethWithInst:
                        sym = arg.mpwiMemo.sym;
                        break;

                    default:
                        Debug.Assert(false, "Shouldn't be here!");
                        continue;
                    }

                    bool fMunge = false;

                    for (int j = i + 1; j < cpsz; j++)
                    {
                        if (prgiarg[j] < 0)
                        {
                            continue;
                        }
                        Debug.Assert(0 != (parameterizedError.GetParameter(prgiarg[j]).eaf & ErrArgFlags.Unique));
                        if (prgpsz[i] != prgpsz[j])
                        {
                            continue;
                        }

                        // The strings are identical. If they are the same symbol, leave them alone.
                        // Otherwise, munge both strings. If j has already been munged, just make
                        // sure we munge i.
                        if (prgpszNew[j] != prgpsz[j])
                        {
                            fMunge = true;
                            continue;
                        }

                        ErrArg arg2 = parameterizedError.GetParameter(prgiarg[j]);
                        Debug.Assert(0 != (arg2.eaf & ErrArgFlags.Unique) && 0 == (arg2.eaf & ErrArgFlags.NoStr));

                        Symbol sym2   = null;
                        CType  pType2 = null;

                        switch (arg2.eak)
                        {
                        case ErrArgKind.Sym:
                            sym2 = arg2.sym;
                            break;

                        case ErrArgKind.Type:
                            pType2 = arg2.pType;
                            break;

                        case ErrArgKind.SymWithType:
                            sym2 = arg2.swtMemo.sym;
                            break;

                        case ErrArgKind.MethWithInst:
                            sym2 = arg2.mpwiMemo.sym;
                            break;

                        default:
                            Debug.Assert(false, "Shouldn't be here!");
                            continue;
                        }

                        if (sym2 == sym && pType2 == pType && !fMunge)
                        {
                            continue;
                        }


                        prgpszNew[j] = prgpsz[j];

                        fMunge = true;
                    }

                    if (fMunge)
                    {
                        prgpszNew[i] = prgpsz[i];
                    }
                }

                prgpsz = prgpszNew;
            }

            CError err = CreateError(parameterizedError.GetErrorNumber(), prgpsz);

            return(err);
        }
Пример #5
0
        // Returns true if the argument could be converted to a string.
        public bool ErrArgToString(out string psz, ErrArg parg, out bool fUserStrings)
        {
            fUserStrings = false;
            psz = null;
            bool result = true;

            switch (parg.eak)
            {
                case ErrArgKind.Ids:
                    ErrId(out psz, parg.ids);
                    break;
                case ErrArgKind.SymKind:
                    ErrSK(out psz, parg.sk);
                    break;
                case ErrArgKind.Type:
                    BeginString();
                    ErrAppendType(parg.pType, null);
                    EndString(out psz);
                    fUserStrings = true;
                    break;
                case ErrArgKind.Sym:
                    BeginString();
                    ErrAppendSym(parg.sym, null);
                    EndString(out psz);
                    fUserStrings = true;
                    break;
                case ErrArgKind.Name:
                    if (parg.name == GetNameManager().GetPredefinedName(PredefinedName.PN_INDEXERINTERNAL))
                    {
                        psz = "this";
                    }
                    else
                    {
                        psz = parg.name.Text;
                    }
                    break;

                case ErrArgKind.Str:
                    psz = parg.psz;
                    break;
                case ErrArgKind.PredefName:
                    BeginString();
                    ErrAppendName(GetNameManager().GetPredefName(parg.pdn));
                    EndString(out psz);
                    break;
                case ErrArgKind.SymWithType:
                    {
                        SubstContext ctx = new SubstContext(parg.swtMemo.ats, null);
                        BeginString();
                        ErrAppendSym(parg.swtMemo.sym, ctx, true);
                        EndString(out psz);
                        fUserStrings = true;
                        break;
                    }

                case ErrArgKind.MethWithInst:
                    {
                        SubstContext ctx = new SubstContext(parg.mpwiMemo.ats, parg.mpwiMemo.typeArgs);
                        BeginString();
                        ErrAppendSym(parg.mpwiMemo.sym, ctx, true);
                        EndString(out psz);
                        fUserStrings = true;
                        break;
                    }
                default:
                    result = false;
                    break;
            }

            return result;
        }
Пример #6
0
 private void ErrorTreeArgs(ErrorCode id, ErrArg[] prgarg)
 {
     CParameterizedError error;
     MakeErrorTreeArgs(out error, id, prgarg);
     SubmitError(error);
 }
Пример #7
0
 private void MakeErrorTreeArgs(out CParameterizedError error, ErrorCode id, ErrArg[] prgarg)
 {
     MakeErrorLocArgs(out error, id, prgarg);
 }
Пример #8
0
 public void MakeErrorLocArgs(out CParameterizedError error, ErrorCode id, ErrArg[] prgarg)
 {
     error = new CParameterizedError();
     error.Initialize(id, prgarg);
 }