forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpragma.dd
126 lines (100 loc) · 3.29 KB
/
pragma.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
Ddoc
$(SPEC_S Pragmas,
$(GRAMMAR
$(GNAME Pragma):
$(B pragma) $(B $(LPAREN)) $(I Identifier) $(B $(RPAREN))
$(B pragma) $(B $(LPAREN)) $(I Identifier) $(B ,) $(GLINK2 expression, ArgumentList) $(B $(RPAREN))
)
$(P Pragmas are a way to pass special information to the compiler
and to add vendor specific extensions to D.
Pragmas can be used by themselves terminated with a $(SINGLEQUOTE ;),
they can influence a statement, a block of statements, a declaration, or
a block of declarations.
)
$(P Pragmas can appear as either declarations,
$(I Pragma) $(GLINK2 attribute, DeclarationBlock),
or as statements,
$(GLINK2 statement, PragmaStatement).
)
-----------------
pragma(ident); // just by itself
pragma(ident) declaration; // influence one declaration
pragma(ident): // influence subsequent declarations
declaration;
declaration;
pragma(ident) { // influence block of declarations
declaration;
declaration;
}
pragma(ident) statement; // influence one statement
pragma(ident) { // influence block of statements
statement;
statement;
}
-----------------
$(P The kind of pragma it is is determined by the $(I Identifier).
$(I ExpressionList) is a comma-separated list of
$(ASSIGNEXPRESSION)s. The $(ASSIGNEXPRESSION)s must be
parsable as expressions, but what they mean semantically
is up to the individual pragma semantics.
)
<h2><a name="Predefined-Pragmas">Predefined Pragmas</a></h2>
$(P All implementations must support these, even if by just ignoring
them:
)
$(DL
$(DT $(B msg))
$(DD Prints a message while compiling, the $(ASSIGNEXPRESSION)s must
be string literals:
-----------------
pragma(msg, "compiling...");
-----------------
)
$(DT $(B lib))
$(DD Inserts a directive in the object file to link in the library
specified by the $(ASSIGNEXPRESSION).
The $(ASSIGNEXPRESSION)s must be a string literal:
-----------------
pragma(lib, "foo.lib");
-----------------
)
$(V2
$(DT $(B startaddress))
$(DD Puts a directive into the object file saying that the
function specified in the first argument will be the
start address for the program:
-----------------
void foo() { ... }
pragma(startaddress, foo);
-----------------
This is not normally used for application level programming,
but is for specialized systems work.
For applications code, the start address is taken care of
by the runtime library.
)
)
)
<h2>Vendor Specific Pragmas</h2>
$(P Vendor specific pragma $(I Identifier)s can be defined if they
are prefixed by the vendor's trademarked name, in a similar manner
to version identifiers:
)
-----------------
pragma(DigitalMars_funky_extension) { ... }
-----------------
$(P Compilers must diagnose an error for unrecognized $(I Pragma)s,
even if they are vendor specific ones. This implies that vendor
specific pragmas should be wrapped in version statements:
)
-----------------
version (DigitalMars)
{
pragma(DigitalMars_funky_extension)
{ ... }
}
-----------------
)
Macros:
TITLE=Pragmas
WIKI=Pragma
CATEGORY_SPEC=$0