//////////////////////////////////////////////////////////////////////////////// // Construct a compiler. All the real work is done in the Init() routine. This // primary initializes all the sub-components. public LangCompiler(CController pCtrl, NameManager pNameMgr) { Debug.Assert(pCtrl != null); _pController = pCtrl; _globalSymbolContext = new GlobalSymbolContext(pNameMgr); _userStringBuilder = new UserStringBuilder(_globalSymbolContext); _errorContext = new ErrorHandling(_userStringBuilder, this, pCtrl.GetErrorFactory()); _symbolLoader = new SymbolLoader(_globalSymbolContext, null, _errorContext); }
public ErrorHandling( UserStringBuilder strBldr, IErrorSink sink, CErrorFactory factory) { Debug.Assert(factory != null); m_userStringBuilder = strBldr; m_errorSink = sink; m_errorFactory = factory; }
public ErrorHandling( UserStringBuilder strBldr, IErrorSink sink, CErrorFactory factory) { Debug.Assert(factory != null); _userStringBuilder = strBldr; _errorSink = sink; _errorFactory = factory; }
public SymbolLoader( GlobalSymbolContext globalSymbols, UserStringBuilder userStringBuilder, ErrorHandling errorContext ) { _nameManager = globalSymbols.GetNameManager(); PredefinedMembers = new PredefinedMembers(this); ErrorContext = errorContext; GlobalSymbolContext = globalSymbols; Debug.Assert(GlobalSymbolContext != null); }
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))); }
public ErrorHandling(GlobalSymbolContext globalSymbols) { _userStringBuilder = new UserStringBuilder(globalSymbols); }