Skip to content

Commit 3ee7112

Browse files
authored
Merge pull request #2122 from WalterBright/pragma-redo
pragma.dd: clarify and tighten up spec
2 parents 6c928c7 + 601c4b8 commit 3ee7112

File tree

1 file changed

+81
-47
lines changed

1 file changed

+81
-47
lines changed

spec/pragma.dd

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ pragma(ident) // influence block of statements
4949
-----------------
5050

5151
$(P The kind of pragma it is determined by the $(I Identifier).
52-
$(I ExpressionList) is a comma-separated list of
52+
$(GLINK2 expression, ArgumentList) is a comma-separated list of
5353
$(ASSIGNEXPRESSION)s. The $(ASSIGNEXPRESSION)s must be
54-
parsable as expressions, but what they mean semantically
54+
parsable as expressions, but their meaning
5555
is up to the individual pragma semantics.
5656
)
5757

@@ -67,22 +67,21 @@ $(UL
6767
$(LI $(LINK2 #startaddress, pragma startaddress))
6868
)
6969

70-
$(DL
70+
$(IMPLEMENTATION_DEFINED An implementation may ignore these pragmas.)
7171

72-
$(DT $(LNAME2 inline, $(D inline)))
73-
$(DD $(P Affects whether functions are inlined or not. If at the declaration level, it
72+
$(H3 $(LNAME2 inline, $(D pragma inline)))
73+
74+
$(P Affects whether functions are inlined or not. If at the declaration level, it
7475
affects the functions declared in the block it controls. If inside a function, it
75-
affects the function it is enclosed by. If there are multiple pragma inlines in a function,
76-
the lexically last one takes effect.)
76+
affects the function it is enclosed by.)
7777

7878
$(P It takes three forms:)
7979
$(OL
8080
$(LI
8181
---
8282
pragma(inline)
8383
---
84-
Sets the behavior to match the default behavior set by the compiler switch
85-
$(DDSUBLINK dmd, switch-inline, $(TT -inline)).
84+
Sets the behavior to match the implementation's default behavior.
8685
)
8786
$(LI
8887
---
@@ -94,12 +93,16 @@ pragma(inline, false)
9493
---
9594
pragma(inline, true)
9695
---
97-
If a function cannot be inlined with the $(DDSUBLINK dmd, switch-inline, $(TT -inline))
98-
switch, an error message is issued. This is expected to be improved in the future to causing
99-
functions to always be inlined regardless of compiler switch settings. Whether a compiler can
100-
inline a particular function or not is implementation defined.
96+
Always inline the functions.
10197
)
10298
)
99+
100+
$(P There can be only zero or one $(I AssignExpression)s. If one is there, it must
101+
be `true`, `false`, or an integer value. An integer value is implicitly converted
102+
to a bool.)
103+
104+
$(P If there are multiple pragma inlines in a function,
105+
the lexically last one takes effect.)
103106
---
104107
pragma(inline):
105108
int foo(int x) // foo() is never inlined
@@ -110,52 +113,77 @@ int foo(int x) // foo() is never inlined
110113
return x + 3;
111114
}
112115
---
113-
)
114116

117+
$(IMPLEMENTATION_DEFINED
118+
$(OL
119+
$(LI The default inline behavior is typically selectable with a compiler switch
120+
such as $(DDSUBLINK dmd, switch-inline, $(TT -inline).))
121+
$(LI Whether a particular function can be inlined or not is implementation defined.)
122+
$(LI What happens for `pragma(inline, true)` if the function cannot be inlined.
123+
An error message is typical.)
124+
))
125+
126+
$(H3 $(LNAME2 lib, $(D pragma lib)))
115127

116-
$(DT $(LNAME2 lib, $(D lib)))
117-
$(DD Inserts a directive in the object file to link in the library
118-
specified by the $(ASSIGNEXPRESSION).
119-
The $(ASSIGNEXPRESSION)s must be a string literal:
128+
$(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a string literal.
129+
)
120130
-----------------
121131
pragma(lib, "foo.lib");
122132
-----------------
133+
134+
$(IMPLEMENTATION_DEFINED
135+
Typically, the string literal specifies the file name of a library file. This name
136+
is inserted into the generated object file, or otherwise is passed to the linker,
137+
so the linker automatically links in that library.
123138
)
124139

140+
$(H3 $(LNAME2 mangle, $(D pragma mangle)))
125141

126-
$(DT $(LNAME2 mangle, $(D mangle)))
127-
$(DD Overrides the default mangling for a symbol. It's only effective
142+
$(P Overrides the default mangling for a symbol.)
143+
144+
$(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a string literal.
145+
)
146+
147+
$(IMPLEMENTATION_DEFINED It's only effective
128148
when the symbol is a function declaration or a variable declaration.
129149
For example this allows linking to a symbol which is a D keyword, which would normally
130150
be disallowed as a symbol name:
151+
)
131152
-----------------
132153
pragma(mangle, "body")
133154
extern(C) void body_func();
134155
-----------------
135-
)
136156

137157

138-
$(DT $(LNAME2 msg, $(D msg)))
139-
$(DD Constructs a message from the arguments and prints to the standard error stream while compiling:
158+
$(H3 $(LNAME2 msg, $(D pragma msg)))
159+
160+
$(P Constructs a message from the $(I ArgumentList).)
161+
140162
-----------------
141163
pragma(msg, "compiling...", 1, 1.0);
142164
-----------------
143-
)
144165

166+
$(IMPLEMENTATION_DEFINED The arguments are typically presented to the user during compilation,
167+
such as by printing them to the standard error stream.)
168+
169+
170+
$(H3 $(LNAME2 startaddress, $(D pragma startaddress)))
171+
172+
$(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a function symbol.)
173+
174+
$(IMPLEMENTATION_DEFINED The function symbol specifies the start address for the program.
175+
The symbol is inserted into the object file or is otherwise presented to the linker to
176+
set the start address.
177+
This is not normally used for application level programming,
178+
but is for specialized systems work.
179+
For applications code, the start address is taken care of
180+
by the runtime library.
145181

146-
$(DT $(LNAME2 startaddress, $(D startaddress)))
147-
$(DD Puts a directive into the object file saying that the
148-
function specified in the first argument will be the
149-
start address for the program:
150182
-----------------
151183
void foo() { ... }
152184
pragma(startaddress, foo);
153185
-----------------
154-
This is not normally used for application level programming,
155-
but is for specialized systems work.
156-
For applications code, the start address is taken care of
157-
by the runtime library.
158-
)
186+
159187
)
160188

161189
$(H2 $(LNAME2 vendor_specific_pragmas, Vendor Specific Pragmas))
@@ -165,22 +193,28 @@ $(H2 $(LNAME2 vendor_specific_pragmas, Vendor Specific Pragmas))
165193
to version identifiers:
166194
)
167195

168-
-----------------
169-
pragma(DigitalMars_funky_extension) { ... }
170-
-----------------
196+
---
197+
pragma(DigitalMars_extension) { ... }
198+
---
171199

172-
$(P Compilers must diagnose an error for unrecognized $(I Pragma)s,
173-
even if they are vendor specific ones. This implies that vendor
174-
specific pragmas should be wrapped in version statements:
175-
)
200+
$(P Implementations must diagnose an error for unrecognized $(I Pragma)s,
201+
even if they are vendor specific ones.
202+
)
176203

177-
-----------------
178-
version (DigitalMars)
179-
{
180-
pragma(DigitalMars_funky_extension)
181-
{ ... }
182-
}
183-
-----------------
204+
$(IMPLEMENTATION_DEFINED Vendor specific pragmas.)
205+
206+
207+
$(BEST_PRACTICE vendor
208+
specific pragmas should be wrapped in version statements
209+
210+
---
211+
version (DigitalMars)
212+
{
213+
pragma(DigitalMars_extension)
214+
{ ... }
215+
}
216+
---
217+
)
184218

185219
$(SPEC_SUBNAV_PREV_NEXT attribute, Attributes, expression, Expressions)
186220
)

0 commit comments

Comments
 (0)