PageRenderTime 71ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Boo.Lang.Compiler/CompilerErrorFactory.cs

http://github.com/bamboo/boo
C# | 1052 lines | 830 code | 197 blank | 25 comment | 13 complexity | 5d2585a58773f5df8cebe4164c442764 MD5 | raw file
Possible License(s): GPL-2.0
  1. #region license
  2. // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without modification,
  6. // are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Rodrigo B. de Oliveira nor the names of its
  14. // contributors may be used to endorse or promote products derived from this
  15. // software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #endregion
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Text;
  32. using Boo.Lang.Compiler.Ast;
  33. using Boo.Lang.Compiler.Services;
  34. using Boo.Lang.Compiler.TypeSystem;
  35. using Boo.Lang.Environments;
  36. using Boo.Lang.Resources;
  37. namespace Boo.Lang.Compiler
  38. {
  39. public static class CompilerErrorFactory
  40. {
  41. public static CompilerError CustomError(Node anchor, string msg)
  42. {
  43. return CustomError(AstUtil.SafeLexicalInfo(anchor), msg);
  44. }
  45. public static CompilerError CustomError(LexicalInfo lexicalInfo, string msg)
  46. {
  47. return new CompilerError(lexicalInfo, msg);
  48. }
  49. public static CompilerError CustomError(string msg)
  50. {
  51. return new CompilerError(msg);
  52. }
  53. public static CompilerError ClassAlreadyHasBaseType(Node node, string className, IType baseType)
  54. {
  55. return Instantiate("BCE0001", node, className, baseType);
  56. }
  57. public static CompilerError NamedParameterMustBeIdentifier(ExpressionPair pair)
  58. {
  59. return Instantiate("BCE0002", pair.First);
  60. }
  61. public static CompilerError NamedArgumentsNotAllowed(Node node)
  62. {
  63. return Instantiate("BCE0003", node);
  64. }
  65. public static CompilerError AmbiguousReference(ReferenceExpression reference, System.Reflection.MemberInfo[] members)
  66. {
  67. return Instantiate("BCE0004", reference, reference.Name, ToNameList(members));
  68. }
  69. public static CompilerError AmbiguousReference(Node node, string name, IEnumerable<IEntity> entities)
  70. {
  71. return Instantiate("BCE0004", node, name, ToStringList(entities));
  72. }
  73. public static CompilerError UnknownIdentifier(Node node, string name)
  74. {
  75. return Instantiate("BCE0005", node, name);
  76. }
  77. public static CompilerError CantCastToValueType(Node node, IType typeName)
  78. {
  79. return Instantiate("BCE0006", node, typeName);
  80. }
  81. public static CompilerError NotAPublicFieldOrProperty(Node node, string name, IType type)
  82. {
  83. return Instantiate("BCE0007", node, name, type);
  84. }
  85. public static CompilerError MissingConstructor(Exception error, Node node, Type type, object[] parameters)
  86. {
  87. return Instantiate("BCE0008", node, error, type, GetSignature(parameters));
  88. }
  89. public static CompilerError AttributeApplicationError(Exception error, Ast.Attribute attribute, Type attributeType)
  90. {
  91. return Instantiate("BCE0009", attribute, error, attributeType, error.Message);
  92. }
  93. public static CompilerError AstAttributeMustBeExternal(Node node, IType attributeType)
  94. {
  95. return Instantiate("BCE0010", node, attributeType);
  96. }
  97. public static CompilerError StepExecutionError(Exception error, ICompilerStep step)
  98. {
  99. return Instantiate("BCE0011", error, step, error.Message);
  100. }
  101. public static CompilerError TypeMustImplementICompilerStep(string typeName)
  102. {
  103. return Instantiate("BCE0012", LexicalInfo.Empty, typeName);
  104. }
  105. public static CompilerError AttributeNotFound(string elementName, string attributeName)
  106. {
  107. return Instantiate("BCE0013", LexicalInfo.Empty, elementName, attributeName);
  108. }
  109. public static CompilerError InvalidAssemblySetUp(Node node)
  110. {
  111. return Instantiate("BCE0014", node);
  112. }
  113. public static CompilerError InvalidNode(Node node)
  114. {
  115. return Instantiate("BCE0015", node, node);
  116. }
  117. public static CompilerError MethodArgumentCount(Node node, string name, int count)
  118. {
  119. return Instantiate("BCE0016", node, name, count);
  120. }
  121. public static CompilerError MethodSignature(Node node, IEntity expectedSignature, string actualSignature)
  122. {
  123. return Instantiate("BCE0017", node, expectedSignature, actualSignature);
  124. }
  125. public static CompilerError NameNotType(Node node, string typeName, IEntity whatItIs, string suggestion)
  126. {
  127. return Instantiate("BCE0018", node, typeName, whatItIs == null ? "not found" : (object)whatItIs, DidYouMeanOrNull(suggestion));
  128. }
  129. public static CompilerError MemberNotFound(MemberReferenceExpression node, INamespace @namespace, string suggestion)
  130. {
  131. return MemberNotFound(node, node.Name, @namespace, suggestion);
  132. }
  133. public static CompilerError MemberNotFound(Node node, string memberName, INamespace @namespace, string suggestion)
  134. {
  135. return Instantiate("BCE0019", node, memberName, @namespace, DidYouMeanOrNull(suggestion));
  136. }
  137. public static CompilerError InstanceRequired(Node node, IMember member)
  138. {
  139. return Instantiate("BCE0020", node, member.DeclaringType, member.Name);
  140. }
  141. public static CompilerError InvalidNamespace(Import import)
  142. {
  143. if (import.AssemblyReference != null)
  144. return Instantiate("BCE0167", import.Expression, import.Namespace, import.AssemblyReference);
  145. return Instantiate("BCE0021", import.Expression, import.Namespace);
  146. }
  147. public static CompilerError IncompatibleExpressionType(Node node, IType expectedType, IType actualType)
  148. {
  149. return Instantiate("BCE0022", node, expectedType, actualType);
  150. }
  151. public static CompilerError NoApropriateOverloadFound(Node node, string signature, string memberName)
  152. {
  153. return Instantiate("BCE0023", node, signature, memberName);
  154. }
  155. public static CompilerError NoApropriateConstructorFound(Node node, IType typeName, string signature)
  156. {
  157. return Instantiate("BCE0024", node, typeName, signature);
  158. }
  159. public static CompilerError InvalidArray(Node node)
  160. {
  161. return Instantiate("BCE0025", node);
  162. }
  163. public static CompilerError BoolExpressionRequired(Node node, IType typeName)
  164. {
  165. return Instantiate("BCE0026", node, typeName);
  166. }
  167. public static CompilerError NoEntryPoint()
  168. {
  169. return Instantiate("BCE0028", LexicalInfo.Empty);
  170. }
  171. public static CompilerError MoreThanOneEntryPoint(Method method)
  172. {
  173. return Instantiate("BCE0029", method);
  174. }
  175. public static CompilerError NotImplemented(Node node, string message)
  176. {
  177. return Instantiate("BCE0031", node, message);
  178. }
  179. public static CompilerError EventArgumentMustBeAMethod(Node node, ITypedEntity eventMember)
  180. {
  181. return Instantiate("BCE0032", node, eventMember, eventMember.Type, LanguageAmbiance.CallableKeyword);
  182. }
  183. public static CompilerError TypeNotAttribute(Node node, IType attributeType)
  184. {
  185. return Instantiate("BCE0033", node, attributeType);
  186. }
  187. public static CompilerError ExpressionMustBeExecutedForItsSideEffects(Node node)
  188. {
  189. return Instantiate("BCE0034", node);
  190. }
  191. public static CompilerError ConflictWithInheritedMember(Node node, IMember member, IMember baseMember)
  192. {
  193. return Instantiate("BCE0035", node, member, baseMember);
  194. }
  195. public static CompilerError InvalidTypeof(Node node)
  196. {
  197. return Instantiate("BCE0036", node);
  198. }
  199. public static CompilerError UnknownMacro(Node node, string name)
  200. {
  201. return Instantiate("BCE0037", node, name);
  202. }
  203. public static CompilerError InvalidMacro(Node node, IType type)
  204. {
  205. return Instantiate("BCE0038", node, type);
  206. }
  207. public static CompilerError AstMacroMustBeExternal(Node node, IType type)
  208. {
  209. return Instantiate("BCE0039", node, type);
  210. }
  211. public static CompilerError UnableToLoadAssembly(Node node, string name, Exception error)
  212. {
  213. return Instantiate("BCE0041", node, error, name);
  214. }
  215. public static CompilerError InputError(string inputName, Exception error)
  216. {
  217. return InputError(new LexicalInfo(inputName), error);
  218. }
  219. public static CompilerError InputError(LexicalInfo lexicalInfo, Exception error)
  220. {
  221. return Instantiate("BCE0042", lexicalInfo, error, lexicalInfo.FileName, error.Message);
  222. }
  223. public static CompilerError UnexpectedToken(LexicalInfo lexicalInfo, Exception error, string token)
  224. {
  225. return Instantiate("BCE0043", lexicalInfo, error, token);
  226. }
  227. public static CompilerError GenericParserError(LexicalInfo lexicalInfo, Exception error)
  228. {
  229. return Instantiate("BCE0044", lexicalInfo, error, error.Message);
  230. }
  231. public static CompilerError MacroExpansionError(Node node, Exception error)
  232. {
  233. return Instantiate("BCE0045", node, error, error.Message);
  234. }
  235. public static CompilerError MacroExpansionError(Node node)
  236. {
  237. return Instantiate("BCE0045", node, StringResources.BooC_InvalidNestedMacroContext);
  238. }
  239. public static CompilerError OperatorCantBeUsedWithValueType(Node node, string operatorName, IType typeName)
  240. {
  241. return Instantiate("BCE0046", node, operatorName, typeName);
  242. }
  243. public static CompilerError CantOverrideNonVirtual(Node node, IMethod method)
  244. {
  245. return Instantiate("BCE0047", node, method);
  246. }
  247. public static CompilerError TypeDoesNotSupportSlicing(Node node, IType fullName)
  248. {
  249. return Instantiate("BCE0048", node, fullName);
  250. }
  251. public static CompilerError LValueExpected(Node node)
  252. {
  253. return Instantiate("BCE0049", node, StripSurroundingParens(node.ToCodeString()));
  254. }
  255. public static CompilerError InvalidOperatorForType(Node node, string operatorName, IType typeName)
  256. {
  257. return Instantiate("BCE0050", node, operatorName, typeName);
  258. }
  259. public static CompilerError InvalidOperatorForTypes(Node node, string operatorName, IType lhs, IType rhs)
  260. {
  261. return Instantiate("BCE0051", node, operatorName, lhs, rhs);
  262. }
  263. public static CompilerError InvalidLen(Node node, IType typeName)
  264. {
  265. return Instantiate("BCE0052", node, typeName);
  266. }
  267. public static CompilerError PropertyIsReadOnly(Node node, IProperty property)
  268. {
  269. return Instantiate("BCE0053", node, property);
  270. }
  271. public static CompilerError IsaArgument(Node node)
  272. {
  273. return Instantiate("BCE0054", node, LanguageAmbiance.IsaKeyword);
  274. }
  275. public static CompilerError InternalError(Node node, Exception error)
  276. {
  277. string message = error != null ? error.Message : string.Empty;
  278. return InternalError(node, message, error);
  279. }
  280. public static CompilerError InternalError(Node node, string message, Exception cause)
  281. {
  282. return Instantiate("BCE0055", node, cause, message);
  283. }
  284. public static CompilerError FileNotFound(string fname)
  285. {
  286. return Instantiate("BCE0056", new LexicalInfo(fname), fname);
  287. }
  288. public static CompilerError CantRedefinePrimitive(Node node, string name)
  289. {
  290. return Instantiate("BCE0057", node, name);
  291. }
  292. public static CompilerError SelfIsNotValidInStaticMember(Node node)
  293. {
  294. return Instantiate("BCE0058", node, SelfKeyword);
  295. }
  296. private static string SelfKeyword
  297. {
  298. get { return LanguageAmbiance.SelfKeyword; }
  299. }
  300. private static LanguageAmbiance LanguageAmbiance
  301. {
  302. get { return My<LanguageAmbiance>.Instance; }
  303. }
  304. public static CompilerError InvalidLockMacroArguments(Node node)
  305. {
  306. return Instantiate("BCE0059", node);
  307. }
  308. public static CompilerError NoMethodToOverride(Node node, IMethod signature, bool incompatibleSignature)
  309. {
  310. return Instantiate("BCE0060", node, signature,
  311. incompatibleSignature ? StringResources.BCE0060_IncompatibleSignature : null);
  312. }
  313. public static CompilerError NoMethodToOverride(Node node, IMethod signature, string suggestion)
  314. {
  315. return Instantiate("BCE0060", node, signature, DidYouMeanOrNull(suggestion));
  316. }
  317. public static CompilerError MethodIsNotOverride(Node node, IMethod method)
  318. {
  319. return Instantiate("BCE0061", node, method);
  320. }
  321. public static CompilerError CouldNotInferReturnType(Node node, string signature)
  322. {
  323. return Instantiate("BCE0062", node, signature);
  324. }
  325. public static CompilerError NoEnclosingLoop(Node node)
  326. {
  327. return Instantiate("BCE0063", node);
  328. }
  329. public static CompilerError UnknownAttribute(Node node, string attributeName, string suggestion)
  330. {
  331. return Instantiate("BCE0064", node, attributeName, DidYouMeanOrNull(suggestion));
  332. }
  333. public static CompilerError InvalidIteratorType(Node node, IType type)
  334. {
  335. return Instantiate("BCE0065", node, type);
  336. }
  337. public static CompilerError InvalidNodeForAttribute(Node node, string attributeName, string expectedNodeTypes)
  338. {
  339. return Instantiate("BCE0066", node, attributeName, expectedNodeTypes);
  340. }
  341. public static CompilerError LocalAlreadyExists(Node node, string name)
  342. {
  343. return Instantiate("BCE0067", node, name);
  344. }
  345. public static CompilerError PropertyRequiresParameters(Node node, IEntity name)
  346. {
  347. return Instantiate("BCE0068", node, name);
  348. }
  349. public static CompilerError InterfaceCanOnlyInheritFromInterface(Node node, IType interfaceType, IType baseType)
  350. {
  351. return Instantiate("BCE0069", node, interfaceType, baseType);
  352. }
  353. public static CompilerError UnresolvedDependency(Node node, IEntity source, IEntity target)
  354. {
  355. return Instantiate("BCE0070", node, source, target);
  356. }
  357. public static CompilerError InheritanceCycle(Node node, IType type)
  358. {
  359. return Instantiate("BCE0071", node, type);
  360. }
  361. public static CompilerError InvalidOverrideReturnType(Node node, IMethod method, IType expectedReturnType, IType actualReturnType)
  362. {
  363. return Instantiate("BCE0072", node, method, expectedReturnType, actualReturnType);
  364. }
  365. public static CompilerError AbstractMethodCantHaveBody(Node node, IMethod method)
  366. {
  367. return Instantiate("BCE0073", node, method);
  368. }
  369. public static CompilerError SelfOutsideMethod(Node node)
  370. {
  371. return Instantiate("BCE0074", node, SelfKeyword);
  372. }
  373. public static CompilerError NamespaceIsNotAnExpression(Node node, string name)
  374. {
  375. return Instantiate("BCE0075", node, name);
  376. }
  377. public static CompilerError RuntimeMethodBodyMustBeEmpty(Node node, IMethod method)
  378. {
  379. return Instantiate("BCE0076", node, method);
  380. }
  381. public static CompilerError TypeIsNotCallable(Node node, IType name)
  382. {
  383. return Instantiate("BCE0077", node, name);
  384. }
  385. public static CompilerError MethodReferenceExpected(Node node)
  386. {
  387. return Instantiate("BCE0078", node);
  388. }
  389. public static CompilerError AddressOfOutsideDelegateConstructor(Node node)
  390. {
  391. return Instantiate("BCE0079", node);
  392. }
  393. public static CompilerError BuiltinCannotBeUsedAsExpression(Node node, string name)
  394. {
  395. return Instantiate("BCE0080", node, name);
  396. }
  397. public static CompilerError ReRaiseOutsideExceptionHandler(Node node)
  398. {
  399. return Instantiate("BCE0081", node, LanguageAmbiance.RaiseKeyword);
  400. }
  401. public static CompilerError EventTypeIsNotCallable(Node node, IType typeName)
  402. {
  403. return Instantiate("BCE0082", node, typeName, LanguageAmbiance.CallableKeyword);
  404. }
  405. public static CompilerError StaticConstructorMustBePrivate(Node node)
  406. {
  407. return Instantiate("BCE0083", node);
  408. }
  409. public static CompilerError StaticConstructorCannotDeclareParameters(Node node)
  410. {
  411. return Instantiate("BCE0084", node);
  412. }
  413. public static CompilerError CantCreateInstanceOfAbstractType(Node node, IType typeName)
  414. {
  415. return Instantiate("BCE0085", node, typeName);
  416. }
  417. public static CompilerError CantCreateInstanceOfInterface(Node node, IType typeName)
  418. {
  419. return Instantiate("BCE0086", node, typeName);
  420. }
  421. public static CompilerError CantCreateInstanceOfEnum(Node node, IType typeName)
  422. {
  423. return Instantiate("BCE0087", node, typeName);
  424. }
  425. public static CompilerError MemberNameConflict(Node node, IType declaringType, string memberName)
  426. {
  427. return Instantiate("BCE0089", node, declaringType, memberName);
  428. }
  429. public static CompilerError DerivedMethodCannotReduceAccess(Node node, IMethod derivedMethod, IMethod superMethod, TypeMemberModifiers derivedAccess, TypeMemberModifiers superAccess)
  430. {
  431. return Instantiate("BCE0090", node, derivedMethod, superMethod, superAccess.ToString().ToLower(), derivedAccess.ToString().ToLower());
  432. }
  433. public static CompilerError EventIsNotAnExpression(Node node, IEntity eventMember)
  434. {
  435. return Instantiate("BCE0091", node, eventMember);
  436. }
  437. public static CompilerError InvalidRaiseArgument(Node node, IType typeName)
  438. {
  439. return Instantiate("BCE0092", node, typeName, LanguageAmbiance.RaiseKeyword);
  440. }
  441. public static CompilerError CannotBranchIntoEnsure(Node node)
  442. {
  443. return Instantiate("BCE0093", node, LanguageAmbiance.EnsureKeyword);
  444. }
  445. public static CompilerError CannotBranchIntoExcept(Node node)
  446. {
  447. return Instantiate("BCE0094", node);
  448. }
  449. public static CompilerError NoSuchLabel(Node node, string label)
  450. {
  451. return Instantiate("BCE0095", node, label);
  452. }
  453. public static CompilerError LabelAlreadyDefined(Node node, IMethod method, string label)
  454. {
  455. return Instantiate("BCE0096", node, method, label);
  456. }
  457. public static CompilerError CannotBranchIntoTry(Node node)
  458. {
  459. return Instantiate("BCE0097", node, LanguageAmbiance.TryKeyword);
  460. }
  461. public static CompilerError InvalidSwitch(Node node)
  462. {
  463. return Instantiate("BCE0098", node);
  464. }
  465. public static CompilerError YieldInsideTryExceptOrEnsureBlock(Node node)
  466. {
  467. return Instantiate("BCE0099", node, LanguageAmbiance.TryKeyword, LanguageAmbiance.ExceptKeyword, LanguageAmbiance.EnsureKeyword);
  468. }
  469. public static CompilerError YieldInsideConstructor(Node node)
  470. {
  471. return Instantiate("BCE0100", node);
  472. }
  473. public static CompilerError InvalidGeneratorReturnType(Node node, IType type)
  474. {
  475. return Instantiate("BCE0101", node, type, LanguageAmbiance.DefaultGeneratorTypeFor(type.DisplayName()));
  476. }
  477. public static CompilerError GeneratorCantReturnValue(Node node)
  478. {
  479. return Instantiate("BCE0102", node);
  480. }
  481. public static CompilerError CannotExtendFinalType(Node node, IType typeName)
  482. {
  483. return Instantiate("BCE0103", node, typeName);
  484. }
  485. public static CompilerError CantBeMarkedTransient(Node node)
  486. {
  487. return Instantiate("BCE0104", node);
  488. }
  489. public static CompilerError CantBeMarkedAbstract(Node node)
  490. {
  491. return Instantiate("BCE0105", node);
  492. }
  493. public static CompilerError FailedToLoadTypesFromAssembly(string assemblyName, Exception x)
  494. {
  495. return Instantiate("BCE0106", LexicalInfo.Empty, x, assemblyName);
  496. }
  497. public static CompilerError ValueTypesCannotDeclareParameterlessConstructors(Node node)
  498. {
  499. return Instantiate("BCE0107", node);
  500. }
  501. public static CompilerError ValueTypeFieldsCannotHaveInitializers(Node node)
  502. {
  503. return Instantiate("BCE0108", node);
  504. }
  505. public static CompilerError InvalidArrayRank(Node node, string arrayName, int real, int given)
  506. {
  507. return Instantiate("BCE0109", node, arrayName, real, given);
  508. }
  509. public static CompilerError NotANamespace(Node node, IEntity entity)
  510. {
  511. return Instantiate("BCE0110", node, entity);
  512. }
  513. public static CompilerError InvalidDestructorModifier(Node node)
  514. {
  515. return Instantiate("BCE0111", node);
  516. }
  517. public static CompilerError CantHaveDestructorParameters(Node node)
  518. {
  519. return Instantiate("BCE0112", node);
  520. }
  521. public static CompilerError InvalidCharLiteral(Node node, string value)
  522. {
  523. return Instantiate("BCE0113", node, value);
  524. }
  525. public static CompilerError InvalidInterfaceForInterfaceMember(Node node, string value)
  526. {
  527. return Instantiate("BCE0114", node, value);
  528. }
  529. public static CompilerError InterfaceImplForInvalidInterface(Node node, string iface, string item)
  530. {
  531. return Instantiate("BCE0115", node, iface, item);
  532. }
  533. public static CompilerError ExplicitImplMustNotHaveModifiers(Node node, string iface, string item)
  534. {
  535. return Instantiate("BCE0116", node, iface, item);
  536. }
  537. public static CompilerError FieldIsReadonly(Node node, string name)
  538. {
  539. return Instantiate("BCE0117", node, name);
  540. }
  541. public static CompilerError ExplodedExpressionMustBeArray(Node node)
  542. {
  543. return Instantiate("BCE0118", node);
  544. }
  545. public static CompilerError ExplodeExpressionMustMatchVarArgCall(Node node)
  546. {
  547. return Instantiate("BCE0119", node, LanguageAmbiance.CallableKeyword);
  548. }
  549. public static CompilerError UnaccessibleMember(Node node, IAccessibleMember name)
  550. {
  551. return Instantiate("BCE0120", node, name);
  552. }
  553. public static CompilerError InvalidSuper(Node node)
  554. {
  555. return Instantiate("BCE0121", node);
  556. }
  557. public static CompilerError ValueTypeCantHaveAbstractMember(Node node, IType type, IMember abstractMember)
  558. {
  559. return Instantiate("BCE0122", node, type, abstractMember);
  560. }
  561. public static CompilerError InvalidParameterType(Node node, IType typeName)
  562. {
  563. return Instantiate("BCE0123", node, typeName, string.Empty);
  564. }
  565. public static CompilerError InvalidGenericParameterType(Node node, IType type)
  566. {
  567. return Instantiate("BCE0123", node, type, "generic ");
  568. }
  569. public static CompilerError InvalidFieldType(Node node, IType typeName)
  570. {
  571. return Instantiate("BCE0124", node, typeName);
  572. }
  573. public static CompilerError InvalidDeclarationType(Node node, IType type)
  574. {
  575. return Instantiate("BCE0125", node, type);
  576. }
  577. public static CompilerError InvalidExpressionType(Node node, IType type)
  578. {
  579. return Instantiate("BCE0126", node, type);
  580. }
  581. public static CompilerError RefArgTakesLValue(Node node)
  582. {
  583. return Instantiate("BCE0127", node, node.ToCodeString());
  584. }
  585. public static CompilerError InvalidTryStatement(Node node)
  586. {
  587. return Instantiate("BCE0128", node, LanguageAmbiance.TryKeyword, LanguageAmbiance.ExceptKeyword, LanguageAmbiance.FailureKeyword, LanguageAmbiance.EnsureKeyword);
  588. }
  589. public static CompilerError InvalidExtensionDefinition(Node node)
  590. {
  591. return Instantiate("BCE0129", node);
  592. }
  593. public static CompilerError CantBeMarkedPartial(Node node)
  594. {
  595. return Instantiate("BCE0130", node);
  596. }
  597. public static CompilerError InvalidCombinationOfModifiers(Node node, IEntity member, string modifiers)
  598. {
  599. return Instantiate("BCE0131", node, member, modifiers);
  600. }
  601. public static CompilerError NamespaceAlreadyContainsMember(Node node, string container, string member)
  602. {
  603. return Instantiate("BCE0132", node, container, member);
  604. }
  605. public static CompilerError InvalidEntryPoint(Node node)
  606. {
  607. return Instantiate("BCE0133", node);
  608. }
  609. public static CompilerError CannotReturnValue(Method node)
  610. {
  611. return Instantiate("BCE0134", node, node);
  612. }
  613. public static CompilerError InvalidName(Node node, string name)
  614. {
  615. return Instantiate("BCE0135", node, name);
  616. }
  617. public static CompilerError ColonInsteadOfEquals(Node node)
  618. {
  619. return Instantiate("BCE0136", node);
  620. }
  621. public static CompilerError PropertyIsWriteOnly(Node node, IEntity property)
  622. {
  623. return Instantiate("BCE0137", node, property);
  624. }
  625. public static CompilerError NotAGenericDefinition(Node node, string name)
  626. {
  627. return Instantiate("BCE0138", node, name);
  628. }
  629. public static CompilerError GenericDefinitionArgumentCount(Node node, IEntity genericDefinition, int expectedCount)
  630. {
  631. return Instantiate("BCE0139", node, genericDefinition, expectedCount);
  632. }
  633. public static CompilerError YieldTypeDoesNotMatchReturnType(Node node, IType yieldType, IType returnType)
  634. {
  635. return Instantiate("BCE0140", node, yieldType, returnType);
  636. }
  637. public static CompilerError DuplicateParameterName(Node node, string parameter, IMethod method)
  638. {
  639. return Instantiate("BCE0141", node, parameter, method);
  640. }
  641. public static CompilerError ValueTypeParameterCannotUseDefaultAttribute(Node node, string parameter)
  642. {
  643. string method = (node is Method) ? ((Method) node).Name : ((Property) node).Name;
  644. return Instantiate("BCE0142", node, parameter, method);
  645. }
  646. public static CompilerError CantReturnFromEnsure(Node node)
  647. {
  648. return Instantiate("BCE0143", node, LanguageAmbiance.EnsureKeyword);
  649. }
  650. public static CompilerError Obsolete(Node node, IMember member, string message)
  651. {
  652. return Instantiate("BCE0144", node, member, message);
  653. }
  654. public static CompilerError InvalidExceptArgument(Node node, IType exceptionType)
  655. {
  656. return Instantiate("BCE0145", node, exceptionType, LanguageAmbiance.ExceptKeyword);
  657. }
  658. public static CompilerError GenericArgumentMustBeReferenceType(Node node, IGenericParameter parameter, IType argument)
  659. {
  660. return Instantiate("BCE0146", node, argument, parameter, parameter.DeclaringEntity);
  661. }
  662. public static CompilerError GenericArgumentMustBeValueType(Node node, IGenericParameter parameter, IType argument)
  663. {
  664. return Instantiate("BCE0147", node, argument, parameter, parameter.DeclaringEntity);
  665. }
  666. public static CompilerError GenericArgumentMustHaveDefaultConstructor(Node node, IGenericParameter parameter, IType argument)
  667. {
  668. return Instantiate("BCE0148", node, argument, parameter, parameter.DeclaringEntity);
  669. }
  670. public static CompilerError GenericArgumentMustHaveBaseType(Node node, IGenericParameter parameter, IType argument, IType baseType)
  671. {
  672. return Instantiate("BCE0149", node, argument, baseType, parameter, parameter.DeclaringEntity);
  673. }
  674. public static CompilerError CantBeMarkedFinal(Node node)
  675. {
  676. return Instantiate("BCE0150", node);
  677. }
  678. public static CompilerError CantBeMarkedStatic(Node node)
  679. {
  680. return Instantiate("BCE0151", node);
  681. }
  682. public static CompilerError ConstructorCantBePolymorphic(Node node, IMethod ctor)
  683. {
  684. return Instantiate("BCE0152", node, ctor);
  685. }
  686. public static CompilerError InvalidAttributeTarget(Node node, Type attrType, AttributeTargets validOn)
  687. {
  688. return Instantiate("BCE0153", node, attrType, validOn);
  689. }
  690. public static CompilerError MultipleAttributeUsage(Node node, Type attrType)
  691. {
  692. return Instantiate("BCE0154", node, attrType);
  693. }
  694. public static CompilerError CannotCreateAnInstanceOfGenericParameterWithoutDefaultConstructorConstraint(Node node, IType type)
  695. {
  696. return Instantiate("BCE0155", node, type);
  697. }
  698. public static CompilerError EventCanOnlyBeInvokedFromWithinDeclaringClass(Node node, IEvent ev)
  699. {
  700. return Instantiate("BCE0156", node, ev.Name, ev.DeclaringType);
  701. }
  702. public static CompilerError GenericTypesMustBeConstructedToBeInstantiated(Node node)
  703. {
  704. return Instantiate("BCE0157", node);
  705. }
  706. public static CompilerError InstanceMethodInvocationBeforeInitialization(Constructor ctor, MemberReferenceExpression mre)
  707. {
  708. return Instantiate("BCE0158", mre, mre.Name, SelfKeyword);
  709. }
  710. public static CompilerError StructAndClassConstraintsConflict(GenericParameterDeclaration gpd)
  711. {
  712. return Instantiate("BCE0159", gpd, gpd.Name);
  713. }
  714. public static CompilerError StructAndConstructorConstraintsConflict(GenericParameterDeclaration gpd)
  715. {
  716. return Instantiate("BCE0160", gpd, gpd.Name);
  717. }
  718. public static CompilerError TypeConstraintConflictsWithSpecialConstraint(GenericParameterDeclaration gpd, TypeReference type, string constraint)
  719. {
  720. return Instantiate("BCE0161", type, gpd.Name, type, constraint);
  721. }
  722. public static CompilerError InvalidTypeConstraint(GenericParameterDeclaration gpd, TypeReference type)
  723. {
  724. return Instantiate("BCE0162", type, gpd.Name, type);
  725. }
  726. public static CompilerError MultipleBaseTypeConstraints(GenericParameterDeclaration gpd, TypeReference type, TypeReference other)
  727. {
  728. return Instantiate("BCE0163", type, gpd.Name, type, other);
  729. }
  730. public static CompilerError CannotInferGenericMethodArguments(Node node, IMethod method)
  731. {
  732. return Instantiate("BCE0164", node, method);
  733. }
  734. public static CompilerError ExceptionAlreadyHandled(ExceptionHandler dupe, ExceptionHandler previous)
  735. {
  736. return Instantiate("BCE0165",
  737. dupe.Declaration, dupe.Declaration.Type, previous.Declaration.Type,
  738. AstUtil.SafePositionOnlyLexicalInfo(previous.Declaration), LanguageAmbiance.ExceptKeyword);
  739. }
  740. public static CompilerError UnknownClassMacroWithFieldHint(MacroStatement node, string name)
  741. {
  742. return Instantiate("BCE0166", node, name);
  743. }
  744. public static CompilerError PointerIncompatibleType(Node node, IType type)
  745. {
  746. return Instantiate("BCE0168", node, type);
  747. }
  748. public static CompilerError NotAMemberOfExplicitInterface(TypeMember member, IType type)
  749. {
  750. return Instantiate("BCE0169", member, member.Name, type);
  751. }
  752. public static CompilerError EnumMemberMustBeConstant(EnumMember member)
  753. {
  754. return Instantiate("BCE0170", member, member.FullName);
  755. }
  756. public static CompilerError ConstantCannotBeConverted(Node node, IType type)
  757. {
  758. return Instantiate("BCE0171", node, node, type);
  759. }
  760. public static CompilerError InterfaceImplementationMustBePublicOrExplicit(TypeMember node, IMember member)
  761. {
  762. return Instantiate("BCE0172", node, member.DeclaringType);
  763. }
  764. public static CompilerError InvalidRegexOption(RELiteralExpression node, char option)
  765. {
  766. return Instantiate("BCE0173", node, option);
  767. }
  768. public static CompilerError InvalidTypeForExplicitMember(Node node, IType type)
  769. {
  770. return Instantiate("BCE0174", node, type);
  771. }
  772. public static CompilerError NestedTypeCannotExtendEnclosingType(Node node, IType nestedType, IType enclosingType)
  773. {
  774. return Instantiate("BCE0175", node, nestedType, enclosingType);
  775. }
  776. public static CompilerError IncompatiblePartialDefinition(Node node, string typeName, string expectedType, string actualType)
  777. {
  778. return Instantiate("BCE0176", node, typeName, expectedType, actualType);
  779. }
  780. public static CompilerError Instantiate(string code, Exception error, params object[] args)
  781. {
  782. return new CompilerError(code, error, args);
  783. }
  784. public static CompilerError Instantiate(string code, Node anchor, Exception error, params object[] args)
  785. {
  786. return Instantiate(code, AstUtil.SafeLexicalInfo(anchor), error, args);
  787. }
  788. private static CompilerError Instantiate(string code, LexicalInfo location, Exception error, params object[] args)
  789. {
  790. return new CompilerError(code, location, error, args);
  791. }
  792. public static CompilerError Instantiate(string code, Node anchor, params object[] args)
  793. {
  794. return Instantiate(code, AstUtil.SafeLexicalInfo(anchor), args);
  795. }
  796. private static CompilerError Instantiate(string code, LexicalInfo location, params object[] args)
  797. {
  798. return new CompilerError(code, location, Array.ConvertAll<object, string>(args, DisplayStringFor));
  799. }
  800. internal static string DisplayStringFor(object o)
  801. {
  802. if (o == null) return "";
  803. var entity = o as IEntity;
  804. return entity != null ? entity.DisplayName() : o.ToString();
  805. }
  806. public static string ToStringList(System.Collections.IEnumerable names)
  807. {
  808. return Builtins.join(names.Cast<object>().Select(o => DisplayStringFor(o)).OrderBy(_ => _), ", ");
  809. }
  810. public static string ToAssemblyQualifiedNameList(List types)
  811. {
  812. var builder = new StringBuilder();
  813. builder.Append(((Type)types[0]).AssemblyQualifiedName);
  814. for (int i=1; i<types.Count; ++i)
  815. {
  816. builder.Append(", ");
  817. builder.Append(((Type)types[i]).AssemblyQualifiedName);
  818. }
  819. return builder.ToString();
  820. }
  821. public static string GetSignature(object[] parameters)
  822. {
  823. var sb = new StringBuilder("(");
  824. for (int i=0; i<parameters.Length; ++i)
  825. {
  826. if (i > 0) sb.Append(", ");
  827. sb.Append(parameters[i].GetType());
  828. }
  829. sb.Append(")");
  830. return sb.ToString();
  831. }
  832. public static string ToNameList(System.Reflection.MemberInfo[] members)
  833. {
  834. var sb = new StringBuilder();
  835. for (int i=0; i<members.Length; ++i)
  836. {
  837. if (i > 0) sb.Append(", ");
  838. sb.Append(members[i].MemberType.ToString());
  839. sb.Append(" ");
  840. sb.Append(members[i].Name);
  841. }
  842. return sb.ToString();
  843. }
  844. private static string DidYouMeanOrNull(string suggestion)
  845. {
  846. return (null != suggestion)
  847. ? string.Format(StringResources.BooC_DidYouMean, suggestion)
  848. : null;
  849. }
  850. private static string StripSurroundingParens(string code)
  851. {
  852. return code.StartsWith("(") ? code.Substring(1, code.Length - 2) : code;
  853. }
  854. }
  855. }