gdscript_warning.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*************************************************************************/
  2. /* gdscript_warning.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GDSCRIPT_WARNINGS
  31. #define GDSCRIPT_WARNINGS
  32. #ifdef DEBUG_ENABLED
  33. #include "core/string/ustring.h"
  34. #include "core/templates/vector.h"
  35. class GDScriptWarning {
  36. public:
  37. enum Code {
  38. UNASSIGNED_VARIABLE, // Variable used but never assigned.
  39. UNASSIGNED_VARIABLE_OP_ASSIGN, // Variable never assigned but used in an assignment operation (+=, *=, etc).
  40. UNUSED_VARIABLE, // Local variable is declared but never used.
  41. UNUSED_LOCAL_CONSTANT, // Local constant is declared but never used.
  42. SHADOWED_VARIABLE, // Variable name shadowed by other variable in same class.
  43. SHADOWED_VARIABLE_BASE_CLASS, // Variable name shadowed by other variable in some base class.
  44. UNUSED_PRIVATE_CLASS_VARIABLE, // Class variable is declared private ("_" prefix) but never used in the file.
  45. UNUSED_PARAMETER, // Function parameter is never used.
  46. UNREACHABLE_CODE, // Code after a return statement.
  47. UNREACHABLE_PATTERN, // Pattern in a match statement after a catch all pattern (wildcard or bind).
  48. STANDALONE_EXPRESSION, // Expression not assigned to a variable.
  49. VOID_ASSIGNMENT, // Function returns void but it's assigned to a variable.
  50. NARROWING_CONVERSION, // Float value into an integer slot, precision is lost.
  51. INCOMPATIBLE_TERNARY, // Possible values of a ternary if are not mutually compatible.
  52. UNUSED_SIGNAL, // Signal is defined but never emitted.
  53. RETURN_VALUE_DISCARDED, // Function call returns something but the value isn't used.
  54. PROPERTY_USED_AS_FUNCTION, // Function not found, but there's a property with the same name.
  55. CONSTANT_USED_AS_FUNCTION, // Function not found, but there's a constant with the same name.
  56. FUNCTION_USED_AS_PROPERTY, // Property not found, but there's a function with the same name.
  57. INTEGER_DIVISION, // Integer divide by integer, decimal part is discarded.
  58. UNSAFE_PROPERTY_ACCESS, // Property not found in the detected type (but can be in subtypes).
  59. UNSAFE_METHOD_ACCESS, // Function not found in the detected type (but can be in subtypes).
  60. UNSAFE_CAST, // Cast used in an unknown type.
  61. UNSAFE_CALL_ARGUMENT, // Function call argument is of a supertype of the require argument.
  62. DEPRECATED_KEYWORD, // The keyword is deprecated and should be replaced.
  63. STANDALONE_TERNARY, // Return value of ternary expression is discarded.
  64. ASSERT_ALWAYS_TRUE, // Expression for assert argument is always true.
  65. ASSERT_ALWAYS_FALSE, // Expression for assert argument is always false.
  66. REDUNDANT_AWAIT, // await is used but expression is synchronous (not a signal nor a coroutine).
  67. WARNING_MAX,
  68. };
  69. Code code = WARNING_MAX;
  70. int start_line = -1, end_line = -1;
  71. int leftmost_column = -1, rightmost_column = -1;
  72. Vector<String> symbols;
  73. String get_name() const;
  74. String get_message() const;
  75. static String get_name_from_code(Code p_code);
  76. static Code get_code_from_name(const String &p_name);
  77. };
  78. #endif // DEBUG_ENABLED
  79. #endif // GDSCRIPT_WARNINGS