MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | NAME |
| 2 | pragma |
| 3 | |
| 4 | DESCRIPTION |
| 5 | The preprocessor directive #pragma can be used to select |
| 6 | several compilation options. Multiple options can be selected |
| 7 | in one #pragma directive by separating them with commas. |
| 8 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | no_inherit: The program can't be inherited. |
| 10 | no_shadow: The program can't be shadowed (similar to declaring |
| 11 | all functions as 'nomask'). |
| 12 | |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame^] | 13 | clone: The blueprint object can be cloned (default, implies |
| 14 | no_lightweight). |
| 15 | no_clone: The blueprint object can't be cloned. |
| 16 | |
| 17 | lightweight: Lightweight objects may be created from the |
| 18 | blueprint (implies no_clone and warn_lightweight). |
| 19 | no_lightweight: Lightweight object cannot be created from it |
| 20 | (default). |
| 21 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 22 | init_variables: Clone variables are initialized by __INIT(). |
| 23 | share_variables: Clone variables are initialized from the |
| 24 | blueprint. |
| 25 | |
| 26 | weak_types: no type checking (this is the default). |
| 27 | strict_types: all functions must be declared with argument |
| 28 | prototypes, and the return values of call_other() must |
| 29 | be casted. |
| 30 | strong_types: all functions must be declared with complete |
| 31 | types of return value and parameters. |
| 32 | save_types: the declaration data is kept after compilation and |
| 33 | checked at runtime. This is important for type-safe |
| 34 | inheritance. |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 35 | no_bytes_type: removes the keyword 'bytes', also 'string' then |
| 36 | denotes the type <string|bytes>. |
| 37 | bytes_type: reactivates the keyword 'bytes' and distinguishes |
| 38 | between the 'bytes' and 'string' type. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | |
| 40 | rtt_checks: runtime checks during execution of this program will be |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 41 | enabled. The interpreter will check for correct datatypes in |
| 42 | the following circumstances: |
| 43 | - arguments on function calls, |
| 44 | - return values of functions, |
| 45 | - assignment to variables, |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame^] | 46 | - declarative type casts, |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 47 | - restoration of values to variables or struct members. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 48 | Don't confuse this with strong/strict_types, they only |
| 49 | check at compile time. |
| 50 | strong_types/strict_types is seriously recommended. |
| 51 | This pragma implicitly enables save_types as well. |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 52 | warn_rtt_checks: runtime checks are enabled, just like rtt_checks, |
| 53 | but errors will be shown as warnings only. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 54 | no_rtt_checks: disable runtime type checks for this program (default). |
| 55 | |
| 56 | pedantic: Certain warnings are treated as errors: |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 57 | - failure to pass enough arguments to simul efuns |
| 58 | - type casts with no effect |
| 59 | - inconsistent declarations |
| 60 | - inconsistent overloads |
| 61 | - double inherits |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 62 | sloppy: Turns off pedantic (the default). |
| 63 | |
| 64 | range_check: Use of questionable ranges (ranges of negative sizes, |
| 65 | or with bounds beyond the array's size) cause a runtime |
| 66 | warning. |
| 67 | no_range_check: Turns off range_check (the default). |
| 68 | |
| 69 | warn_deprecated: Use of deprecated efuns or indexing operations |
| 70 | causes the compiler to issue a warning (the default). |
| 71 | no_warn_deprecated: Turns off warn_deprecated. |
| 72 | |
| 73 | warn_empty_casts: A cast of a value to its own type generates |
Zesstra | 7ea4a03 | 2019-11-26 20:11:40 +0100 | [diff] [blame] | 74 | a warning. Also casting a value of mixed/unknown type or |
| 75 | casting to mixed will generate a warning (the default). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 76 | no_warn_empty_casts: Turns off warn_empty_casts. |
| 77 | |
| 78 | warn_missing_return: Warn if a value-returning function is missing |
| 79 | a return statement (the default). If possible, the driver |
| 80 | will try to detect this at compile time; otherwise a runtime |
| 81 | warning will be generated when the function is executed. |
| 82 | The check applies only to functions with a declared return |
| 83 | type other than 'void'. |
| 84 | no_warn_missing_return: Turn off warn_missing_return. |
| 85 | |
| 86 | warn_function_inconsistent: If an inherited function is |
| 87 | overloaded with inconsistent return types or arguments, |
| 88 | a warning is generated; or if pragma_pedantic is in effect, |
| 89 | an error. By default this is active. |
| 90 | no_warn_function_inconsistent: An inherited function can |
| 91 | be overloaded with inconsistent return types or arguments, |
| 92 | as long as pragma_pedantic is not in effect. |
| 93 | |
| 94 | This pragma is meant to easen the adaption of legacy |
| 95 | mudlib code - in general one should fix the warnings, |
| 96 | not turn them off. |
| 97 | |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame^] | 98 | warn_unused_variables: Warn about variables that are not used. |
| 99 | If will warn about variables never written to, variables |
| 100 | never read from or variables never used at all. |
| 101 | This applies to local variables and private global variables. |
| 102 | no_warn_unused_variables: Turn off warn_unused_variables |
| 103 | (the default). |
| 104 | |
| 105 | warn_lightweight: Warn about efuns that are not suitable for |
| 106 | lightweight objects. |
| 107 | no_warn_lightweight: Turn off warn_lightweight. |
| 108 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 109 | When an object is compiled with type testing (#pragma |
| 110 | strict_types), all types are saved of the arguments for that |
| 111 | function during compilation. If the #pragma save_types is |
| 112 | specified, then the types are saved even after compilation, to |
| 113 | be used when the object is inherited. |
| 114 | |
| 115 | The following two pragmas are available if the driver was |
| 116 | compiled with DEBUG and TRACE_CODE options: |
| 117 | |
| 118 | set_code_window: Sets an offset to the current program writing |
| 119 | position. Use this BEFORE a piece of code where you |
| 120 | want to check to what bytecodes it is compiled. |
| 121 | show_code_window: shows some bytes starting at or near the |
| 122 | last point set_code_window was called. |
| 123 | |
| 124 | EXAMPLES |
| 125 | #pragma strict_types |
| 126 | #pragma no_clone, no_inherit |
| 127 | |
| 128 | HISTORY |
| 129 | LDMud 3.2.7 added local_scopes, no_local_scopes, no_clone |
| 130 | and no_inherit. |
| 131 | LDMud 3.2.8 added weak_types, pedantic and sloppy. |
| 132 | LDMud 3.2.9 allowed to specify multiple pragmas in one directive. |
| 133 | LDMud 3.2.9 added (no_)warn_deprecated. |
| 134 | LDMud 3.2.10 added (no_)warn_empty_casts. |
| 135 | Starting with LDMud 3.2.10, #pragma xxx_types in an included file are |
| 136 | no longer valid only until the end of the file, but remain active |
| 137 | when processing returns to the including file. |
| 138 | LDMud 3.2.11 added (no_)warn_function_inconsistent. |
| 139 | LDMud 3.3.378 added init_variables, share_variables. |
| 140 | LDMud 3.3.357 added (no_)warn_missing_return. |
| 141 | LDMud 3.3.646 added (no_)range_check. |
| 142 | LDMud 3.5.0 removed combine_strings and no_combine_strings. |
| 143 | LDMud 3.5.0 removed local_scopes and no_local_scopes. |
| 144 | LDMud 3.5.0 removed verbose_errors (making its behaviour mandatory). |
| 145 | LDMud 3.5.0 enabled warn_deprecated by default. |
| 146 | |
| 147 | SEE ALSO |
| 148 | inheritance(LPC), initialisation(LPC), objects(C), |
| 149 | operators(LPC) |