summaryrefslogtreecommitdiff
path: root/support/splint/cweb/common.w
diff options
context:
space:
mode:
Diffstat (limited to 'support/splint/cweb/common.w')
-rw-r--r--support/splint/cweb/common.w38
1 files changed, 28 insertions, 10 deletions
diff --git a/support/splint/cweb/common.w b/support/splint/cweb/common.w
index 0f50fdcabd..5112fb5414 100644
--- a/support/splint/cweb/common.w
+++ b/support/splint/cweb/common.w
@@ -1,4 +1,4 @@
-@q Copyright 2012-2020, Alexander Shibakov@>
+@q Copyright 2012-2024, Alexander Shibakov@>
@q This file is part of SPLinT@>
@q SPLinT is free software: you can redistribute it and/or modify@>
@@ -454,6 +454,19 @@ code easier to look at. Further explanation is given in the grammar
file. If the parser is doing its job, this is the only place where one
would actually see these as functions (or, rather, macros).
+In case one wishes to use the `native' \bison\ way of referencing
+terms (i.e.\ something along the lines of~\.{\\the\char`\$[term]})
+these macros should be used with a trailing underscore (say, \.{TeXa\_})
+to let the postprocessor know that the code inside should be
+postprocessed. The postprocessor will then create three files: one,
+destined for \CWEAVE, will use the same macro withough the underscore
+(i.e.\ \.{TeXa} to continue our example, and have the native \bison\
+terms replaced wih the appropriate \TeX\ commands. Another file is
+intended for \CTANGLE, where the whole macro will be replaced first
+with a special identifier, which in turn, after \CTANGLE\ finishes,
+will be replaced by an appropriately constructed call to \.{TeX\_\_}. The
+third file will contain the substitutions.
+
In compliance with paragraph 6.10.8(2)\footnote{[$\ldots$] {\it Any
other predefined macro names shall begin with a leading underscore
followed by an uppercase letter or a second underscore.}} of the \ISO\
@@ -482,7 +495,7 @@ macros which produces undesirable typesetting artefacts.}.
@q \CWEB\ is not aware of variadic macros, so this has to be done the old way@>
@<\Cee\ preamble@>=
-#define TeX__( string, ... ) @[fprintf( tables_out, " " string "%s\n", __VA_ARGS__, "%" )@]
+#define TeX__( string, ... ) @[fprintf( tables_out, " " string "%%\n", __VA_ARGS__ )@]
@ If a full parser is not needed, the lexing mechanism is not required. To satisfy the compiler
and the linker, the lexer and other functions still have to be declared and defined, since these functions
@@ -524,27 +537,32 @@ values. When the names are concatenated with other tokens, however,
the \Cee\ preprocessor postpones the macro expansion until the
concatenation is complete (see clauses 6.10.3.1, 6.10.3.2, and
6.10.3.3 of the \ISO\ \Cee\ Standard, \cite[ISO/C11]). Unless the result of the
-concatenation is still expandable, the expansion will halt.
+concatenation is still expandable, the expansion will halt\footnote{Another trick
+to halt expansion is to use {\it function macros} which will expand only when
+they are followed by parentheses. Since we do not have control over how
+constants are defined by \bison, we cannot take advantage of this feature of the
+\Cee\ preprocessor.}.
@<Global variables and types@>=
struct const_d {
char *format;
char *name;
+ int value;
};
@ @<Local variable and type declarations@>=
-#define _register_const_d(c_name) @[struct const_d c_name##_desc;@]
+#define _register_const_d(c_name,...) @[struct const_d c_name##_desc;@]
@<Constant names@>@;
#undef _register_const_d
@ @<Output descriptor fields@>=
-#define _register_const_d(c_name) @[bool output_##c_name:1;@]
+#define _register_const_d(c_name,...) @[bool output_##c_name:1;@]
@<Constant names@>@;
#undef _register_const_d
@ @<Default outputs@>=
-#define _register_const_d(c_name) @[@[@].output_##c_name = 0,@[@]@]
+#define _register_const_d(c_name,...) @[@[@].output_##c_name = 0,@[@]@]
@<Constant names@>@;
#undef _register_const_d
@@ -556,10 +574,10 @@ concatenation is still expandable, the expansion will halt.
{
int any_constants = 0;
-#define _register_const_d(c_name) \
+#define _register_const_d(c_name,...) \
\
if ( output_desc.output_##c_name ) { \
- const_out( tables_out, c_name##_desc, c_name)@; \
+ const_out( tables_out, c_name##_desc)@; \
any_constants = 1; \
}
@@ -575,7 +593,7 @@ concatenation is still expandable, the expansion will halt.
@<Constant names@>=
@ A macro to help with constant output.
-@d const_out(stream, c_desc, c_name) fprintf(stream, c_desc.format, c_desc.name, c_name);
+@d const_out(stream, c_desc) fprintf(stream, c_desc.format, c_desc.name, c_desc.value);
@ Action switch output routines modify the automata tables and
therefore have to be output last. Since action output is highly
@@ -728,7 +746,7 @@ specific cases are added to in the course of adding new features.
FOREVER {
- c = getopt_long (argc, argv, ( char [] ){':'@t, @>@<Short option list@>}, long_options, &option_index);
+ c = getopt_long (argc, argv, ( char [] )@[{':'@t, @>@<Short option list@>}@], long_options, &option_index);
if (c == -1) break;