doc/syntax.tex: Promote `Integer literals' to subsection.
[sod] / doc / syntax.tex
... / ...
CommitLineData
1%%% -*-latex-*-
2%%%
3%%% Module syntax
4%%%
5%%% (c) 2015 Straylight/Edgeware
6%%%
7
8%%%----- Licensing notice ---------------------------------------------------
9%%%
10%%% This file is part of the Sensible Object Design, an object system for C.
11%%%
12%%% SOD is free software; you can redistribute it and/or modify
13%%% it under the terms of the GNU General Public License as published by
14%%% the Free Software Foundation; either version 2 of the License, or
15%%% (at your option) any later version.
16%%%
17%%% SOD is distributed in the hope that it will be useful,
18%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
19%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20%%% GNU General Public License for more details.
21%%%
22%%% You should have received a copy of the GNU General Public License
23%%% along with SOD; if not, write to the Free Software Foundation,
24%%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26\chapter{Module syntax} \label{ch:syntax}
27
28%%%--------------------------------------------------------------------------
29\section{Lexical syntax} \label{sec:syntax.lex}
30
31Whitespace and comments are discarded. The remaining characters are
32collected into tokens according to the following syntax.
33
34\begin{grammar}
35<token> ::= <identifier>
36\alt <string-literal>
37\alt <char-literal>
38\alt <integer-literal>
39\alt <punctuation>
40\end{grammar}
41
42This syntax is slightly ambiguous, and is disambiguated by the \emph{maximal
43munch} rule: at each stage we take the longest sequence of characters which
44could be a token.
45
46
47\subsection{Identifiers} \label{sec:syntax.lex.id}
48
49\begin{grammar}
50<identifier> ::= <id-start-char> @<id-body-char>^*
51
52<id-start-char> ::= <alpha-char> | "_"
53
54<id-body-char> ::= <id-start-char> @! <digit-char>
55
56<alpha-char> ::= "A" | "B" | \dots\ | "Z"
57\alt "a" | "b" | \dots\ | "z"
58\alt <extended-alpha-char>
59
60<digit-char> ::= "0" | <nonzero-digit-char>
61
62<nonzero-digit-char> ::= "1" | "2" $| \ldots |$ "9"
63\end{grammar}
64
65The precise definition of @<alpha-char> is left to the function
66\textsf{alpha-char-p} in the hosting Lisp system. For portability,
67programmers are encouraged to limit themselves to the standard ASCII letters.
68
69There are no reserved words at the lexical level, but the higher-level syntax
70recognizes certain identifiers as \emph{keywords} in some contexts. There is
71also an ambiguity (inherited from C) in the declaration syntax which is
72settled by distinguishing type names from other identifiers at a lexical
73level.
74
75
76\subsection{String and character literals} \label{sec:syntax.lex.string}
77
78\begin{grammar}
79<string-literal> ::= "\"" @<string-literal-char>^* "\""
80
81<char-literal> ::= "'" <char-literal-char> "'"
82
83<string-literal-char> ::= any character other than "\\" or "\""
84\alt "\\" <char>
85
86<char-literal-char> ::= any character other than "\\" or "'"
87\alt "\\" <char>
88
89<char> ::= any single character
90\end{grammar}
91
92The syntax for string and character literals differs from~C. In particular,
93escape sequences such as @`\textbackslash n' are not recognized. The use
94of string and character literals in Sod, outside of C~fragments, is limited,
95and the simple syntax seems adequate. For the sake of future compatibility,
96the use of character sequences which resemble C escape sequences is
97discouraged.
98
99
100\subsection{Integer literals} \label{sec:syntax.lex.int}
101
102\begin{grammar}
103<integer-literal> ::= <decimal-integer>
104\alt <binary-integer>
105\alt <octal-integer>
106\alt <hex-integer>
107
108<decimal-integer> ::= "0" | <nonzero-digit-char> @<digit-char>^*
109
110<binary-integer> ::= "0" @("b"|"B"@) @<binary-digit-char>^+
111
112<binary-digit-char> ::= "0" | "1"
113
114<octal-integer> ::= "0" @["o"|"O"@] @<octal-digit-char>^+
115
116<octal-digit-char> ::= "0" | "1" $| \ldots |$ "7"
117
118<hex-integer> ::= "0" @("x"|"X"@) @<hex-digit-char>^+
119
120<hex-digit-char> ::= <digit-char>
121\alt "A" | "B" | "C" | "D" | "E" | "F"
122\alt "a" | "b" | "c" | "d" | "e" | "f"
123\end{grammar}
124
125Sod understands only integers, not floating-point numbers; its integer syntax
126goes slightly beyond C in allowing a @`0o' prefix for octal and @`0b' for
127binary. However, length and signedness indicators are not permitted.
128
129
130\subsection{Punctuation} \label{sec:syntax.lex.punct}
131
132\begin{grammar}
133<punctuation> ::= any nonalphanumeric character other than "_", "\"" or "'"
134\end{grammar}
135
136
137\subsection{Comments} \label{sec:syntax.lex.comment}
138
139\begin{grammar}
140<comment> ::= <block-comment>
141\alt <line-comment>
142
143<block-comment> ::=
144 "/*"
145 @<not-star>^* @(@<star>^+ <not-star-or-slash> @<not-star>^*@)^*
146 @<star>^*
147 "*/"
148
149<star> ::= "*"
150
151<not-star> ::= any character other than "*"
152
153<not-star-or-slash> ::= any character other than "*" or "/"
154
155<line-comment> ::= "/\,/" @<not-newline>^* <newline>
156
157<newline> ::= a newline character
158
159<not-newline> ::= any character other than newline
160\end{grammar}
161
162Comments are exactly as in C99: both traditional block comments `@|/*| \dots\
163@|*/|' and \Cplusplus-style `@|/\,/| \dots' comments are permitted and
164ignored.
165
166
167\subsection{Special nonterminals} \label{sec:syntax.lex.special}
168
169Aside from the lexical syntax presented above (\xref{sec:lexical-syntax}),
170two special nonterminals occur in the module syntax.
171
172\subsubsection{S-expressions}
173\begin{grammar}
174<s-expression> ::= an S-expression, as parsed by the Lisp reader
175\end{grammar}
176
177When an S-expression is expected, the Sod parser simply calls the host Lisp
178system's @|read| function. Sod modules are permitted to modify the read
179table to extend the S-expression syntax.
180
181S-expressions are self-delimiting, so no end-marker is needed.
182
183\subsubsection{C fragments}
184\begin{grammar}
185<c-fragment> ::= a sequence of C tokens, with matching brackets
186\end{grammar}
187
188Sequences of C code are simply stored and written to the output unchanged
189during translation. They are read using a simple scanner which nonetheless
190understands C comments and string and character literals.
191
192A C fragment is terminated by one of a small number of delimiter characters
193determined by the immediately surrounding context -- usually a closing brace
194or bracket. The first such delimiter character which is not enclosed in
195brackets, braces or parenthesis ends the fragment.
196
197%%%--------------------------------------------------------------------------
198\section{Module syntax} \label{sec:syntax.module}
199
200\begin{grammar}
201<module> ::= @<definition>^*
202
203<definition> ::= <import-definition>
204\alt <load-definition>
205\alt <lisp-definition>
206\alt <code-definition>
207\alt <typename-definition>
208\alt <class-definition>
209\end{grammar}
210
211A @<module> is the top-level syntactic item. A module consists of a sequence
212of definitions.
213
214\fixme{describe syntax; expand}
215Properties:
216\begin{description}
217\item[@|module_class|] A symbol naming the Lisp class to use to
218 represent the module.
219\item[@|guard|] An identifier to use as the guard symbol used to prevent
220 multiple inclusion in the header file.
221\end{description}
222
223
224\subsection{Simple definitions} \label{sec:syntax.module.simple}
225
226\subsubsection{Importing modules}
227\begin{grammar}
228<import-definition> ::= "import" <string> ";"
229\end{grammar}
230
231The module named @<string> is processed and its definitions made available.
232
233A search is made for a module source file as follows.
234\begin{itemize}
235\item The module name @<string> is converted into a filename by appending
236 @`.sod', if it has no extension already.\footnote{%
237 Technically, what happens is \textsf{(merge-pathnames name (make-pathname
238 :type "SOD" :case :common))}, so exactly what this means varies
239 according to the host system.} %
240\item The file is looked for relative to the directory containing the
241 importing module.
242\item If that fails, then the file is looked for in each directory on the
243 module search path in turn.
244\item If the file still isn't found, an error is reported and the import
245 fails.
246\end{itemize}
247At this point, if the file has previously been imported, nothing further
248happens.\footnote{%
249 This check is done using \textsf{truename}, so it should see through simple
250 tricks like symbolic links. However, it may be confused by fancy things
251 like bind mounts and so on.} %
252
253Recursive imports, either direct or indirect, are an error.
254
255\subsubsection{Loading extensions}
256\begin{grammar}
257<load-definition> ::= "load" <string> ";"
258\end{grammar}
259
260The Lisp file named @<string> is loaded and evaluated.
261
262A search is made for a Lisp source file as follows.
263\begin{itemize}
264\item The name @<string> is converted into a filename by appending @`.lisp',
265 if it has no extension already.\footnote{%
266 Technically, what happens is \textsf{(merge-pathnames name (make-pathname
267 :type "LISP" :case :common))}, so exactly what this means varies
268 according to the host system.} %
269\item A search is then made in the same manner as for module imports
270 (\xref{sec:syntax-module}).
271\end{itemize}
272If the file is found, it is loaded using the host Lisp's \textsf{load}
273function.
274
275Note that Sod doesn't attempt to compile Lisp files, or even to look for
276existing compiled files. The right way to package a substantial extension to
277the Sod translator is to provide the extension as a standard ASDF system (or
278similar) and leave a dropping @|foo-extension.lisp| in the module path saying
279something like
280\begin{quote}
281 \textsf{(asdf:load-system :foo-extension)}
282\end{quote}
283which will arrange for the extension to be compiled if necessary.
284
285(This approach means that the language doesn't need to depend on any
286particular system definition facility. It's bad enough already that it
287depends on Common Lisp.)
288
289\subsubsection{Lisp escapes}
290\begin{grammar}
291<lisp-definition> ::= "lisp" <s-expression> ";"
292\end{grammar}
293
294The @<s-expression> is evaluated immediately. It can do anything it likes.
295
296\begin{boxy}[Warning!]
297 This means that hostile Sod modules are a security hazard. Lisp code can
298 read and write files, start other programs, and make network connections.
299 Don't install Sod modules from sources that you don't trust.\footnote{%
300 Presumably you were going to run the corresponding code at some point, so
301 this isn't as unusually scary as it sounds. But please be careful.} %
302\end{boxy}
303
304\subsubsection{Declaring type names}
305\begin{grammar}
306<typename-definition> ::=
307 "typename" <list>$[\mbox{@<identifier>}]$ ";"
308\end{grammar}
309
310Each @<identifier> is declared as naming a C type. This is important because
311the C type syntax -- which Sod uses -- is ambiguous, and disambiguation is
312done by distinguishing type names from other identifiers.
313
314Don't declare class names using @"typename"; use @"class" forward
315declarations instead.
316
317
318\subsection{Literal code} \label{sec:syntax.module.literal}
319
320\begin{grammar}
321<code-definition> ::=
322 "code" <identifier> ":" <item-name> @[<constraints>@]
323 "{" <c-fragment> "}"
324
325<constraints> ::= "[" <list>$[\mbox{@<constraint>}]$ "]"
326
327<constraint> ::= @<item-name>^+
328
329<item-name> ::= <identifier> @! "(" @<identifier>^+ ")"
330\end{grammar}
331
332The @<c-fragment> will be output unchanged to one of the output files.
333
334The first @<identifier> is the symbolic name of an output file. Predefined
335output file names are @|c| and @|h|, which are the implementation code and
336header file respectively; other output files can be defined by extensions.
337
338Output items are named with a sequence of identifiers, separated by
339whitespace, and enclosed in parentheses. As an abbreviation, a name
340consisting of a single identifier may be written as just that identifier,
341without the parentheses.
342
343The @<constraints> provide a means for specifying where in the output file
344the output item should appear. (Note the two kinds of square brackets shown
345in the syntax: square brackets must appear around the constraints if they are
346present, but that they may be omitted.) Each comma-separated @<constraint>
347is a sequence of names of output items, and indicates that the output items
348must appear in the order given -- though the translator is free to insert
349additional items in between them. (The particular output items needn't be
350defined already -- indeed, they needn't be defined ever.)
351
352There is a predefined output item @|includes| in both the @|c| and @|h|
353output files which is a suitable place for inserting @|\#include|
354preprocessor directives in order to declare types and functions for use
355elsewhere in the generated output files.
356
357
358\subsection{Property sets} \label{sec:syntax.module.properties}
359\begin{grammar}
360<properties> ::= "[" <list>$[\mbox{@<property>}]$ "]"
361
362<property> ::= <identifier> "=" <expression>
363\end{grammar}
364
365Property sets are a means for associating miscellaneous information with
366classes and related items. By using property sets, additional information
367can be passed to extensions without the need to introduce idiosyncratic
368syntax.
369
370A property has a name, given as an @<identifier>, and a value computed by
371evaluating an @<expression>. The value can be one of a number of types,
372though the only operators currently defined act on integer values only.
373
374\subsubsection{The expression evaluator}
375\begin{grammar}
376<expression> ::= <term> | <expression> "+" <term> | <expression> "--" <term>
377
378<term> ::= <factor> | <term> "*" <factor> | <term> "/" <factor>
379
380<factor> ::= <primary> | "+" <factor> | "--" <factor>
381
382<primary> ::=
383 <integer-literal> | <string-literal> | <char-literal> | <identifier>
384\alt "<" <plain-type> ">"
385\alt "?" <s-expression>
386\alt "(" <expression> ")"
387\end{grammar}
388
389The arithmetic expression syntax is simple and standard; there are currently
390no bitwise, logical, or comparison operators.
391
392A @<primary> expression may be a literal or an identifier. Note that
393identifiers stand for themselves: they \emph{do not} denote values. For more
394fancy expressions, the syntax
395\begin{quote}
396 @"?" @<s-expression>
397\end{quote}
398causes the @<s-expression> to be evaluated using the Lisp \textsf{eval}
399function.
400%%% FIXME crossref to extension docs
401
402
403\subsection{C types} \label{sec:syntax.module.types}
404
405Sod's syntax for C types closely mirrors the standard C syntax. A C type has
406two parts: a sequence of @<declaration-specifier>s and a @<declarator>. In
407Sod, a type must contain at least one @<declaration-specifier> (i.e.,
408`implicit @"int"' is forbidden), and storage-class specifiers are not
409recognized.
410
411\subsubsection{Declaration specifiers}
412\begin{grammar}
413<declaration-specifier> ::= <type-name>
414\alt "struct" <identifier> | "union" <identifier> | "enum" <identifier>
415\alt "void" | "char" | "int" | "float" | "double"
416\alt "short" | "long"
417\alt "signed" | "unsigned"
418\alt "bool" | "_Bool"
419\alt "imaginary" | "_Imaginary" | "complex" | "_Complex"
420\alt <qualifier>
421\alt <storage-specifier>
422\alt <atomic-type>
423
424<qualifier> ::= <atomic> | "const" | "volatile" | "restrict"
425
426<plain-type> ::= @<declaration-specifier>^+ <abstract-declarator>
427
428<atomic-type> ::=
429 <atomic> "(" <plain-type> ")"
430
431<atomic> ::= "atomic" | "_Atomic"
432
433<storage-specifier> ::= <alignas> "(" <c-fragment> ")"
434
435<alignas> ::= "alignas" "_Alignas"
436
437<type-name> ::= <identifier>
438\end{grammar}
439
440A @<type-name> is an identifier which has been declared as being a type name,
441using the @"typename" or @"class" definitions. The following type names are
442defined in the built-in module.
443\begin{itemize}
444\item @"va_list"
445\item @"size_t"
446\item @"ptrdiff_t"
447\item @"wchar_t"
448\end{itemize}
449
450Declaration specifiers may appear in any order. However, not all
451combinations are permitted. A declaration specifier must consist of zero or
452more @<qualifier>s, zero or more @<storage-specifier>s, and one of the
453following, up to reordering.
454\begin{itemize}
455\item @<type-name>
456\item @<atomic-type>
457\item @"struct" @<identifier>, @"union" @<identifier>, @"enum" @<identifier>
458\item @"void"
459\item @"_Bool", @"bool"
460\item @"char", @"unsigned char", @"signed char"
461\item @"short", @"unsigned short", @"signed short"
462\item @"short int", @"unsigned short int", @"signed short int"
463\item @"int", @"unsigned int", @"signed int", @"unsigned", @"signed"
464\item @"long", @"unsigned long", @"signed long"
465\item @"long int", @"unsigned long int", @"signed long int"
466\item @"long long", @"unsigned long long", @"signed long long"
467\item @"long long int", @"unsigned long long int", @"signed long long int"
468\item @"float", @"double", @"long double"
469\item @"float _Imaginary", @"double _Imaginary", @"long double _Imaginary"
470\item @"float imaginary", @"double imaginary", @"long double imaginary"
471\item @"float _Complex", @"double _Complex", @"long double _Complex"
472\item @"float complex", @"double complex", @"long double complex"
473\end{itemize}
474All of these have their usual C meanings.
475
476\subsubsection{Declarators}
477\begin{grammar}
478<declarator>$[k, a]$ ::= @<pointer>^* <primary-declarator>$[k, a]$
479
480<primary-declarator>$[k, a]$ ::= $k$
481\alt "(" <primary-declarator>$[k, a]$ ")"
482\alt <primary-declarator>$[k, a]$ @<declarator-suffix>$[a]$
483
484<pointer> ::= "*" @<qualifier>^*
485
486<declarator-suffix>$[a]$ ::= "[" <c-fragment> "]"
487\alt "(" $a$ ")"
488
489<argument-list> ::= $\epsilon$ | "\dots"
490\alt <list>$[\mbox{@<argument>}]$ @["," "\dots"@]
491
492<argument> ::= @<declaration-specifier>^+ <argument-declarator>
493
494<abstract-declarator> ::= <declarator>$[\epsilon, \mbox{@<argument-list>}]$
495
496<argument-declarator> ::=
497 <declarator>$[\mbox{@<identifier> @! $\epsilon$}, \mbox{@<argument-list>}]$
498
499<simple-declarator> ::=
500 <declarator>$[\mbox{@<identifier>}, \mbox{@<argument-list>}]$
501\end{grammar}
502
503The declarator syntax is taken from C, but with some differences.
504\begin{itemize}
505\item Array dimensions are uninterpreted @<c-fragments>, terminated by a
506 closing square bracket. This allows array dimensions to contain arbitrary
507 constant expressions.
508\item A declarator may have either a single @<identifier> at its centre or a
509 pair of @<identifier>s separated by a @`.'; this is used to refer to
510 slots or messages defined in superclasses.
511\end{itemize}
512The remaining differences are (I hope) a matter of presentation rather than
513substance.
514
515There is additional syntax to support messages and methods which accept
516keyword arguments.
517
518\begin{grammar}
519<keyword-argument> ::= <argument> @["=" <c-fragment>@]
520
521<keyword-argument-list> ::=
522 @[<list>$[\mbox{@<argument>}]$@]
523 "?" @[<list>$[\mbox{@<keyword-argument>}]$@]
524
525<method-argument-list> ::= <argument-list> @! <keyword-argument-list>
526
527<dotted-name> ::= <identifier> "." <identifier>
528
529<keyword-declarator>$[k]$ ::=
530 <declarator>$[k, \mbox{@<method-argument-list>}]$
531\end{grammar}
532
533
534\subsection{Class definitions} \label{sec:syntax.module.class}
535
536\begin{grammar}
537<class-definition> ::= <class-forward-declaration>
538\alt <full-class-definition>
539\end{grammar}
540
541\subsubsection{Forward declarations}
542\begin{grammar}
543<class-forward-declaration> ::= "class" <identifier> ";"
544\end{grammar}
545
546A @<class-forward-declaration> informs Sod that an @<identifier> will be used
547to name a class which is currently undefined. Forward declarations are
548necessary in order to resolve certain kinds of circularity. For example,
549\begin{prog}
550class Sub; \\+
551
552class Super: SodObject \{ \\ \ind
553 Sub *sub; \-\\
554\}; \\+
555
556class Sub: Super \{ \\ \ind
557 /* \dots\ */ \-\\
558\};
559\end{prog}
560
561\subsubsection{Full class definitions}
562\begin{grammar}
563<full-class-definition> ::=
564 @[<properties>@]
565 "class" <identifier> ":" <list>$[\mbox{@<identifier>}]$
566 "{" @<properties-class-item>^* "}"
567
568<properties-class-item> ::= @[<properties>@] <class-item>
569
570<class-item> ::= <slot-item>
571\alt <initializer-item>
572\alt <initarg-item>
573\alt <fragment-item>
574\alt <message-item>
575\alt <method-item>
576\end{grammar}
577
578A full class definition provides a complete description of a class.
579
580The first @<identifier> gives the name of the class. It is an error to
581give the name of an existing class (other than a forward-referenced class),
582or an existing type name. It is conventional to give classes `MixedCase'
583names, to distinguish them from other kinds of identifiers.
584
585The @<list>$[\mbox{@<identifier>}]$ names the direct superclasses for the new
586class. It is an error if any of these @<identifier>s does not name a defined
587class. The superclass list is required, and must not be empty; listing
588@|SodObject| as your class's superclass is a good choice if nothing else
589seems suitable. It's not possible to define a \emph{root class} in the Sod
590language: you must use Lisp to do this, and it's quite involved.
591
592The @<properties> provide additional information. The standard class
593properties are as follows.
594\begin{description}
595\item[@|lisp_class|] The name of the Lisp class to use within the translator
596 to represent this class. The property value must be an identifier; the
597 default is @|sod_class|. Extensions may define classes with additional
598 behaviour, and may recognize additional class properties.
599\item[@|metaclass|] The name of the Sod metaclass for this class. In the
600 generated code, a class is itself an instance of another class -- its
601 \emph{metaclass}. The metaclass defines which slots the class will have,
602 which messages it will respond to, and what its behaviour will be when it
603 receives them. The property value must be an identifier naming a defined
604 subclass of @|SodClass|. The default metaclass is @|SodClass|.
605 See \xref{sec:concepts.metaclasses} for more details.
606\item[@|nick|] A nickname for the class, to be used to distinguish it from
607 other classes in various limited contexts. The property value must be an
608 identifier; the default is constructed by forcing the class name to
609 lower-case.
610\end{description}
611
612The class body consists of a sequence of @<class-item>s enclosed in braces.
613These items are discussed on the following sections.
614
615\subsubsection{Slot items}
616\begin{grammar}
617<slot-item> ::=
618 @<declaration-specifier>^+ <list>$[\mbox{@<init-declarator>}]$ ";"
619
620<init-declarator> ::= <simple-declarator> @["=" <initializer>@]
621\end{grammar}
622
623A @<slot-item> defines one or more slots. All instances of the class and any
624subclass will contain these slot, with the names and types given by the
625@<declaration-specifiers> and the @<declarators>. Slot declarators may not
626contain dotted names.
627
628It is not possible to declare a slot with function type: such an item is
629interpreted as being a @<message-item> or @<method-item>. Pointers to
630functions are fine.
631
632Properties:
633\begin{description}
634\item[@|slot_class|] A symbol naming the Lisp class to use to represent the
635 direct slot.
636\item[@|initarg|] An identifier naming an initialization argument which can
637 be used to provide a value for the slot. See
638 \xref{sec:concepts.lifecycle.birth} for the details.
639\item[@|initarg_class|] A symbol naming the Lisp class to use to represent
640 the initarg. Only permitted if @|initarg| is also set.
641\end{description}
642
643An @<initializer>, if present, is treated as if a separate
644@<initializer-item> containing the slot name and initializer were present.
645For example,
646\begin{prog}
647[nick = eg] \\
648class Example: Super \{ \\ \ind
649 int foo = 17; \-\\
650\};
651\end{prog}
652means the same as
653\begin{prog}
654[nick = eg] \\
655class Example: Super \{ \\ \ind
656 int foo; \\
657 eg.foo = 17; \-\\
658\};
659\end{prog}
660
661\subsubsection{Initializer items}
662\begin{grammar}
663<initializer-item> ::= @["class"@] <list>$[\mbox{@<slot-initializer>}]$ ";"
664
665<slot-initializer> ::= <dotted-name> @["=" <initializer>@]
666
667<initializer> ::= <c-fragment>
668\end{grammar}
669
670An @<initializer-item> provides an initial value for one or more slots. If
671prefixed by @|class|, then the initial values are for class slots (i.e.,
672slots of the class object itself); otherwise they are for instance slots.
673
674The first component of the @<dotted-name> must be the nickname of one of the
675class's superclasses (including itself); the second must be the name of a
676slot defined in that superclass.
677
678Properties:
679\begin{description}
680\item[@|initializer_class|] A symbol naming the Lisp class to use to
681 represent the initializer.
682\item[@|initarg|] An identifier naming an initialization argument which can
683 be used to provide a value for the slot. See
684 \xref{sec:concepts.lifecycle.birth} for the details. An initializer item
685 must have either an @|initarg| property, or an initializer expression, or
686 both.
687\item[@|initarg_class|] A symbol naming the Lisp class to use to represent
688 the initarg. Only permitted if @|initarg| is also set.
689\end{description}
690
691Each class may define at most one initializer item with an explicit
692initializer expression for a given slot.
693
694\subsubsection{Initarg items}
695\begin{grammar}
696<initarg-item> ::=
697 "initarg"
698 @<declaration-specifier>^+
699 <list>$[\mbox{@<init-declarator>}]$ ";"
700\end{grammar}
701Properties:
702\begin{description}
703\item[@|initarg_class|] A symbol naming the Lisp class to use to represent
704 the initarg.
705\end{description}
706
707\subsubsection{Fragment items}
708\begin{grammar}
709<fragment-item> ::= <fragment-kind> "{" <c-fragment> "}"
710
711<fragment-kind> ::= "init" | "teardown"
712\end{grammar}
713
714\subsubsection{Message items}
715\begin{grammar}
716<message-item> ::=
717 @<declaration-specifier>^+
718 <keyword-declarator>$[\mbox{@<identifier>}]$
719 @[<method-body>@]
720\end{grammar}
721Properties:
722\begin{description}
723\item[@|message_class|] A symbol naming the Lisp class to use to represent
724 the message.
725\item[@|combination|] A keyword naming the aggregating method combination to
726 use.
727\item[@|most_specific|] A keyword, either @`first' or @`last', according to
728 whether the most specific applicable method should be invoked first or
729 last.
730\end{description}
731
732Properties for the @|custom| aggregating method combination:
733\begin{description}
734\item[@|retvar|] An identifier for the return value from the effective
735 method. The default is @|sod__ret|. Only permitted if the message return
736 type is not @|void|.
737\item[@|valvar|] An identifier holding each return value from a direct method
738 in the effective method. The default is @|sod__val|. Only permitted if
739 the method return type (see @|methty| below) is not @|void|.
740\item[@|methty|] A C type, which is the return type for direct methods of
741 this message. The default is the return type of the message.
742\item[@|decls|] A code fragment containing declarations to be inserted at the
743 head of the effective method body. The default is to insert nothing.
744\item[@|before|] A code fragment containing initialization to be performed at
745 the beginning of the effective method body. The default is to insert
746 nothing.
747\item[@|empty|] A code fragment executed if there are no primary methods;
748 it should usually store a suitable (identity) value in @<retvar>. The
749 default is not to emit an effective method at all if there are no primary
750 methods.
751\item[@|first|] A code fragment to set the return value after calling the
752 first applicable direct method. The default is to use the @|each|
753 fragment.
754\item[@|each|] A code fragment to set the return value after calling a direct
755 method. If @|first| is also set, then it is used after the first direct
756 method instead of this. The default is to insert nothing, which is
757 probably not what you want.
758\item[@|after|] A code fragment inserted at the end of the effective method
759 body. The default is to insert nothing.
760\item[@|count|] An identifier naming a variable to be declared in the
761 effective method body, of type @|size_t|, holding the number of applicable
762 methods. The default is not to provide such a variable.
763\end{description}
764
765\subsubsection{Method items}
766\begin{grammar}
767<method-item> ::=
768 @<declaration-specifier>^+
769 <keyword-declarator>$[\mbox{@<dotted-name>}]$
770 <method-body>
771
772<method-body> ::= "{" <c-fragment> "}" | "extern" ";"
773\end{grammar}
774Properties:
775\begin{description}
776\item[@|method_class|] A symbol naming the Lisp class to use to represent
777 the direct method.
778\item[@|role|] A keyword naming the direct method's rôle. For the built-in
779 `simple' message classes, the acceptable rôle names are @|before|,
780 @|after|, and @|around|. By default, a primary method is constructed.
781\end{description}
782
783%%%----- That's all, folks --------------------------------------------------
784
785%%% Local variables:
786%%% mode: LaTeX
787%%% TeX-master: "sod.tex"
788%%% TeX-PDF-mode: t
789%%% End: