blob: d005ce3933f5ecaa3ff66295d8c7c60ac54bdbb3 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001NAME
2 pragma
3
4DESCRIPTION
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 User88f12472016-06-24 23:31:02 +02009 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
Zesstra5481d492021-04-08 20:07:06 +020013 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 User88f12472016-06-24 23:31:02 +020022 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.
Zesstra7ea4a032019-11-26 20:11:40 +010035 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 User88f12472016-06-24 23:31:02 +020039
40 rtt_checks: runtime checks during execution of this program will be
Zesstra7ea4a032019-11-26 20:11:40 +010041 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,
Zesstra5481d492021-04-08 20:07:06 +020046 - declarative type casts,
Zesstra7ea4a032019-11-26 20:11:40 +010047 - restoration of values to variables or struct members.
MG Mud User88f12472016-06-24 23:31:02 +020048 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.
Zesstra7ea4a032019-11-26 20:11:40 +010052 warn_rtt_checks: runtime checks are enabled, just like rtt_checks,
53 but errors will be shown as warnings only.
MG Mud User88f12472016-06-24 23:31:02 +020054 no_rtt_checks: disable runtime type checks for this program (default).
55
56 pedantic: Certain warnings are treated as errors:
Zesstra7ea4a032019-11-26 20:11:40 +010057 - 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 User88f12472016-06-24 23:31:02 +020062 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
Zesstra7ea4a032019-11-26 20:11:40 +010074 a warning. Also casting a value of mixed/unknown type or
75 casting to mixed will generate a warning (the default).
MG Mud User88f12472016-06-24 23:31:02 +020076 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
Zesstra98e90af2021-05-07 19:18:04 +020086 warn_dead_code: Warn about dead code. Code is considered dead if
87 it can never be executed. The driver has only limited
88 analysis capabilities and cannot detect all instances
89 of dead code.
90 no_warn_dead_code: Turn off warn_dead_code (the default).
91
MG Mud User88f12472016-06-24 23:31:02 +020092 warn_function_inconsistent: If an inherited function is
93 overloaded with inconsistent return types or arguments,
94 a warning is generated; or if pragma_pedantic is in effect,
95 an error. By default this is active.
96 no_warn_function_inconsistent: An inherited function can
97 be overloaded with inconsistent return types or arguments,
98 as long as pragma_pedantic is not in effect.
99
100 This pragma is meant to easen the adaption of legacy
101 mudlib code - in general one should fix the warnings,
102 not turn them off.
103
Zesstra98e90af2021-05-07 19:18:04 +0200104 warn_applied_functions: If a function is known to be an applied
105 lfun, warn if its declaration differs from the specification.
106 no_warn_applied_functions: Turn of warn_applied_functions
107 (the default).
108
Zesstra5481d492021-04-08 20:07:06 +0200109 warn_unused_variables: Warn about variables that are not used.
110 If will warn about variables never written to, variables
111 never read from or variables never used at all.
112 This applies to local variables and private global variables.
113 no_warn_unused_variables: Turn off warn_unused_variables
114 (the default).
115
116 warn_lightweight: Warn about efuns that are not suitable for
117 lightweight objects.
118 no_warn_lightweight: Turn off warn_lightweight.
119
MG Mud User88f12472016-06-24 23:31:02 +0200120 When an object is compiled with type testing (#pragma
121 strict_types), all types are saved of the arguments for that
122 function during compilation. If the #pragma save_types is
123 specified, then the types are saved even after compilation, to
124 be used when the object is inherited.
125
126 The following two pragmas are available if the driver was
127 compiled with DEBUG and TRACE_CODE options:
128
129 set_code_window: Sets an offset to the current program writing
130 position. Use this BEFORE a piece of code where you
131 want to check to what bytecodes it is compiled.
132 show_code_window: shows some bytes starting at or near the
133 last point set_code_window was called.
134
135EXAMPLES
136 #pragma strict_types
137 #pragma no_clone, no_inherit
138
139HISTORY
140 LDMud 3.2.7 added local_scopes, no_local_scopes, no_clone
141 and no_inherit.
142 LDMud 3.2.8 added weak_types, pedantic and sloppy.
143 LDMud 3.2.9 allowed to specify multiple pragmas in one directive.
144 LDMud 3.2.9 added (no_)warn_deprecated.
145 LDMud 3.2.10 added (no_)warn_empty_casts.
146 Starting with LDMud 3.2.10, #pragma xxx_types in an included file are
147 no longer valid only until the end of the file, but remain active
148 when processing returns to the including file.
149 LDMud 3.2.11 added (no_)warn_function_inconsistent.
150 LDMud 3.3.378 added init_variables, share_variables.
151 LDMud 3.3.357 added (no_)warn_missing_return.
152 LDMud 3.3.646 added (no_)range_check.
153 LDMud 3.5.0 removed combine_strings and no_combine_strings.
154 LDMud 3.5.0 removed local_scopes and no_local_scopes.
155 LDMud 3.5.0 removed verbose_errors (making its behaviour mandatory).
156 LDMud 3.5.0 enabled warn_deprecated by default.
157
158SEE ALSO
159 inheritance(LPC), initialisation(LPC), objects(C),
160 operators(LPC)