1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Diagnostics; 7 using Microsoft.CSharp.RuntimeBinder.Semantics; 8 using Microsoft.CSharp.RuntimeBinder.Syntax; 9 10 namespace Microsoft.CSharp.RuntimeBinder.Errors 11 { 12 // Things related to the construction of a formatted error. Reporting 13 // an error involves constructing a formatted message, and then passing 14 // that message on to an object that gets it to the user. The interface 15 // that declares the error submission API is separate from this. 16 17 internal enum ErrArgKind 18 { 19 Int, 20 SymKind, 21 Sym, 22 Type, 23 Name, 24 Str, 25 SymWithType, 26 MethWithInst, 27 } 28 29 [Flags] 30 internal enum ErrArgFlags 31 { 32 None = 0x0000, 33 NoStr = 0x0002, // The arg should NOT be included in the error message, just the location 34 Unique = 0x0004, // The string should be distinct from other args marked with Unique 35 UseGetErrorInfo = 0x0008, 36 } 37 38 internal sealed class SymWithTypeMemo 39 { 40 public Symbol sym; 41 public AggregateType ats; 42 } 43 44 internal sealed class MethPropWithInstMemo 45 { 46 public Symbol sym; 47 public AggregateType ats; 48 public TypeArray typeArgs; 49 } 50 51 internal class ErrArg 52 { 53 public ErrArgKind eak; 54 public ErrArgFlags eaf; 55 internal int n; 56 internal SYMKIND sk; 57 internal Name name; 58 internal Symbol sym; 59 internal string psz; 60 internal CType pType; 61 internal MethPropWithInstMemo mpwiMemo; 62 internal SymWithTypeMemo swtMemo; 63 ErrArg()64 public ErrArg() 65 { 66 } 67 ErrArg(int n)68 public ErrArg(int n) 69 { 70 this.eak = ErrArgKind.Int; 71 this.eaf = ErrArgFlags.None; 72 this.n = n; 73 } 74 ErrArg(Name name)75 public ErrArg(Name name) 76 { 77 this.eak = ErrArgKind.Name; 78 this.eaf = ErrArgFlags.None; 79 this.name = name; 80 } 81 ErrArg(string psz)82 public ErrArg(string psz) 83 { 84 this.eak = ErrArgKind.Str; 85 this.eaf = ErrArgFlags.None; 86 this.psz = psz; 87 } 88 ErrArg(CType pType)89 public ErrArg(CType pType) 90 : this(pType, ErrArgFlags.None) 91 { 92 } 93 ErrArg(CType pType, ErrArgFlags eaf)94 public ErrArg(CType pType, ErrArgFlags eaf) 95 { 96 this.eak = ErrArgKind.Type; 97 this.eaf = eaf; 98 this.pType = pType; 99 } 100 ErrArg(Symbol pSym)101 public ErrArg(Symbol pSym) 102 : this(pSym, ErrArgFlags.None) 103 { 104 } 105 ErrArg(Symbol pSym, ErrArgFlags eaf)106 private ErrArg(Symbol pSym, ErrArgFlags eaf) 107 { 108 this.eak = ErrArgKind.Sym; 109 this.eaf = eaf; 110 this.sym = pSym; 111 } ErrArg(SymWithType swt)112 public ErrArg(SymWithType swt) 113 { 114 this.eak = ErrArgKind.SymWithType; 115 this.eaf = ErrArgFlags.None; 116 this.swtMemo = new SymWithTypeMemo(); 117 this.swtMemo.sym = swt.Sym; 118 this.swtMemo.ats = swt.Ats; 119 } ErrArg(MethPropWithInst mpwi)120 public ErrArg(MethPropWithInst mpwi) 121 { 122 this.eak = ErrArgKind.MethWithInst; 123 this.eaf = ErrArgFlags.None; 124 this.mpwiMemo = new MethPropWithInstMemo(); 125 this.mpwiMemo.sym = mpwi.Sym; 126 this.mpwiMemo.ats = mpwi.Ats; 127 this.mpwiMemo.typeArgs = mpwi.TypeArgs; 128 } operator ErrArg(int n)129 public static implicit operator ErrArg(int n) 130 { 131 return new ErrArg(n); 132 } operator ErrArg(CType type)133 public static implicit operator ErrArg(CType type) 134 { 135 return new ErrArg(type); 136 } operator ErrArg(string psz)137 public static implicit operator ErrArg(string psz) 138 { 139 return new ErrArg(psz); 140 } operator ErrArg(Name name)141 public static implicit operator ErrArg(Name name) 142 { 143 return new ErrArg(name); 144 } operator ErrArg(Symbol pSym)145 public static implicit operator ErrArg(Symbol pSym) 146 { 147 return new ErrArg(pSym); 148 } operator ErrArg(SymWithType swt)149 public static implicit operator ErrArg(SymWithType swt) 150 { 151 return new ErrArg(swt); 152 } operator ErrArg(MethPropWithInst mpwi)153 public static implicit operator ErrArg(MethPropWithInst mpwi) 154 { 155 return new ErrArg(mpwi); 156 } 157 } 158 159 internal sealed class ErrArgRefOnly : ErrArg 160 { ErrArgRefOnly(Symbol sym)161 public ErrArgRefOnly(Symbol sym) 162 : base(sym) 163 { 164 eaf = ErrArgFlags.NoStr; 165 } 166 } 167 168 // This is used with COMPILER_BASE::ErrorRef to indicate no reference. 169 internal sealed class ErrArgNoRef : ErrArg 170 { ErrArgNoRef(CType pType)171 public ErrArgNoRef(CType pType) 172 { 173 this.eak = ErrArgKind.Type; 174 this.eaf = ErrArgFlags.None; 175 this.pType = pType; 176 } 177 } 178 179 internal sealed class ErrArgSymKind : ErrArg 180 { ErrArgSymKind(Symbol sym)181 public ErrArgSymKind(Symbol sym) 182 { 183 eak = ErrArgKind.SymKind; 184 eaf = ErrArgFlags.None; 185 sk = sym.getKind(); 186 } 187 } 188 } 189