gdscript_warning.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**************************************************************************/
  2. /* gdscript_warning.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_WARNING_H
  31. #define GDSCRIPT_WARNING_H
  32. #ifdef DEBUG_ENABLED
  33. #include "core/object/object.h"
  34. #include "core/string/ustring.h"
  35. #include "core/templates/vector.h"
  36. class GDScriptWarning {
  37. public:
  38. enum WarnLevel {
  39. IGNORE,
  40. WARN,
  41. ERROR
  42. };
  43. enum Code {
  44. UNASSIGNED_VARIABLE, // Variable used but never assigned.
  45. UNASSIGNED_VARIABLE_OP_ASSIGN, // Variable never assigned but used in an assignment operation (+=, *=, etc).
  46. UNUSED_VARIABLE, // Local variable is declared but never used.
  47. UNUSED_LOCAL_CONSTANT, // Local constant is declared but never used.
  48. SHADOWED_VARIABLE, // Variable name shadowed by other variable in same class.
  49. SHADOWED_VARIABLE_BASE_CLASS, // Variable name shadowed by other variable in some base class.
  50. UNUSED_PRIVATE_CLASS_VARIABLE, // Class variable is declared private ("_" prefix) but never used in the file.
  51. UNUSED_PARAMETER, // Function parameter is never used.
  52. UNREACHABLE_CODE, // Code after a return statement.
  53. UNREACHABLE_PATTERN, // Pattern in a match statement after a catch all pattern (wildcard or bind).
  54. STANDALONE_EXPRESSION, // Expression not assigned to a variable.
  55. NARROWING_CONVERSION, // Float value into an integer slot, precision is lost.
  56. INCOMPATIBLE_TERNARY, // Possible values of a ternary if are not mutually compatible.
  57. UNUSED_SIGNAL, // Signal is defined but never emitted.
  58. RETURN_VALUE_DISCARDED, // Function call returns something but the value isn't used.
  59. PROPERTY_USED_AS_FUNCTION, // Function not found, but there's a property with the same name.
  60. CONSTANT_USED_AS_FUNCTION, // Function not found, but there's a constant with the same name.
  61. FUNCTION_USED_AS_PROPERTY, // Property not found, but there's a function with the same name.
  62. INTEGER_DIVISION, // Integer divide by integer, decimal part is discarded.
  63. UNSAFE_PROPERTY_ACCESS, // Property not found in the detected type (but can be in subtypes).
  64. UNSAFE_METHOD_ACCESS, // Function not found in the detected type (but can be in subtypes).
  65. UNSAFE_CAST, // Cast used in an unknown type.
  66. UNSAFE_CALL_ARGUMENT, // Function call argument is of a supertype of the require argument.
  67. DEPRECATED_KEYWORD, // The keyword is deprecated and should be replaced.
  68. STANDALONE_TERNARY, // Return value of ternary expression is discarded.
  69. ASSERT_ALWAYS_TRUE, // Expression for assert argument is always true.
  70. ASSERT_ALWAYS_FALSE, // Expression for assert argument is always false.
  71. REDUNDANT_AWAIT, // await is used but expression is synchronous (not a signal nor a coroutine).
  72. EMPTY_FILE, // A script file is empty.
  73. SHADOWED_GLOBAL_IDENTIFIER, // A global class or function has the same name as variable.
  74. INT_AS_ENUM_WITHOUT_CAST, // An integer value was used as an enum value without casting.
  75. INT_AS_ENUM_WITHOUT_MATCH, // An integer value was used as an enum value without matching enum member.
  76. STATIC_CALLED_ON_INSTANCE, // A static method was called on an instance of a class instead of on the class itself.
  77. CONFUSABLE_IDENTIFIER, // The identifier contains misleading characters that can be confused. E.g. "usеr" (has Cyrillic "е" instead of Latin "e").
  78. RENAMED_IN_GD4_HINT, // A variable or function that could not be found has been renamed in Godot 4
  79. WARNING_MAX,
  80. };
  81. Code code = WARNING_MAX;
  82. int start_line = -1, end_line = -1;
  83. int leftmost_column = -1, rightmost_column = -1;
  84. Vector<String> symbols;
  85. String get_name() const;
  86. String get_message() const;
  87. static int get_default_value(Code p_code);
  88. static PropertyInfo get_property_info(Code p_code);
  89. static String get_name_from_code(Code p_code);
  90. static String get_settings_path_from_code(Code p_code);
  91. static Code get_code_from_name(const String &p_name);
  92. };
  93. #endif // DEBUG_ENABLED
  94. #endif // GDSCRIPT_WARNING_H