summaryrefslogtreecommitdiffstats
path: root/Source/cmCommandArgumentParser.y
blob: b1d53f6edec051440aa36c71e67ef004105b8ea3 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
%{
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
/*

This file must be translated to C and modified to build everywhere.

Run bison like this:

  bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y

Modify cmCommandArgumentParser.cxx:
  - remove TABs
  - remove use of the 'register' storage class specifier
  - put header block at top of file

*/

#include "cmStandardIncludes.h"

/* Configure the parser to use a lexer object.  */
#define YYPARSE_PARAM yyscanner
#define YYLEX_PARAM yyscanner
#define YYERROR_VERBOSE 1
#define cmCommandArgument_yyerror(x) \
        cmCommandArgumentError(yyscanner, x)
#define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))

/* Make sure malloc and free are available on QNX.  */
#ifdef __QNX__
# include <malloc.h>
#endif

/* Make sure the parser uses standard memory allocation.  The default
   generated parser malloc/free declarations do not work on all
   platforms.  */
#include <stdlib.h>
#define YYMALLOC malloc
#define YYFREE free

/*-------------------------------------------------------------------------*/
#include "cmCommandArgumentParserHelper.h" /* Interface to parser object.  */
#include "cmCommandArgumentLexer.h"  /* Interface to lexer object.  */
#include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL.  */

/* Forward declare the lexer entry point.  */
YY_DECL;

/* Internal utility functions.  */
static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);

#define YYDEBUG 1
/* Configure the parser to support large input.  */
#define YYMAXDEPTH 100000
#define YYINITDEPTH 10000

/* Disable some warnings in the generated code.  */
#ifdef _MSC_VER
# pragma warning (disable: 4102) /* Unused goto label.  */
# pragma warning (disable: 4065) /* Switch statement contains default but no
                                    case. */
# pragma warning (disable: 4244) /* loss of precision */
# pragma warning (disable: 4702) /* unreachable code */
#endif
%}

/* Generate a reentrant parser object.  */
%pure_parser

/*
%union {
  char* string;
}
*/

/*-------------------------------------------------------------------------*/
/* Tokens */
%token cal_ENVCURLY
%token cal_NCURLY
%token cal_DCURLY
%token cal_DOLLAR "$"
%token cal_LCURLY "{"
%token cal_RCURLY "}"
%token cal_NAME
%token cal_BSLASH "\\"
%token cal_SYMBOL
%token cal_AT     "@"
%token cal_ERROR
%token cal_ATNAME

/*-------------------------------------------------------------------------*/
/* grammar */
%%


Start:
GoalWithOptionalBackSlash
{
  $<str>$ = 0;
  yyGetParser->SetResult($<str>1);
}

GoalWithOptionalBackSlash:
Goal
{
  $<str>$ = $<str>1;
}
|
Goal cal_BSLASH
{
  $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
}

Goal:
{
  $<str>$ = 0;
}
|
String Goal
{
  $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
}

String:
OuterText
{
  $<str>$ = $<str>1;
}
|
Variable
{
  $<str>$ = $<str>1;
}

OuterText:
cal_NAME
{
  $<str>$ = $<str>1;
}
|
cal_AT
{
  $<str>$ = $<str>1;
}
|
cal_DOLLAR
{
  $<str>$ = $<str>1;
}
|
cal_LCURLY
{
  $<str>$ = $<str>1;
}
|
cal_RCURLY
{
  $<str>$ = $<str>1;
}
|
cal_SYMBOL
{
  $<str>$ = $<str>1;
}

Variable:
cal_ENVCURLY EnvVarName cal_RCURLY
{
  $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
}
|
cal_NCURLY MultipleIds cal_RCURLY
{
  $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
}
|
cal_DCURLY MultipleIds cal_RCURLY
{
  $<str>$ = yyGetParser->ExpandVariable($<str>2);
  //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
}
|
cal_ATNAME
{
  $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
}

EnvVarName:
MultipleIds
{
  $<str>$ = $<str>1;
}
|
cal_SYMBOL EnvVarName
{
  $<str>$ = $<str>1;
}

MultipleIds:
{
  $<str>$ = 0;
}
|
ID MultipleIds
{
  $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
}

ID:
cal_NAME
{
  $<str>$ = $<str>1;
}
|
Variable
{
  $<str>$ = $<str>1;
}


%%
/* End of grammar */

/*--------------------------------------------------------------------------*/
void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
{
  yyGetParser->Error(message);
}

andling package (H5E) is described <a href="Errors.html">elsewhere</a>. <h2>Invariant Conditions</h2> <p>To include checks for invariant conditions the library should be configured with <code>--disable-production</code>, the default for versions before 1.2. The library designers have made every attempt to handle error conditions gracefully but an invariant condition assertion may fail in certain cases. The output from a failure usually looks something like this: <p> <center> <table border align=center width="100%"> <tr> <td> <p><code><pre> Assertion failed: H5.c:123: i&lt;NELMTS(H5_debug_g) IOT Trap, core dumped. </code></pre> </td> </tr> </table> </center> <h2>Timings and Statistics</h2> <p>Code to accumulate statistics is included at compile time by using the <code>--enable-debug</code> configure switch. The switch can be followed by an equal sign and a comma-separated list of package names or else a default list is used. <p> <center> <table border align=center width="80%"> <tr> <th>Name</th> <th>Default</th> <th>Description</th> </tr> <tr> <td align=center>a</td> <td align=center>No</td> <td>Attributes</td> </tr> <tr> <td align=center>ac</td> <td align=center>Yes</td> <td>Meta data cache</td> </tr> <tr> <td align=center>b</td> <td align=center>Yes</td> <td>B-Trees</td> </tr> <tr> <td align=center>d</td> <td align=center>Yes</td> <td>Datasets</td> </tr> <tr> <td align=center>e</td> <td align=center>Yes</td> <td>Error handling</td> </tr> <tr> <td align=center>f</td> <td align=center>Yes</td> <td>Files</td> </tr> <tr> <td align=center>g</td> <td align=center>Yes</td> <td>Groups</td> </tr> <tr> <td align=center>hg</td> <td align=center>Yes</td> <td>Global heap</td> </tr> <tr> <td align=center>hl</td> <td align=center>No</td> <td>Local heaps</td> </tr> <tr> <td align=center>i</td> <td align=center>Yes</td> <td>Interface abstraction</td> </tr> <tr> <td align=center>mf</td> <td align=center>No</td> <td>File memory management</td> </tr> <tr> <td align=center>mm</td> <td align=center>Yes</td> <td>Library memory managment</td> </tr> <tr> <td align=center>o</td> <td align=center>No</td> <td>Object headers and messages</td> </tr> <tr> <td align=center>p</td> <td align=center>Yes</td> <td>Property lists</td> </tr> <tr> <td align=center>s</td> <td align=center>Yes</td> <td>Data spaces</td> </tr> <tr> <td align=center>t</td> <td align=center>Yes</td> <td>Data types</td> </tr> <tr> <td align=center>v</td> <td align=center>Yes</td> <td>Vectors</td> </tr> <tr> <td align=center>z</td> <td align=center>Yes</td> <td>Raw data filters</td> </tr> </table> </center> <p>In addition to including the code at compile time the application must enable each package at runtime. This is done by listing the package names in the <code>HDF5_DEBUG</code> environment variable. That variable may also contain file descriptor numbers (the default is `2') which control the output for all following packages up to the next file number. The word <code>all</code> refers to all packages. Any word my be preceded by a minus sign to turn debugging off for the package. <p> <center> <table border align=center width="100%"> <caption align=top><b>Sample debug specifications</b></caption> <tr valign=top> <td><code>all</code></td> <td>This causes debugging output from all packages to be sent to the standard error stream.</td> </tr> <tr valign=top> <td><code>all -t -s</code></td> <td>Debugging output for all packages except data types and data spaces will appear on the standard error stream.</td> </tr> <tr valign=top> <td><code>-all ac 255 t,s</code></td> <td>This disables all debugging even if the default was to debug something, then output from the meta data cache is send to the standard error stream and output from data types and spaces is sent to file descriptor 255 which should be redirected by the shell.</td> </tr> </table> </center> <p>The components of the <code>HDF5_DEBUG</code> value may be separated by any non-lowercase letter. <h2>API Tracing</h2> <p>The HDF5 library can trace API calls by printing the function name, the argument names and their values, and the return value. Some people like to see lots of output during program execution instead of using a good symbolic debugger, and this feature is intended for their consumption. For example, the output from <code>h5ls foo</code> after turning on tracing, includes: <p> <center> <table border align=center width="100%"> <tr> <td> <code><pre> H5Tcopy(type=184549388) = 184549419 (type); H5Tcopy(type=184549392) = 184549424 (type); H5Tlock(type=184549424) = SUCCEED; H5Tcopy(type=184549393) = 184549425 (type); H5Tlock(type=184549425) = SUCCEED; H5Fopen(filename="foo", flags=0, access=H5P_DEFAULT) = FAIL; HDF5-DIAG: Error detected in thread 0. Back trace follows. #000: H5F.c line 1245 in H5Fopen(): unable to open file major(04): File interface minor(10): Unable to open file #001: H5F.c line 846 in H5F_open(): file does not exist major(04): File interface minor(10): Unable to open file </pre></code> </td> </tr> </table> </center> <p>The code that performs the tracing must be included in the library by specifying the <code>--enable-trace</code> configuration switch (the default for versions before 1.2). Then the word <code>trace</code> must appear in the value of the <code>HDF5_DEBUG</code> variable. The output will appear on the last file descriptor before the word <code>trace</code> or two (standard error) by default. <p> <center> <table border align=center width="100%"> <tr> <td>To display the trace on the standard error stream: <code><pre> $ env HDF5_DEBUG=trace a.out </pre></code> </td> </tr> <tr> <td>To send the trace to a file: <code><pre> $ env HDF5_DEBUG="55 trace" a.out 55>trace-output </pre></code> </td> </tr> </table> </center> <h3>Performance</h3> <p>If the library was not configured for tracing then there is no unnecessary overhead since all tracing code is excluded. However, if tracing is enabled but not used there is a small penalty. First, code size is larger because of extra statically-declared character strings used to store argument types and names and extra auto variable pointer in each function. Also, execution is slower because each function sets and tests a local variable and each API function calls the <code>H5_trace()</code> function. <p>If tracing is enabled and turned on then the penalties from the previous paragraph apply plus the time required to format each line of tracing information. There is also an extra call to H5_trace() for each API function to print the return value. <h3>Safety</h3> <p>The tracing mechanism is invoked for each API function before arguments are checked for validity. If bad arguments are passed to an API function it could result in a segmentation fault. However, the tracing output is line-buffered so all previous output will appear. <h3>Completeness</h3> <p>There are two API functions that don't participate in tracing. They are <code>H5Eprint()</code> and <code>H5Eprint_cb()</code> because their participation would mess up output during automatic error reporting. <p>On the other hand, a number of API functions are called during library initialization and they print tracing information. <h3>Implementation</h3> <p>For those interested in the implementation here is a description. Each API function should have a call to one of the <code>H5TRACE()</code> macros immediately after the <code>FUNC_ENTER()</code> macro. The first argument is the return type encoded as a string. The second argument is the types of all the function arguments encoded as a string. The remaining arguments are the function arguments. This macro was designed to be as terse and unobtrousive as possible. <p>In order to keep the <code>H5TRACE()</code> calls synchronized with the source code we've written a perl script which gets called automatically just before Makefile dependencies are calculated for the file. However, this only works when one is using GNU make. To reinstrument the tracing explicitly, invoke the <code>trace</code> program from the hdf5 bin directory with the names of the source files that need to be updated. If any file needs to be modified then a backup is created by appending a tilde to the file name. <p> <center> <table border align=center width="100%"> <caption align=top><b>Explicit Instrumentation</b></caption> <tr> <td> <code><pre> $ ../bin/trace *.c H5E.c: in function `H5Ewalk_cb': H5E.c:336: warning: trace info was not inserted </pre></code> </td> </tr> </table> </center> <p>Note: The warning message is the result of a comment of the form <code>/*NO TRACE*/</code> somewhere in the function body. Tracing information will not be updated or inserted if such a comment exists. <p>Error messages have the same format as a compiler so that they can be parsed from program development environments like Emacs. Any function which generates an error will not be modified. <!-- <hr> <address><a href="mailto:matzke@llnl.gov">Robb Matzke</a></address> --> <!-- Created: Wed Jun 17 12:29:12 EDT 1998 --> <!-- hhmts start --> <!-- Last modified: Thu Aug 20 10:43:42 PDT 1998 --> <!-- hhmts end --> <hr> <address> <a href="mailto:hdfhelp@ncsa.uiuc.edu">HDF Help Desk</a> </address> Last modified: 9 September 1998 </body> </html>